Support PCU power metrics in turbostat
PATCH 1/1 Support PCU power metrics in turbostat
From: Andi Kleen <[email protected]>
Add support for reading PCU power metrics on Sandy Bridge / Ivy Bridge EP and Haswell Server in turbostat. This is done using the perf ABI, using the perf uncore driver. This requires the kernel to have uncore perf driver support.
The PCU has a large number of events, but only allows to monitor four of them at the same time. We always need the PCU cycles event, so this leaves three events per event group.
The user has to specify the event group using a new -x option. All more sensible option characters were already taken. When -x is not specified no behavior changes.
perf in principle supports time based multi-plexing, which allows monitoring multiple group at the same time, but support for that is not implemented in the tool so far. It would also require enabling an potentially idle-disturbing timer. So right now we don't multiplex.
I modeled the event groups after the proven ones in pcm-power in the PCM (Intel Performance Counter Monitor) tool. That is where the numbers come from.
However unlike PCM this uses the perf interfaces, instead of directly accessing the hardware.
The current groups are:
0: This should 3 monitor frequency bands. It could give more accurate information than the average frequency from turbostat, as it can keep multiple buckets.
However this currently runs into a problem with the uncore driver that only makes us able to monitor a single band. Disabled until this is fixed.
1: C-state residencies. Already covered in turbostat and not implemented.
2/3/4: Various reasons for frequency limits.
5: Number of frequency transitions and time of PCU transition duration. (note this is not the full time of the transition)
Other power metrics could be added later using the same frame work. For example it would be possible to implement the memory power saving metrics from pcm-power, which would output power state statistics per channel. This would definitely need a new output format, as it won't fit into any terminal with the current one.
Custom user metrics would be also possible.
The event resolution code is derived from the jevents library (parts of pmu-tools, http://github.com/andikleen/pmu-tools)
and is BSD licensed.
--- tools/power/x86/turbostat/Makefile | 11 +- tools/power/x86/turbostat/resolve.c | 233 ++++++++++++++++++++++++++++++++++ tools/power/x86/turbostat/resolve.h | 2 + tools/power/x86/turbostat/turbostat.8 | 5 + tools/power/x86/turbostat/turbostat.c | 206 +++++++++++++++++++++++++++++- 5 files changed, 449 insertions(+), 8 deletions(-) create mode 100644 tools/power/x86/turbostat/resolve.c create mode 100644 tools/power/x86/turbostat/resolve.h
tools/power/x86/turbostat/Makefile +7 -4
@@ -3,17 +3,20 @@ BUILD_OUTPUT := $(PWD) PREFIX := /usr DESTDIR := -turbostat : turbostat.c +turbostat : turbostat.o resolve.o + @mkdir -p $(BUILD_OUTPUT) + $(CC) $(LDFLAGS) $^ -o $(BUILD_OUTPUT)/$@ + CFLAGS += -Wall CFLAGS += -DMSRHEADER='"../../../../arch/x86/include/uapi/asm/msr-index.h"' -%: %.c +%.o: %.c @mkdir -p $(BUILD_OUTPUT) - $(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ + $(CC) $(CFLAGS) $< -c -o $(BUILD_OUTPUT)/$@ .PHONY : clean clean : - @rm -f $(BUILD_OUTPUT)/turbostat + @rm -f $(BUILD_OUTPUT)/turbostat turbostat.o resolve.o install : turbostat install -d $(DESTDIR)$(PREFIX)/bin
tools/power/x86/turbostat/resolve.c new file +233 -0
233 lines not on this page · raw message
tools/power/x86/turbostat/resolve.h new file +2 -0
@@ -0,0 +1,2 @@ +struct perf_event_attr ; +int tjevent_name_to_attr (char *str,struct perf_event_attr *attr);
tools/power/x86/turbostat/turbostat.8 +5 -0
@@ -42,6 +42,11 @@ The \fB-M MSR#\fP option includes the the specified 64-bit MSR value. The \fB-i interval_sec\fP option prints statistics every \fiinterval_sec\fP seconds. The default is 5 seconds. .PP +The \fB-x GROUP\fP option enables PCU event group monitoring. Valid groups are +2 for thermal frequency limits, 3 and 4 for other frequency limits, +5 for frequency transitions statistics. Requires the kernel +to support the perf uncore driver for this platform. +.PP The \fBcommand\fP parameter forks \fBcommand\fP and upon its exit, displays the statistics gathered since it was forked. .PP
tools/power/x86/turbostat/turbostat.c +202 -4
320 lines not on this page · raw message
Signature · 1 line
1.9.3