perf updates for 4.9
Linus,
please pull the latest perf-urgent-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-for-linus
This update contains:
- Handle uretprobe placement proper on little endian PPC64
- Fix buffer handling in libtraceevent.
- Add a missing pointer derefence in perf probe.
- Fix the build of host tools in cross builds.
- Fix Intel PT timestamp handling
- Synchronize memcpy, cpufeatures and bpf headers with the kernel headers.
- Support for vendor supplied JSON files describing PMU events.
- A new set of tool tips.
- Initial work for clang/llvm support.
- Address some style issues found by cppcheck
Thanks,
tglx
------------------>
Adrian Hunter (2):
perf intel-pt: Fix estimated timestamps for cycle-accurate mode perf intel-pt: Fix MTC timestamp calculation for large MTC periods
Andi Kleen (13):
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 perf jevents: Fix Intel JSON fixed counter conversions
Arnaldo Carvalho de Melo (4):
perf tools: Experiment with cppcheck
perf bench mem: Sync memcpy assembly sources with the kernel
tools: Synchronize tools/arch/x86/include/asm/cpufeatures.h
tools: Synchronize tools/include/uapi/linux/bpf.h
Colin Ian King (1):
perf probe: Check if *ptr2 is zero and not ptr2
Donghyun Kim (1):
perf report/top: Add a tip about system-wide collection from all CPUs
Jiri Olsa (2):
tools build: Add support for host programs format tools build: Make fixdep a hostprog
Kim SeonYoung (1):
perf report/top: Add a tip about source line numbers with overhead
Nambong Ha (1):
perf top/report: Add tips about a list option
Namhyung Kim (1):
tools lib traceevent: Fix kbuffer_read_at_offset()
Ravi Bangoria (1):
perf uretprobe ppc64le: Fix probe location
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.
Wang Nan (2):
tools build: Support compiling C++ source file tools build: Add feature detection for g++
tools/arch/x86/include/asm/cpufeatures.h | 1 - tools/arch/x86/lib/memcpy_64.S | 6 +- tools/build/Build | 2 + tools/build/Build.include | 6 + tools/build/Makefile | 8 +- tools/build/Makefile.build | 26 +- tools/build/Makefile.feature | 2 +- tools/build/Makefile.include | 4 - tools/build/feature/Makefile | 10 +- tools/build/feature/test-cxx.cpp | 15 + tools/include/uapi/linux/bpf.h | 4 +- tools/lib/subcmd/pager.c | 16 + tools/lib/subcmd/pager.h | 1 + tools/lib/traceevent/kbuffer-parse.c | 1 + tools/perf/Documentation/perf-list.txt | 12 +- tools/perf/Documentation/tips.txt | 4 + tools/perf/Makefile.perf | 34 +- tools/perf/arch/powerpc/util/header.c | 11 + tools/perf/arch/powerpc/util/sym-handling.c | 3 +- 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 | 814 +++++++++++++++++++++ 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 + .../perf/util/intel-pt-decoder/intel-pt-decoder.c | 38 + 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 +- 42 files changed, 2011 insertions(+), 75 deletions(-) create mode 100644 tools/build/feature/test-cxx.cpp 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
tools/arch/x86/include/asm/cpufeatures.h +0 -1
@@ -106,7 +106,6 @@#define X86_FEATURE_APERFMPERF ( 3*32+28)/* APERFMPERF */ #define X86_FEATURE_EAGER_FPU ( 3*32+29)/* "eagerfpu" Non lazy FPU restore */ #define X86_FEATURE_NONSTOP_TSC_S3 ( 3*32+30)/* TSC doesn't stop in S3 state */ -#define X86_FEATURE_MCE_RECOVERY ( 3*32+31)/* cpu has recoverable machine checks */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 ( 4*32+ 0)/* "pni" SSE-3 */
tools/arch/x86/lib/memcpy_64.S +3 -3
@@ -181,11 +181,11 @@ ENDPROC(memcpy_orig) #ifndef CONFIG_UML /* - * memcpy_mcsafe - memory copy with machine check exception handling + * memcpy_mcsafe_unrolled - memory copy with machine check exception handling * Note that we only catch machine checks when reading the source addresses. * Writes to target are posted and don't generate machine checks. */ -ENTRY(memcpy_mcsafe) +ENTRY(memcpy_mcsafe_unrolled) cmpl $8, %edx /* Less than 8 bytes? Go to byte copy loop */ jb .L_no_whole_words
@@ -273,7 +273,7 @@ ENTRY(memcpy_mcsafe) .L_done_memcpy_trap: xorq %rax, %rax ret -ENDPROC(memcpy_mcsafe) +ENDPROC(memcpy_mcsafe_unrolled) .section .fixup, "ax" /* Return -EFAULT for any failure */
tools/build/Build +2 -0
@@ -1 +1,3 @@ +hostprogs := fixdep + fixdep-y := fixdep.o
tools/build/Build.include +6 -0
@@ -90,3 +90,9 @@ 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)) +cxx_flags = -Wp,-MD,$(depfile),-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(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 +7 -1
@@ -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
@@ -36,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.build +22 -4
@@ -58,6 +58,12 @@ 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_cxx_o_c = CXX $@ + cmd_cxx_o_c = $(CXX) $(cxx_flags) -c -o $@ $< + quiet_cmd_cpp_i_c = CPP $@ cmd_cpp_i_c = $(CC) $(c_flags) -E -o $@ $<
@@ -70,16 +76,28 @@ 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: %.cpp FORCE + $(call rule_mkdir) + $(call if_changed_dep,cxx_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 +137,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) @:
tools/build/Makefile.feature +1 -1
@@ -7,7 +7,7 @@ endif feature_check = $(eval $(feature_check_code)) define feature_check_code - feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0) + feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" CXXFLAGS="$(EXTRA_CXXFLAGS) $(FEATURE_CHECK_CXXFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0) endef feature_set = $(eval $(feature_set_code))
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
tools/build/feature/Makefile +9 -1
@@ -46,11 +46,13 @@ FILES= \ test-lzma.bin \ test-bpf.bin \ test-get_cpuid.bin \ - test-sdt.bin + test-sdt.bin \ + test-cxx.bin FILES := $(addprefix $(OUTPUT),$(FILES)) CC := $(CROSS_COMPILE)gcc -MD +CXX := $(CROSS_COMPILE)g++ -MD PKG_CONFIG := $(CROSS_COMPILE)pkg-config all: $(FILES)
@@ -58,6 +60,9 @@ all: $(FILES) __BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 +__BUILDXX = $(CXX) $(CXXFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) + BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 + ############################### $(OUTPUT)test-all.bin:
@@ -217,6 +222,9 @@ $(OUTPUT)test-bpf.bin: $(OUTPUT)test-sdt.bin: $(BUILD) +$(OUTPUT)test-cxx.bin: + $(BUILDXX) -std=gnu++11 + -include $(OUTPUT)*.d ###############################
tools/build/feature/test-cxx.cpp new file +15 -0
@@ -0,0 +1,15 @@ +#include <iostream> +#include <memory> + +static void print_str(std::string s) +{ + std::cout << s << std::endl; +} + +int main() +{ + std::string s("Hello World!"); + print_str(std::move(s)); + std::cout << "|" << s << "|" << std::endl; + return 0; +}
tools/include/uapi/linux/bpf.h +2 -2
@@ -339,7 +339,7 @@ enum bpf_func_id { BPF_FUNC_skb_change_type,/** -* bpf_skb_in_cgroup(skb, map, index) - Check cgroup2 membership of skb +* bpf_skb_under_cgroup(skb, map, index) - Check cgroup2 membership of skb * @skb: pointer to skb * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type * @index: index of the cgroup in the bpf_map
@@ -348,7 +348,7 @@ enum bpf_func_id {* == 1 skb succeeded the cgroup2 descendant test * < 0 error */ - BPF_FUNC_skb_in_cgroup, + BPF_FUNC_skb_under_cgroup,/** * bpf_get_hash_recalc(skb)
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/lib/traceevent/kbuffer-parse.c +1 -0
@@ -622,6 +622,7 @@ void *kbuffer_read_at_offset(struct kbuffer *kbuf, int offset,/* Reset the buffer */ kbuffer_load_subbuffer (kbuf, kbuf->subbuffer); + data =kbuffer_read_event (kbuf, ts);while (kbuf->curr < offset) { data =kbuffer_next_event (kbuf, ts);
tools/perf/Documentation/perf-list.txt +11 -1
@@ -8,13 +8,23 @@ perf-list - List all symbolic event types SYNOPSIS -------- [verse] -'perf list' [hw|sw|cache|tracepoint|pmu|event_glob] +'perf list' [--no-desc] [--long-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. + +-v:: +--long-desc:: +Print longer event descriptions. + + [[EVENT_MODIFIERS]] EVENT MODIFIERS ---------------
tools/perf/Documentation/tips.txt +4 -0
@@ -28,3 +28,7 @@ To change sampling frequency to 100 Hz: perf record -F 100 See assembly instructions with percentage: perf annotate <symbol> If you prefer Intel style assembly, try: perf annotate -M intel For hierarchical output, try: perf report --hierarchy +Order by the overhead of source file name and line number: perf report -s srcline +System-wide collection from all CPUs: perf record -a +Show current config key-value pairs: perf config --list +Show user configuration overrides: perf config --user --list
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/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; +}
tools/perf/arch/powerpc/util/sym-handling.c +2 -1
@@ -82,7 +82,8 @@ void arch__fix_tev_from_maps(struct perf_probe_event *pev,* * In addition, we shouldn't specify an offset for kretprobes. */ -if (pev->point.offset || pev->point.retprobe || !map || !sym) +if (pev->point.offset || (!pev->uprobes && pev->point.retprobe) || + !map || !sym)return ; lep_offset =PPC64_LOCAL_ENTRY_OFFSET (sym->arch_sym);
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; +}
tools/perf/builtin-list.c +15 -5
@@ -16,16 +16,23 @@#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; +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 [hw|sw|cache|tracepoint|pmu|sdt|event_glob]" , +"perf list [<options>] [hw|sw|cache|tracepoint|pmu|sdt|event_glob]" ,NULL };
@@ -40,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); +print_events (NULL , raw_dump, !desc_flag, long_desc_flag);return 0 ; }
@@ -61,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); +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); + print_events(argv[i], raw_dump, !desc_flag, + long_desc_flag); continue; } sep_idx = sep - argv[i];
@@ -90,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); +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/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/README new file +147 -0
147 lines not on this page · raw message
tools/perf/pmu-events/jevents.c new file +814 -0
814 lines not on this page · raw message
tools/perf/pmu-events/jevents.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef JEVENTS_H +#define JEVENTS_H 1 + +int json_events (const char *fn, +int (*func)(void *data,char *name,char *event,char *desc, +char *long_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/jsmn.c new file +313 -0
313 lines not on this page · raw message
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 +38 -0
@@ -0,0 +1,38 @@ +#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__) + +#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) ( \ +{ \ + const typeof(y) __y = y; \ + (((x) + (__y - 1)) / __y) * __y; \ +} \ +) +#endif + +#endif
tools/perf/pmu-events/pmu-events.h new file +37 -0
@@ -0,0 +1,37 @@ +#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; +const char *long_desc; +}; + +/* +* +* 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
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/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/intel-pt-decoder/intel-pt-decoder.c +38 -0
@@ -90,6 +90,7 @@ struct intel_pt_decoder {bool pge;bool have_tma;bool have_cyc; +bool fixup_last_mtc;uint64_t pos;uint64_t last_ip;uint64_t ip;
@@ -586,10 +587,31 @@ struct intel_pt_calc_cyc_to_tsc_info {uint64_t tsc_timestamp;uint64_t timestamp;bool have_tma; +bool fixup_last_mtc;bool from_mtc;double cbr_cyc_to_tsc; }; +/* +* MTC provides a 8-bit slice of CTC but the TMA packet only provides the lower +* 16 bits of CTC. If mtc_shift > 8 then some of the MTC bits are not in the CTC +* provided by the TMA packet. Fix-up the last_mtc calculated from the TMA +* packet by copying the missing bits from the current MTC assuming the least +* difference between the two, and that the current MTC comes after last_mtc. +*/ +static void intel_pt_fixup_last_mtc (uint32_t mtc,int mtc_shift, +uint32_t *last_mtc) +{ +uint32_t first_missing_bit =1U << (16 - mtc_shift); +uint32_t mask = ~(first_missing_bit -1 ); + + *last_mtc |= mtc & mask; +if (*last_mtc >= mtc) { + *last_mtc -= first_missing_bit; + *last_mtc &=0xff ; + } +} +static int intel_pt_calc_cyc_cb (struct intel_pt_pkt_info *pkt_info) {struct intel_pt_decoder *decoder = pkt_info->decoder;
@@ -619,6 +641,11 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info)return 0 ; mtc = pkt_info->packet.payload; +if (decoder->mtc_shift >8 && data->fixup_last_mtc) { + data->fixup_last_mtc = false; +intel_pt_fixup_last_mtc (mtc, decoder->mtc_shift, + &data->last_mtc); + }if (mtc > data->last_mtc) mtc_delta = mtc - data->last_mtc;else
@@ -687,6 +714,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) data->ctc_delta =0 ; data->have_tma = true; + data->fixup_last_mtc = true;return 0 ;
@@ -753,6 +781,7 @@ static void intel_pt_calc_cyc_to_tsc(struct intel_pt_decoder *decoder, .tsc_timestamp = decoder->tsc_timestamp, .timestamp = decoder->timestamp, .have_tma = decoder->have_tma, + .fixup_last_mtc = decoder->fixup_last_mtc, .from_mtc = from_mtc, .cbr_cyc_to_tsc = 0, };
@@ -1271,6 +1300,7 @@ static void intel_pt_calc_tma(struct intel_pt_decoder *decoder) } decoder->ctc_delta =0 ; decoder->have_tma = true; + decoder->fixup_last_mtc = true;intel_pt_log ("CTC timestamp " x64_fmt" last MTC %#x CTC rem %#x\n" , decoder->ctc_timestamp, decoder->last_mtc, ctc_rem); }
@@ -1285,6 +1315,12 @@ static void intel_pt_calc_mtc_timestamp(struct intel_pt_decoder *decoder) mtc = decoder->packet.payload; +if (decoder->mtc_shift >8 && decoder->fixup_last_mtc) { + decoder->fixup_last_mtc = false; +intel_pt_fixup_last_mtc (mtc, decoder->mtc_shift, + &decoder->last_mtc); + } +if (mtc > decoder->last_mtc) mtc_delta = mtc - decoder->last_mtc;else
@@ -1353,6 +1389,8 @@ static void intel_pt_calc_cyc_timestamp(struct intel_pt_decoder *decoder) timestamp, decoder->timestamp); else decoder->timestamp = timestamp; + + decoder->timestamp_insn_cnt =0 ; }/* Walk PSB+ packets when already in sync. */
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/parse-events.c +5 -3
@@ -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)
@@ -1458,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 )
@@ -2263,7 +2264,8 @@ 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, +bool long_desc) {print_symbol_events (event_glob,PERF_TYPE_HARDWARE , event_symbols_hw,PERF_COUNT_HW_MAX , name_only);
@@ -2273,7 +2275,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, 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); +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 +158 -18
268 lines not on this page · raw message
tools/perf/util/pmu.h +5 -1
@@ -40,6 +40,9 @@ struct perf_pmu_info {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 ];
@@ -71,7 +74,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); +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,
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 ;
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);