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.

Dependency Surface

Detected Declarations

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

Implementation Notes