cpupowerutils: Add basic functions to detect AMD CPB information
Subsystems (2)
PATCH 1/1 cpupowerutils: Add basic functions to detect AMD CPB information
To gather boost state information on AMD we need to access CPU northbridge PCI functions.
Thus this change introduces a dependency on libpci (part of pciutils and usually installed on Linux systems).
Detect whether CPB is enabled/disabled and number of boosted states.
--- Makefile | 4 +- lib/amdpci.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/amdpci.h | 1 + lib/cpufreq.c | 8 +++--- lib/cpufreq.h | 2 +- lib/msr.c | 11 -------- lib/msr.h | 2 - utils/cpufreq-info.c | 5 ++- 8 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 lib/amdpci.c create mode 100644 lib/amdpci.h
I am about to add also the frequency information for boosted Pstates. But first I wanted to know whether its acceptable to add a dependency to libpci for PCI config space accesses. The capability to access PCI config space is useful also for other interesting stuff in the future.
The patch is against cpupowerutils branch.
Output looks like:
# ./utils/cpufreq-info -bAnalyzing Boost Capabilities on CPU 0: Supported: yes Active: yes Boost States: 1
Comments welcome.
Andreas
Makefile +2 -2
@@ -115,7 +115,7 @@ UTIL_SRC = utils/cpufreq-info.c utils/cpufreq-set.c utils/cpufreq-aperf.c utils UTIL_BINS = utils/cpufreq-info utils/cpufreq-set utils/cpufreq-aperf utils/cpuidle-info LIB_HEADERS = lib/cpufreq.h lib/cpuidle.h lib/sysfs.h lib/msr.h lib/cpuid.h LIB_SRC = lib/cpufreq.c lib/cpuidle.c lib/sysfs.c lib/msr.c -LIB_OBJS = lib/cpufreq.o lib/cpuidle.o lib/sysfs.o lib/msr.o +LIB_OBJS = lib/cpufreq.o lib/cpuidle.o lib/sysfs.o lib/msr.o lib/amdpci.o CFLAGS += -pipe
@@ -163,7 +163,7 @@ lib/%.o: $(LIB_SRC) $(LIB_HEADERS) build/ccdv $(QUIET) $(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c lib/$*.c libcpupower.so.$(LIB_MAJ): $(LIB_OBJS) - $(CC) -shared $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ + $(CC) -shared $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ -l pci \ -Wl,-soname,libcpupower.so.$(LIB_MIN) $(LIB_OBJS) @ln -sf $@ libcpupower.so @ln -sf $@ libcpupower.so.$(LIB_MIN)
lib/amdpci.c new file +68 -0
68 lines not on this page · raw message
lib/amdpci.h new file +1 -0
@@ -0,0 +1 @@ +extern int amd_pci_get_num_boost_states (int *active,int *states);
lib/cpufreq.c +4 -4
@@ -14,6 +14,7 @@#include "sysfs.h" #include "cpuid.h" #include "msr.h" +#include "amdpci.h" int cpufreq_cpu_exists (unsigned int cpu) {
@@ -191,12 +192,12 @@ unsigned long cpufreq_get_transitions(unsigned int cpu) {return (ret); } -int cpufreq_has_boost_support (unsigned int cpu,int *support,int *active) +int cpufreq_has_boost_support (unsigned int cpu,int *support,int *active,int * states) {struct cpupower_cpu_info cpu_info;int ret; - *support = *active =0 ; + *support = *active = *states =0 ; ret =get_cpu_info (0 , &cpu_info);if (ret)
@@ -218,10 +219,9 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active) *support =1 ; else return 0; - ret =msr_amd_boost_is_active (cpu); +amd_pci_get_num_boost_states (active, states);if (ret <=0 )return ret; - *active = ret; }return 0 ; }
lib/cpufreq.h +1 -1
@@ -213,7 +213,7 @@ extern int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequenc* Check whether Intel's "Turbo Boost Technology" or AMD's * "Dynamic Speed Boost Technology" is supported and if, whether it's activated */ -extern int cpufreq_has_boost_support (unsigned int cpu,int *support,int *active); +extern int cpufreq_has_boost_support (unsigned int cpu,int *support,int *active,int *states);#ifdef __cplusplus
lib/msr.c +0 -11
@@ -127,17 +127,6 @@ int msr_amd_get_fidvid(unsigned int cpu, uint32_t *fid, uint32_t *vid)return 0 ; } -int msr_amd_boost_is_active (unsigned int cpu) -{ -uint64_t k7_hwcr; -int ret; - - ret =read_msr (cpu,MSR_K7_HWCR , &k7_hwcr); -if (ret) -return ret; -return !((k7_hwcr >>25 ) &0x1 ); -} -/* Intel X86 MSRs **********************************/ int msr_intel_get_perf_status (unsigned int cpu,uint64_t perf_status) {
lib/msr.h +0 -2
@@ -6,5 +6,3 @@ extern int msr_intel_get_perf_status(unsigned int cpu, uint64_t perf_status);extern int msr_intel_has_boost_support (unsigned int cpu);extern int msr_intel_boost_is_active (unsigned int cpu); - -extern int msr_amd_boost_is_active (unsigned int cpu);
utils/cpufreq-info.c +3 -2
@@ -290,9 +290,9 @@ static void debug_output(unsigned int cpu, unsigned int all) {/* --boost / -b */ static int get_boost_mode (unsigned int cpu) { -int support, active, ret; +int support, active, states, ret; - ret =cpufreq_has_boost_support (cpu, &support, &active); + ret =cpufreq_has_boost_support (cpu, &support, &active, &states);if (ret) {printf (gettext ("Error while evaluating Boost Capabilities" " on CPU %d -- are you root?\n" ), cpu);
@@ -302,6 +302,7 @@ static int get_boost_mode(unsigned int cpu) {printf (gettext ("Analyzing Boost Capabilities on CPU %d:\n" ), cpu);printf ("Supported: %s\n" , support ?"yes" :"no" );printf ("Active: %s\n" , active ?"yes" :"no" ); +printf ("Boost States: %d\n" , states);return 0 ; }
Signature · 1 line
1.7.3.1
Hey,
Quoted 5 lines · Andreas Herrmann
To gather boost state information on AMD we need to access CPU northbridge PCI functions.
Thus this change introduces a dependency on libpci (part of pciutils and usually installed on Linux systems).
It seems acceptable to me, as long as we don't need to depend on PCI on non-x86 systems. But it seems to me this got broken already when we added the MSR read functions?
Quoted 3 lines
Output looks like:
# ./utils/cpufreq-info -bAnalyzing Boost Capabilities on CPU 0:
Missing line break?
Quoted 1 line
+static struct
pci_access*pacc;
Do we need to worry about concurrent access?
lib/amdpci.h line 1
Quoted 3 lines
+++
b/lib/amdpci.hlib/amdpci.h new file +1
-0@@ -0,0 +1 @@ +extern int amd_pci_get_num_boost_states (int *active,int *states);
Do we need a whole file for this one line?
Otherwise, looks really fine and acceptable to me.
Best,
Dominik