tools/power/cpupower/lib/cpufreq.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/lib/cpufreq.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/lib/cpufreq.c- Extension
.c- Size
- 17270 bytes
- Lines
- 804
- 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.herrno.hstdlib.hstring.hsys/types.hsys/stat.hfcntl.hunistd.hcpufreq.hcpupower_intern.h
Detected Declarations
enum cpufreq_valueenum cpufreq_stringenum cpufreq_writefunction sysfs_cpufreq_read_filefunction sysfs_cpufreq_write_filefunction cpufreq_get_sysfs_value_from_tablefunction sysfs_cpufreq_get_one_valuefunction sysfs_cpufreq_write_one_valuefunction cpufreq_get_freq_kernelfunction cpufreq_get_freq_hardwarefunction cpufreq_get_transition_latencyfunction cpufreq_put_energy_performance_preferencefunction cpufreq_get_hardware_limitsfunction cpufreq_put_driverfunction cpufreq_put_policyfunction cpufreq_put_available_governorsfunction cpufreq_put_available_frequenciesfunction cpufreq_put_boost_frequenciesfunction cpufreq_put_affected_cpusfunction cpufreq_put_related_cpusfunction verify_govfunction cpufreq_set_policyfunction cpufreq_modify_policy_minfunction cpufreq_modify_policy_maxfunction cpufreq_modify_policy_governorfunction cpufreq_set_frequencyfunction cpufreq_put_statsfunction cpufreq_get_transitions
Annotated Snippet
if (linebuf[i] == ' ' || linebuf[i] == '\n') {
if (i - pos < 2)
continue;
if (current) {
current->next = malloc(sizeof(*current));
if (!current->next)
goto error_out;
current = current->next;
} else {
first = malloc(sizeof(*first));
if (!first)
return NULL;
current = first;
}
current->first = first;
current->next = NULL;
current->governor = malloc(i - pos + 1);
if (!current->governor)
goto error_out;
memcpy(current->governor, linebuf + pos, i - pos);
current->governor[i - pos] = '\0';
pos = i + 1;
}
}
return first;
error_out:
while (first) {
current = first->next;
if (first->governor)
free(first->governor);
free(first);
first = current;
}
return NULL;
}
void cpufreq_put_available_governors(struct cpufreq_available_governors *any)
{
struct cpufreq_available_governors *tmp, *next;
if (!any)
return;
tmp = any->first;
while (tmp) {
next = tmp->next;
if (tmp->governor)
free(tmp->governor);
free(tmp);
tmp = next;
}
}
struct cpufreq_available_frequencies
*cpufreq_get_available_frequencies(unsigned int cpu)
{
struct cpufreq_available_frequencies *first = NULL;
struct cpufreq_available_frequencies *current = NULL;
char one_value[SYSFS_PATH_MAX];
char linebuf[MAX_LINE_LEN];
unsigned int pos, i;
unsigned int len;
len = sysfs_cpufreq_read_file(cpu, "scaling_available_frequencies",
linebuf, sizeof(linebuf));
if (len == 0)
return NULL;
pos = 0;
for (i = 0; i < len; i++) {
if (linebuf[i] == ' ' || linebuf[i] == '\n') {
if (i - pos < 2)
continue;
if (i - pos >= SYSFS_PATH_MAX)
goto error_out;
if (current) {
current->next = malloc(sizeof(*current));
if (!current->next)
goto error_out;
current = current->next;
} else {
first = malloc(sizeof(*first));
if (!first)
return NULL;
current = first;
Annotation
- Immediate include surface: `stdio.h`, `errno.h`, `stdlib.h`, `string.h`, `sys/types.h`, `sys/stat.h`, `fcntl.h`, `unistd.h`.
- Detected declarations: `enum cpufreq_value`, `enum cpufreq_string`, `enum cpufreq_write`, `function sysfs_cpufreq_read_file`, `function sysfs_cpufreq_write_file`, `function cpufreq_get_sysfs_value_from_table`, `function sysfs_cpufreq_get_one_value`, `function sysfs_cpufreq_write_one_value`, `function cpufreq_get_freq_kernel`, `function cpufreq_get_freq_hardware`.
- 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.