tools/power/cpupower/utils/helpers/misc.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/helpers/misc.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/utils/helpers/misc.c- Extension
.c- Size
- 7204 bytes
- Lines
- 331
- 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.
Dependency Surface
stdio.herrno.hstdlib.hstring.hhelpers/helpers.hhelpers/sysfs.hcpufreq.hcpupower_intern.h
Detected Declarations
function cpufreq_has_x86_boost_supportfunction cpupower_set_intel_turbo_boostfunction cpupower_intel_get_perf_biasfunction cpupower_intel_set_perf_biasfunction cpupower_set_eppfunction cpupower_set_amd_pstate_modefunction cpupower_amd_pstate_enabledfunction cpufreq_has_generic_boost_supportfunction get_cpustatefunction print_online_cpusfunction print_offline_cpusfunction print_speedfunction cpupower_set_generic_turbo_boost
Annotated Snippet
if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_CPB_MSR) {
if (!read_msr(cpu, MSR_AMD_HWCR, &val)) {
if (!(val & CPUPOWER_AMD_CPBDIS))
*active = 1;
}
} else {
ret = amd_pci_get_num_boost_states(active, states);
if (ret)
return ret;
}
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATE) {
amd_pstate_boost_init(cpu, support, active);
} else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA) {
*support = *active = 1;
snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");
if (!is_valid_path(path))
return 0;
if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)
return -1;
val = strtol(linebuf, &endp, 0);
if (endp == linebuf || errno == ERANGE)
return -1;
*active = !val;
}
return 0;
}
int cpupower_set_intel_turbo_boost(int turbo_boost)
{
char path[SYSFS_PATH_MAX];
char linebuf[2] = {};
snprintf(path, sizeof(path), PATH_TO_CPU "intel_pstate/no_turbo");
/* Fallback to generic solution when intel_pstate driver not running */
if (!is_valid_path(path))
return cpupower_set_generic_turbo_boost(turbo_boost);
snprintf(linebuf, sizeof(linebuf), "%d", !turbo_boost);
if (cpupower_write_sysfs(path, linebuf, 2) <= 0)
return -1;
return 0;
}
int cpupower_intel_get_perf_bias(unsigned int cpu)
{
char linebuf[MAX_LINE_LEN];
char path[SYSFS_PATH_MAX];
unsigned long val;
char *endp;
if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS))
return -1;
snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/power/energy_perf_bias", cpu);
if (cpupower_read_sysfs(path, linebuf, MAX_LINE_LEN) == 0)
return -1;
val = strtol(linebuf, &endp, 0);
if (endp == linebuf || errno == ERANGE)
return -1;
return val;
}
int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val)
{
char path[SYSFS_PATH_MAX];
char linebuf[3] = {};
if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_PERF_BIAS))
return -1;
snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/power/energy_perf_bias", cpu);
snprintf(linebuf, sizeof(linebuf), "%d", val);
if (cpupower_write_sysfs(path, linebuf, 3) <= 0)
return -1;
return 0;
}
Annotation
- Immediate include surface: `stdio.h`, `errno.h`, `stdlib.h`, `string.h`, `helpers/helpers.h`, `helpers/sysfs.h`, `cpufreq.h`, `cpupower_intern.h`.
- Detected declarations: `function cpufreq_has_x86_boost_support`, `function cpupower_set_intel_turbo_boost`, `function cpupower_intel_get_perf_bias`, `function cpupower_intel_set_perf_bias`, `function cpupower_set_epp`, `function cpupower_set_amd_pstate_mode`, `function cpupower_amd_pstate_enabled`, `function cpufreq_has_generic_boost_support`, `function get_cpustate`, `function print_online_cpus`.
- 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.