perf/core improvements and fixes
Arnaldo Carvalho de Melo
maintainerHi Ingo,
Please consider pulling,
- Arnaldo
Build and test stats at the end of the message.
The following changes since commit 41aad2a6d4fcdda8d73c9739daf7a9f3f49499d6:
Merge tag 'perf-core-for-mingo-20160929' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2016-09-29 19:09:58 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo-20161003
for you to fetch changes up to b42c7369e3f451e22c2b0be5d193955498d37546:
perf pmu-events: Add Skylake frontend MSR support (2016-10-03 21:52:01 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
- Allow vendors to provide JSON files describing PMU events, that then get parsed to generate C tables that are linked against perf, allowing the use of the names in their documentations, such as:
# perf list l1d
List of pre-defined events (to be used in -e):
Cache:
l1d.replacement
[L1D data line replacements]
l1d_pend_miss.fb_full
[Cycles a demand request was blocked due to Fill Buffers inavailability]
l1d_pend_miss.pending
[L1D miss oustandings duration in cycles]
l1d_pend_miss.pending_cycles
[Cycles with L1D load Misses outstanding]
l1d_pend_miss.pending_cycles_any
[Cycles with L1D load Misses outstanding from any thread on physical core]
l2_trans.l1d_wb
[L1D writebacks that access L2 cache]
Pipeline:
cycle_activity.cycles_l1d_miss
[Cycles while L1 cache miss demand load is outstanding]
cycle_activity.cycles_l1d_pending
[Cycles while L1 cache miss demand load is outstanding]
cycle_activity.stalls_l1d_miss
[Execution stalls while L1 cache miss demand load is outstanding]
cycle_activity.stalls_l1d_pending
[Execution stalls while L1 cache miss demand load is outstanding]
The above example was done on a Broadwell based ThinkPad t450s after downloading and installing such JSON files which will be added to the tools/perf/pmu-events/ directory in a subsequent patchkit.
Now one can use those names with -e/--event in all 'perf tools'. (Andi Kleen, Sukadev Bhattiprolu)
- Add a missing pointer dereference in 'perf probe' (Colin Ian King)
- Add support for building host programs to be used in generating files to be used in the build process, such as fixdep and jevents, fixing the usage of these features in a cross compilation setup (Jiri Olsa)
----------------------------------------------------------------
Andi Kleen (12):
perf tools: Add jsmn `jasmine' JSON parser perf jevents: Program to convert JSON file perf tools: Support CPU id matching for x86 v2 perf jevents: Handle header line in mapfile perf pmu: Support alias descriptions
perf tools: Query terminal width and use in perf list perf list: Add a --no-desc flag
perf pmu: Add override support for event list CPUID perf list jevents: Add support for event list topics perf tools: Make alias matching case-insensitive perf pmu-events: Fix fixed counters on Intel perf pmu-events: Add Skylake frontend MSR support
Arnaldo Carvalho de Melo (1):
perf tools: Experiment with cppcheck
Colin Ian King (1):
perf probe: Check if *ptr2 is zero and not ptr2
Jiri Olsa (2):
tools build: Add support for host programs format tools build: Make fixdep a hostprog
Sukadev Bhattiprolu (6):
perf pmu: Use pmu_events table to create aliases perf powerpc: Support CPU ID matching for Powerpc perf jevents: Add support for long descriptions perf list: Support long jevents descriptions
perf tools: Add README for info on parsing JSON/map files perf tools: Allow period= in perf stat CPU event descriptions.
tools/build/Build | 2 + tools/build/Build.include | 5 + tools/build/Makefile | 8 +- tools/build/Makefile.build | 19 +- tools/build/Makefile.include | 4 - tools/lib/subcmd/pager.c | 16 + tools/lib/subcmd/pager.h | 1 + tools/perf/Documentation/perf-list.txt | 12 +- tools/perf/Makefile.perf | 34 +- tools/perf/arch/powerpc/util/header.c | 11 + tools/perf/arch/x86/util/header.c | 24 +- tools/perf/builtin-list.c | 20 +- tools/perf/pmu-events/Build | 13 + tools/perf/pmu-events/README | 147 ++++++ tools/perf/pmu-events/jevents.c | 812 +++++++++++++++++++++++++++++++++ tools/perf/pmu-events/jevents.h | 18 + tools/perf/pmu-events/jsmn.c | 313 +++++++++++++ tools/perf/pmu-events/jsmn.h | 67 +++ tools/perf/pmu-events/json.c | 162 +++++++ tools/perf/pmu-events/json.h | 38 ++ tools/perf/pmu-events/pmu-events.h | 37 ++ tools/perf/util/evlist.c | 12 +- tools/perf/util/evsel.c | 3 +- tools/perf/util/header.h | 1 + tools/perf/util/machine.c | 6 +- tools/perf/util/parse-events.c | 8 +- tools/perf/util/parse-events.h | 3 +- tools/perf/util/pmu.c | 176 ++++++- tools/perf/util/pmu.h | 6 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/strbuf.h | 3 +- tools/perf/util/thread.c | 9 +- 32 files changed, 1926 insertions(+), 66 deletions(-) create mode 100644 tools/perf/pmu-events/Build create mode 100644 tools/perf/pmu-events/README create mode 100644 tools/perf/pmu-events/jevents.c create mode 100644 tools/perf/pmu-events/jevents.h create mode 100644 tools/perf/pmu-events/jsmn.c create mode 100644 tools/perf/pmu-events/jsmn.h create mode 100644 tools/perf/pmu-events/json.c create mode 100644 tools/perf/pmu-events/json.h create mode 100644 tools/perf/pmu-events/pmu-events.h
# time dm 1 alpine:3.4: Ok 2 android-ndk:r12b-arm: Ok 3 archlinux:latest: Ok 4 centos:5: Ok 5 centos:6: Ok 6 centos:7: Ok 7 debian:7: Ok 8 debian:8: Ok 9 debian:experimental: Ok 10 fedora:20: Ok 11 fedora:21: Ok 12 fedora:22: Ok 13 fedora:23: Ok 14 fedora:24: Ok 15 fedora:24-x-ARC-uClibc: Ok 16 fedora:rawhide: Ok 17 mageia:5: Ok 18 opensuse:13.2: Ok 19 opensuse:42.1: Ok 20 opensuse:tumbleweed: Ok 21 ubuntu:12.04.5: Ok 22 ubuntu:14.04: Ok 23 ubuntu:14.04.4: Ok 24 ubuntu:15.10: Ok 25 ubuntu:16.04: Ok 26 ubuntu:16.04-x-arm: Ok 27 ubuntu:16.04-x-arm64: Ok 28 ubuntu:16.04-x-powerpc: Ok 29 ubuntu:16.04-x-powerpc64: Ok 30 ubuntu:16.04-x-powerpc64el: Ok 31 ubuntu:16.04-x-s390: Ok 32 ubuntu:16.10: Ok
real 33m23.855s
user 0m2.128s
sys 0m2.305s
#
# perf test 1: vmlinux symtab matches kallsyms : Ok 2: detect openat syscall event : Ok 3: detect openat syscall event on all cpus : Ok 4: read samples using the mmap interface : Ok 5: parse events tests : Ok 6: Validate PERF_RECORD_* events & perf_sample fields : Ok 7: Test perf pmu format parsing : Ok 8: Test dso data read : Ok 9: Test dso data cache : Ok 10: Test dso data reopen : Ok 11: roundtrip evsel->name check : Ok 12: Check parsing of sched tracepoints fields : Ok 13: Generate and check syscalls:sys_enter_openat event fields: Ok 14: struct perf_event_attr setup : Ok 15: Test matching and linking multiple hists : Ok 16: Try 'import perf' in python, checking link problems : Ok 17: Test breakpoint overflow signal handler : Ok 18: Test breakpoint overflow sampling : Ok 19: Test number of exit event of a simple workload : Ok 20: Test software clock events have valid period values : Ok 21: Test object code reading : Ok 22: Test sample parsing : Ok 23: Test using a dummy software event to keep tracking : Ok 24: Test parsing with no sample_id_all bit set : Ok 25: Test filtering hist entries : Ok 26: Test mmap thread lookup : Ok 27: Test thread mg sharing : Ok 28: Test output sorting of hist entries : Ok 29: Test cumulation of child hist entries : Ok 30: Test tracking with sched_switch : Ok 31: Filter fds with revents mask in a fdarray : Ok 32: Add fd to a fdarray, making it autogrow : Ok 33: Test kmod_path__parse function : Ok 34: Test thread map : Ok 35: Test LLVM searching and compiling : 35.1: Basic BPF llvm compiling test : Ok 35.2: Test kbuild searching : Ok 35.3: Compile source for BPF prologue generation test : Ok 35.4: Compile source for BPF relocation test : Ok 36: Test topology in session : Ok 37: Test BPF filter : 37.1: Test basic BPF filtering : Ok 37.2: Test BPF prologue generation : Ok 37.3: Test BPF relocation checker : Ok 38: Test thread map synthesize : Ok 39: Test cpu map synthesize : Ok 40: Test stat config synthesize : Ok 41: Test stat synthesize : Ok 42: Test stat round synthesize : Ok 43: Test attr update synthesize : Ok 44: Test events times : Ok 45: Test backward reading from ring buffer : Ok 46: Test cpu map print : Ok 47: Test SDT event probing : Ok 48: Test is_printable_array function : Ok 49: Test bitmap print : Ok 50: x86 rdpmc test : Ok 51: Test converting perf time to TSC : Ok 52: Test dwarf unwind : Ok 53: Test x86 instruction decoder - new instructions : Ok 54: Test intel cqm nmi context read : Skip #
$ make -C tools/perf build-test
make: Entering directory '/home/acme/git/linux/tools/perf'
- tarpkg: ./tests/perf-targz-src-pkg .
make_no_libperl_O: make NO_LIBPERL=1
make_no_newt_O: make NO_NEWT=1
make_no_slang_O: make NO_SLANG=1
make_no_libnuma_O: make NO_LIBNUMA=1
make_with_babeltrace_O: make LIBBABELTRACE=1
make_install_prefix_slash_O: make install prefix=/tmp/krava/
make_no_libbpf_O: make NO_LIBBPF=1
make_no_demangle_O: make NO_DEMANGLE=1
make_install_bin_O: make install-bin
make_install_O: make install
make_no_libbionic_O: make NO_LIBBIONIC=1
make_no_libunwind_O: make NO_LIBUNWIND=1
make_no_libaudit_O: make NO_LIBAUDIT=1
make_no_libpython_O: make NO_LIBPYTHON=1
make_tags_O: make tags
make_perf_o_O: make perf.o
make_static_O: make LDFLAGS=-static
make_clean_all_O: make clean all
make_install_prefix_O: make install prefix=/tmp/krava
make_help_O: make help
make_util_map_o_O: make util/map.o
make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1
make_minimal_O: make NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 NO_LIBCRYPTO=1 NO_SDT=1
make_no_backtrace_O: make NO_BACKTRACE=1
make_debug_O: make DEBUG=1
make_no_libelf_O: make NO_LIBELF=1
make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
make_no_auxtrace_O: make NO_AUXTRACE=1
make_doc_O: make doc
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_no_gtk2_O: make NO_GTK2=1
OKArnaldo Carvalho de Melo
maintainerPATCH 1/22 perf probe: Check if *ptr2 is zero and not ptr2
From: Colin Ian King <[email protected]>
Static anaylsis with cppcheck[1] detected an incorrect comparison:
[tools/perf/util/probe-event.c:216]: (warning) Char literal compared with pointer 'ptr2'. Did you intend to dereference it?
Dereference ptr2 for the comparison to fix this.
1: https://sourceforge.net/p/cppcheck/wiki/Home/
--- tools/perf/util/probe-event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
@@ -213,7 +213,7 @@ static int convert_exec_to_group(const char *exec, char **result) goto out; } -for (ptr2 = ptr1; ptr2 !='\0' ; ptr2++) { +for (ptr2 = ptr1; *ptr2 !='\0' ; ptr2++) {if (!isalnum (*ptr2) && *ptr2 !='_' ) { *ptr2 ='\0' ;break ;
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 2/22 perf tools: Experiment with cppcheck
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
Experimenting a bit using cppcheck[1], a static checker brought to my attention by Colin, reducing the scope of some variables, reducing the line of source code lines in the process:
$ cppcheck --enable=style tools/perf/util/thread.c Checking tools/perf/util/thread.c... [tools/perf/util/thread.c:17]: (style) The scope of the variable 'leader' can be reduced. [tools/perf/util/thread.c:133]: (style) The scope of the variable 'err' can be reduced. [tools/perf/util/thread.c:273]: (style) The scope of the variable 'err' can be reduced.
Will continue later, but these are already useful, keep them.
1: https://sourceforge.net/p/cppcheck/wiki/Home/
--- tools/perf/util/evlist.c | 12 +++++------- tools/perf/util/evsel.c | 3 +-- tools/perf/util/machine.c | 6 +++--- tools/perf/util/strbuf.h | 3 +-- tools/perf/util/thread.c | 9 +++------ 5 files changed, 13 insertions(+), 20 deletions(-)
tools/perf/util/evlist.c +5 -7
@@ -384,15 +384,14 @@ void perf_evlist__toggle_enable(struct perf_evlist *evlist)static int perf_evlist__enable_event_cpu (struct perf_evlist *evlist,struct perf_evsel *evsel,int cpu) { -int thread, err; +int thread;int nr_threads =perf_evlist__nr_threads (evlist, evsel);if (!evsel->fd)return -EINVAL ;for (thread =0 ; thread < nr_threads; thread++) { - err =ioctl (FD (evsel, cpu, thread), -PERF_EVENT_IOC_ENABLE ,0 ); +int err =ioctl (FD (evsel, cpu, thread),PERF_EVENT_IOC_ENABLE ,0 );if (err)return err; }
@@ -403,14 +402,14 @@ static int perf_evlist__enable_event_thread(struct perf_evlist *evlist,struct perf_evsel *evsel, int thread) { - int cpu, err; + int cpu;int nr_cpus =cpu_map__nr (evlist->cpus);if (!evsel->fd)return -EINVAL ;for (cpu =0 ; cpu < nr_cpus; cpu++) { - err =ioctl (FD (evsel, cpu, thread),PERF_EVENT_IOC_ENABLE ,0 ); +int err =ioctl (FD (evsel, cpu, thread),PERF_EVENT_IOC_ENABLE ,0 );if (err)return err; }
@@ -1606,10 +1605,9 @@ void perf_evlist__close(struct perf_evlist *evlist)struct perf_evsel *evsel;int ncpus =cpu_map__nr (evlist->cpus);int nthreads =thread_map__nr (evlist->threads); -int n;evlist__for_each_entry_reverse (evlist, evsel) { - n = evsel->cpus ? evsel->cpus->nr : ncpus; +int n = evsel->cpus ? evsel->cpus->nr : ncpus;perf_evsel__close (evsel, n, nthreads); } }
tools/perf/util/evsel.c +1 -2
@@ -985,14 +985,13 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,static int perf_evsel__alloc_fd (struct perf_evsel *evsel,int ncpus,int nthreads) { -int cpu, thread; -if (evsel->system_wide) nthreads =1 ; evsel->fd =xyarray__new (ncpus, nthreads,sizeof (int ));if (evsel->fd) { +int cpu, thread;for (cpu =0 ; cpu < ncpus; cpu++) {for (thread =0 ; thread < nthreads; thread++) {FD (evsel, cpu, thread) =-1 ;
tools/perf/util/machine.c +3 -3
@@ -1745,9 +1745,8 @@ static int resolve_lbr_callchain_sample(struct thread *thread, int max_stack) {struct ip_callchain *chain = sample->callchain; -int chain_nr =min (max_stack, (int )chain->nr); +int chain_nr =min (max_stack, (int )chain->nr), i;u8 cpumode =PERF_RECORD_MISC_USER ; -int i, j, err;u64 ip;for (i =0 ; i < chain_nr; i++) {
@@ -1758,7 +1757,7 @@ static int resolve_lbr_callchain_sample(struct thread *thread,/* LBR only affects the user callchain */ if (i != chain_nr) {struct branch_stack *lbr_stack = sample->branch_stack; -int lbr_nr = lbr_stack->nr; +int lbr_nr = lbr_stack->nr, j;/* * LBR callstack can only get user call chain. * The mix_chain_nr is kernel call chain
@@ -1772,6 +1771,7 @@ static int resolve_lbr_callchain_sample(struct thread *thread,int mix_chain_nr = i +1 + lbr_nr +1 ;for (j =0 ; j < mix_chain_nr; j++) { +int err;if (callchain_param.order ==ORDER_CALLEE ) {if (j < i +1 ) ip = chain->ips[j];
tools/perf/util/strbuf.h +1 -2
@@ -66,9 +66,8 @@ static inline ssize_t strbuf_avail(const struct strbuf *sb) {int strbuf_grow (struct strbuf *buf,size_t );static inline int strbuf_setlen (struct strbuf *sb,size_t len) { -int ret;if (!sb->alloc) { - ret =strbuf_grow (sb,0 ); +int ret =strbuf_grow (sb,0 );if (ret)return ret; }
tools/perf/util/thread.c +3 -6
@@ -14,13 +14,12 @@int thread__init_map_groups (struct thread *thread,struct machine *machine) { -struct thread *leader;pid_t pid = thread->pid_;if (pid == thread->tid || pid ==-1 ) { thread->mg =map_groups__new (machine); }else { - leader =__machine__findnew_thread (machine, pid, pid); +struct thread *leader =__machine__findnew_thread (machine, pid, pid);if (leader) { thread->mg =map_groups__get (leader->mg);thread__put (leader);
@@ -130,11 +129,10 @@ int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, bool exec) {struct comm *new, *curr =thread__comm (thread); -int err;/* Override the default :tid entry */ if (!thread->comm_set) { - err =comm__override (curr, str, timestamp, exec); +int err =comm__override (curr, str, timestamp, exec);if (err)return err; }else {
@@ -270,10 +268,9 @@ static int thread__clone_map_groups(struct thread *thread,int thread__fork (struct thread *thread,struct thread *parent,u64 timestamp) { -int err; -if (parent->comm_set) {const char *comm =thread__comm_str (parent); +int err;if (!comm)return -ENOMEM ; err =thread__set_comm (thread, comm, timestamp);
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 3/22 tools build: Add support for host programs format
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
In some cases, like for fixdep and shortly for jevents, we need to build a tool to run on the host that will be used in building a tool, such as perf, that is being cross compiled, so do like the kernel and provide HOSTCC, HOSTLD and HOSTAR to do that.
--- tools/build/Build.include | 5 +++++ tools/build/Makefile | 6 ++++++ tools/build/Makefile.build | 19 +++++++++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-)
tools/build/Build.include +5 -0
@@ -90,3 +90,8 @@ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ # - per object C flags # - BUILD_STR macro to allow '-D"$(variable)"' constructs c_flags = -Wp,-MD,$(depfile),-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj)) + +### +## HOSTCC C flags + +host_c_flags = -Wp,-MD,$(depfile),-MT,$@ $(CHOSTFLAGS) -D"BUILD_STR(s)=\#s" $(CHOSTFLAGS_$(basetarget).o) $(CHOSTFLAGS_$(obj))
tools/build/Makefile +6 -0
@@ -14,6 +14,12 @@ endef $(call allow-override,CC,$(CROSS_COMPILE)gcc) $(call allow-override,LD,$(CROSS_COMPILE)ld) +HOSTCC ?= gcc +HOSTLD ?= ld +HOSTAR ?= ar + +export HOSTCC HOSTLD HOSTAR + ifeq ($(V),1) Q = else
tools/build/Makefile.build +15 -4
@@ -58,6 +58,9 @@ quiet_cmd_mkdir = MKDIR $(dir $@) quiet_cmd_cc_o_c = CC $@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< +quiet_cmd_host_cc_o_c = HOSTCC $@ + cmd_host_cc_o_c = $(HOSTCC) $(host_c_flags) -c -o $@ $< + quiet_cmd_cpp_i_c = CPP $@ cmd_cpp_i_c = $(CC) $(c_flags) -E -o $@ $<
@@ -70,16 +73,24 @@ quiet_cmd_gen = GEN $@ # If there's nothing to link, create empty $@ object. quiet_cmd_ld_multi = LD $@ cmd_ld_multi = $(if $(strip $(obj-y)),\ - $(LD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(AR) rcs $@) + $(LD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(AR) rcs $@) + +quiet_cmd_host_ld_multi = HOSTLD $@ + cmd_host_ld_multi = $(if $(strip $(obj-y)),\ + $(HOSTLD) -r -o $@ $(filter $(obj-y),$^),rm -f $@; $(HOSTAR) rcs $@) + +ifneq ($(filter $(obj),$(hostprogs)),) + host = host_ +endif # Build rules $(OUTPUT)%.o: %.c FORCE $(call rule_mkdir) - $(call if_changed_dep,cc_o_c) + $(call if_changed_dep,$(host)cc_o_c) $(OUTPUT)%.o: %.S FORCE $(call rule_mkdir) - $(call if_changed_dep,cc_o_c) + $(call if_changed_dep,$(host)cc_o_c) $(OUTPUT)%.i: %.c FORCE $(call rule_mkdir)
@@ -119,7 +130,7 @@ $(sort $(subdir-obj-y)): $(subdir-y) ; $(in-target): $(obj-y) FORCE $(call rule_mkdir) - $(call if_changed,ld_multi) + $(call if_changed,$(host)ld_multi) __build: $(in-target) @:
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 4/22 tools build: Make fixdep a hostprog
In reply to Arnaldo Carvalho de MeloFrom: Jiri Olsa <[email protected]>
It is used in the build process, so stop suppressing its build in tools cross builds.
[ Use HOSTCC on the $(OUTPUT)fixdep target, it was using the x-compiler
to link fixdep-in.o, that was correctly built with HOSTCC and thus failing ]
--- tools/build/Build | 2 ++ tools/build/Makefile | 2 +- tools/build/Makefile.include | 4 ---- 3 files changed, 3 insertions(+), 5 deletions(-)
tools/build/Build +2 -0
@@ -1 +1,3 @@ +hostprogs := fixdep + fixdep-y := fixdep.o
tools/build/Makefile +1 -1
@@ -42,7 +42,7 @@ $(OUTPUT)fixdep-in.o: FORCE $(Q)$(MAKE) $(build)=fixdep $(OUTPUT)fixdep: $(OUTPUT)fixdep-in.o - $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $< + $(QUIET_LINK)$(HOSTCC) $(LDFLAGS) -o $@ $< FORCE:
tools/build/Makefile.include +0 -4
@@ -1,10 +1,6 @@ build := -f $(srctree)/tools/build/Makefile.build dir=. obj -ifdef CROSS_COMPILE -fixdep: -else fixdep: $(Q)$(MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= $(OUTPUT)fixdep -endif .PHONY: fixdep
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 5/22 perf tools: Add jsmn `jasmine' JSON parser
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
I need a JSON parser. This adds the simplest JSON parser I could find -- Serge Zaitsev's jsmn `jasmine' -- to the perf library. I merely converted it to (mostly) Linux style and added support for non 0 terminated input.
The parser is quite straight forward and does not copy any data, just returns tokens with offsets into the input buffer. So it's relatively efficient and simple to use.
The code is not fully checkpatch clean, but I didn't want to completely fork the upstream code.
Original source: http://zserge.bitbucket.org/jsmn.html
In addition I added a simple wrapper that mmaps a json file and provides some straight forward access functions.
Used in follow-on patches to parse event files.
[ Use fcntl.h instead of sys/fcntl.h to fix the build on Alpine Linux 3.4/musl libc,
use stdbool.h to avoid clashing with 'bool' typedef there ]
--- tools/perf/pmu-events/jsmn.c | 313 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/pmu-events/jsmn.h | 67 +++++++++ tools/perf/pmu-events/json.c | 162 ++++++++++++++++++++++ tools/perf/pmu-events/json.h | 32 +++++ 4 files changed, 574 insertions(+) create mode 100644 tools/perf/pmu-events/jsmn.c create mode 100644 tools/perf/pmu-events/jsmn.h create mode 100644 tools/perf/pmu-events/json.c create mode 100644 tools/perf/pmu-events/json.h
tools/perf/pmu-events/jsmn.c new file +313 -0
@@ -0,0 +1,313 @@ +/* +* Copyright (c) 2010 Serge A. Zaitsev +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +* Slightly modified by AK to not assume 0 terminated input. +*/ + +#include <stdlib.h> +#include "jsmn.h" + +/* +* Allocates a fresh unused token from the token pool. +*/ +static jsmntok_t *jsmn_alloc_token (jsmn_parser *parser, +jsmntok_t *tokens,size_t num_tokens) +{ +jsmntok_t *tok; + +if ((unsigned )parser->toknext >= num_tokens) +return NULL ; + tok = &tokens[parser->toknext++]; + tok->start = tok->end =-1 ; + tok->size =0 ; +return tok; +} + +/* +* Fills token type and boundaries. +*/ +static void jsmn_fill_token (jsmntok_t *token,jsmntype_t type, +int start,int end) +{ + token->type = type; + token->start = start; + token->end = end; + token->size =0 ; +} + +/* +* Fills next available token with JSON primitive. +*/ +static jsmnerr_t jsmn_parse_primitive (jsmn_parser *parser,const char *js, +size_t len, +jsmntok_t *tokens,size_t num_tokens) +{ +jsmntok_t *token; +int start; + + start = parser->pos; + +for (; parser->pos < len; parser->pos++) { +switch (js[parser->pos]) { +#ifndef JSMN_STRICT +/* +* In strict mode primitive must be followed by "," +* or "}" or "]" +*/ +case ':' : +#endif +case '\t' : +case '\r' : +case '\n' : +case ' ' : +case ',' : +case ']' : +case '}' : + goto found; +default : +break ; + } +if (js[parser->pos] <32 || js[parser->pos] >=127 ) { + parser->pos = start; +return JSMN_ERROR_INVAL ; + } + } +#ifdef JSMN_STRICT +/* +* In strict mode primitive must be followed by a +* comma/object/array. +*/ + parser->pos = start; +return JSMN_ERROR_PART ; +#endif + +found: + token =jsmn_alloc_token (parser, tokens, num_tokens); +if (token ==NULL ) { + parser->pos = start; +return JSMN_ERROR_NOMEM ; + } +jsmn_fill_token (token,JSMN_PRIMITIVE , start, parser->pos); + parser->pos--;/* parent sees closing brackets */ +return JSMN_SUCCESS ; +} + +/* +* Fills next token with JSON string. +*/ +static jsmnerr_t jsmn_parse_string (jsmn_parser *parser,const char *js, +size_t len, +jsmntok_t *tokens,size_t num_tokens) +{ +jsmntok_t *token; +int start = parser->pos; + +/* Skip starting quote */ + parser->pos++; + +for (; parser->pos < len; parser->pos++) { +char c = js[parser->pos]; + +/* Quote: end of string */ +if (c =='\"' ) { + token =jsmn_alloc_token (parser, tokens, num_tokens); +if (token ==NULL ) { + parser->pos = start; +return JSMN_ERROR_NOMEM ; + } +jsmn_fill_token (token,JSMN_STRING , start+1 , + parser->pos); +return JSMN_SUCCESS ; + } + +/* Backslash: Quoted symbol expected */ +if (c =='\\' ) { + parser->pos++; +switch (js[parser->pos]) { +/* Allowed escaped symbols */ +case '\"' : +case '/' : +case '\\' : +case 'b' : +case 'f' : +case 'r' : +case 'n' : +case 't' : +break ; +/* Allows escaped symbol \uXXXX */ +case 'u' : +/* TODO */ +break ; +/* Unexpected symbol */ +default : + parser->pos = start; +return JSMN_ERROR_INVAL ; + } + } + } + parser->pos = start; +return JSMN_ERROR_PART ; +} + +/* +* Parse JSON string and fill tokens. +*/ +jsmnerr_t jsmn_parse (jsmn_parser *parser,const char *js,size_t len, +jsmntok_t *tokens,unsigned int num_tokens) +{ +jsmnerr_t r; +int i; +jsmntok_t *token; + +for (; parser->pos < len; parser->pos++) { +char c; +jsmntype_t type; + + c = js[parser->pos]; +switch (c) { +case '{' : +case '[' : + token =jsmn_alloc_token (parser, tokens, num_tokens); +if (token ==NULL ) +return JSMN_ERROR_NOMEM ; +if (parser->toksuper !=-1 ) + tokens[parser->toksuper].size++; + token->type = (c =='{' ?JSMN_OBJECT :JSMN_ARRAY ); + token->start = parser->pos; + parser->toksuper = parser->toknext -1 ; +break ; +case '}' : +case ']' : + type = (c =='}' ?JSMN_OBJECT :JSMN_ARRAY ); +for (i = parser->toknext -1 ; i >=0 ; i--) { + token = &tokens[i]; +if (token->start !=-1 && token->end ==-1 ) { +if (token->type != type) +return JSMN_ERROR_INVAL ; + parser->toksuper =-1 ; + token->end = parser->pos +1 ; +break ; + } + } +/* Error if unmatched closing bracket */ +if (i ==-1 ) +return JSMN_ERROR_INVAL ; +for (; i >=0 ; i--) { + token = &tokens[i]; +if (token->start !=-1 && token->end ==-1 ) { + parser->toksuper = i; +break ; + } + } +break ; +case '\"' : + r =jsmn_parse_string (parser, js, len, tokens, + num_tokens); +if (r <0 ) +return r; +if (parser->toksuper !=-1 ) + tokens[parser->toksuper].size++; +break ; +case '\t' : +case '\r' : +case '\n' : +case ':' : +case ',' : +case ' ' : +break ; +#ifdef JSMN_STRICT +/* +* In strict mode primitives are: +* numbers and booleans. +*/ +case '-' : +case '0' : +case '1' : +case '2' : +case '3' : +case '4' : +case '5' : +case '6' : +case '7' : +case '8' : +case '9' : +case 't' : +case 'f' : +case 'n' : +#else +/* +* In non-strict mode every unquoted value +* is a primitive. +*/ +/*FALL THROUGH */ +default : +#endif + r =jsmn_parse_primitive (parser, js, len, tokens, + num_tokens); +if (r <0 ) +return r; +if (parser->toksuper !=-1 ) + tokens[parser->toksuper].size++; +break ; + +#ifdef JSMN_STRICT +/* Unexpected char in strict mode */ +default : +return JSMN_ERROR_INVAL ; +#endif + } + } + +for (i = parser->toknext -1 ; i >=0 ; i--) { +/* Unmatched opened object or array */ +if (tokens[i].start !=-1 && tokens[i].end ==-1 ) +return JSMN_ERROR_PART ; + } + +return JSMN_SUCCESS ; +} + +/* +* Creates a new parser based over a given buffer with an array of tokens +* available. +*/ +void jsmn_init (jsmn_parser *parser) +{ + parser->pos =0 ; + parser->toknext =0 ; + parser->toksuper =-1 ; +} + +const char *jsmn_strerror (jsmnerr_t err) +{ +switch (err) { +case JSMN_ERROR_NOMEM : +return "No enough tokens" ; +case JSMN_ERROR_INVAL : +return "Invalid character inside JSON string" ; +case JSMN_ERROR_PART : +return "The string is not a full JSON packet, more bytes expected" ; +case JSMN_SUCCESS : +return "Success" ; +default : +return "Unknown json error" ; + } +}
tools/perf/pmu-events/jsmn.h new file +67 -0
67 lines not on this page · raw message
tools/perf/pmu-events/json.c new file +162 -0
162 lines not on this page · raw message
tools/perf/pmu-events/json.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef JSON_H +#define JSON_H 1 + +#include "jsmn.h" + +jsmntok_t *parse_json (const char *fn,char **map,size_t *size,int *len); +void free_json (char *map,size_t size,jsmntok_t *tokens); +int json_line (char *map,jsmntok_t *t); +const char *json_name (jsmntok_t *t); +int json_streq (char *map,jsmntok_t *t,const char *s); +int json_len (jsmntok_t *t); + +extern int verbose; + +#include <stdbool.h> + +extern int eprintf (int level,int var,const char *fmt, ...); +#define pr_fmt (fmt) fmt + +#define pr_err (fmt, ...) \ + eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) + +#ifndef roundup +#define roundup (x, y) ( \ +{ \ + const typeof(y) __y = y; \ + (((x) + (__y - 1)) / __y) * __y; \ +} \ +) +#endif + +#endif
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 6/22 perf jevents: Program to convert JSON file
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
This is a modified version of an earlier patch by Andi Kleen.
We expect architectures to create JSON files describing the performance monitoring (PMU) events that each CPU model/family of the architecture supports.
Following is an example of the JSON file entry for an x86 event:
[
...
{
"EventCode": "0x00",
"UMask": "0x01",
"EventName": "INST_RETIRED.ANY",
"BriefDescription": "Instructions retired from execution.",
"PublicDescription": "Instructions retired from execution.",
"Counter": "Fixed counter 1",
"CounterHTOff": "Fixed counter 1",
"SampleAfterValue": "2000003",
"SampleAfterValue": "2000003",
"MSRIndex": "0",
"MSRValue": "0",
"TakenAlone": "0",
"CounterMask": "0",
"Invert": "0",
"AnyThread": "0",
"EdgeDetect": "0",
"PEBS": "0",
"PRECISE_STORE": "0",
"Errata": "null",
"Offcore": "0"
},
...
]All the PMU events supported by a CPU model/family must be grouped into "topics" such as "Pipelining", "Floating-point", "Virtual-memory" etc.
All events belonging to a topic must be placed in a separate JSON file (eg: "Pipelining.json") and all the topic JSON files for a CPU model must be in a separate directory.
Eg: for the CPU model "Silvermont_core":
$ ls tools/perf/pmu-events/arch/x86/Silvermont_core Floating-point.json
Memory.json
Other.json
Pipelining.json
Virtualmemory.json
Finally, to allow multiple CPU models to share a single set of JSON files, architectures must provide a mapping between a model and its set of events:
$ grep Silvermont tools/perf/pmu-events/arch/x86/mapfile.csv
GenuineIntel-6-4D,V13,Silvermont_core,core
GenuineIntel-6-4C,V13,Silvermont_core,corewhich maps each CPU, identified by [vendor, family, model, version, type] to a directory of JSON files. Thus two (or more) CPU models support the set of PMU events listed in the directory.
tools/perf/pmu-events/arch/x86/Silvermont_core/
Given this organization of files, the program, jevents:
- locates all JSON files for each CPU-model of the architecture,
- parses all JSON files for the CPU-model and generates a C-style "PMU-events table" (pmu-events.c) for the model
- locates a mapfile for the architecture
- builds a global table, mapping each model of CPU to the corresponding PMU-events table.
The 'pmu-events.c' is generated when building perf and added to libperf.a. The global table pmu_events_map[] table in this pmu-events.c will be used in perf in a follow-on patch.
If the architecture does not have any JSON files or there is an error in processing them, an empty mapping file is created. This would allow the build of perf to proceed even if we are not able to provide aliases for events.
The parser for JSON files allows parsing Intel style JSON event files. This allows to use an Intel event list directly with perf. The Intel event lists can be quite large and are too big to store in unswappable kernel memory.
The conversion from JSON to C-style is straight forward. The parser knows (very little) Intel specific information, and can be easily extended to handle fields for other CPUs.
The parser code is partially shared with an independent parsing library, which is 2-clause BSD licensed. To avoid any conflicts I marked those files as BSD licensed too. As part of perf they become GPLv2.
Committer notes:
Fixes:
1) Limit maxfds to 512 to avoid nftd() segfaulting on alloca() with a big rlim_max, as in docker containers - acme
2) Make jevents a hostprog, supporting cross compilation - jolsa
3) Use HOSTCC for jevents final step - acme
4) Define _GNU_SOURCE for asprintf, as we can't use CC's EXTRA_CFLAGS, that has to have --sysroot on the Android NDK 24 - acme
5) Removed $(srctree)/tools/perf/pmu-events/pmu-events.c from the 'clean' target, it is generated on $(OUTPUT)pmu-events/pmu-events.c, which is already taken care of in the original patch - acme
--- tools/perf/Makefile.perf | 34 +- tools/perf/pmu-events/Build | 13 + tools/perf/pmu-events/jevents.c | 767 +++++++++++++++++++++++++++++++++++++ tools/perf/pmu-events/jevents.h | 17 + tools/perf/pmu-events/json.h | 6 + tools/perf/pmu-events/pmu-events.h | 36 ++ 6 files changed, 869 insertions(+), 4 deletions(-) create mode 100644 tools/perf/pmu-events/Build create mode 100644 tools/perf/pmu-events/jevents.c create mode 100644 tools/perf/pmu-events/jevents.h create mode 100644 tools/perf/pmu-events/pmu-events.h
tools/perf/Makefile.perf +30 -4
@@ -144,6 +144,10 @@ $(call allow-override,LD,$(CROSS_COMPILE)ld) LD += $(EXTRA_LDFLAGS) +HOSTCC ?= gcc +HOSTLD ?= ld +HOSTAR ?= ar + PKG_CONFIG = $(CROSS_COMPILE)pkg-config RM = rm -f
@@ -345,8 +349,18 @@ strip: $(PROGRAMS) $(OUTPUT)perf PERF_IN := $(OUTPUT)perf-in.o export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK +export HOSTCC HOSTLD HOSTAR include $(srctree)/tools/build/Makefile.include +JEVENTS := $(OUTPUT)pmu-events/jevents +JEVENTS_IN := $(OUTPUT)pmu-events/jevents-in.o + +PMU_EVENTS_IN := $(OUTPUT)pmu-events/pmu-events-in.o + +export JEVENTS + +build := -f $(srctree)/tools/build/Makefile.build dir=. obj + $(PERF_IN): prepare FORCE @(test -f ../../include/uapi/linux/perf_event.h && ( \ (diff -B ../include/uapi/linux/perf_event.h ../../include/uapi/linux/perf_event.h >/dev/null) \
@@ -443,9 +457,18 @@ $(PERF_IN): prepare FORCE || echo "Warning: tools/include/uapi/linux/mman.h differs from kernel" >&2 )) || true $(Q)$(MAKE) $(build)=perf -$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST) +$(JEVENTS_IN): FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=jevents + +$(JEVENTS): $(JEVENTS_IN) + $(QUIET_LINK)$(HOSTCC) $(JEVENTS_IN) -o $@ + +$(PMU_EVENTS_IN): $(JEVENTS) FORCE + $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events + +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBTRACEEVENT_DYNAMIC_LIST) $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS) \ - $(PERF_IN) $(LIBS) -o $@ + $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@ $(GTK_IN): fixdep FORCE $(Q)$(MAKE) $(build)=gtk
@@ -474,6 +497,8 @@ perf.spec $(SCRIPTS) \ ifneq ($(OUTPUT),) %.o: $(OUTPUT)%.o @echo " # Redirected target $@ => $(OUTPUT)$@" +pmu-events/%.o: $(OUTPUT)pmu-events/%.o + @echo " # Redirected target $@ => $(OUTPUT)$@" util/%.o: $(OUTPUT)util/%.o @echo " # Redirected target $@ => $(OUTPUT)$@" bench/%.o: $(OUTPUT)bench/%.o
@@ -729,10 +754,11 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) $(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) $(OUTPUT).config-detected - $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 + $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 $(OUTPUT)pmu-events/jevents $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \ $(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \ - $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c + $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c \ + $(OUTPUT)pmu-events/pmu-events.c $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean $(python-clean)
tools/perf/pmu-events/Build new file +13 -0
@@ -0,0 +1,13 @@ +hostprogs := jevents + +jevents-y += json.o jsmn.o jevents.o +pmu-events-y += pmu-events.o +JDIR = pmu-events/arch/$(ARCH) +JSON = $(shell [ -d $(JDIR) ] && \ + find $(JDIR) -name '*.json' -o -name 'mapfile.csv') +# +# Locate/process JSON files in pmu-events/arch/ +# directory and create tables in pmu-events.c. +# +$(OUTPUT)pmu-events/pmu-events.c: $(JSON) $(JEVENTS) + $(Q)$(call echo-cmd,gen)$(JEVENTS) $(ARCH) pmu-events/arch $(OUTPUT)pmu-events/pmu-events.c $(V)
tools/perf/pmu-events/jevents.c new file +767 -0
767 lines not on this page · raw message
tools/perf/pmu-events/jevents.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef JEVENTS_H +#define JEVENTS_H 1 + +int json_events (const char *fn, +int (*func)(void *data,char *name,char *event,char *desc), +void *data); +char *get_cpu_str (void ); + +#ifndef min +#define min (x, y) ({ \ + typeof(x) _min1 = (x); \ + typeof(y) _min2 = (y); \ + (void) (&_min1 == &_min2); \ + _min1 < _min2 ? _min1 : _min2; }) +#endif + +#endif
tools/perf/pmu-events/json.h +6 -0
@@ -20,6 +20,12 @@ extern int eprintf(int level, int var, const char *fmt, ...);#define pr_err (fmt, ...) \ eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info (fmt, ...) \ + eprintf(1, verbose, pr_fmt(fmt), ##__VA_ARGS__) + +#define pr_debug (fmt, ...) \ + eprintf(2, verbose, pr_fmt(fmt), ##__VA_ARGS__) +#ifndef roundup#define roundup (x, y) ( \ { \
tools/perf/pmu-events/pmu-events.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef PMU_EVENTS_H +#define PMU_EVENTS_H + +/* +* Describe each PMU event. Each CPU has a table of PMU events. +*/ +struct pmu_event { +const char *name; +const char *event; +const char *desc; +const char *topic; +}; + +/* +* +* Map a CPU to its table of PMU events. The CPU is identified by the +* cpuid field, which is an arch-specific identifier for the CPU. +* The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile +* must match the get_cpustr() in tools/perf/arch/xxx/util/header.c) +* +* The cpuid can contain any character other than the comma. +*/ +struct pmu_events_map { +const char *cpuid; +const char *version; +const char *type;/* core, uncore etc */ +struct pmu_event *table; +}; + +/* +* Global table mapping each known CPU for the architecture to its +* table of PMU events. +*/ +extern struct pmu_events_map pmu_events_map[]; + +#endif
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 7/22 perf pmu: Use pmu_events table to create aliases
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
At run time (when 'perf' is starting up), locate the specific table of PMU events that corresponds to the current CPU. Using that table, create aliases for the each of the PMU events in the CPU. The use these aliases to parse the user specified perf event.
In short this would allow the user to specify events using their aliases rather than raw event codes.
Based on input and some earlier patches from Andi Kleen, Jiri Olsa.
[ Make pmu_add_cpu_aliases() return void, since it was returning just '0' and
furthermore, even that was being discarded via an explicit (void) cast ]
--- tools/perf/util/header.h | 1 + tools/perf/util/pmu.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
tools/perf/util/header.h +1 -0
@@ -151,4 +151,5 @@ int write_padded(int fd, const void *bf, size_t count, size_t count_aligned);*/ int get_cpuid (char *buffer,size_t sz); +char *get_cpuid_str (void );#endif /* __PERF_HEADER_H */
tools/perf/util/pmu.c +60 -0
78 lines not on this page · raw message
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 8/22 perf powerpc: Support CPU ID matching for Powerpc
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
Implement code that returns the generic CPU ID string for Powerpc. This will be used to identify the specific table of PMU events to parse/compare user specified events against.
--- tools/perf/arch/powerpc/util/header.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/perf/arch/powerpc/util/header.c +11 -0
@@ -32,3 +32,14 @@ get_cpuid(char *buffer, size_t sz) }return -1 ; } + +char * +get_cpuid_str (void ) +{ +char *bufp; + +if (asprintf (&bufp,"%.8lx" ,mfspr (SPRN_PVR )) <0 ) + bufp =NULL ; + +return bufp; +}
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 9/22 perf tools: Support CPU id matching for x86 v2
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Implement the code to match CPU types to mapfile types for x86 based on CPUID. This extends an existing similar function, but changes it to use the x86 mapfile cpu description. This allows to resolve event lists generated by jevents.
--- tools/perf/arch/x86/util/header.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
tools/perf/arch/x86/util/header.c +21 -3
@@ -19,8 +19,8 @@ cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c, : "a" (op)); } -int -get_cpuid (char *buffer,size_t sz) +static int +__get_cpuid (char *buffer,size_t sz,const char *fmt) {unsigned int a, b, c, d, lvl;int family =-1 , model =-1 , step =-1 ;
@@ -48,7 +48,7 @@ get_cpuid(char *buffer, size_t sz)if (family >=0x6 ) model += ((a >>16 ) &0xf ) <<4 ; } - nb =scnprintf (buffer, sz,"%s,%u,%u,%u$" , vendor, family, model, step); + nb =scnprintf (buffer, sz, fmt, vendor, family, model, step);/* look for end marker to ensure the entire data fit */ if (strchr (buffer,'$' )) {
@@ -57,3 +57,21 @@ get_cpuid(char *buffer, size_t sz) }return -1 ; } + +int +get_cpuid (char *buffer,size_t sz) +{ +return __get_cpuid (buffer, sz,"%s,%u,%u,%u$" ); +} + +char * +get_cpuid_str (void ) +{ +char *buf =malloc (128 ); + +if (__get_cpuid (buf,128 ,"%s-%u-%X$" ) <0 ) { +free (buf); +return NULL ; + } +return buf; +}
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 10/22 perf jevents: Handle header line in mapfile
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
To work with existing mapfiles, assume that the first line in 'mapfile.csv' is a header line and skip over it.
--- tools/perf/pmu-events/jevents.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/pmu-events/jevents.c +7 -2
@@ -477,7 +477,12 @@ static int process_mapfile(FILE *outfp, char *fpath)print_mapping_table_prefix (outfp); - line_num =0 ; +/* Skip first line (header) */ + p =fgets (line, n, mapfp); +if (!p) + goto out; + + line_num =1 ;while (1 ) {char *cpuid, *version, *type, *fname;
@@ -521,8 +526,8 @@ static int process_mapfile(FILE *outfp, char *fpath)fprintf (outfp,"},\n" ); } +out:print_mapping_table_suffix (outfp); -return 0 ; }
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 11/22 perf pmu: Support alias descriptions
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Add support to print alias descriptions in perf list, which are taken from the generated event files.
The sorting code is changed to put the events with descriptions at the end. The descriptions are printed as possibly multiple word wrapped lines.
Example output:
% perf list
...
arith.fpu_div
[Divide operations executed]
arith.fpu_div_active
[Cycles when divider is busy executing divide operations]
Committer notes:
Further testing on a Broadwell machine (ThinkPad t450s), using these files:
$ find tools/perf/pmu-events/arch/x86/ tools/perf/pmu-events/arch/x86/ tools/perf/pmu-events/arch/x86/Broadwell tools/perf/pmu-events/arch/x86/Broadwell/Cache.json tools/perf/pmu-events/arch/x86/Broadwell/Other.json tools/perf/pmu-events/arch/x86/Broadwell/Frontend.json tools/perf/pmu-events/arch/x86/Broadwell/Virtual-Memory.json tools/perf/pmu-events/arch/x86/Broadwell/Pipeline.json tools/perf/pmu-events/arch/x86/Broadwell/Floating-point.json tools/perf/pmu-events/arch/x86/Broadwell/Memory.json tools/perf/pmu-events/arch/x86/mapfile.csv $
Taken from:
https://github.com/sukadev/linux/tree/json-code+data-v21/tools/perf/pmu-events/arch/x86/
to get this machinery to actually parse JSON files, generate $(OUTPUT)pmu-events/pmu-events.c, compile it and link it with perf, that will then use the table it contains, these files will be submitted right after this patchkit.
[acme@jouet linux]$ perf list page_walker
List of pre-defined events (to be used in -e):
page_walker_loads.dtlb_l1
[Number of DTLB page walker hits in the L1+FB]
page_walker_loads.dtlb_l2
[Number of DTLB page walker hits in the L2]
page_walker_loads.dtlb_l3
[Number of DTLB page walker hits in the L3 + XSNP]
page_walker_loads.dtlb_memory
[Number of DTLB page walker hits in Memory]
page_walker_loads.itlb_l1
[Number of ITLB page walker hits in the L1+FB]
page_walker_loads.itlb_l2
[Number of ITLB page walker hits in the L2]
page_walker_loads.itlb_l3
[Number of ITLB page walker hits in the L3 + XSNP]
[acme@jouet linux]$
--- tools/perf/util/pmu.c | 83 +++++++++++++++++++++++++++++++++++++++++---------- tools/perf/util/pmu.h | 1 + 2 files changed, 68 insertions(+), 16 deletions(-)
tools/perf/util/pmu.c +67 -16
@@ -222,7 +222,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, }static int __perf_pmu__new_alias (struct list_head *list,char *dir,char *name, -char *desc__maybe_unused ,char *val) +char *desc,char *val) {struct perf_pmu_alias *alias;int ret;
@@ -255,6 +255,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,perf_pmu__parse_snapshot (alias, dir, name); } + alias->desc = desc ?strdup (desc) :NULL ; +list_add_tail (&alias->list, list);return 0 ;
@@ -1043,11 +1045,42 @@ static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,return buf; } -static int cmp_string (const void *a,const void *b) +struct pair { +char *name; +char *desc; +}; + +static int cmp_pair (const void *a,const void *b) +{ +const struct pair *as = a; +const struct pair *bs = b; + +/* Put extra events last */ +if (!!as->desc != !!bs->desc) +return !!as->desc - !!bs->desc; +return strcmp (as->name, bs->name); +} + +static void wordwrap (char *s,int start,int max,int corr) { -const char *const *as = a; -const char *const *bs = b; -return strcmp (*as, *bs); +int column = start; +int n; + +while (*s) { +int wlen =strcspn (s," \t" ); + +if (column + wlen >= max && column > start) { +printf ("\n%*s" , start,"" ); + column = start + corr; + } + n =printf ("%s%.*s" , column > start ?" " :"" , wlen, s); +if (n <=0 ) +break ; + s += wlen; + column += n; +while (isspace (*s)) + s++; + } }void print_pmu_events (const char *event_glob,bool name_only)
@@ -1057,7 +1090,9 @@ void print_pmu_events(const char *event_glob, bool name_only)char buf[1024 ];int printed =0 ;int len, j; -char **aliases; +struct pair *aliases; +int numdesc =0 ; +int columns =78 ; pmu =NULL ; len =0 ;
@@ -1067,14 +1102,15 @@ void print_pmu_events(const char *event_glob, bool name_only)if (pmu->selectable) len++; } - aliases =zalloc (sizeof (char *) * len); + aliases =zalloc (sizeof (struct pair ) * len);if (!aliases) goto out_enomem; pmu =NULL ; j =0 ;while ((pmu =perf_pmu__scan (pmu)) !=NULL ) {list_for_each_entry (alias, &pmu->aliases, list) { -char *name =format_alias (buf,sizeof (buf), pmu, alias); +char *name = alias->desc ? alias->name : +format_alias (buf,sizeof (buf), pmu, alias);bool is_cpu = !strcmp (pmu->name,"cpu" ); if (event_glob != NULL &&
@@ -1083,12 +1119,19 @@ void print_pmu_events(const char *event_glob, bool name_only) event_glob))))continue ; -if (is_cpu && !name_only) +if (is_cpu && !name_only && !alias->desc) name =format_alias_or (buf,sizeof (buf), pmu, alias); - aliases[j] =strdup (name); -if (aliases[j] ==NULL ) + aliases[j].name = name; +if (is_cpu && !name_only && !alias->desc) + aliases[j].name =format_alias_or (buf, +sizeof (buf), + pmu, alias); + aliases[j].name =strdup (aliases[j].name); +if (!aliases[j].name) goto out_enomem; + + aliases[j].desc = alias->desc; j++; } if (pmu->selectable &&
@@ -1096,25 +1139,33 @@ void print_pmu_events(const char *event_glob, bool name_only)char *s;if (asprintf (&s,"%s//" , pmu->name) <0 ) goto out_enomem; - aliases[j] = s; + aliases[j].name = s; j++; } } len = j; -qsort (aliases, len,sizeof (char *), cmp_string); +qsort (aliases, len,sizeof (struct pair ), cmp_pair);for (j =0 ; j < len; j++) {if (name_only) { -printf ("%s " , aliases[j]); +printf ("%s " , aliases[j].name);continue ; } -printf (" %-50s [Kernel PMU event]\n" , aliases[j]); +if (aliases[j].desc) { +if (numdesc++ ==0 ) +printf ("\n" ); +printf (" %-50s\n" , aliases[j].name); +printf ("%*s" ,8 ,"[" ); +wordwrap (aliases[j].desc,8 , columns,0 ); +printf ("]\n" ); + }else +printf (" %-50s [Kernel PMU event]\n" , aliases[j].name); printed++; }if (printed &&pager_in_use ())printf ("\n" ); out_free:for (j =0 ; j < len; j++) -zfree (&aliases[j]); +zfree (&aliases[j].name);zfree (&aliases);return ;
tools/perf/util/pmu.h +1 -0
@@ -40,6 +40,7 @@ struct perf_pmu_info {struct perf_pmu_alias {char *name; +char *desc;struct list_head terms;/* HEAD struct parse_events_term -> list */ struct list_head list;/* ELEM */ char unit[UNIT_MAX_LEN +1 ];
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 12/22 perf tools: Query terminal width and use in perf list
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Automatically adapt the now wider and word wrapped perf list output to wider terminals. This requires querying the terminal before the auto pager takes over, and exporting this information from the pager subsystem.
--- tools/lib/subcmd/pager.c | 16 ++++++++++++++++ tools/lib/subcmd/pager.h | 1 + tools/perf/util/pmu.c | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-)
tools/lib/subcmd/pager.c +16 -0
@@ -3,6 +3,7 @@#include <stdio.h> #include <string.h> #include <signal.h> +#include <sys/ioctl.h> #include "pager.h" #include "run-command.h" #include "sigchain.h"
@@ -14,6 +15,7 @@*/ static int spawned_pager; +static int pager_columns;void pager_init (const char *pager_env) {
@@ -58,9 +60,12 @@ static void wait_for_pager_signal(int signo)void setup_pager (void ) {const char *pager =getenv (subcmd_config.pager_env); +struct winsize sz;if (!isatty (1 ))return ; +if (ioctl (1 ,TIOCGWINSZ , &sz) ==0 ) + pager_columns = sz.ws_col;if (!pager) pager =getenv ("PAGER" );if (!(pager ||access ("/usr/bin/pager" ,X_OK )))
@@ -98,3 +103,14 @@ int pager_in_use(void) {return spawned_pager; } + +int pager_get_columns (void ) +{ +char *s; + + s =getenv ("COLUMNS" ); +if (s) +return atoi (s); + +return (pager_columns ? pager_columns :80 ) -2 ; +}
tools/lib/subcmd/pager.h +1 -0
@@ -5,5 +5,6 @@ extern void pager_init(const char *pager_env);extern void setup_pager (void );extern int pager_in_use (void ); +extern int pager_get_columns (void );#endif /* __SUBCMD_PAGER_H */
tools/perf/util/pmu.c +2 -1
@@ -14,6 +14,7 @@#include "cpumap.h" #include "header.h" #include "pmu-events/pmu-events.h" +#include "cache.h" struct perf_pmu_format {char *name;
@@ -1092,7 +1093,7 @@ void print_pmu_events(const char *event_glob, bool name_only)int len, j;struct pair *aliases;int numdesc =0 ; -int columns =78 ; +int columns =pager_get_columns (); pmu =NULL ; len =0 ;
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 13/22 perf list: Add a --no-desc flag
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Add a --no-desc flag to 'perf list' to not print the event descriptions that were earlier added for JSON events. This may be useful to get a less crowded listing.
It's still default to print descriptions as that is the more useful default for most users.
--- tools/perf/Documentation/perf-list.txt | 8 +++++++- tools/perf/builtin-list.c | 14 +++++++++----- tools/perf/util/parse-events.c | 4 ++-- tools/perf/util/parse-events.h | 2 +- tools/perf/util/pmu.c | 4 ++-- tools/perf/util/pmu.h | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-)
tools/perf/Documentation/perf-list.txt +7 -1
@@ -8,13 +8,19 @@ perf-list - List all symbolic event types SYNOPSIS -------- [verse] -'perf list' [hw|sw|cache|tracepoint|pmu|event_glob] +'perf list' [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob] DESCRIPTION ----------- This command displays the symbolic event types which can be selected in the various perf commands with the -e option. +OPTIONS +------- +--no-desc:: +Don't print descriptions. + + [[EVENT_MODIFIERS]] EVENT MODIFIERS ---------------
tools/perf/builtin-list.c +9 -5
@@ -16,16 +16,20 @@#include "util/pmu.h" #include <subcmd/parse-options.h> +static bool desc_flag = true; +int cmd_list (int argc,const char **argv,const char *prefix__maybe_unused ) {int i;bool raw_dump = false;struct option list_options[] = {OPT_BOOLEAN (0 ,"raw-dump" , &raw_dump,"Dump raw events" ), +OPT_BOOLEAN ('d' ,"desc" , &desc_flag, +"Print extra event descriptions. --no-desc to not print." ),OPT_END () };const char *const list_usage[] = { -"perf list [hw|sw|cache|tracepoint|pmu|sdt|event_glob]" , +"perf list [--no-desc] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]" ,NULL };
@@ -40,7 +44,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)printf ("\nList of pre-defined events (to be used in -e):\n\n" );if (argc ==0 ) { -print_events (NULL , raw_dump); +print_events (NULL , raw_dump, !desc_flag);return 0 ; }
@@ -61,14 +65,14 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) strcmp(argv[i], "hwcache") == 0)print_hwcache_events (NULL , raw_dump); else if (strcmp(argv[i], "pmu") == 0) - print_pmu_events(NULL, raw_dump); + print_pmu_events(NULL, raw_dump, !desc_flag); else if (strcmp(argv[i], "sdt") == 0) print_sdt_events(NULL, NULL, raw_dump); else if ((sep = strchr(argv[i], ':')) != NULL) {int sep_idx;if (sep ==NULL ) { -print_events (argv[i], raw_dump); +print_events (argv[i], raw_dump, !desc_flag);continue ; } sep_idx = sep - argv[i];
@@ -90,7 +94,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)print_symbol_events (s,PERF_TYPE_SOFTWARE , event_symbols_sw,PERF_COUNT_SW_MAX , raw_dump);print_hwcache_events (s, raw_dump); -print_pmu_events (s, raw_dump); +print_pmu_events (s, raw_dump, !desc_flag);print_tracepoint_events (NULL , s, raw_dump);print_sdt_events (NULL , s, raw_dump);free (s);
tools/perf/util/parse-events.c +2 -2
@@ -2263,7 +2263,7 @@ out_enomem:/* * Print the help text for the event symbols: */ -void print_events (const char *event_glob,bool name_only) +void print_events (const char *event_glob,bool name_only,bool quiet_flag) {print_symbol_events (event_glob,PERF_TYPE_HARDWARE , event_symbols_hw,PERF_COUNT_HW_MAX , name_only);
@@ -2273,7 +2273,7 @@ void print_events(const char *event_glob, bool name_only)print_hwcache_events (event_glob, name_only); -print_pmu_events (event_glob, name_only); +print_pmu_events (event_glob, name_only, quiet_flag);if (event_glob !=NULL )return ;
tools/perf/util/parse-events.h +1 -1
@@ -172,7 +172,7 @@ void parse_events_update_lists(struct list_head *list_event,void parse_events_evlist_error (struct parse_events_evlist *data,int idx,const char *str); -void print_events (const char *event_glob,bool name_only); +void print_events (const char *event_glob,bool name_only,bool quiet);struct event_symbol {const char *symbol;
tools/perf/util/pmu.c +2 -2
@@ -1084,7 +1084,7 @@ static void wordwrap(char *s, int start, int max, int corr) } } -void print_pmu_events (const char *event_glob,bool name_only) +void print_pmu_events (const char *event_glob,bool name_only,bool quiet_flag) {struct perf_pmu *pmu;struct perf_pmu_alias *alias;
@@ -1151,7 +1151,7 @@ void print_pmu_events(const char *event_glob, bool name_only)printf ("%s " , aliases[j].name);continue ; } -if (aliases[j].desc) { +if (aliases[j].desc && !quiet_flag) {if (numdesc++ ==0 )printf ("\n" );printf (" %-50s\n" , aliases[j].name);
tools/perf/util/pmu.h +1 -1
@@ -72,7 +72,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);struct perf_pmu *perf_pmu__scan (struct perf_pmu *pmu); -void print_pmu_events (const char *event_glob,bool name_only); +void print_pmu_events (const char *event_glob,bool name_only,bool quiet);bool pmu_have_event (const char *pname,const char *name); int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 14/22 perf pmu: Add override support for event list CPUID
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Add a PERF_CPUID variable to override the CPUID of the current CPU (within the current architecture). This is useful for testing, so that all event lists can be tested on a single system.
--- tools/perf/util/pmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/perf/util/pmu.c +7 -1
@@ -501,10 +501,16 @@ static void pmu_add_cpu_aliases(struct list_head *head)struct pmu_event *pe;char *cpuid; - cpuid =get_cpuid_str (); + cpuid =getenv ("PERF_CPUID" ); +if (cpuid) + cpuid =strdup (cpuid); +if (!cpuid) + cpuid =get_cpuid_str ();if (!cpuid)return ; +pr_debug ("Using CPUID %s\n" , cpuid); + i =0 ;while (1 ) { map = &pmu_events_map[i++];
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 15/22 perf jevents: Add support for long descriptions
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
Implement support in jevents to parse long descriptions for events that may have them in the JSON files. A follow on patch will make this long description available to user through the 'perf list' command.
--- tools/perf/pmu-events/jevents.c | 32 ++++++++++++++++++++++++-------- tools/perf/pmu-events/jevents.h | 3 ++- tools/perf/pmu-events/pmu-events.h | 1 + 3 files changed, 27 insertions(+), 9 deletions(-)
tools/perf/pmu-events/jevents.c +24 -8
@@ -269,7 +269,7 @@ static void print_events_table_prefix(FILE *fp, const char *tblname) }static int print_events_table_entry (void *data,char *name,char *event, -char *desc) +char *desc,char *long_desc) {struct perf_entry_data *pd = data;FILE *outfp = pd->outfp;
@@ -285,6 +285,8 @@ static int print_events_table_entry(void *data, char *name, char *event,fprintf (outfp,"\t.event = \"%s\",\n" , event);fprintf (outfp,"\t.desc = \"%s\",\n" , desc);fprintf (outfp,"\t.topic = \"%s\",\n" , topic); +if (long_desc && long_desc[0 ]) +fprintf (outfp,"\t.long_desc = \"%s\",\n" , long_desc);fprintf (outfp,"},\n" );
@@ -306,7 +308,8 @@ static void print_events_table_suffix(FILE *outfp)/* Call func with each event in the json file */ int json_events (const char *fn, -int (*func)(void *data,char *name,char *event,char *desc), +int (*func)(void *data,char *name,char *event,char *desc, +char *long_desc),void *data) {int err = -EIO ;
@@ -325,6 +328,8 @@ int json_events(const char *fn, tok = tokens +1 ;for (i =0 ; i < tokens->size; i++) {char *event =NULL , *desc =NULL , *name =NULL ; +char *long_desc =NULL ; +char *extra_desc =NULL ;struct msrmap *msr =NULL ;jsmntok_t *msrval =NULL ;jsmntok_t *precise =NULL ;
@@ -350,6 +355,10 @@ int json_events(const char *fn, }else if (json_streq (map, field,"BriefDescription" )) {addfield (map, &desc,"" ,"" , val);fixdesc (desc); + }else if (json_streq (map, field, +"PublicDescription" )) { +addfield (map, &long_desc,"" ,"" , val); +fixdesc (long_desc); }else if (json_streq (map, field,"PEBS" ) && nz) { precise = val; }else if (json_streq (map, field,"MSRIndex" ) && nz) {
@@ -358,10 +367,10 @@ int json_events(const char *fn, msrval = val; }else if (json_streq (map, field,"Errata" ) && !json_streq (map, val,"null" )) { -addfield (map, &desc,". " , +addfield (map, &extra_desc,". " ," Spec update: " , val); }else if (json_streq (map, field,"Data_LA" ) && nz) { -addfield (map, &desc,". " , +addfield (map, &extra_desc,". " ," Supports address when precise" ,NULL ); }
@@ -369,19 +378,26 @@ int json_events(const char *fn, }if (precise && desc && !strstr (desc,"(Precise Event)" )) {if (json_streq (map, precise,"2" )) -addfield (map, &desc," " ,"(Must be precise)" , -NULL ); +addfield (map, &extra_desc," " , +"(Must be precise)" ,NULL );else -addfield (map, &desc," " , +addfield (map, &extra_desc," " ,"(Precise event)" ,NULL ); } +if (desc && extra_desc) +addfield (map, &desc," " , extra_desc,NULL ); +if (long_desc && extra_desc) +addfield (map, &long_desc," " , extra_desc,NULL );if (msr !=NULL )addfield (map, &event,"," , msr->pname, msrval);fixname (name); - err =func (data, name, event, desc); + + err =func (data, name, event, desc, long_desc);free (event);free (desc);free (name); +free (long_desc); +free (extra_desc);if (err)break ; tok += j;
tools/perf/pmu-events/jevents.h +2 -1
@@ -2,7 +2,8 @@#define JEVENTS_H 1int json_events (const char *fn, -int (*func)(void *data,char *name,char *event,char *desc), +int (*func)(void *data,char *name,char *event,char *desc, +char *long_desc),void *data);char *get_cpu_str (void );
tools/perf/pmu-events/pmu-events.h +1 -0
@@ -9,6 +9,7 @@ struct pmu_event {const char *event;const char *desc;const char *topic; +const char *long_desc; };/*
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 16/22 perf list: Support long jevents descriptions
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
Previously we were dropping the useful longer descriptions that some events have in the event list completely. This patch makes them appear with perf list.
Old perf list:
baclears:
baclears.all
[Counts the number of baclears]
vs new:
perf list -v:
...
baclears:
baclears.all
[The BACLEARS event counts the number of times the front end is
resteered, mainly when the Branch Prediction Unit cannot provide a correct prediction and this is corrected by the Branch Address Calculator at the front end. The BACLEARS.ANY event counts the number of baclears for any type of branch]
--- tools/perf/Documentation/perf-list.txt | 6 +++++- tools/perf/builtin-list.c | 16 +++++++++++----- tools/perf/util/parse-events.c | 5 +++-- tools/perf/util/parse-events.h | 3 ++- tools/perf/util/pmu.c | 15 ++++++++++----- tools/perf/util/pmu.h | 4 +++- 6 files changed, 34 insertions(+), 15 deletions(-)
tools/perf/Documentation/perf-list.txt +5 -1
@@ -8,7 +8,7 @@ perf-list - List all symbolic event types SYNOPSIS -------- [verse] -'perf list' [--no-desc] [hw|sw|cache|tracepoint|pmu|event_glob] +'perf list' [--no-desc] [--long-desc] [hw|sw|cache|tracepoint|pmu|event_glob] DESCRIPTION -----------
@@ -20,6 +20,10 @@ OPTIONS --no-desc:: Don't print descriptions. +-v:: +--long-desc:: +Print longer event descriptions. + [[EVENT_MODIFIERS]] EVENT MODIFIERS
tools/perf/builtin-list.c +11 -5
@@ -22,14 +22,17 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) {int i;bool raw_dump = false; +bool long_desc_flag = false;struct option list_options[] = {OPT_BOOLEAN (0 ,"raw-dump" , &raw_dump,"Dump raw events" ),OPT_BOOLEAN ('d' ,"desc" , &desc_flag,"Print extra event descriptions. --no-desc to not print." ), +OPT_BOOLEAN ('v' ,"long-desc" , &long_desc_flag, +"Print longer event descriptions." ),OPT_END () };const char *const list_usage[] = { -"perf list [--no-desc] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]" , +"perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]" ,NULL };
@@ -44,7 +47,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)printf ("\nList of pre-defined events (to be used in -e):\n\n" );if (argc ==0 ) { -print_events (NULL , raw_dump, !desc_flag); +print_events (NULL , raw_dump, !desc_flag, long_desc_flag);return 0 ; }
@@ -65,14 +68,16 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) strcmp(argv[i], "hwcache") == 0)print_hwcache_events (NULL , raw_dump); else if (strcmp(argv[i], "pmu") == 0) - print_pmu_events(NULL, raw_dump, !desc_flag); +print_pmu_events (NULL , raw_dump, !desc_flag, + long_desc_flag); else if (strcmp(argv[i], "sdt") == 0) print_sdt_events(NULL, NULL, raw_dump); else if ((sep = strchr(argv[i], ':')) != NULL) { int sep_idx; if (sep == NULL) { -print_events (argv[i], raw_dump, !desc_flag); + print_events(argv[i], raw_dump, !desc_flag, + long_desc_flag); continue; } sep_idx = sep - argv[i];
@@ -94,7 +99,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)print_symbol_events (s,PERF_TYPE_SOFTWARE , event_symbols_sw,PERF_COUNT_SW_MAX , raw_dump);print_hwcache_events (s, raw_dump); -print_pmu_events (s, raw_dump, !desc_flag); +print_pmu_events (s, raw_dump, !desc_flag, + long_desc_flag);print_tracepoint_events (NULL , s, raw_dump);print_sdt_events (NULL , s, raw_dump);free (s);
tools/perf/util/parse-events.c +3 -2
@@ -2263,7 +2263,8 @@ out_enomem:/* * Print the help text for the event symbols: */ -void print_events (const char *event_glob,bool name_only,bool quiet_flag) +void print_events (const char *event_glob,bool name_only,bool quiet_flag, +bool long_desc) {print_symbol_events (event_glob,PERF_TYPE_HARDWARE , event_symbols_hw,PERF_COUNT_HW_MAX , name_only);
@@ -2273,7 +2274,7 @@ void print_events(const char *event_glob, bool name_only, bool quiet_flag)print_hwcache_events (event_glob, name_only); -print_pmu_events (event_glob, name_only, quiet_flag); +print_pmu_events (event_glob, name_only, quiet_flag, long_desc);if (event_glob !=NULL )return ;
tools/perf/util/parse-events.h +2 -1
@@ -172,7 +172,8 @@ void parse_events_update_lists(struct list_head *list_event,void parse_events_evlist_error (struct parse_events_evlist *data,int idx,const char *str); -void print_events (const char *event_glob,bool name_only,bool quiet); +void print_events (const char *event_glob,bool name_only,bool quiet, +bool long_desc);struct event_symbol {const char *symbol;
tools/perf/util/pmu.c +10 -5
@@ -223,7 +223,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, }static int __perf_pmu__new_alias (struct list_head *list,char *dir,char *name, -char *desc,char *val) +char *desc,char *val,char *long_desc) {struct perf_pmu_alias *alias;int ret;
@@ -257,6 +257,8 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, } alias->desc = desc ?strdup (desc) :NULL ; + alias->long_desc = long_desc ?strdup (long_desc) : + desc ?strdup (desc) :NULL ;list_add_tail (&alias->list, list);
@@ -274,7 +276,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI buf[ret] =0 ; -return __perf_pmu__new_alias (list, dir, name,NULL , buf); +return __perf_pmu__new_alias (list, dir, name,NULL , buf,NULL ); }static inline bool pmu_alias_info_file (char *name)
@@ -532,7 +534,8 @@ static void pmu_add_cpu_aliases(struct list_head *head)/* need type casts to override 'const' */ __perf_pmu__new_alias (head,NULL , (char *)pe->name, - (char *)pe->desc, (char *)pe->event); + (char *)pe->desc, (char *)pe->event, + (char *)pe->long_desc); } out:
@@ -1090,7 +1093,8 @@ static void wordwrap(char *s, int start, int max, int corr) } } -void print_pmu_events (const char *event_glob,bool name_only,bool quiet_flag) +void print_pmu_events (const char *event_glob,bool name_only,bool quiet_flag, +bool long_desc) {struct perf_pmu *pmu;struct perf_pmu_alias *alias;
@@ -1138,7 +1142,8 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag)if (!aliases[j].name) goto out_enomem; - aliases[j].desc = alias->desc; + aliases[j].desc = long_desc ? alias->long_desc : + alias->desc; j++; } if (pmu->selectable &&
tools/perf/util/pmu.h +3 -1
@@ -41,6 +41,7 @@ struct perf_pmu_info {struct perf_pmu_alias {char *name;char *desc; +char *long_desc;struct list_head terms;/* HEAD struct parse_events_term -> list */ struct list_head list;/* ELEM */ char unit[UNIT_MAX_LEN +1 ];
@@ -72,7 +73,8 @@ int perf_pmu__format_parse(char *dir, struct list_head *head);struct perf_pmu *perf_pmu__scan (struct perf_pmu *pmu); -void print_pmu_events (const char *event_glob,bool name_only,bool quiet); +void print_pmu_events (const char *event_glob,bool name_only,bool quiet, +bool long_desc);bool pmu_have_event (const char *pname,const char *name); int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 17/22 perf list jevents: Add support for event list topics
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Add support to group the output of perf list by the Topic field in the JSON file.
Example output:
% perf list
...
Cache:
l1d.replacement
[L1D data line replacements]
l1d_pend_miss.pending
[L1D miss oustandings duration in cycles]
l1d_pend_miss.pending_cycles
[Cycles with L1D load Misses outstanding]
l2_l1d_wb_rqsts.all
[Not rejected writebacks from L1D to L2 cache lines in any state]
l2_l1d_wb_rqsts.hit_e
[Not rejected writebacks from L1D to L2 cache lines in E state]
l2_l1d_wb_rqsts.hit_m
[Not rejected writebacks from L1D to L2 cache lines in M state]
...
Pipeline:
arith.fpu_div
[Divide operations executed]
arith.fpu_div_active
[Cycles when divider is busy executing divide operations]
baclears.any
[Counts the total number when the front end is resteered, mainly when the BPU cannot provide a correct prediction and this is corrected by other branch handling mechanisms at the front end]
br_inst_exec.all_branches
[Speculative and retired branches]
br_inst_exec.all_conditional
[Speculative and retired macro-conditional branches]
br_inst_exec.all_direct_jmp
[Speculative and retired macro-unconditional branches excluding calls and indirects]
br_inst_exec.all_direct_near_call
[Speculative and retired direct near calls]
br_inst_exec.all_indirect_jump_non_call_ret
--- tools/perf/util/pmu.c | 37 +++++++++++++++++++++++++++---------- tools/perf/util/pmu.h | 1 + 2 files changed, 28 insertions(+), 10 deletions(-)
tools/perf/util/pmu.c +27 -10
@@ -223,7 +223,8 @@ static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias, }static int __perf_pmu__new_alias (struct list_head *list,char *dir,char *name, -char *desc,char *val,char *long_desc) +char *desc,char *val,char *long_desc, +char *topic) {struct perf_pmu_alias *alias;int ret;
@@ -259,6 +260,7 @@ static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name, alias->desc = desc ?strdup (desc) :NULL ; alias->long_desc = long_desc ?strdup (long_desc) : desc ?strdup (desc) :NULL ; + alias->topic = topic ?strdup (topic) :NULL ;list_add_tail (&alias->list, list);
@@ -276,7 +278,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI buf[ret] =0 ; -return __perf_pmu__new_alias (list, dir, name,NULL , buf,NULL ); +return __perf_pmu__new_alias (list, dir, name,NULL , buf,NULL ,NULL ); }static inline bool pmu_alias_info_file (char *name)
@@ -535,7 +537,7 @@ static void pmu_add_cpu_aliases(struct list_head *head)/* need type casts to override 'const' */ __perf_pmu__new_alias (head,NULL , (char *)pe->name, (char *)pe->desc, (char *)pe->event, - (char *)pe->long_desc); + (char *)pe->long_desc, (char *)pe->topic); } out:
@@ -1055,19 +1057,26 @@ static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,return buf; } -struct pair { +struct sevent {char *name;char *desc; +char *topic; }; -static int cmp_pair (const void *a,const void *b) +static int cmp_sevent (const void *a,const void *b) { -const struct pair *as = a; -const struct pair *bs = b; +const struct sevent *as = a; +const struct sevent *bs = b;/* Put extra events last */ if (!!as->desc != !!bs->desc)return !!as->desc - !!bs->desc; +if (as->topic && bs->topic) { +int n =strcmp (as->topic, bs->topic); + +if (n) +return n; + }return strcmp (as->name, bs->name); }
@@ -1101,9 +1110,10 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,char buf[1024 ];int printed =0 ;int len, j; -struct pair *aliases; +struct sevent *aliases;int numdesc =0 ;int columns =pager_get_columns (); +char *topic =NULL ; pmu =NULL ; len =0 ;
@@ -1113,7 +1123,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,if (pmu->selectable) len++; } - aliases =zalloc (sizeof (struct pair ) * len); + aliases =zalloc (sizeof (struct sevent ) * len);if (!aliases) goto out_enomem; pmu =NULL ;
@@ -1144,6 +1154,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, aliases[j].desc = long_desc ? alias->long_desc : alias->desc; + aliases[j].topic = alias->topic; j++; } if (pmu->selectable &&
@@ -1156,7 +1167,7 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag, } } len = j; -qsort (aliases, len,sizeof (struct pair ), cmp_pair); +qsort (aliases, len,sizeof (struct sevent ), cmp_sevent);for (j =0 ; j < len; j++) {if (name_only) {printf ("%s " , aliases[j].name);
@@ -1165,6 +1176,12 @@ void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,if (aliases[j].desc && !quiet_flag) {if (numdesc++ ==0 )printf ("\n" ); +if (aliases[j].topic && (!topic || +strcmp (topic, aliases[j].topic))) { +printf ("%s%s:\n" , topic ?"\n" :"" , + aliases[j].topic); + topic = aliases[j].topic; + }printf (" %-50s\n" , aliases[j].name);printf ("%*s" ,8 ,"[" );wordwrap (aliases[j].desc,8 , columns,0 );
tools/perf/util/pmu.h +1 -0
@@ -42,6 +42,7 @@ struct perf_pmu_alias {char *name;char *desc;char *long_desc; +char *topic;struct list_head terms;/* HEAD struct parse_events_term -> list */ struct list_head list;/* ELEM */ char unit[UNIT_MAX_LEN +1 ];
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 18/22 perf tools: Add README for info on parsing JSON/map files
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
--- tools/perf/pmu-events/README | 147 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 tools/perf/pmu-events/README
tools/perf/pmu-events/README new file +147 -0
@@ -0,0 +1,147 @@ + +The contents of this directory allow users to specify PMU events in their +CPUs by their symbolic names rather than raw event codes (see example below). + +The main program in this directory, is the 'jevents', which is built and +executed _BEFORE_ the perf binary itself is built. + +The 'jevents' program tries to locate and process JSON files in the directory +tree tools/perf/pmu-events/arch/foo. + + - Regular files with '.json' extension in the name are assumed to be + JSON files, each of which describes a set of PMU events. + + - Regular files with basename starting with 'mapfile.csv' are assumed + to be a CSV file that maps a specific CPU to its set of PMU events. + (see below for mapfile format) + + - Directories are traversed, but all other files are ignored. + +The PMU events supported by a CPU model are expected to grouped into topics +such as Pipelining, Cache, Memory, Floating-point etc. All events for a topic +should be placed in a separate JSON file - where the file name identifies +the topic. Eg: "Floating-point.json". + +All the topic JSON files for a CPU model/family should be in a separate +sub directory. Thus for the Silvermont X86 CPU: + + $ ls tools/perf/pmu-events/arch/x86/Silvermont_core + Cache.json Memory.json Virtual-Memory.json + Frontend.json Pipeline.json + +Using the JSON files and the mapfile, 'jevents' generates the C source file, +'pmu-events.c', which encodes the two sets of tables: + + - Set of 'PMU events tables' for all known CPUs in the architecture, + (one table like the following, per JSON file; table name 'pme_power8' + is derived from JSON file name, 'power8.json'). + + struct pmu_event pme_power8[] = { + + ... + + { + .name = "pm_1plus_ppc_cmpl", + .event = "event=0x100f2", + .desc = "1 or more ppc insts finished,", + }, + + ... + } + + - A 'mapping table' that maps each CPU of the architecture, to its + 'PMU events table' + + struct pmu_events_map pmu_events_map[] = { + { + .cpuid = "004b0000", + .version = "1", + .type = "core", + .table = pme_power8 + }, + ... + + }; + +After the 'pmu-events.c' is generated, it is compiled and the resulting +'pmu-events.o' is added to 'libperf.a' which is then used to build perf. + +NOTES: + 1. Several CPUs can support same set of events and hence use a common + JSON file. Hence several entries in the pmu_events_map[] could map + to a single 'PMU events table'. + + 2. The 'pmu-events.h' has an extern declaration for the mapping table + and the generated 'pmu-events.c' defines this table. + + 3. _All_ known CPU tables for architecture are included in the perf + binary. + +At run time, perf determines the actual CPU it is running on, finds the +matching events table and builds aliases for those events. This allows +users to specify events by their name: + + $ perf stat -e pm_1plus_ppc_cmpl sleep 1 + +where 'pm_1plus_ppc_cmpl' is a Power8 PMU event. + +In case of errors when processing files in the tools/perf/pmu-events/arch +directory, 'jevents' tries to create an empty mapping file to allow the perf +build to succeed even if the PMU event aliases cannot be used. + +However some errors in processing may cause the perf build to fail. + +Mapfile format +=============== + +The mapfile enables multiple CPU models to share a single set of PMU events. +It is required even if such mapping is 1:1. + +The mapfile.csv format is expected to be: + + Header line + CPUID,Version,Dir/path/name,Type + +where: + + Comma: + is the required field delimiter (i.e other fields cannot + have commas within them). + + Comments: + Lines in which the first character is either '\n' or '#' + are ignored. + + Header line + The header line is the first line in the file, which is + always _IGNORED_. It can empty. + + CPUID: + CPUID is an arch-specific char string, that can be used + to identify CPU (and associate it with a set of PMU events + it supports). Multiple CPUIDS can point to the same + File/path/name.json. + + Example: + CPUID == 'GenuineIntel-6-2E' (on x86). + CPUID == '004b0100' (PVR value in Powerpc) + Version: + is the Version of the mapfile. + + Dir/path/name: + is the pathname to the directory containing the CPU's JSON + files, relative to the directory containing the mapfile.csv + + Type: + indicates whether the events or "core" or "uncore" events. + + + Eg: + + $ grep Silvermont tools/perf/pmu-events/arch/x86/mapfile.csv + GenuineIntel-6-37,V13,Silvermont_core,core + GenuineIntel-6-4D,V13,Silvermont_core,core + GenuineIntel-6-4C,V13,Silvermont_core,core + + i.e the three CPU models use the JSON files (i.e PMU events) listed + in the directory 'tools/perf/pmu-events/arch/x86/Silvermont_core'.
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 19/22 perf tools: Allow period= in perf stat CPU event descriptions.
In reply to Arnaldo Carvalho de MeloFrom: Sukadev Bhattiprolu <[email protected]>
This avoids the JSON PMU events parser having to know whether its aliases are for perf stat or perf record.
--- tools/perf/util/parse-events.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/parse-events.c +1 -0
@@ -924,6 +924,7 @@ config_term_avail(int term_type, struct parse_events_error *err)case PARSE_EVENTS__TERM_TYPE_CONFIG1 :case PARSE_EVENTS__TERM_TYPE_CONFIG2 :case PARSE_EVENTS__TERM_TYPE_NAME : +case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD :return true;default :if (!err)
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 20/22 perf tools: Make alias matching case-insensitive
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Make alias matching the events parser case-insensitive. This is useful with the JSON events. perf uses lower case events, but the CPU manuals generally use upper case event names. The JSON files use lower case by default too. But if we search case insensitively then users can cut-n-paste the upper case event names.
So the following works:
% perf stat -e BR_INST_EXEC.TAKEN_INDIRECT_NEAR_CALL true
Performance counter stats for 'true':
305 BR_INST_EXEC.TAKEN_INDIRECT_NEAR_CALL
0.000492799 seconds time elapsed--- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/parse-events.c +1 -1
@@ -1459,7 +1459,7 @@ comp_pmu(const void *p1, const void *p2)struct perf_pmu_event_symbol *pmu1 = (struct perf_pmu_event_symbol *) p1;struct perf_pmu_event_symbol *pmu2 = (struct perf_pmu_event_symbol *) p2; -return strcmp (pmu1->symbol, pmu2->symbol); +return strcasecmp (pmu1->symbol, pmu2->symbol); }static void perf_pmu__parse_cleanup (void )
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 21/22 perf pmu-events: Fix fixed counters on Intel
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
The JSON event lists use a different encoding for fixed counters than perf for instructions and cycles (ref-cycles is ok)
This lead to some common events like inst_retired.any or cpu_clk_unhalted.thread not counting, when specified with their JSON name.
Special case these events in the jevents conversion process. I prefer to not touch the JSON files for this, as it's intended that standard JSON files can be just dropped into the perf build without changes.
--- tools/perf/pmu-events/jevents.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
tools/perf/pmu-events/jevents.c +24 -1
@@ -306,6 +306,29 @@ static void print_events_table_suffix(FILE *outfp) close_table =0 ; } +static struct fixed { +const char *name; +const char *event; +} fixed[] = { + {"inst_retired.any" ,"event=0xc0" }, + {"cpu_clk_unhalted.thread" ,"event=0x3c" }, + {"cpu_clk_unhalted.thread_any" ,"event=0x3c,any=1" }, + {NULL ,NULL }, +}; + +/* +* Handle different fixed counter encodings between JSON and perf. +*/ +static char *real_event (const char *name,char *event) +{ +int i; + +for (i =0 ; fixed[i].name; i++) +if (!strcasecmp (name, fixed[i].name)) +return (char *)fixed[i].event; +return event; +} +/* Call func with each event in the json file */ int json_events(const char *fn, int (*func)(void *data, char *name, char *event, char *desc,
@@ -392,7 +415,7 @@ int json_events(const char *fn,addfield (map, &event,"," , msr->pname, msrval);fixname (name); - err =func (data, name, event, desc, long_desc); + err =func (data, name,real_event (name, event), desc, long_desc);free (event);free (desc);free (name);
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerPATCH 22/22 perf pmu-events: Add Skylake frontend MSR support
In reply to Arnaldo Carvalho de MeloFrom: Andi Kleen <[email protected]>
Add support for the "frontend" extra MSR on Skylake in the JSON conversion.
--- tools/perf/pmu-events/jevents.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/pmu-events/jevents.c +1 -0
@@ -127,6 +127,7 @@ static struct msrmap { { "0x3F6", "ldlat=" }, { "0x1A6", "offcore_rsp=" }, { "0x1A7", "offcore_rsp=" }, + { "0x3F7", "frontend=" }, { NULL, NULL } };
Signature · 1 line
2.7.4
Quoted 277 lines · Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
- Arnaldo
Build and test stats at the end of the message.
The following changes since commit
41aad2a6d4fcdda8d73c9739daf7a9f3f49499d6:Merge tag 'perf-core-for-mingo-20160929' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linuxinto perf/core (2016-09-29 19:09:58 +0200)are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.gittags/perf-core-for-mingo-20161003for you to fetch changes up to
b42c7369e3f451e22c2b0be5d193955498d37546:perf pmu-events: Add Skylake frontend MSR support (2016-10-03 21:52:01 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:- Allow vendors to provide JSON files describing PMU events, that then get parsed to generate C tables that are linked against perf, allowing the use of the names in their documentations, such as:
# perf list l1dList of pre-defined events (to be used in -e):
Cache:
l1d.replacement
[L1D data line replacements]
l1d_pend_miss.fb_full
[Cycles a demand request was blocked due to Fill Buffers inavailability]
l1d_pend_miss.pending
[L1D miss oustandings duration in cycles]
l1d_pend_miss.pending_cycles
[Cycles with L1D load Misses outstanding]
l1d_pend_miss.pending_cycles_any
[Cycles with L1D load Misses outstanding from any thread on physical core]
l2_trans.l1d_wb
[L1D writebacks that access L2 cache]Pipeline:
cycle_activity.cycles_l1d_miss
[Cycles while L1 cache miss demand load is outstanding]
cycle_activity.cycles_l1d_pending
[Cycles while L1 cache miss demand load is outstanding]
cycle_activity.stalls_l1d_miss
[Execution stalls while L1 cache miss demand load is outstanding]
cycle_activity.stalls_l1d_pending
[Execution stalls while L1 cache miss demand load is outstanding]The above example was done on a Broadwell based ThinkPad t450s after downloading and installing such JSON files which will be added to the
tools/perf/pmu-events/directory in a subsequent patchkit.Now one can use those names with -e/--event in all 'perf tools'. (Andi Kleen, Sukadev Bhattiprolu)
- Add a missing pointer dereference in 'perf probe' (Colin Ian King)
- Add support for building host programs to be used in generating files to be used in the build process, such as fixdep and jevents, fixing the usage of these features in a cross compilation setup (Jiri Olsa)
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>----------------------------------------------------------------
Andi Kleen (12):
perf tools: Add jsmn `jasmine' JSON parser perf jevents: Program to convert JSON file perf tools: Support CPU id matching for x86 v2 perf jevents: Handle header line in mapfile perf pmu: Support alias descriptions
perf tools: Query terminal width and use in perf list perf list: Add a --no-desc flag
perf pmu: Add override support for event list CPUID perf list jevents: Add support for event list topics perf tools: Make alias matching case-insensitive perf pmu-events: Fix fixed counters on Intel perf pmu-events: Add Skylake frontend MSR supportArnaldo Carvalho de Melo (1):
perf tools: Experiment with cppcheckColin Ian King (1):
perf probe: Check if *ptr2 is zero and not ptr2Jiri Olsa (2):
tools build: Add support for host programs format tools build: Make fixdep a hostprogSukadev Bhattiprolu (6):
perf pmu: Usepmu_eventstable to create aliases perf powerpc: Support CPU ID matching for Powerpc perf jevents: Add support for long descriptions perf list: Support long jevents descriptions
perf tools: Add README for info on parsing JSON/map files perf tools: Allow period= in perf stat CPU event descriptions.tools/build/Build | 2 + tools/build/Build.include | 5 + tools/build/Makefile | 8 +- tools/build/Makefile.build | 19 +- tools/build/Makefile.include | 4 - tools/lib/subcmd/pager.c | 16 + tools/lib/subcmd/pager.h | 1 + tools/perf/Documentation/perf-list.txt | 12 +- tools/perf/Makefile.perf | 34 +- tools/perf/arch/powerpc/util/header.c | 11 + tools/perf/arch/x86/util/header.c | 24 +- tools/perf/builtin-list.c | 20 +- tools/perf/pmu-events/Build | 13 + tools/perf/pmu-events/README | 147 ++++++ tools/perf/pmu-events/jevents.c | 812 +++++++++++++++++++++++++++++++++ tools/perf/pmu-events/jevents.h | 18 + tools/perf/pmu-events/jsmn.c | 313 +++++++++++++ tools/perf/pmu-events/jsmn.h | 67 +++ tools/perf/pmu-events/json.c | 162 +++++++ tools/perf/pmu-events/json.h | 38 ++ tools/perf/pmu-events/pmu-events.h | 37 ++ tools/perf/util/evlist.c | 12 +- tools/perf/util/evsel.c | 3 +- tools/perf/util/header.h | 1 + tools/perf/util/machine.c | 6 +- tools/perf/util/parse-events.c | 8 +- tools/perf/util/parse-events.h | 3 +- tools/perf/util/pmu.c | 176 ++++++- tools/perf/util/pmu.h | 6 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/strbuf.h | 3 +- tools/perf/util/thread.c | 9 +- 32 files changed, 1926 insertions(+), 66 deletions(-) create mode 100644 tools/perf/pmu-events/Build create mode 100644 tools/perf/pmu-events/README create mode 100644 tools/perf/pmu-events/jevents.c create mode 100644 tools/perf/pmu-events/jevents.h create mode 100644 tools/perf/pmu-events/jsmn.c create mode 100644 tools/perf/pmu-events/jsmn.h create mode 100644 tools/perf/pmu-events/json.c create mode 100644 tools/perf/pmu-events/json.h create mode 100644 tools/perf/pmu-events/pmu-events.h# time dm 1 alpine:3.4: Ok 2 android-ndk:r12b-arm: Ok 3 archlinux:latest: Ok 4 centos:5: Ok 5 centos:6: Ok 6 centos:7: Ok 7 debian:7: Ok 8 debian:8: Ok 9 debian:experimental: Ok 10 fedora:20: Ok 11 fedora:21: Ok 12 fedora:22: Ok 13 fedora:23: Ok 14 fedora:24: Ok 15 fedora:24-x-ARC-uClibc: Ok 16 fedora:rawhide: Ok 17 mageia:5: Ok 18 opensuse:13.2: Ok 19 opensuse:42.1: Ok 20 opensuse:tumbleweed: Ok 21 ubuntu:12.04.5: Ok 22 ubuntu:14.04: Ok 23 ubuntu:14.04.4: Ok 24 ubuntu:15.10: Ok 25 ubuntu:16.04: Ok 26 ubuntu:16.04-x-arm: Ok 27 ubuntu:16.04-x-arm64: Ok 28 ubuntu:16.04-x-powerpc: Ok 29 ubuntu:16.04-x-powerpc64: Ok 30 ubuntu:16.04-x-powerpc64el: Ok 31 ubuntu:16.04-x-s390: Ok 32 ubuntu:16.10: Okreal 33m23.855s
user 0m2.128s
sys 0m2.305s
## perf test 1: vmlinux symtab matches kallsyms : Ok 2: detect openat syscall event : Ok 3: detect openat syscall event on all cpus : Ok 4: read samples using the mmap interface : Ok 5: parse events tests : Ok 6: Validate PERF_RECORD_* events & perf_sample fields : Ok 7: Test perf pmu format parsing : Ok 8: Test dso data read : Ok 9: Test dso data cache : Ok 10: Test dso data reopen : Ok 11: roundtrip evsel->name check : Ok 12: Check parsing of sched tracepoints fields : Ok 13: Generate and check syscalls:sys_enter_openat event fields: Ok 14: struct perf_event_attr setup : Ok 15: Test matching and linking multiple hists : Ok 16: Try 'import perf' in python, checking link problems : Ok 17: Test breakpoint overflow signal handler : Ok 18: Test breakpoint overflow sampling : Ok 19: Test number of exit event of a simple workload : Ok 20: Test software clock events have valid period values : Ok 21: Test object code reading : Ok 22: Test sample parsing : Ok 23: Test using a dummy software event to keep tracking : Ok 24: Test parsing with no sample_id_all bit set : Ok 25: Test filtering hist entries : Ok 26: Test mmap thread lookup : Ok 27: Test thread mg sharing : Ok 28: Test output sorting of hist entries : Ok 29: Test cumulation of child hist entries : Ok 30: Test tracking with sched_switch : Ok 31: Filter fds with revents mask in a fdarray : Ok 32: Add fd to a fdarray, making it autogrow : Ok 33: Test kmod_path__parse function : Ok 34: Test thread map : Ok 35: Test LLVM searching and compiling : 35.1: Basic BPF llvm compiling test : Ok 35.2: Test kbuild searching : Ok 35.3: Compile source for BPF prologue generation test : Ok 35.4: Compile source for BPF relocation test : Ok 36: Test topology in session : Ok 37: Test BPF filter : 37.1: Test basic BPF filtering : Ok 37.2: Test BPF prologue generation : Ok 37.3: Test BPF relocation checker : Ok 38: Test thread map synthesize : Ok 39: Test cpu map synthesize : Ok 40: Test stat config synthesize : Ok 41: Test stat synthesize : Ok 42: Test stat round synthesize : Ok 43: Test attr update synthesize : Ok 44: Test events times : Ok 45: Test backward reading from ring buffer : Ok 46: Test cpu map print : Ok 47: Test SDT event probing : Ok 48: Test is_printable_array function : Ok 49: Test bitmap print : Ok 50: x86 rdpmc test : Ok 51: Test converting perf time to TSC : Ok 52: Test dwarf unwind : Ok 53: Test x86 instruction decoder - new instructions : Ok 54: Test intel cqm nmi context read : Skip #$ make -C tools/perf build-test make: Entering directory '/home/acme/git/linux/tools/perf' - tarpkg: ./tests/perf-targz-src-pkg . make_no_libperl_O: make NO_LIBPERL=1 make_no_newt_O: make NO_NEWT=1 make_no_slang_O: make NO_SLANG=1 make_no_libnuma_O: make NO_LIBNUMA=1 make_with_babeltrace_O: make LIBBABELTRACE=1 make_install_prefix_slash_O: make install prefix=/tmp/krava/ make_no_libbpf_O: make NO_LIBBPF=1 make_no_demangle_O: make NO_DEMANGLE=1 make_install_bin_O: make install-bin make_install_O: make install make_no_libbionic_O: make NO_LIBBIONIC=1 make_no_libunwind_O: make NO_LIBUNWIND=1 make_no_libaudit_O: make NO_LIBAUDIT=1 make_no_libpython_O: make NO_LIBPYTHON=1 make_tags_O: make tags make_perf_o_O: make perf.o make_static_O: make LDFLAGS=-static make_clean_all_O: make clean all make_install_prefix_O: make install prefix=/tmp/krava make_help_O: make help make_util_map_o_O: make util/map.o make_no_ui_O: make NO_NEWT=1 NO_SLANG=1 NO_GTK2=1 make_no_libdw_dwarf_unwind_O: make NO_LIBDW_DWARF_UNWIND=1 make_minimal_O: make NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 NO_LIBCRYPTO=1 NO_SDT=1 make_no_backtrace_O: make NO_BACKTRACE=1
Quoted 8 lines
make_debug_O: make DEBUG=1
make_no_libelf_O: make NO_LIBELF=1
make_no_scripts_O: make NO_LIBPYTHON=1 NO_LIBPERL=1
make_no_auxtrace_O: make NO_AUXTRACE=1
make_doc_O: make doc
make_util_pmu_bison_o_O: make util/pmu-bison.o
make_no_gtk2_O: make NO_GTK2=1
OKPulled, thanks a lot Arnaldo!
Ingo