tools/power/cpupower/utils/cpufreq-info.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/cpufreq-info.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/utils/cpufreq-info.c- Extension
.c- Size
- 15727 bytes
- Lines
- 694
- 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
unistd.hstdio.herrno.hstdlib.hstring.hlimits.hgetopt.hcpufreq.hhelpers/sysfs.hhelpers/helpers.hhelpers/bitmask.h
Detected Declarations
function count_cpusfunction proc_cpufreq_outputfunction print_durationfunction get_boost_mode_x86function get_boost_mode_genericfunction get_boost_modefunction get_freq_kernelfunction get_freq_hardwarefunction get_hardware_limitsfunction get_driverfunction get_policyfunction get_available_governorsfunction get_affected_cpusfunction get_related_cpusfunction get_freq_statsfunction get_eppfunction get_latencyfunction get_perf_capfunction debug_output_onefunction cmd_freq_info
Annotated Snippet
if (cpufreq_get_hardware_limits(cpu, &min, &max)) {
max = 0;
} else {
min_pctg = (policy->min * 100) / max;
max_pctg = (policy->max * 100) / max;
}
printf("CPU%3d %9lu kHz (%3d %%) - %9lu kHz (%3d %%) - %s\n",
cpu , policy->min, max ? min_pctg : 0, policy->max,
max ? max_pctg : 0, policy->governor);
cpufreq_put_policy(policy);
}
}
static int no_rounding;
static void print_duration(unsigned long duration)
{
unsigned long tmp;
if (no_rounding) {
if (duration > 1000000)
printf("%u.%06u ms", ((unsigned int) duration/1000000),
((unsigned int) duration%1000000));
else if (duration > 100000)
printf("%u us", ((unsigned int) duration/1000));
else if (duration > 1000)
printf("%u.%03u us", ((unsigned int) duration/1000),
((unsigned int) duration%1000));
else
printf("%lu ns", duration);
} else {
if (duration > 1000000) {
tmp = duration%10000;
if (tmp >= 5000)
duration += 10000;
printf("%u.%02u ms", ((unsigned int) duration/1000000),
((unsigned int) (duration%1000000)/10000));
} else if (duration > 100000) {
tmp = duration%1000;
if (tmp >= 500)
duration += 1000;
printf("%u us", ((unsigned int) duration / 1000));
} else if (duration > 1000) {
tmp = duration%100;
if (tmp >= 50)
duration += 100;
printf("%u.%01u us", ((unsigned int) duration/1000),
((unsigned int) (duration%1000)/100));
} else
printf("%lu ns", duration);
}
}
static int get_boost_mode_x86(unsigned int cpu)
{
int support, active, b_states = 0, ret, pstate_no, i;
/* ToDo: Make this more global */
unsigned long pstates[MAX_HW_PSTATES] = {0,};
ret = cpufreq_has_x86_boost_support(cpu, &support, &active, &b_states);
if (ret) {
printf(_("Error while evaluating Boost Capabilities"
" on CPU %d -- are you root?\n"), cpu);
return ret;
}
/* P state changes via MSR are identified via cpuid 80000007
on Intel and AMD, but we assume boost capable machines can do that
if (cpuid_eax(0x80000000) >= 0x80000007
&& (cpuid_edx(0x80000007) & (1 << 7)))
*/
printf(_(" boost state support:\n"));
printf(_(" Supported: %s\n"), support ? _("yes") : _("no"));
printf(_(" Active: %s\n"), active ? _("yes") : _("no"));
if (cpupower_cpu_info.vendor == X86_VENDOR_AMD &&
cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATE) {
return 0;
} else if ((cpupower_cpu_info.vendor == X86_VENDOR_AMD &&
cpupower_cpu_info.family >= 0x10) ||
cpupower_cpu_info.vendor == X86_VENDOR_HYGON) {
ret = decode_pstates(cpu, b_states, pstates, &pstate_no);
if (ret)
return ret;
printf(_(" Boost States: %d\n"), b_states);
printf(_(" Total States: %d\n"), pstate_no);
for (i = 0; i < pstate_no; i++) {
if (!pstates[i])
Annotation
- Immediate include surface: `unistd.h`, `stdio.h`, `errno.h`, `stdlib.h`, `string.h`, `limits.h`, `getopt.h`, `cpufreq.h`.
- Detected declarations: `function count_cpus`, `function proc_cpufreq_output`, `function print_duration`, `function get_boost_mode_x86`, `function get_boost_mode_generic`, `function get_boost_mode`, `function get_freq_kernel`, `function get_freq_hardware`, `function get_hardware_limits`, `function get_driver`.
- 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.