aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2018-05-16 11:56:43 -0400
committerIngo Molnar <mingo@kernel.org>2018-05-16 11:56:43 -0400
commit5aafae8d097e2161ee5c6a12ad532100f8885d2b (patch)
tree6ac544e378616c0522a0162d5ed1d42bab7efe81 /tools
parenteaeb1f4d892936133c5f8d3aafb36b7f384fe59c (diff)
parent7a36a287de9fbb1ba906e70573d3f2315f7fd609 (diff)
Merge tag 'perf-core-for-mingo-4.18-20180516' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo: - Add '-e intel_pt//u' test to the 'parse-events' 'perf test' entry, to help avoiding regressions in the events parser such as one that caused a revert in v4.17-rc (Arnaldo Carvalho de Melo) - Fix NULL return handling in bpf__prepare_load() (YueHaibing) - Warn about 'perf buildid-cache --purge-all' failures (Ravi Bangoria) - Add infrastructure to help in writing eBPF C programs to be used with '-e name.c' type events in tools such as 'record' and 'trace', with headers for common constructs and an examples directory that will get populated as we add more such helpers and the 'perf bpf' branch that Jiri Olsa has been working on (Arnaldo Carvalho de Melo) - Handle uncore event aliases in small groups properly (Kan Liang) - Use the "_stest" symbol to identify the kernel map when loading kcore (Adrian Hunter) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/arch/arm/include/uapi/asm/kvm.h6
-rw-r--r--tools/arch/arm64/include/uapi/asm/kvm.h6
-rw-r--r--tools/arch/x86/include/asm/cpufeatures.h1
-rw-r--r--tools/bpf/Makefile2
-rw-r--r--tools/bpf/bpf_dbg.c7
-rw-r--r--tools/include/uapi/linux/kvm.h7
-rw-r--r--tools/perf/Makefile.config14
-rw-r--r--tools/perf/Makefile.perf8
-rw-r--r--tools/perf/bench/numa.c2
-rw-r--r--tools/perf/builtin-buildid-cache.c8
-rw-r--r--tools/perf/examples/bpf/5sec.c49
-rw-r--r--tools/perf/examples/bpf/empty.c3
-rw-r--r--tools/perf/include/bpf/bpf.h13
-rw-r--r--tools/perf/pmu-events/arch/x86/mapfile.csv1
-rw-r--r--tools/perf/tests/parse-events.c13
-rwxr-xr-xtools/perf/tests/shell/record+probe_libc_inet_pton.sh2
-rw-r--r--tools/perf/util/Build2
-rw-r--r--tools/perf/util/annotate.c3
-rw-r--r--tools/perf/util/bpf-loader.c6
-rw-r--r--tools/perf/util/cs-etm.c28
-rw-r--r--tools/perf/util/evsel.h1
-rw-r--r--tools/perf/util/llvm-utils.c19
-rw-r--r--tools/perf/util/parse-events.c132
-rw-r--r--tools/perf/util/parse-events.h7
-rw-r--r--tools/perf/util/parse-events.y14
-rw-r--r--tools/perf/util/symbol.c16
-rw-r--r--tools/power/acpi/Makefile.config1
-rw-r--r--tools/testing/selftests/bpf/test_progs.c4
-rw-r--r--tools/testing/selftests/lib.mk8
-rw-r--r--tools/testing/selftests/net/Makefile3
-rw-r--r--tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json11
31 files changed, 347 insertions, 50 deletions
diff --git a/tools/arch/arm/include/uapi/asm/kvm.h b/tools/arch/arm/include/uapi/asm/kvm.h
index 2ba95d6fe852..caae4843cb70 100644
--- a/tools/arch/arm/include/uapi/asm/kvm.h
+++ b/tools/arch/arm/include/uapi/asm/kvm.h
@@ -195,6 +195,12 @@ struct kvm_arch_memory_slot {
195#define KVM_REG_ARM_VFP_FPINST 0x1009 195#define KVM_REG_ARM_VFP_FPINST 0x1009
196#define KVM_REG_ARM_VFP_FPINST2 0x100A 196#define KVM_REG_ARM_VFP_FPINST2 0x100A
197 197
198/* KVM-as-firmware specific pseudo-registers */
199#define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT)
200#define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM | KVM_REG_SIZE_U64 | \
201 KVM_REG_ARM_FW | ((r) & 0xffff))
202#define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0)
203
198/* Device Control API: ARM VGIC */ 204/* Device Control API: ARM VGIC */
199#define KVM_DEV_ARM_VGIC_GRP_ADDR 0 205#define KVM_DEV_ARM_VGIC_GRP_ADDR 0
200#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 206#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
diff --git a/tools/arch/arm64/include/uapi/asm/kvm.h b/tools/arch/arm64/include/uapi/asm/kvm.h
index 9abbf3044654..04b3256f8e6d 100644
--- a/tools/arch/arm64/include/uapi/asm/kvm.h
+++ b/tools/arch/arm64/include/uapi/asm/kvm.h
@@ -206,6 +206,12 @@ struct kvm_arch_memory_slot {
206#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2) 206#define KVM_REG_ARM_TIMER_CNT ARM64_SYS_REG(3, 3, 14, 3, 2)
207#define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2) 207#define KVM_REG_ARM_TIMER_CVAL ARM64_SYS_REG(3, 3, 14, 0, 2)
208 208
209/* KVM-as-firmware specific pseudo-registers */
210#define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT)
211#define KVM_REG_ARM_FW_REG(r) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
212 KVM_REG_ARM_FW | ((r) & 0xffff))
213#define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0)
214
209/* Device Control API: ARM VGIC */ 215/* Device Control API: ARM VGIC */
210#define KVM_DEV_ARM_VGIC_GRP_ADDR 0 216#define KVM_DEV_ARM_VGIC_GRP_ADDR 0
211#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1 217#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
diff --git a/tools/arch/x86/include/asm/cpufeatures.h b/tools/arch/x86/include/asm/cpufeatures.h
index d554c11e01ff..578793e97431 100644
--- a/tools/arch/x86/include/asm/cpufeatures.h
+++ b/tools/arch/x86/include/asm/cpufeatures.h
@@ -320,6 +320,7 @@
320#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */ 320#define X86_FEATURE_AVX512_VPOPCNTDQ (16*32+14) /* POPCNT for vectors of DW/QW */
321#define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */ 321#define X86_FEATURE_LA57 (16*32+16) /* 5-level page tables */
322#define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */ 322#define X86_FEATURE_RDPID (16*32+22) /* RDPID instruction */
323#define X86_FEATURE_CLDEMOTE (16*32+25) /* CLDEMOTE instruction */
323 324
324/* AMD-defined CPU features, CPUID level 0x80000007 (EBX), word 17 */ 325/* AMD-defined CPU features, CPUID level 0x80000007 (EBX), word 17 */
325#define X86_FEATURE_OVERFLOW_RECOV (17*32+ 0) /* MCA overflow recovery support */ 326#define X86_FEATURE_OVERFLOW_RECOV (17*32+ 0) /* MCA overflow recovery support */
diff --git a/tools/bpf/Makefile b/tools/bpf/Makefile
index 1ea545965ee3..53b60ad452f5 100644
--- a/tools/bpf/Makefile
+++ b/tools/bpf/Makefile
@@ -76,6 +76,8 @@ $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.le
76 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ 76 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
77 77
78$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c 78$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
79$(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c
80$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c
79 81
80clean: bpftool_clean 82clean: bpftool_clean
81 $(call QUIET_CLEAN, bpf-progs) 83 $(call QUIET_CLEAN, bpf-progs)
diff --git a/tools/bpf/bpf_dbg.c b/tools/bpf/bpf_dbg.c
index 4f254bcc4423..61b9aa5d6415 100644
--- a/tools/bpf/bpf_dbg.c
+++ b/tools/bpf/bpf_dbg.c
@@ -1063,7 +1063,7 @@ static int cmd_load_pcap(char *file)
1063 1063
1064static int cmd_load(char *arg) 1064static int cmd_load(char *arg)
1065{ 1065{
1066 char *subcmd, *cont, *tmp = strdup(arg); 1066 char *subcmd, *cont = NULL, *tmp = strdup(arg);
1067 int ret = CMD_OK; 1067 int ret = CMD_OK;
1068 1068
1069 subcmd = strtok_r(tmp, " ", &cont); 1069 subcmd = strtok_r(tmp, " ", &cont);
@@ -1073,7 +1073,10 @@ static int cmd_load(char *arg)
1073 bpf_reset(); 1073 bpf_reset();
1074 bpf_reset_breakpoints(); 1074 bpf_reset_breakpoints();
1075 1075
1076 ret = cmd_load_bpf(cont); 1076 if (!cont)
1077 ret = CMD_ERR;
1078 else
1079 ret = cmd_load_bpf(cont);
1077 } else if (matches(subcmd, "pcap") == 0) { 1080 } else if (matches(subcmd, "pcap") == 0) {
1078 ret = cmd_load_pcap(cont); 1081 ret = cmd_load_pcap(cont);
1079 } else { 1082 } else {
diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h
index 1065006c9bf5..b02c41e53d56 100644
--- a/tools/include/uapi/linux/kvm.h
+++ b/tools/include/uapi/linux/kvm.h
@@ -676,6 +676,13 @@ struct kvm_ioeventfd {
676 __u8 pad[36]; 676 __u8 pad[36];
677}; 677};
678 678
679#define KVM_X86_DISABLE_EXITS_MWAIT (1 << 0)
680#define KVM_X86_DISABLE_EXITS_HTL (1 << 1)
681#define KVM_X86_DISABLE_EXITS_PAUSE (1 << 2)
682#define KVM_X86_DISABLE_VALID_EXITS (KVM_X86_DISABLE_EXITS_MWAIT | \
683 KVM_X86_DISABLE_EXITS_HTL | \
684 KVM_X86_DISABLE_EXITS_PAUSE)
685
679/* for KVM_ENABLE_CAP */ 686/* for KVM_ENABLE_CAP */
680struct kvm_enable_cap { 687struct kvm_enable_cap {
681 /* in */ 688 /* in */
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index ae7dc46e8f8a..b5ac356ba323 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -885,6 +885,8 @@ endif
885 885
886# Among the variables below, these: 886# Among the variables below, these:
887# perfexecdir 887# perfexecdir
888# perf_include_dir
889# perf_examples_dir
888# template_dir 890# template_dir
889# mandir 891# mandir
890# infodir 892# infodir
@@ -904,6 +906,8 @@ bindir = $(abspath $(prefix)/$(bindir_relative))
904mandir = share/man 906mandir = share/man
905infodir = share/info 907infodir = share/info
906perfexecdir = libexec/perf-core 908perfexecdir = libexec/perf-core
909perf_include_dir = lib/include/perf
910perf_examples_dir = lib/examples/perf
907sharedir = $(prefix)/share 911sharedir = $(prefix)/share
908template_dir = share/perf-core/templates 912template_dir = share/perf-core/templates
909STRACE_GROUPS_DIR = share/perf-core/strace/groups 913STRACE_GROUPS_DIR = share/perf-core/strace/groups
@@ -934,6 +938,8 @@ bindir_SQ = $(subst ','\'',$(bindir))
934mandir_SQ = $(subst ','\'',$(mandir)) 938mandir_SQ = $(subst ','\'',$(mandir))
935infodir_SQ = $(subst ','\'',$(infodir)) 939infodir_SQ = $(subst ','\'',$(infodir))
936perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) 940perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
941perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir))
942perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
937template_dir_SQ = $(subst ','\'',$(template_dir)) 943template_dir_SQ = $(subst ','\'',$(template_dir))
938htmldir_SQ = $(subst ','\'',$(htmldir)) 944htmldir_SQ = $(subst ','\'',$(htmldir))
939tipdir_SQ = $(subst ','\'',$(tipdir)) 945tipdir_SQ = $(subst ','\'',$(tipdir))
@@ -944,14 +950,20 @@ srcdir_SQ = $(subst ','\'',$(srcdir))
944 950
945ifneq ($(filter /%,$(firstword $(perfexecdir))),) 951ifneq ($(filter /%,$(firstword $(perfexecdir))),)
946perfexec_instdir = $(perfexecdir) 952perfexec_instdir = $(perfexecdir)
953perf_include_instdir = $(perf_include_dir)
954perf_examples_instdir = $(perf_examples_dir)
947STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) 955STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
948tip_instdir = $(tipdir) 956tip_instdir = $(tipdir)
949else 957else
950perfexec_instdir = $(prefix)/$(perfexecdir) 958perfexec_instdir = $(prefix)/$(perfexecdir)
959perf_include_instdir = $(prefix)/$(perf_include_dir)
960perf_examples_instdir = $(prefix)/$(perf_examples_dir)
951STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) 961STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
952tip_instdir = $(prefix)/$(tipdir) 962tip_instdir = $(prefix)/$(tipdir)
953endif 963endif
954perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) 964perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
965perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
966perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
955STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) 967STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
956tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) 968tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
957 969
@@ -999,6 +1011,8 @@ $(call detected_var,ETC_PERFCONFIG_SQ)
999$(call detected_var,STRACE_GROUPS_DIR_SQ) 1011$(call detected_var,STRACE_GROUPS_DIR_SQ)
1000$(call detected_var,prefix_SQ) 1012$(call detected_var,prefix_SQ)
1001$(call detected_var,perfexecdir_SQ) 1013$(call detected_var,perfexecdir_SQ)
1014$(call detected_var,perf_include_dir_SQ)
1015$(call detected_var,perf_examples_dir_SQ)
1002$(call detected_var,tipdir_SQ) 1016$(call detected_var,tipdir_SQ)
1003$(call detected_var,srcdir_SQ) 1017$(call detected_var,srcdir_SQ)
1004$(call detected_var,LIBDIR) 1018$(call detected_var,LIBDIR)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 83e453de36f8..c63a3971d719 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -767,6 +767,14 @@ ifndef NO_JVMTI
767endif 767endif
768 $(call QUIET_INSTALL, libexec) \ 768 $(call QUIET_INSTALL, libexec) \
769 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' 769 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
770ifndef NO_LIBBPF
771 $(call QUIET_INSTALL, lib) \
772 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
773 $(INSTALL) include/bpf/*.h '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
774 $(call QUIET_INSTALL, lib) \
775 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
776 $(INSTALL) examples/bpf/*.c '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
777endif
770 $(call QUIET_INSTALL, perf-archive) \ 778 $(call QUIET_INSTALL, perf-archive) \
771 $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' 779 $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
772 $(call QUIET_INSTALL, perf-with-kcore) \ 780 $(call QUIET_INSTALL, perf-with-kcore) \
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index 944070e98a2c..63eb49082774 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -175,7 +175,7 @@ static const struct option options[] = {
175 OPT_UINTEGER('s', "nr_secs" , &p0.nr_secs, "max number of seconds to run (default: 5 secs)"), 175 OPT_UINTEGER('s', "nr_secs" , &p0.nr_secs, "max number of seconds to run (default: 5 secs)"),
176 OPT_UINTEGER('u', "usleep" , &p0.sleep_usecs, "usecs to sleep per loop iteration"), 176 OPT_UINTEGER('u', "usleep" , &p0.sleep_usecs, "usecs to sleep per loop iteration"),
177 177
178 OPT_BOOLEAN('R', "data_reads" , &p0.data_reads, "access the data via writes (can be mixed with -W)"), 178 OPT_BOOLEAN('R', "data_reads" , &p0.data_reads, "access the data via reads (can be mixed with -W)"),
179 OPT_BOOLEAN('W', "data_writes" , &p0.data_writes, "access the data via writes (can be mixed with -R)"), 179 OPT_BOOLEAN('W', "data_writes" , &p0.data_writes, "access the data via writes (can be mixed with -R)"),
180 OPT_BOOLEAN('B', "data_backwards", &p0.data_backwards, "access the data backwards as well"), 180 OPT_BOOLEAN('B', "data_backwards", &p0.data_backwards, "access the data backwards as well"),
181 OPT_BOOLEAN('Z', "data_zero_memset", &p0.data_zero_memset,"access the data via glibc bzero only"), 181 OPT_BOOLEAN('Z', "data_zero_memset", &p0.data_zero_memset,"access the data via glibc bzero only"),
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 7a7403913b57..115110a4796a 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -488,8 +488,12 @@ int cmd_buildid_cache(int argc, const char **argv)
488 } 488 }
489 } 489 }
490 490
491 if (purge_all) 491 if (purge_all) {
492 ret = build_id_cache__purge_all(); 492 if (build_id_cache__purge_all()) {
493 pr_warning("Couldn't remove some caches. Error: %s.\n",
494 str_error_r(errno, sbuf, sizeof(sbuf)));
495 }
496 }
493 497
494 if (missing_filename) 498 if (missing_filename)
495 ret = build_id_cache__fprintf_missing(session, stdout); 499 ret = build_id_cache__fprintf_missing(session, stdout);
diff --git a/tools/perf/examples/bpf/5sec.c b/tools/perf/examples/bpf/5sec.c
new file mode 100644
index 000000000000..b9c203219691
--- /dev/null
+++ b/tools/perf/examples/bpf/5sec.c
@@ -0,0 +1,49 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 Description:
4
5 . Disable strace like syscall tracing (--no-syscalls), or try tracing
6 just some (-e *sleep).
7
8 . Attach a filter function to a kernel function, returning when it should
9 be considered, i.e. appear on the output.
10
11 . Run it system wide, so that any sleep of >= 5 seconds and < than 6
12 seconds gets caught.
13
14 . Ask for callgraphs using DWARF info, so that userspace can be unwound
15
16 . While this is running, run something like "sleep 5s".
17
18 . If we decide to add tv_nsec as well, then it becomes:
19
20 int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec)
21
22 I.e. add where it comes from (rqtp->tv_nsec) and where it will be
23 accessible in the function body (nsec)
24
25 # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/
26 0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5
27 hrtimer_nanosleep ([kernel.kallsyms])
28 __x64_sys_nanosleep ([kernel.kallsyms])
29 do_syscall_64 ([kernel.kallsyms])
30 entry_SYSCALL_64 ([kernel.kallsyms])
31 __GI___nanosleep (/usr/lib64/libc-2.26.so)
32 rpl_nanosleep (/usr/bin/sleep)
33 xnanosleep (/usr/bin/sleep)
34 main (/usr/bin/sleep)
35 __libc_start_main (/usr/lib64/libc-2.26.so)
36 _start (/usr/bin/sleep)
37 ^C#
38
39 Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo <acme@redhat.com>
40*/
41
42#include <bpf.h>
43
44int probe(hrtimer_nanosleep, rqtp->tv_sec)(void *ctx, int err, long sec)
45{
46 return sec == 5;
47}
48
49license(GPL);
diff --git a/tools/perf/examples/bpf/empty.c b/tools/perf/examples/bpf/empty.c
new file mode 100644
index 000000000000..3776d26db9e7
--- /dev/null
+++ b/tools/perf/examples/bpf/empty.c
@@ -0,0 +1,3 @@
1#include <bpf.h>
2
3license(GPL);
diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h
new file mode 100644
index 000000000000..dd764ad5efdf
--- /dev/null
+++ b/tools/perf/include/bpf/bpf.h
@@ -0,0 +1,13 @@
1// SPDX-License-Identifier: GPL-2.0
2#ifndef _PERF_BPF_H
3#define _PERF_BPF_H
4#define SEC(NAME) __attribute__((section(NAME), used))
5
6#define probe(function, vars) \
7 SEC(#function "=" #function " " #vars) function
8
9#define license(name) \
10char _license[] SEC("license") = #name; \
11int _version SEC("version") = LINUX_VERSION_CODE;
12
13#endif /* _PERF_BPF_H */
diff --git a/tools/perf/pmu-events/arch/x86/mapfile.csv b/tools/perf/pmu-events/arch/x86/mapfile.csv
index 93656f2fd53a..7e3cce3bcf3b 100644
--- a/tools/perf/pmu-events/arch/x86/mapfile.csv
+++ b/tools/perf/pmu-events/arch/x86/mapfile.csv
@@ -29,7 +29,6 @@ GenuineIntel-6-4D,v13,silvermont,core
29GenuineIntel-6-4C,v13,silvermont,core 29GenuineIntel-6-4C,v13,silvermont,core
30GenuineIntel-6-2A,v15,sandybridge,core 30GenuineIntel-6-2A,v15,sandybridge,core
31GenuineIntel-6-2C,v2,westmereep-dp,core 31GenuineIntel-6-2C,v2,westmereep-dp,core
32GenuineIntel-6-2C,v2,westmereep-dp,core
33GenuineIntel-6-25,v2,westmereep-sp,core 32GenuineIntel-6-25,v2,westmereep-sp,core
34GenuineIntel-6-2F,v2,westmereex,core 33GenuineIntel-6-2F,v2,westmereex,core
35GenuineIntel-6-55,v1,skylakex,core 34GenuineIntel-6-55,v1,skylakex,core
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 18b06444f230..6829dd416a99 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1309,6 +1309,14 @@ static int test__checkevent_config_cache(struct perf_evlist *evlist)
1309 return 0; 1309 return 0;
1310} 1310}
1311 1311
1312static int test__intel_pt(struct perf_evlist *evlist)
1313{
1314 struct perf_evsel *evsel = perf_evlist__first(evlist);
1315
1316 TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "intel_pt//u") == 0);
1317 return 0;
1318}
1319
1312static int count_tracepoints(void) 1320static int count_tracepoints(void)
1313{ 1321{
1314 struct dirent *events_ent; 1322 struct dirent *events_ent;
@@ -1637,6 +1645,11 @@ static struct evlist_test test__events[] = {
1637 .check = test__checkevent_config_cache, 1645 .check = test__checkevent_config_cache,
1638 .id = 51, 1646 .id = 51,
1639 }, 1647 },
1648 {
1649 .name = "intel_pt//u",
1650 .check = test__intel_pt,
1651 .id = 52,
1652 },
1640}; 1653};
1641 1654
1642static struct evlist_test test__events_pmu[] = { 1655static struct evlist_test test__events_pmu[] = {
diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
index 016882dbbc16..ee86473643be 100755
--- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
+++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
@@ -16,7 +16,7 @@ nm -g $libc 2>/dev/null | fgrep -q inet_pton || exit 254
16trace_libc_inet_pton_backtrace() { 16trace_libc_inet_pton_backtrace() {
17 idx=0 17 idx=0
18 expected[0]="ping[][0-9 \.:]+probe_libc:inet_pton: \([[:xdigit:]]+\)" 18 expected[0]="ping[][0-9 \.:]+probe_libc:inet_pton: \([[:xdigit:]]+\)"
19 expected[1]=".*inet_pton[[:space:]]\($libc\)$" 19 expected[1]=".*inet_pton[[:space:]]\($libc|inlined\)$"
20 case "$(uname -m)" in 20 case "$(uname -m)" in
21 s390x) 21 s390x)
22 eventattr='call-graph=dwarf,max-stack=4' 22 eventattr='call-graph=dwarf,max-stack=4'
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8052373bcd6a..5d4c45b76895 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -152,6 +152,8 @@ libperf-y += perf-hooks.o
152libperf-$(CONFIG_CXX) += c++/ 152libperf-$(CONFIG_CXX) += c++/
153 153
154CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))" 154CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
155CFLAGS_llvm-utils.o += -DPERF_INCLUDE_DIR="BUILD_STR($(perf_include_dir_SQ))"
156
155# avoid compiler warnings in 32-bit mode 157# avoid compiler warnings in 32-bit mode
156CFLAGS_genelf_debug.o += -Wno-packed 158CFLAGS_genelf_debug.o += -Wno-packed
157 159
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 536ee148bff8..5d74a30fe00f 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1263,6 +1263,9 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
1263 max_percent = sample->percent; 1263 max_percent = sample->percent;
1264 } 1264 }
1265 1265
1266 if (al->samples_nr > nr_percent)
1267 nr_percent = al->samples_nr;
1268
1266 if (max_percent < min_pcnt) 1269 if (max_percent < min_pcnt)
1267 return -1; 1270 return -1;
1268 1271
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index af7ad814b2c3..cee658733e2c 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -66,7 +66,7 @@ bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name)
66 } 66 }
67 67
68 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name); 68 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name);
69 if (IS_ERR(obj)) { 69 if (IS_ERR_OR_NULL(obj)) {
70 pr_debug("bpf: failed to load buffer\n"); 70 pr_debug("bpf: failed to load buffer\n");
71 return ERR_PTR(-EINVAL); 71 return ERR_PTR(-EINVAL);
72 } 72 }
@@ -102,14 +102,14 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
102 pr_debug("bpf: successfull builtin compilation\n"); 102 pr_debug("bpf: successfull builtin compilation\n");
103 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename); 103 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename);
104 104
105 if (!IS_ERR(obj) && llvm_param.dump_obj) 105 if (!IS_ERR_OR_NULL(obj) && llvm_param.dump_obj)
106 llvm__dump_obj(filename, obj_buf, obj_buf_sz); 106 llvm__dump_obj(filename, obj_buf, obj_buf_sz);
107 107
108 free(obj_buf); 108 free(obj_buf);
109 } else 109 } else
110 obj = bpf_object__open(filename); 110 obj = bpf_object__open(filename);
111 111
112 if (IS_ERR(obj)) { 112 if (IS_ERR_OR_NULL(obj)) {
113 pr_debug("bpf: failed to load %s\n", filename); 113 pr_debug("bpf: failed to load %s\n", filename);
114 return obj; 114 return obj;
115 } 115 }
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 6533b1adb50b..822ba915d144 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -239,6 +239,7 @@ static void cs_etm__free(struct perf_session *session)
239 for (i = 0; i < aux->num_cpu; i++) 239 for (i = 0; i < aux->num_cpu; i++)
240 zfree(&aux->metadata[i]); 240 zfree(&aux->metadata[i]);
241 241
242 thread__zput(aux->unknown_thread);
242 zfree(&aux->metadata); 243 zfree(&aux->metadata);
243 zfree(&aux); 244 zfree(&aux);
244} 245}
@@ -610,8 +611,8 @@ cs_etm__get_trace(struct cs_etm_buffer *buff, struct cs_etm_queue *etmq)
610 return buff->len; 611 return buff->len;
611} 612}
612 613
613static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, 614static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm,
614 struct auxtrace_queue *queue) 615 struct auxtrace_queue *queue)
615{ 616{
616 struct cs_etm_queue *etmq = queue->priv; 617 struct cs_etm_queue *etmq = queue->priv;
617 618
@@ -1355,6 +1356,23 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
1355 etm->auxtrace.free = cs_etm__free; 1356 etm->auxtrace.free = cs_etm__free;
1356 session->auxtrace = &etm->auxtrace; 1357 session->auxtrace = &etm->auxtrace;
1357 1358
1359 etm->unknown_thread = thread__new(999999999, 999999999);
1360 if (!etm->unknown_thread)
1361 goto err_free_queues;
1362
1363 /*
1364 * Initialize list node so that at thread__zput() we can avoid
1365 * segmentation fault at list_del_init().
1366 */
1367 INIT_LIST_HEAD(&etm->unknown_thread->node);
1368
1369 err = thread__set_comm(etm->unknown_thread, "unknown", 0);
1370 if (err)
1371 goto err_delete_thread;
1372
1373 if (thread__init_map_groups(etm->unknown_thread, etm->machine))
1374 goto err_delete_thread;
1375
1358 if (dump_trace) { 1376 if (dump_trace) {
1359 cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu); 1377 cs_etm__print_auxtrace_info(auxtrace_info->priv, num_cpu);
1360 return 0; 1378 return 0;
@@ -1369,16 +1387,18 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
1369 1387
1370 err = cs_etm__synth_events(etm, session); 1388 err = cs_etm__synth_events(etm, session);
1371 if (err) 1389 if (err)
1372 goto err_free_queues; 1390 goto err_delete_thread;
1373 1391
1374 err = auxtrace_queues__process_index(&etm->queues, session); 1392 err = auxtrace_queues__process_index(&etm->queues, session);
1375 if (err) 1393 if (err)
1376 goto err_free_queues; 1394 goto err_delete_thread;
1377 1395
1378 etm->data_queued = etm->queues.populated; 1396 etm->data_queued = etm->queues.populated;
1379 1397
1380 return 0; 1398 return 0;
1381 1399
1400err_delete_thread:
1401 thread__zput(etm->unknown_thread);
1382err_free_queues: 1402err_free_queues:
1383 auxtrace_queues__free(&etm->queues); 1403 auxtrace_queues__free(&etm->queues);
1384 session->auxtrace = NULL; 1404 session->auxtrace = NULL;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 92ec009a292d..b13f5f234c8f 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -127,6 +127,7 @@ struct perf_evsel {
127 bool precise_max; 127 bool precise_max;
128 bool ignore_missing_thread; 128 bool ignore_missing_thread;
129 bool forced_leader; 129 bool forced_leader;
130 bool use_uncore_alias;
130 /* parse modifier helper */ 131 /* parse modifier helper */
131 int exclude_GH; 132 int exclude_GH;
132 int nr_members; 133 int nr_members;
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 1cca0a2fa641..976e658e38dc 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -14,11 +14,12 @@
14#include "config.h" 14#include "config.h"
15#include "util.h" 15#include "util.h"
16#include <sys/wait.h> 16#include <sys/wait.h>
17#include <subcmd/exec-cmd.h>
17 18
18#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ 19#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
19 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ 20 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
20 "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \ 21 "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
21 "$CLANG_OPTIONS $KERNEL_INC_OPTIONS " \ 22 "$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \
22 "-Wno-unused-value -Wno-pointer-sign " \ 23 "-Wno-unused-value -Wno-pointer-sign " \
23 "-working-directory $WORKING_DIR " \ 24 "-working-directory $WORKING_DIR " \
24 "-c \"$CLANG_SOURCE\" -target bpf -O2 -o -" 25 "-c \"$CLANG_SOURCE\" -target bpf -O2 -o -"
@@ -212,7 +213,7 @@ version_notice(void)
212" \t\thttp://llvm.org/apt\n\n" 213" \t\thttp://llvm.org/apt\n\n"
213" \tIf you are using old version of clang, change 'clang-bpf-cmd-template'\n" 214" \tIf you are using old version of clang, change 'clang-bpf-cmd-template'\n"
214" \toption in [llvm] section of ~/.perfconfig to:\n\n" 215" \toption in [llvm] section of ~/.perfconfig to:\n\n"
215" \t \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS \\\n" 216" \t \"$CLANG_EXEC $CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS \\\n"
216" \t -working-directory $WORKING_DIR -c $CLANG_SOURCE \\\n" 217" \t -working-directory $WORKING_DIR -c $CLANG_SOURCE \\\n"
217" \t -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -\"\n" 218" \t -emit-llvm -o - | /path/to/llc -march=bpf -filetype=obj -o -\"\n"
218" \t(Replace /path/to/llc with path to your llc)\n\n" 219" \t(Replace /path/to/llc with path to your llc)\n\n"
@@ -431,9 +432,11 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
431 const char *clang_opt = llvm_param.clang_opt; 432 const char *clang_opt = llvm_param.clang_opt;
432 char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64]; 433 char clang_path[PATH_MAX], abspath[PATH_MAX], nr_cpus_avail_str[64];
433 char serr[STRERR_BUFSIZE]; 434 char serr[STRERR_BUFSIZE];
434 char *kbuild_dir = NULL, *kbuild_include_opts = NULL; 435 char *kbuild_dir = NULL, *kbuild_include_opts = NULL,
436 *perf_bpf_include_opts = NULL;
435 const char *template = llvm_param.clang_bpf_cmd_template; 437 const char *template = llvm_param.clang_bpf_cmd_template;
436 char *command_echo, *command_out; 438 char *command_echo = NULL, *command_out;
439 char *perf_include_dir = system_path(PERF_INCLUDE_DIR);
437 440
438 if (path[0] != '-' && realpath(path, abspath) == NULL) { 441 if (path[0] != '-' && realpath(path, abspath) == NULL) {
439 err = errno; 442 err = errno;
@@ -471,12 +474,14 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
471 474
472 snprintf(linux_version_code_str, sizeof(linux_version_code_str), 475 snprintf(linux_version_code_str, sizeof(linux_version_code_str),
473 "0x%x", kernel_version); 476 "0x%x", kernel_version);
474 477 if (asprintf(&perf_bpf_include_opts, "-I%s/bpf", perf_include_dir) < 0)
478 goto errout;
475 force_set_env("NR_CPUS", nr_cpus_avail_str); 479 force_set_env("NR_CPUS", nr_cpus_avail_str);
476 force_set_env("LINUX_VERSION_CODE", linux_version_code_str); 480 force_set_env("LINUX_VERSION_CODE", linux_version_code_str);
477 force_set_env("CLANG_EXEC", clang_path); 481 force_set_env("CLANG_EXEC", clang_path);
478 force_set_env("CLANG_OPTIONS", clang_opt); 482 force_set_env("CLANG_OPTIONS", clang_opt);
479 force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts); 483 force_set_env("KERNEL_INC_OPTIONS", kbuild_include_opts);
484 force_set_env("PERF_BPF_INC_OPTIONS", perf_bpf_include_opts);
480 force_set_env("WORKING_DIR", kbuild_dir ? : "."); 485 force_set_env("WORKING_DIR", kbuild_dir ? : ".");
481 486
482 /* 487 /*
@@ -512,6 +517,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
512 free(command_out); 517 free(command_out);
513 free(kbuild_dir); 518 free(kbuild_dir);
514 free(kbuild_include_opts); 519 free(kbuild_include_opts);
520 free(perf_bpf_include_opts);
521 free(perf_include_dir);
515 522
516 if (!p_obj_buf) 523 if (!p_obj_buf)
517 free(obj_buf); 524 free(obj_buf);
@@ -526,6 +533,8 @@ errout:
526 free(kbuild_dir); 533 free(kbuild_dir);
527 free(kbuild_include_opts); 534 free(kbuild_include_opts);
528 free(obj_buf); 535 free(obj_buf);
536 free(perf_bpf_include_opts);
537 free(perf_include_dir);
529 if (p_obj_buf) 538 if (p_obj_buf)
530 *p_obj_buf = NULL; 539 *p_obj_buf = NULL;
531 if (p_obj_buf_sz) 540 if (p_obj_buf_sz)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 2fb0272146d8..2fc4ee8b86c1 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1219,13 +1219,16 @@ int parse_events_add_numeric(struct parse_events_state *parse_state,
1219 1219
1220int parse_events_add_pmu(struct parse_events_state *parse_state, 1220int parse_events_add_pmu(struct parse_events_state *parse_state,
1221 struct list_head *list, char *name, 1221 struct list_head *list, char *name,
1222 struct list_head *head_config, bool auto_merge_stats) 1222 struct list_head *head_config,
1223 bool auto_merge_stats,
1224 bool use_alias)
1223{ 1225{
1224 struct perf_event_attr attr; 1226 struct perf_event_attr attr;
1225 struct perf_pmu_info info; 1227 struct perf_pmu_info info;
1226 struct perf_pmu *pmu; 1228 struct perf_pmu *pmu;
1227 struct perf_evsel *evsel; 1229 struct perf_evsel *evsel;
1228 struct parse_events_error *err = parse_state->error; 1230 struct parse_events_error *err = parse_state->error;
1231 bool use_uncore_alias;
1229 LIST_HEAD(config_terms); 1232 LIST_HEAD(config_terms);
1230 1233
1231 pmu = perf_pmu__find(name); 1234 pmu = perf_pmu__find(name);
@@ -1244,11 +1247,14 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
1244 memset(&attr, 0, sizeof(attr)); 1247 memset(&attr, 0, sizeof(attr));
1245 } 1248 }
1246 1249
1250 use_uncore_alias = (pmu->is_uncore && use_alias);
1251
1247 if (!head_config) { 1252 if (!head_config) {
1248 attr.type = pmu->type; 1253 attr.type = pmu->type;
1249 evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats); 1254 evsel = __add_event(list, &parse_state->idx, &attr, NULL, pmu, NULL, auto_merge_stats);
1250 if (evsel) { 1255 if (evsel) {
1251 evsel->pmu_name = name; 1256 evsel->pmu_name = name;
1257 evsel->use_uncore_alias = use_uncore_alias;
1252 return 0; 1258 return 0;
1253 } else { 1259 } else {
1254 return -ENOMEM; 1260 return -ENOMEM;
@@ -1282,6 +1288,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
1282 evsel->metric_expr = info.metric_expr; 1288 evsel->metric_expr = info.metric_expr;
1283 evsel->metric_name = info.metric_name; 1289 evsel->metric_name = info.metric_name;
1284 evsel->pmu_name = name; 1290 evsel->pmu_name = name;
1291 evsel->use_uncore_alias = use_uncore_alias;
1285 } 1292 }
1286 1293
1287 return evsel ? 0 : -ENOMEM; 1294 return evsel ? 0 : -ENOMEM;
@@ -1317,7 +1324,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
1317 list_add_tail(&term->list, head); 1324 list_add_tail(&term->list, head);
1318 1325
1319 if (!parse_events_add_pmu(parse_state, list, 1326 if (!parse_events_add_pmu(parse_state, list,
1320 pmu->name, head, true)) { 1327 pmu->name, head,
1328 true, true)) {
1321 pr_debug("%s -> %s/%s/\n", str, 1329 pr_debug("%s -> %s/%s/\n", str,
1322 pmu->name, alias->str); 1330 pmu->name, alias->str);
1323 ok++; 1331 ok++;
@@ -1339,7 +1347,120 @@ int parse_events__modifier_group(struct list_head *list,
1339 return parse_events__modifier_event(list, event_mod, true); 1347 return parse_events__modifier_event(list, event_mod, true);
1340} 1348}
1341 1349
1342void parse_events__set_leader(char *name, struct list_head *list) 1350/*
1351 * Check if the two uncore PMUs are from the same uncore block
1352 * The format of the uncore PMU name is uncore_#blockname_#pmuidx
1353 */
1354static bool is_same_uncore_block(const char *pmu_name_a, const char *pmu_name_b)
1355{
1356 char *end_a, *end_b;
1357
1358 end_a = strrchr(pmu_name_a, '_');
1359 end_b = strrchr(pmu_name_b, '_');
1360
1361 if (!end_a || !end_b)
1362 return false;
1363
1364 if ((end_a - pmu_name_a) != (end_b - pmu_name_b))
1365 return false;
1366
1367 return (strncmp(pmu_name_a, pmu_name_b, end_a - pmu_name_a) == 0);
1368}
1369
1370static int
1371parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *list,
1372 struct parse_events_state *parse_state)
1373{
1374 struct perf_evsel *evsel, *leader;
1375 uintptr_t *leaders;
1376 bool is_leader = true;
1377 int i, nr_pmu = 0, total_members, ret = 0;
1378
1379 leader = list_first_entry(list, struct perf_evsel, node);
1380 evsel = list_last_entry(list, struct perf_evsel, node);
1381 total_members = evsel->idx - leader->idx + 1;
1382
1383 leaders = calloc(total_members, sizeof(uintptr_t));
1384 if (WARN_ON(!leaders))
1385 return 0;
1386
1387 /*
1388 * Going through the whole group and doing sanity check.
1389 * All members must use alias, and be from the same uncore block.
1390 * Also, storing the leader events in an array.
1391 */
1392 __evlist__for_each_entry(list, evsel) {
1393
1394 /* Only split the uncore group which members use alias */
1395 if (!evsel->use_uncore_alias)
1396 goto out;
1397
1398 /* The events must be from the same uncore block */
1399 if (!is_same_uncore_block(leader->pmu_name, evsel->pmu_name))
1400 goto out;
1401
1402 if (!is_leader)
1403 continue;
1404 /*
1405 * If the event's PMU name starts to repeat, it must be a new
1406 * event. That can be used to distinguish the leader from
1407 * other members, even they have the same event name.
1408 */
1409 if ((leader != evsel) && (leader->pmu_name == evsel->pmu_name)) {
1410 is_leader = false;
1411 continue;
1412 }
1413 /* The name is always alias name */
1414 WARN_ON(strcmp(leader->name, evsel->name));
1415
1416 /* Store the leader event for each PMU */
1417 leaders[nr_pmu++] = (uintptr_t) evsel;
1418 }
1419
1420 /* only one event alias */
1421 if (nr_pmu == total_members) {
1422 parse_state->nr_groups--;
1423 goto handled;
1424 }
1425
1426 /*
1427 * An uncore event alias is a joint name which means the same event
1428 * runs on all PMUs of a block.
1429 * Perf doesn't support mixed events from different PMUs in the same
1430 * group. The big group has to be split into multiple small groups
1431 * which only include the events from the same PMU.
1432 *
1433 * Here the uncore event aliases must be from the same uncore block.
1434 * The number of PMUs must be same for each alias. The number of new
1435 * small groups equals to the number of PMUs.
1436 * Setting the leader event for corresponding members in each group.
1437 */
1438 i = 0;
1439 __evlist__for_each_entry(list, evsel) {
1440 if (i >= nr_pmu)
1441 i = 0;
1442 evsel->leader = (struct perf_evsel *) leaders[i++];
1443 }
1444
1445 /* The number of members and group name are same for each group */
1446 for (i = 0; i < nr_pmu; i++) {
1447 evsel = (struct perf_evsel *) leaders[i];
1448 evsel->nr_members = total_members / nr_pmu;
1449 evsel->group_name = name ? strdup(name) : NULL;
1450 }
1451
1452 /* Take the new small groups into account */
1453 parse_state->nr_groups += nr_pmu - 1;
1454
1455handled:
1456 ret = 1;
1457out:
1458 free(leaders);
1459 return ret;
1460}
1461
1462void parse_events__set_leader(char *name, struct list_head *list,
1463 struct parse_events_state *parse_state)
1343{ 1464{
1344 struct perf_evsel *leader; 1465 struct perf_evsel *leader;
1345 1466
@@ -1348,6 +1469,9 @@ void parse_events__set_leader(char *name, struct list_head *list)
1348 return; 1469 return;
1349 } 1470 }
1350 1471
1472 if (parse_events__set_leader_for_uncore_aliase(name, list, parse_state))
1473 return;
1474
1351 __perf_evlist__set_leader(list); 1475 __perf_evlist__set_leader(list);
1352 leader = list_entry(list->next, struct perf_evsel, node); 1476 leader = list_entry(list->next, struct perf_evsel, node);
1353 leader->group_name = name ? strdup(name) : NULL; 1477 leader->group_name = name ? strdup(name) : NULL;
@@ -1715,7 +1839,7 @@ int parse_events(struct perf_evlist *evlist, const char *str,
1715 struct perf_evsel *last; 1839 struct perf_evsel *last;
1716 1840
1717 if (list_empty(&parse_state.list)) { 1841 if (list_empty(&parse_state.list)) {
1718 WARN_ONCE(true, "WARNING: event parser found nothing"); 1842 WARN_ONCE(true, "WARNING: event parser found nothing\n");
1719 return -1; 1843 return -1;
1720 } 1844 }
1721 1845
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 5015cfd58277..4473dac27aee 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -167,7 +167,9 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
167 void *ptr, char *type, u64 len); 167 void *ptr, char *type, u64 len);
168int parse_events_add_pmu(struct parse_events_state *parse_state, 168int parse_events_add_pmu(struct parse_events_state *parse_state,
169 struct list_head *list, char *name, 169 struct list_head *list, char *name,
170 struct list_head *head_config, bool auto_merge_stats); 170 struct list_head *head_config,
171 bool auto_merge_stats,
172 bool use_alias);
171 173
172int parse_events_multi_pmu_add(struct parse_events_state *parse_state, 174int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
173 char *str, 175 char *str,
@@ -178,7 +180,8 @@ int parse_events_copy_term_list(struct list_head *old,
178 180
179enum perf_pmu_event_symbol_type 181enum perf_pmu_event_symbol_type
180perf_pmu__parse_check(const char *name); 182perf_pmu__parse_check(const char *name);
181void parse_events__set_leader(char *name, struct list_head *list); 183void parse_events__set_leader(char *name, struct list_head *list,
184 struct parse_events_state *parse_state);
182void parse_events_update_lists(struct list_head *list_event, 185void parse_events_update_lists(struct list_head *list_event,
183 struct list_head *list_all); 186 struct list_head *list_all);
184void parse_events_evlist_error(struct parse_events_state *parse_state, 187void parse_events_evlist_error(struct parse_events_state *parse_state,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index d14464c42714..e37608a87dba 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -161,7 +161,7 @@ PE_NAME '{' events '}'
161 struct list_head *list = $3; 161 struct list_head *list = $3;
162 162
163 inc_group_count(list, _parse_state); 163 inc_group_count(list, _parse_state);
164 parse_events__set_leader($1, list); 164 parse_events__set_leader($1, list, _parse_state);
165 $$ = list; 165 $$ = list;
166} 166}
167| 167|
@@ -170,7 +170,7 @@ PE_NAME '{' events '}'
170 struct list_head *list = $2; 170 struct list_head *list = $2;
171 171
172 inc_group_count(list, _parse_state); 172 inc_group_count(list, _parse_state);
173 parse_events__set_leader(NULL, list); 173 parse_events__set_leader(NULL, list, _parse_state);
174 $$ = list; 174 $$ = list;
175} 175}
176 176
@@ -224,15 +224,15 @@ event_def: event_pmu |
224 event_bpf_file 224 event_bpf_file
225 225
226event_pmu: 226event_pmu:
227PE_NAME '/' event_config '/' 227PE_NAME opt_event_config
228{ 228{
229 struct list_head *list, *orig_terms, *terms; 229 struct list_head *list, *orig_terms, *terms;
230 230
231 if (parse_events_copy_term_list($3, &orig_terms)) 231 if (parse_events_copy_term_list($2, &orig_terms))
232 YYABORT; 232 YYABORT;
233 233
234 ALLOC_LIST(list); 234 ALLOC_LIST(list);
235 if (parse_events_add_pmu(_parse_state, list, $1, $3, false)) { 235 if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
236 struct perf_pmu *pmu = NULL; 236 struct perf_pmu *pmu = NULL;
237 int ok = 0; 237 int ok = 0;
238 char *pattern; 238 char *pattern;
@@ -251,7 +251,7 @@ PE_NAME '/' event_config '/'
251 free(pattern); 251 free(pattern);
252 YYABORT; 252 YYABORT;
253 } 253 }
254 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true)) 254 if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
255 ok++; 255 ok++;
256 parse_events_terms__delete(terms); 256 parse_events_terms__delete(terms);
257 } 257 }
@@ -262,7 +262,7 @@ PE_NAME '/' event_config '/'
262 if (!ok) 262 if (!ok)
263 YYABORT; 263 YYABORT;
264 } 264 }
265 parse_events_terms__delete($3); 265 parse_events_terms__delete($2);
266 parse_events_terms__delete(orig_terms); 266 parse_events_terms__delete(orig_terms);
267 $$ = list; 267 $$ = list;
268} 268}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index f48dc157c2bd..4a39f4d0a174 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1149,7 +1149,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
1149 bool is_64_bit; 1149 bool is_64_bit;
1150 int err, fd; 1150 int err, fd;
1151 char kcore_filename[PATH_MAX]; 1151 char kcore_filename[PATH_MAX];
1152 struct symbol *sym; 1152 u64 stext;
1153 1153
1154 if (!kmaps) 1154 if (!kmaps)
1155 return -EINVAL; 1155 return -EINVAL;
@@ -1198,13 +1198,13 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
1198 old_map = next; 1198 old_map = next;
1199 } 1199 }
1200 1200
1201 /* Find the kernel map using the first symbol */ 1201 /* Find the kernel map using the '_stext' symbol */
1202 sym = dso__first_symbol(dso); 1202 if (!kallsyms__get_function_start(kallsyms_filename, "_stext", &stext)) {
1203 list_for_each_entry(new_map, &md.maps, node) { 1203 list_for_each_entry(new_map, &md.maps, node) {
1204 if (sym && sym->start >= new_map->start && 1204 if (stext >= new_map->start && stext < new_map->end) {
1205 sym->start < new_map->end) { 1205 replacement_map = new_map;
1206 replacement_map = new_map; 1206 break;
1207 break; 1207 }
1208 } 1208 }
1209 } 1209 }
1210 1210
diff --git a/tools/power/acpi/Makefile.config b/tools/power/acpi/Makefile.config
index 2cccbba64418..f304be71c278 100644
--- a/tools/power/acpi/Makefile.config
+++ b/tools/power/acpi/Makefile.config
@@ -56,6 +56,7 @@ INSTALL_SCRIPT = ${INSTALL_PROGRAM}
56# to compile vs uClibc, that can be done here as well. 56# to compile vs uClibc, that can be done here as well.
57CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- 57CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
58CROSS_COMPILE ?= $(CROSS) 58CROSS_COMPILE ?= $(CROSS)
59LD = $(CC)
59HOSTCC = gcc 60HOSTCC = gcc
60 61
61# check if compiler option is supported 62# check if compiler option is supported
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index faadbe233966..4123d0ab90ba 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -1108,7 +1108,7 @@ static void test_stacktrace_build_id(void)
1108 1108
1109 assert(system("dd if=/dev/urandom of=/dev/zero count=4 2> /dev/null") 1109 assert(system("dd if=/dev/urandom of=/dev/zero count=4 2> /dev/null")
1110 == 0); 1110 == 0);
1111 assert(system("./urandom_read if=/dev/urandom of=/dev/zero count=4 2> /dev/null") == 0); 1111 assert(system("./urandom_read") == 0);
1112 /* disable stack trace collection */ 1112 /* disable stack trace collection */
1113 key = 0; 1113 key = 0;
1114 val = 1; 1114 val = 1;
@@ -1158,7 +1158,7 @@ static void test_stacktrace_build_id(void)
1158 } while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0); 1158 } while (bpf_map_get_next_key(stackmap_fd, &previous_key, &key) == 0);
1159 1159
1160 CHECK(build_id_matches < 1, "build id match", 1160 CHECK(build_id_matches < 1, "build id match",
1161 "Didn't find expected build ID from the map"); 1161 "Didn't find expected build ID from the map\n");
1162 1162
1163disable_pmu: 1163disable_pmu:
1164 ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE); 1164 ioctl(pmu_fd, PERF_EVENT_IOC_DISABLE);
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 195e9d4739a9..c1b1a4dc6a96 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -20,10 +20,10 @@ all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
20 20
21.ONESHELL: 21.ONESHELL:
22define RUN_TESTS 22define RUN_TESTS
23 @export KSFT_TAP_LEVEL=`echo 1`; 23 @export KSFT_TAP_LEVEL=`echo 1`; \
24 @test_num=`echo 0`; 24 test_num=`echo 0`; \
25 @echo "TAP version 13"; 25 echo "TAP version 13"; \
26 @for TEST in $(1); do \ 26 for TEST in $(1); do \
27 BASENAME_TEST=`basename $$TEST`; \ 27 BASENAME_TEST=`basename $$TEST`; \
28 test_num=`echo $$test_num+1 | bc`; \ 28 test_num=`echo $$test_num+1 | bc`; \
29 echo "selftests: $$BASENAME_TEST"; \ 29 echo "selftests: $$BASENAME_TEST"; \
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 8f1e13d2e547..3ff81a478dbe 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -5,7 +5,8 @@ CFLAGS = -Wall -Wl,--no-as-needed -O2 -g
5CFLAGS += -I../../../../usr/include/ 5CFLAGS += -I../../../../usr/include/
6 6
7TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh 7TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh
8TEST_PROGS += fib_tests.sh fib-onlink-tests.sh in_netns.sh pmtu.sh 8TEST_PROGS += fib_tests.sh fib-onlink-tests.sh pmtu.sh
9TEST_PROGS_EXTENDED := in_netns.sh
9TEST_GEN_FILES = socket 10TEST_GEN_FILES = socket
10TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy 11TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy
11TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa 12TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
diff --git a/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json b/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
index 5b012f4981d4..6f289a49e5ec 100644
--- a/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
+++ b/tools/testing/selftests/tc-testing/tc-tests/actions/bpf.json
@@ -66,7 +66,7 @@
66 "cmdUnderTest": "$TC action add action bpf object-file _b.o index 667", 66 "cmdUnderTest": "$TC action add action bpf object-file _b.o index 667",
67 "expExitCode": "0", 67 "expExitCode": "0",
68 "verifyCmd": "$TC action get action bpf index 667", 68 "verifyCmd": "$TC action get action bpf index 667",
69 "matchPattern": "action order [0-9]*: bpf _b.o:\\[action\\] id [0-9]* tag 3b185187f1855c4c default-action pipe.*index 667 ref", 69 "matchPattern": "action order [0-9]*: bpf _b.o:\\[action\\] id [0-9]* tag 3b185187f1855c4c( jited)? default-action pipe.*index 667 ref",
70 "matchCount": "1", 70 "matchCount": "1",
71 "teardown": [ 71 "teardown": [
72 "$TC action flush action bpf", 72 "$TC action flush action bpf",
@@ -92,10 +92,15 @@
92 "cmdUnderTest": "$TC action add action bpf object-file _c.o index 667", 92 "cmdUnderTest": "$TC action add action bpf object-file _c.o index 667",
93 "expExitCode": "255", 93 "expExitCode": "255",
94 "verifyCmd": "$TC action get action bpf index 667", 94 "verifyCmd": "$TC action get action bpf index 667",
95 "matchPattern": "action order [0-9]*: bpf _b.o:\\[action\\] id [0-9].*index 667 ref", 95 "matchPattern": "action order [0-9]*: bpf _c.o:\\[action\\] id [0-9].*index 667 ref",
96 "matchCount": "0", 96 "matchCount": "0",
97 "teardown": [ 97 "teardown": [
98 "$TC action flush action bpf", 98 [
99 "$TC action flush action bpf",
100 0,
101 1,
102 255
103 ],
99 "rm -f _c.o" 104 "rm -f _c.o"
100 ] 105 ]
101 }, 106 },