tools/power/cpupower/bench/benchmark.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/bench/benchmark.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/bench/benchmark.c- Extension
.c- Size
- 4924 bytes
- Lines
- 182
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hunistd.hmath.hconfig.hsystem.hbenchmark.h
Detected Declarations
function Copyrightfunction calculate_timespacefunction start_benchmark
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/* cpufreq-bench CPUFreq microbenchmark
*
* Copyright (C) 2008 Christian Kornacker <ckornacker@suse.de>
*/
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include "config.h"
#include "system.h"
#include "benchmark.h"
/* Print out progress if we log into a file */
#define show_progress(total_time, progress_time) \
if (config->output != stdout) { \
fprintf(stdout, "Progress: %02lu %%\r", \
(progress_time * 100) / total_time); \
fflush(stdout); \
}
/**
* compute how many rounds of calculation we should do
* to get the given load time
*
* @param load aimed load time in µs
*
* @retval rounds of calculation
**/
unsigned int calculate_timespace(long load, struct config *config)
{
int i;
long long now, then;
unsigned int estimated = GAUGECOUNT;
unsigned int rounds = 0;
unsigned int timed = 0;
if (config->verbose)
printf("calibrating load of %lius, please wait...\n", load);
/* get the initial calculation time for a specific number of rounds */
now = get_time();
ROUNDS(estimated);
then = get_time();
timed = (unsigned int)(then - now);
/* approximation of the wanted load time by comparing with the
* initial calculation time */
for (i = 0; i < 4; i++) {
rounds = (unsigned int)(load * estimated / timed);
dprintf("calibrating with %u rounds\n", rounds);
now = get_time();
ROUNDS(rounds);
then = get_time();
timed = (unsigned int)(then - now);
estimated = rounds;
}
if (config->verbose)
printf("calibration done\n");
return estimated;
}
/**
* benchmark
* generates a specific sleep an load time with the performance
* governor and compares the used time for same calculations done
* with the configured powersave governor
*
* @param config config values for the benchmark
*
**/
void start_benchmark(struct config *config)
{
unsigned int _round, cycle;
long long now, then;
long sleep_time = 0, load_time = 0;
long performance_time = 0, powersave_time = 0;
unsigned int calculations;
unsigned long total_time = 0, progress_time = 0;
sleep_time = config->sleep;
load_time = config->load;
/* For the progress bar */
Annotation
- Immediate include surface: `stdio.h`, `unistd.h`, `math.h`, `config.h`, `system.h`, `benchmark.h`.
- Detected declarations: `function Copyright`, `function calculate_timespace`, `function start_benchmark`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.