Commit 4a49db7b authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

Merge tag 'linux-cpupower-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux

Pull cpupower utility updates for 5.18-rc1 from Shuah Khan:

"This cpupower update for Linux 5.18-rc1 adds AMD P-State Support to
 cpupower tool. AMD P-State kernel support went into 5.17-rc1."

* tag 'linux-cpupower-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux:
  cpupower: Add "perf" option to print AMD P-State information
  cpupower: Add function to print AMD P-State performance capabilities
  cpupower: Move print_speed function into misc helper
  cpupower: Enable boost state support for AMD P-State module
  cpupower: Add AMD P-State sysfs definition and access helper
  cpupower: Introduce ACPI CPPC library
  cpupower: Add the function to get the sysfs value from specific table
  cpupower: Initial AMD P-State capability
  cpupower: Add the function to check AMD P-State enabled
  cpupower: Add AMD P-State capability flag
parents caa28245 8382dce5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -143,9 +143,9 @@ UTIL_HEADERS = utils/helpers/helpers.h utils/idle_monitor/cpupower-monitor.h \
	utils/helpers/bitmask.h \
	utils/idle_monitor/idle_monitors.h utils/idle_monitor/idle_monitors.def

LIB_HEADERS = 	lib/cpufreq.h lib/cpupower.h lib/cpuidle.h
LIB_SRC = 	lib/cpufreq.c lib/cpupower.c lib/cpuidle.c
LIB_OBJS = 	lib/cpufreq.o lib/cpupower.o lib/cpuidle.o
LIB_HEADERS = 	lib/cpufreq.h lib/cpupower.h lib/cpuidle.h lib/acpi_cppc.h
LIB_SRC = 	lib/cpufreq.c lib/cpupower.c lib/cpuidle.c lib/acpi_cppc.c
LIB_OBJS = 	lib/cpufreq.o lib/cpupower.o lib/cpuidle.o lib/acpi_cppc.o
LIB_OBJS :=	$(addprefix $(OUTPUT),$(LIB_OBJS))

override CFLAGS +=	-pipe
+59 −0
Original line number Diff line number Diff line
// 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;
}
+21 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */

#ifndef __ACPI_CPPC_H__
#define __ACPI_CPPC_H__

enum acpi_cppc_value {
	HIGHEST_PERF,
	LOWEST_PERF,
	NOMINAL_PERF,
	LOWEST_NONLINEAR_PERF,
	LOWEST_FREQ,
	NOMINAL_FREQ,
	REFERENCE_PERF,
	WRAPAROUND_TIME,
	MAX_CPPC_VALUE_FILES
};

unsigned long acpi_cppc_get_data(unsigned int cpu,
				 enum acpi_cppc_value which);

#endif /* _ACPI_CPPC_H */
+16 −7
Original line number Diff line number Diff line
@@ -83,20 +83,21 @@ static const char *cpufreq_value_files[MAX_CPUFREQ_VALUE_READ_FILES] = {
	[STATS_NUM_TRANSITIONS] = "stats/total_trans"
};


static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
						 enum cpufreq_value which)
unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,
						 const char **table,
						 unsigned int index,
						 unsigned int size)
{
	unsigned long value;
	unsigned int len;
	char linebuf[MAX_LINE_LEN];
	char *endp;

	if (which >= MAX_CPUFREQ_VALUE_READ_FILES)
	if (!table || index >= size || !table[index])
		return 0;

	len = sysfs_cpufreq_read_file(cpu, cpufreq_value_files[which],
				linebuf, sizeof(linebuf));
	len = sysfs_cpufreq_read_file(cpu, table[index], linebuf,
				      sizeof(linebuf));

	if (len == 0)
		return 0;
@@ -109,6 +110,14 @@ static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
	return value;
}

static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu,
						 enum cpufreq_value which)
{
	return cpufreq_get_sysfs_value_from_table(cpu, cpufreq_value_files,
						  which,
						  MAX_CPUFREQ_VALUE_READ_FILES);
}

/* read access to files which contain one string */

enum cpufreq_string {
+12 −0
Original line number Diff line number Diff line
@@ -203,6 +203,18 @@ int cpufreq_modify_policy_governor(unsigned int cpu, char *governor);
int cpufreq_set_frequency(unsigned int cpu,
				unsigned long target_frequency);

/*
 * get the sysfs value from specific table
 *
 * Read the value with the sysfs file name from specific table. Does
 * only work if the cpufreq driver has the specific sysfs interfaces.
 */

unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu,
						 const char **table,
						 unsigned int index,
						 unsigned int size);

#ifdef __cplusplus
}
#endif
Loading