tools/power/cpupower/utils/cpupower-set.c

Source file repositories/reference/linux-study-clean/tools/power/cpupower/utils/cpupower-set.c

File Facts

System
Linux kernel
Corpus path
tools/power/cpupower/utils/cpupower-set.c
Extension
.c
Size
3666 bytes
Lines
172
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

switch (ret) {
		case 'b':
			if (params.perf_bias)
				print_wrong_arg_exit();
			perf_bias = atoi(optarg);
			if (perf_bias < 0 || perf_bias > 15) {
				printf(_("--perf-bias param out "
					 "of range [0-%d]\n"), 15);
				print_wrong_arg_exit();
			}
			params.perf_bias = 1;
			break;
		case 'e':
			if (params.epp)
				print_wrong_arg_exit();
			if (sscanf(optarg, "%29s", epp) != 1) {
				print_wrong_arg_exit();
				return -EINVAL;
			}
			params.epp = 1;
			break;
		case 'm':
			if (cpupower_cpu_info.vendor != X86_VENDOR_AMD)
				print_wrong_arg_exit();
			if (params.mode)
				print_wrong_arg_exit();
			if (sscanf(optarg, "%19s", mode) != 1) {
				print_wrong_arg_exit();
				return -EINVAL;
			}
			params.mode = 1;
			break;
		case 't':
			if (params.turbo_boost)
				print_wrong_arg_exit();
			turbo_boost = atoi(optarg);
			if (turbo_boost < 0 || turbo_boost > 1) {
				printf("--turbo-boost param out of range [0-1]\n");
				print_wrong_arg_exit();
			}
			params.turbo_boost = 1;
			break;


		default:
			print_wrong_arg_exit();
		}
	}

	if (!params.params)
		print_wrong_arg_exit();

	if (params.mode) {
		ret = cpupower_set_amd_pstate_mode(mode);
		if (ret)
			fprintf(stderr, "Error setting mode\n");
	}

	if (params.turbo_boost) {
		if (cpupower_cpu_info.vendor == X86_VENDOR_INTEL)
			ret = cpupower_set_intel_turbo_boost(turbo_boost);
		else
			ret = cpupower_set_generic_turbo_boost(turbo_boost);

		if (ret)
			fprintf(stderr, "Error setting turbo-boost\n");
	}

	/* Default is: set all CPUs */
	if (bitmask_isallclear(cpus_chosen))
		bitmask_setall(cpus_chosen);

	/* loop over CPUs */
	for (cpu = bitmask_first(cpus_chosen);
	     cpu <= bitmask_last(cpus_chosen); cpu++) {

		if (!bitmask_isbitset(cpus_chosen, cpu))
			continue;

		if (sysfs_is_cpu_online(cpu) != 1){
			fprintf(stderr, _("Cannot set values on CPU %d:"), cpu);
			fprintf(stderr, _(" *is offline\n"));
			continue;
		}

		if (params.perf_bias) {
			ret = cpupower_intel_set_perf_bias(cpu, perf_bias);
			if (ret) {
				fprintf(stderr, _("Error setting perf-bias "
						  "value on CPU %d\n"), cpu);

Annotation

Implementation Notes