perf: add new uncore command
cover perf: add new uncore command
This patchset adds a new command to perf: perf uncore. It is used to measure processor socket-level metrics on a system-wide basis and at all priv levels.
The command comes with a set of predefined key metrics which are useful to measure multi-socket system imbalance and various bandwidths.
The following metrics are currently defined:
- memory bandwidth (Nehalem, Westmere, SandyBridge-EP)
- PCIe bandwidth (SandyBridge-EP)
- QPI bandwidth (SandyBridge-EP)
- C-state residency (SandyBridge-EP)
Others can be added in the future.
The command provides options to modify the unit of the metrics (default: MB/s for bandwidth).
Example on Nehalem:
# perf uncore
#------------------------------
# Socket0 |
#------------------------------
# RAM Bandwidth |
# Wr Rd|
# MB/s MB/s|
#------------------------------
4954.99 14897.29
4953.97 14894.56
4947.52 14874.97To make plotting easier, the output can be augmented with a timestamp:
# perf uncore -T
#----------------------------------------
# | Socket0 |
# |------------------------------
# Time | RAM Bandwidth |
# in | Wr Rd|
# secs | MB/s MB/s|
#----------------------------------------
1 4952.50 14890.49
2 4955.55 14900.19
3 4949.13 14879.60
4 4954.66 14896.26The code is split between generic layer (builtin-uncore.c) and an arch specific layer (arch/*/util/uncore.c). All events are hardcoded because they don't change for a given processor and metric computation requires combining multiple events.
---
Stephane Eranian (2):
perf tools: add cpu_map__get_socket()
perf: add new perf uncore command
tools/perf/Documentation/perf-uncore.txt | 88 ++++ tools/perf/Makefile | 1 + tools/perf/arch/x86/Makefile | 1 + tools/perf/arch/x86/util/uncore.c | 539 ++++++++++++++++++++++ tools/perf/builtin-uncore.c | 739 ++++++++++++++++++++++++++++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + tools/perf/util/cpumap.c | 26 ++ tools/perf/util/cpumap.h | 1 + tools/perf/util/uncore.h | 56 +++ 11 files changed, 1454 insertions(+) create mode 100644 tools/perf/Documentation/perf-uncore.txt create mode 100644 tools/perf/arch/x86/util/uncore.c create mode 100644 tools/perf/builtin-uncore.c create mode 100644 tools/perf/util/uncore.h
Signature · 1 line
1.7.10.4
PATCH 1/2 perf tools: add cpu_map__get_socket()
To get the socket number associated with a CPU.
Useful for uncore output.
--- tools/perf/util/cpumap.c | 26 ++++++++++++++++++++++++++ tools/perf/util/cpumap.h | 1 + 2 files changed, 27 insertions(+)
tools/perf/util/cpumap.c +26 -0
@@ -1,4 +1,5 @@#include "util.h" +#include "sysfs.h" #include "../perf.h" #include "cpumap.h" #include <assert.h>
@@ -201,3 +202,28 @@ void cpu_map__delete(struct cpu_map *map) {free (map); } + +int cpu_map__get_socket (struct cpu_map *map,int idx) +{ +FILE *fp; +char path[PATH_MAX ]; +const char *sysfs; +int cpu, ret; + +if (idx > map->nr) +return -1 ; + + cpu = map->map[idx]; + + sysfs =sysfs_find_mountpoint (); +if (!sysfs) +return -1 ; + +sprintf (path,"%s/devices/system/cpu/cpu%d/topology/physical_package_id" , sysfs, cpu); + fp =fopen (path,"r" ); +if (!fp) +return -1 ; + ret =fscanf (fp,"%d" , &cpu); +fclose (fp); +return ret ==1 ? cpu :-1 ; +}
tools/perf/util/cpumap.h +1 -0
@@ -14,6 +14,7 @@ struct cpu_map *cpu_map__dummy_new(void);void cpu_map__delete (struct cpu_map *map);struct cpu_map *cpu_map__read (FILE *file);size_t cpu_map__fprintf (struct cpu_map *map,FILE *fp); +int cpu_map__get_socket (struct cpu_map *map,int idx);static inline int cpu_map__nr (const struct cpu_map *map) {
Signature · 1 line
1.7.10.4
PATCH 2/2 perf: add new perf uncore command
In reply to Stephane EranianThe perf uncore command measures key metrics at the processor socket level for select Intel processors. It operates like perf stat, except it prints metrics directly instead of raw event values. The metrics are printed at regular time intervals.
The defined metrics are:
- memory bandwidth (Nehalem, Westmere, SandyBridge-EP)
- PCIe bandwidth (SandyBridge-EP)
- QPI bandwidth (SandyBridge-EP)
- C-state residency (SandyBridge-EP)
Running perf uncore requires root pivilege as all the measurements are done in system-wide mode. Note that metrics are collected at the socket-level and at all privilege level.
The command provides options to modify the unit of the metrics (default: MB/s for bandwidth).
Example on Nehalem:
# perf uncore
#------------------------------
# Socket0 |
#------------------------------
# RAM Bandwidth |
# Wr Rd|
# MB/s MB/s|
#------------------------------
4954.99 14897.29
4953.97 14894.56
4947.52 14874.97To make plotting easier, the output can be augmented with a timestamp:
# perf uncore -T
#----------------------------------------
# | Socket0 |
# |------------------------------
# Time | RAM Bandwidth |
# in | Wr Rd|
# secs | MB/s MB/s|
#----------------------------------------
1 4952.50 14890.49
2 4955.55 14900.19
3 4949.13 14879.60
4 4954.66 14896.26The code is split between generic layer (builtin-uncore.c) and an arch specific layer (arch/*/util/uncore.c). All events are hardcoded because they don't change for a given processor and metric computation requires combining multiple events.
--- tools/perf/Documentation/perf-uncore.txt | 88 ++++ tools/perf/Makefile | 1 + tools/perf/arch/x86/Makefile | 1 + tools/perf/arch/x86/util/uncore.c | 539 ++++++++++++++++++++++ tools/perf/builtin-uncore.c | 739 ++++++++++++++++++++++++++++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + tools/perf/util/uncore.h | 56 +++ 9 files changed, 1427 insertions(+) create mode 100644 tools/perf/Documentation/perf-uncore.txt create mode 100644 tools/perf/arch/x86/util/uncore.c create mode 100644 tools/perf/builtin-uncore.c create mode 100644 tools/perf/util/uncore.h
tools/perf/Documentation/perf-uncore.txt new file +88 -0
@@ -0,0 +1,88 @@ +perf-uncore(1) +=============== + +NAME +---- +perf-uncore - Collect processor socket-level metrics + +SYNOPSIS +-------- +[verse] +'perf uncore' [-M metrics] [-m unit] [-L] <command> + +DESCRIPTION +----------- +This command runs a binary and gathers system-wide socket-level performance counter +statistics. Depending on the perf_event security settings, it may be required to +have super user privliege to run this command as it operates in system-wide monitoring +mode. This command may not work on all processors. + +The list of predefined metrics is dependent on the host processor. Use the -L option +to list the metrics available. By default all the metrics are measured across all the +processor sockets. It is possible to restrict the certain metrics using the -M option. + +The output operates in a way similar to vmstat. One line of output per second. The +interval can be adjusted with the -I option. + +It is possible to add a Time column to make it easier to plot the values later on. +The -T option enables the Time column. + +OPTIONS +------- +<command>...:: + Any command you can specify in a shell. To control the duration of the + measurement without influencing too much, the sleep command can be used. + +-M:: +--metrics metrics[, metrics]:: + Comma separated list of metrics to measure. Metrics' name can be obtained + via the -L option. +-m:: +--mem-unit unit:: + Modify the bandwidth metric unit. The default bandwidth metric is Megabytes + (1000*1000 bytes). Bytes (B) and bits (b) metrics are supported. The available + metrics are: KB, MB, GB, KiB, MiB, GiB, Kb, Mb, Gb, Kib, Mib, Gib. + The metrics are obviously case sensitive. + +-T:: +--time:: + Add a Time column expressed in seconds (default: off). + +-v:: +--verbose:: + be more verbose (show counter open errors, etc) + +-o file:: +--output file:: + Print the output into the designated file. + +--append:: + Append to the output file designated with the -o option. Ignored if -o is not specified. + +--log-fd:: + Log output to fd, instead of stderr. Complementary to --output, and mutually exclusive + with it. --append may be used here. Examples: + 3>results perf stat --log-fd 3 -- $cmd + 3>>results perf stat --log-fd 3 --append -- $cmd + +EXAMPLES +-------- + +[verse] +$ perf uncore -T sleep 5 +#---------------------------------------- +# | Socket0 | +# |------------------------------ +# Time | RAM Bandwidth | +# in | Wr Rd| +# secs | MB/s MB/s| +#---------------------------------------- + 1 1254.23 3781.76 + 2 1265.19 3813.70 + 3 1261.62 3803.81 + 4 1265.28 3814.09 + 5 1253.54 3780.13 + +SEE ALSO +-------- +linkperf:perf-stat[1]
tools/perf/Makefile +1 -0
@@ -520,6 +520,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-lock.o BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o BUILTIN_OBJS += $(OUTPUT)builtin-inject.o BUILTIN_OBJS += $(OUTPUT)tests/builtin-test.o +BUILTIN_OBJS += $(OUTPUT)builtin-uncore.o PERFLIBS = $(LIB_FILE) $(LIBTRACEEVENT)
tools/perf/arch/x86/Makefile +1 -0
@@ -6,3 +6,4 @@ ifndef NO_LIBUNWIND LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind.o endif LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o +LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/uncore.o
tools/perf/arch/x86/util/uncore.c new file +539 -0
539 lines not on this page · raw message
tools/perf/builtin-uncore.c new file +739 -0
739 lines not on this page · raw message
tools/perf/builtin.h +1 -0
@@ -36,6 +36,7 @@ extern int cmd_kvm(int argc, const char **argv, const char *prefix);extern int cmd_test (int argc,const char **argv,const char *prefix);extern int cmd_trace (int argc,const char **argv,const char *prefix);extern int cmd_inject (int argc,const char **argv,const char *prefix); +extern int cmd_uncore (int argc,const char **argv,const char *prefix);extern int find_scripts (char **scripts_array,char **scripts_path_array);#endif
tools/perf/command-list.txt +1 -0
@@ -24,3 +24,4 @@ perf-kmem mainporcelain common perf-lock mainporcelain common perf-kvm mainporcelain common perf-test mainporcelain common +perf-uncore mainporcelain common
tools/perf/perf.c +1 -0
@@ -60,6 +60,7 @@ static struct cmd_struct commands[] = { { "trace", cmd_trace, 0 }, #endif { "inject", cmd_inject, 0 }, + { "uncore", cmd_uncore, 0 }, }; struct pager_config {
tools/perf/util/uncore.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Namhyung Kim
maintainerRe: [PATCH 2/2] perf: add new perf uncore command
Just a nitpick. But maybe I shows it can be done with perf stat. :)
tools/perf/builtin-uncore.c line 2
Quoted 8 lines · Stephane Eranian
tools/perf/builtin-uncore.c new file +2
-0@@ -0,0 +1,739 @@ +/* +* builtin-stat.c
s/stat/uncore/ :)
tools/perf/builtin-uncore.c line 4
Quoted 2 lines
tools/perf/builtin-uncore.c new file +2
-0+* +* Builtin stat command: Give a precise performance counters summary
Ditto.
Thanks,
Namhyung
Quoted 35 lines · Stephane Eranian
This patchset adds a new command to perf: perf uncore. It is used to measure processor socket-level metrics on a system-wide basis and at all priv levels.
The command comes with a set of predefined key metrics which are useful to measure multi-socket system imbalance and various bandwidths.
The following metrics are currently defined:
- memory bandwidth (Nehalem, Westmere, SandyBridge-EP)
- PCIe bandwidth (SandyBridge-EP)
- QPI bandwidth (SandyBridge-EP)
- C-state residency (SandyBridge-EP)Others can be added in the future.
The command provides options to modify the unit of the metrics (default: MB/s for bandwidth).
Example on Nehalem:
# perf uncore #------------------------------ # Socket0 | #------------------------------ # RAM Bandwidth | # Wr Rd| # MB/s MB/s| #------------------------------ 4954.99 14897.29 4953.97 14894.56 4947.52 14874.97To make plotting easier, the output can be augmented with a timestamp:
Quoted 12 lines
# perf uncore -T
#----------------------------------------
# | Socket0 |
# |------------------------------
# Time | RAM Bandwidth |
# in | Wr Rd|
# secs | MB/s MB/s|
#----------------------------------------
1 4952.50 14890.49
2 4955.55 14900.19
3 4949.13 14879.60
4 4954.66 14896.26Looks really useful - how about naming it in a bit more generic way, because I'm quite sure this command will become popular and 'perf uncore' is a bit un-intutive.
A couple of possibilities:
perf system
perf hw
perf hw-stat
and also adding subcommands instead of options for the various views/metrics, such as:
perf hw ram
perf hw pci
perf hw qpi
perf hw cstate
etc.
A plain 'perf hw' command would then list the available sub-commands and inform the user about the (current) set of hw subsystems that provide metrics.
Hm?
Thanks,
Ingo
Quoted 55 lines · Ingo Molnar
Quoted 35 lines · Stephane Eranian
This patchset adds a new command to perf: perf uncore. It is used to measure processor socket-level metrics on a system-wide basis and at all priv levels.
The command comes with a set of predefined key metrics which are useful to measure multi-socket system imbalance and various bandwidths.
The following metrics are currently defined:
- memory bandwidth (Nehalem, Westmere, SandyBridge-EP)
- PCIe bandwidth (SandyBridge-EP)
- QPI bandwidth (SandyBridge-EP)
- C-state residency (SandyBridge-EP)Others can be added in the future.
The command provides options to modify the unit of the metrics (default: MB/s for bandwidth).
Example on Nehalem:
# perf uncore #------------------------------ # Socket0 | #------------------------------ # RAM Bandwidth | # Wr Rd| # MB/s MB/s| #------------------------------ 4954.99 14897.29 4953.97 14894.56 4947.52 14874.97To make plotting easier, the output can be augmented with a timestamp:
Quoted 12 lines
# perf uncore -T #---------------------------------------- # | Socket0 | # |------------------------------ # Time | RAM Bandwidth | # in | Wr Rd| # secs | MB/s MB/s| #---------------------------------------- 1 4952.50 14890.49 2 4955.55 14900.19 3 4949.13 14879.60 4 4954.66 14896.26Looks really useful - how about naming it in a bit more generic way, because I'm quite sure this command will become popular and 'perf uncore' is a bit un-intutive.
Quoted 6 lines
A couple of possibilities:
perf system
perf hw
perf hw-stat
I am fine with that. I prefer hw or systems for the command name.
Quoted 7 lines
and also adding subcommands instead of options for the various views/metrics, such as:
perf hw ram
perf hw pci
perf hw qpi
perf hw cstate
Yes, could do that. Even though having all of them measure at once is also useful (this is how it currently works by default).
Quoted 6 lines
etc.
A plain 'perf hw' command would then list the available sub-commands and inform the user about the (current) set of hw subsystems that provide metrics.
Yes. this is what perf uncore -L already does.
For instance on SNB-EP:
$ perf uncore -L mem_bw : SNB-EP MEM Bandwidth qpi_bw : SNB-EP QPI Bandwidth pcie_bw : SNB-EP PCIe Bandwidth cstate : SNB-EP C-state residency
Namhyung Kim
maintainerHi, Stephane
Quoted 48 lines · Stephane Eranian
This patchset adds a new command to perf: perf uncore. It is used to measure processor socket-level metrics on a system-wide basis and at all priv levels.
The command comes with a set of predefined key metrics which are useful to measure multi-socket system imbalance and various bandwidths.
The following metrics are currently defined:
- memory bandwidth (Nehalem, Westmere, SandyBridge-EP)
- PCIe bandwidth (SandyBridge-EP)
- QPI bandwidth (SandyBridge-EP)
- C-state residency (SandyBridge-EP)Others can be added in the future.
The command provides options to modify the unit of the metrics (default: MB/s for bandwidth).
Example on Nehalem:
# perf uncore #------------------------------ # Socket0 | #------------------------------ # RAM Bandwidth | # Wr Rd| # MB/s MB/s| #------------------------------ 4954.99 14897.29 4953.97 14894.56 4947.52 14874.97To make plotting easier, the output can be augmented with a timestamp:
# perf uncore -T #---------------------------------------- # | Socket0 | # |------------------------------ # Time | RAM Bandwidth | # in | Wr Rd| # secs | MB/s MB/s| #---------------------------------------- 1 4952.50 14890.49 2 4955.55 14900.19 3 4949.13 14879.60 4 4954.66 14896.26
Quoted 6 lines
The code is split between generic layer (
builtin-uncore.c) and an arch specific layer (arch/*/util/uncore.c). All events are hardcoded because they don't change for a given processor and metric computation requires combining multiple events.From a quick glancing, I think this is basically what perf stat does
with selected events, right? As we now have your interval printing I can't find much difference.
And there's a patchset [1] from Jiri to support some kind of formula - yeah, now I've written the correct spelling. :) - that might fit to this purpose if you provide suitable formula file IMHO. So I guess we don't need to have another command and can reuse perf stat, no?
Thanks,
Namhyung
Quoted 4 lines
And there's a patchset [1] from Jiri to support some kind of formula - yeah, now I've written the correct spelling. :) - that might fit to this purpose if you provide suitable formula file IMHO. So I guess we don't need to have another command and can reuse perf stat, no?
Yes with a proper expression engine it's all redundant. I haven't looked at Jiri's stuff in detail, but it seemed very simple-minded and may not support all the computation needed.
Also would allow to finally replace the bogus perf stat -d frontend/backend counters.
For stat there's no really a compelling reason to integrate it, the usual wrappers work as well. They have the advantage that they can be written in real programing languages, instead of trying to invent a new one.
Expressions integrated would be mainly useful for things like "counting perf top"
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only
Quoted 8 lines · Andi Kleen
Quoted 4 lines
And there's a patchset [1] from Jiri to support some kind of formula - yeah, now I've written the correct spelling. :) - that might fit to this purpose if you provide suitable formula file IMHO. So I guess we don't need to have another command and can reuse perf stat, no?
Yes with a proper expression engine it's all redundant. I haven't looked at Jiri's stuff in detail, but it seemed very simple-minded and may not support all the computation needed.
yep, it was just an idea proposal.. it'd need more changes too be able to handle this uncore stuff, but it's possible
Quoted 3 lines
Also would allow to finally replace the bogus perf stat -d frontend/backend counters.
yep
Quoted 8 lines
For stat there's no really a compelling reason to integrate it, the usual wrappers work as well. They have the advantage that they can be written in real programing languages, instead of trying to invent a new one.
Expressions integrated would be mainly useful for things like "counting perf top"
nice idea
jirka