File: acpi_cppc.c

package info (click to toggle)
linux 6.19.2-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,759,612 kB
  • sloc: ansic: 27,004,852; asm: 273,402; sh: 151,313; python: 81,277; makefile: 58,544; perl: 34,311; xml: 21,064; cpp: 5,984; yacc: 4,841; lex: 2,901; awk: 1,707; sed: 30; ruby: 25
file content (59 lines) | stat: -rw-r--r-- 1,405 bytes parent folder | download | duplicates (29)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: GPL-2.0-only

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include "cpupower_intern.h"
#include "acpi_cppc.h"

/* ACPI CPPC sysfs access ***********************************************/

static int acpi_cppc_read_file(unsigned int cpu, const char *fname,
			       char *buf, size_t buflen)
{
	char path[SYSFS_PATH_MAX];

	snprintf(path, sizeof(path), PATH_TO_CPU "cpu%u/acpi_cppc/%s",
		 cpu, fname);
	return cpupower_read_sysfs(path, buf, buflen);
}

static const char * const acpi_cppc_value_files[] = {
	[HIGHEST_PERF] = "highest_perf",
	[LOWEST_PERF] = "lowest_perf",
	[NOMINAL_PERF] = "nominal_perf",
	[LOWEST_NONLINEAR_PERF] = "lowest_nonlinear_perf",
	[LOWEST_FREQ] = "lowest_freq",
	[NOMINAL_FREQ] = "nominal_freq",
	[REFERENCE_PERF] = "reference_perf",
	[WRAPAROUND_TIME] = "wraparound_time"
};

unsigned long acpi_cppc_get_data(unsigned int cpu, enum acpi_cppc_value which)
{
	unsigned long long value;
	unsigned int len;
	char linebuf[MAX_LINE_LEN];
	char *endp;

	if (which >= MAX_CPPC_VALUE_FILES)
		return 0;

	len = acpi_cppc_read_file(cpu, acpi_cppc_value_files[which],
				  linebuf, sizeof(linebuf));
	if (len == 0)
		return 0;

	value = strtoull(linebuf, &endp, 0);

	if (endp == linebuf || errno == ERANGE)
		return 0;

	return value;
}