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.

Dependency Surface

Detected Declarations

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

Implementation Notes