tools/power/cpupower/lib/cpupower.c
Source file repositories/reference/linux-study-clean/tools/power/cpupower/lib/cpupower.c
File Facts
- System
- Linux kernel
- Corpus path
tools/power/cpupower/lib/cpupower.c- Extension
.c- Size
- 5782 bytes
- Lines
- 252
- 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
sys/types.hsys/stat.hfcntl.hunistd.hstdio.herrno.hstdlib.hstring.hcpupower.hcpupower_intern.h
Detected Declarations
function is_valid_pathfunction cpupower_read_sysfsfunction cpupower_write_sysfsfunction cpupower_is_cpu_onlinefunction sysfs_topology_read_filefunction __comparefunction __compare_core_cpu_listfunction get_cpu_topologyfunction cpu_topology_release
Annotated Snippet
if (cpu_top->core_info[cpu].core == -1) {
strncpy(cpu_top->core_info[cpu].core_cpu_list, "-1", CPULIST_BUFFER);
continue;
}
snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/topology/%s",
cpu, "core_cpus_list");
if (cpupower_read_sysfs(
path,
cpu_top->core_info[cpu].core_cpu_list,
CPULIST_BUFFER) < 1) {
printf("Warning CPU%u has a 0 size core_cpus_list string", cpu);
}
}
/* Count the number of distinct cpu lists to get the physical core
* count.
*/
qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info),
__compare_core_cpu_list);
last_cpu_list = cpu_top->core_info[0].core_cpu_list;
cpu_top->cores = 1;
for (cpu = 1; cpu < cpus; cpu++) {
if (strcmp(cpu_top->core_info[cpu].core_cpu_list, last_cpu_list) != 0 &&
cpu_top->core_info[cpu].pkg != -1) {
last_cpu_list = cpu_top->core_info[cpu].core_cpu_list;
cpu_top->cores++;
}
}
qsort(cpu_top->core_info, cpus, sizeof(struct cpuid_core_info),
__compare);
/* Count the number of distinct pkgs values. This works
because the primary sort of the core_info struct was just
done by pkg value. */
last_pkg = cpu_top->core_info[0].pkg;
for(cpu = 1; cpu < cpus; cpu++) {
if (cpu_top->core_info[cpu].pkg != last_pkg &&
cpu_top->core_info[cpu].pkg != -1) {
last_pkg = cpu_top->core_info[cpu].pkg;
cpu_top->pkgs++;
}
}
if (!(cpu_top->core_info[0].pkg == -1))
cpu_top->pkgs++;
return cpus;
}
void cpu_topology_release(struct cpupower_topology cpu_top)
{
free(cpu_top.core_info);
}
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `fcntl.h`, `unistd.h`, `stdio.h`, `errno.h`, `stdlib.h`, `string.h`.
- Detected declarations: `function is_valid_path`, `function cpupower_read_sysfs`, `function cpupower_write_sysfs`, `function cpupower_is_cpu_online`, `function sysfs_topology_read_file`, `function __compare`, `function __compare_core_cpu_list`, `function get_cpu_topology`, `function cpu_topology_release`.
- 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.