Skip to content

Commit 3a36281

Browse files
committed
Merge tag 'perf-tools-for-v5.12-2020-02-19' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tool updates from Arnaldo Carvalho de Melo: "New features: - Support instruction latency in 'perf report', with both memory latency (weight) and instruction latency information, users can locate expensive load instructions and understand time spent in different stages. - Extend 'perf c2c' to display the number of loads which were blocked by data or address conflict. - Add 'perf stat' support for L2 topdown events in systems such as Intel's Sapphire rapids server. - Add support for PERF_SAMPLE_CODE_PAGE_SIZE in various tools, as a sort key, for instance: perf report --stdio --sort=comm,symbol,code_page_size - New 'perf daemon' command to run long running sessions while providing a way to control the enablement of events without restarting a traditional 'perf record' session. - Enable counting events for BPF programs in 'perf stat' just like for other targets (tid, cgroup, cpu, etc), e.g.: # perf stat -e ref-cycles,cycles -b 254 -I 1000 1.487903822 115,200 ref-cycles 1.487903822 86,012 cycles 2.489147029 80,560 ref-cycles 2.489147029 73,784 cycles ^C The example above counts 'cycles' and 'ref-cycles' of BPF program of id 254. It is similar to bpftool-prog-profile command, but more flexible. - Support the new layout for PERF_RECORD_MMAP2 to carry the DSO build-id using infrastructure generalised from the eBPF subsystem, removing the need for traversing the perf.data file to collect build-ids at the end of 'perf record' sessions and helping with long running sessions where binaries can get replaced in updates, leading to possible mis-resolution of symbols. - Support filtering by hex address in 'perf script'. - Support DSO filter in 'perf script', like in other perf tools. - Add namespaces support to 'perf inject' - Add support for SDT (Dtrace Style Markers) events on ARM64. perf record: - Fix handling of eventfd() when draining a buffer in 'perf record'. - Improvements to the generation of metadata events for pre-existing threads (mmaps, comm, etc), speeding up the work done at the start of system wide or per CPU 'perf record' sessions. Hardware tracing: - Initial support for tracing KVM with Intel PT. - Intel PT fixes for IPC - Support Intel PT PSB (synchronization packets) events. - Automatically group aux-output events to overcome --filter syntax. - Enable PERF_SAMPLE_DATA_SRC on ARMs SPE. - Update ARM's CoreSight hardware tracing OpenCSD library to v1.0.0. perf annotate TUI: - Fix handling of 'k' ("show line number") hotkey - Fix jump parsing for C++ code. perf probe: - Add protection to avoid endless loop. cgroups: - Avoid reading cgroup mountpoint multiple times, caching it. - Fix handling of cgroup v1/v2 in mixed hierarchy. Symbol resolving: - Add OCaml symbol demangling. - Further fixes for handling PE executables when using perf with Wine and .exe/.dll files. - Fix 'perf unwind' DSO handling. - Resolve symbols against debug file first, to deal with artifacts related to LTO. - Fix gap between kernel end and module start on powerpc. Reporting tools: - The DSO filter shouldn't show samples in unresolved maps. - Improve debuginfod support in various tools. build ids: - Fix 16-byte build ids in 'perf buildid-cache', add a 'perf test' entry for that case. perf test: - Support for PERF_SAMPLE_WEIGHT_STRUCT. - Add test case for PERF_SAMPLE_CODE_PAGE_SIZE. - Shell based tests for 'perf daemon's commands ('start', 'stop, 'reconfig', 'list', etc). - ARM cs-etm 'perf test' fixes. - Add parse-metric memory bandwidth testcase. Compiler related: - Fix 'perf probe' kretprobe issue caused by gcc 11 bug when used with -fpatchable-function-entry. - Fix ARM64 build with gcc 11's -Wformat-overflow. - Fix unaligned access in sample parsing test. - Fix printf conversion specifier for IP addresses on arm64, s390 and powerpc. Arch specific: - Support exposing Performance Monitor Counter SPRs as part of extended regs on powerpc. - Add JSON 'perf stat' metrics for ARM64's imx8mp, imx8mq and imx8mn DDR, fix imx8mm ones. - Fix common and uarch events for ARM64's A76 and Ampere eMag" * tag 'perf-tools-for-v5.12-2020-02-19' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: (148 commits) perf buildid-cache: Don't skip 16-byte build-ids perf buildid-cache: Add test for 16-byte build-id perf symbol: Remove redundant libbfd checks perf test: Output the sub testing result in cs-etm perf test: Suppress logs in cs-etm testing perf tools: Fix arm64 build error with gcc-11 perf intel-pt: Add documentation for tracing virtual machines perf intel-pt: Split VM-Entry and VM-Exit branches perf intel-pt: Adjust sample flags for VM-Exit perf intel-pt: Allow for a guest kernel address filter perf intel-pt: Support decoding of guest kernel perf machine: Factor out machine__idle_thread() perf machine: Factor out machines__find_guest() perf intel-pt: Amend decoder to track the NR flag perf intel-pt: Retain the last PIP packet payload as is perf intel_pt: Add vmlaunch and vmresume as branches perf script: Add branch types for VM-Entry and VM-Exit perf auxtrace: Automatically group aux-output events perf test: Fix unaligned access in sample parsing test perf tools: Support arch specific PERF_SAMPLE_WEIGHT_STRUCT processing ...
2 parents 7c70f3a + 3027ce3 commit 3a36281

183 files changed

Lines changed: 6938 additions & 974 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tools/arch/powerpc/include/uapi/asm/perf_regs.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,33 @@ enum perf_event_powerpc_regs {
5555
PERF_REG_POWERPC_MMCR3,
5656
PERF_REG_POWERPC_SIER2,
5757
PERF_REG_POWERPC_SIER3,
58+
PERF_REG_POWERPC_PMC1,
59+
PERF_REG_POWERPC_PMC2,
60+
PERF_REG_POWERPC_PMC3,
61+
PERF_REG_POWERPC_PMC4,
62+
PERF_REG_POWERPC_PMC5,
63+
PERF_REG_POWERPC_PMC6,
5864
/* Max regs without the extended regs */
5965
PERF_REG_POWERPC_MAX = PERF_REG_POWERPC_MMCRA + 1,
6066
};
6167

6268
#define PERF_REG_PMU_MASK ((1ULL << PERF_REG_POWERPC_MAX) - 1)
6369

64-
/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300 */
65-
#define PERF_REG_PMU_MASK_300 (((1ULL << (PERF_REG_POWERPC_MMCR2 + 1)) - 1) - PERF_REG_PMU_MASK)
66-
/* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31 */
67-
#define PERF_REG_PMU_MASK_31 (((1ULL << (PERF_REG_POWERPC_SIER3 + 1)) - 1) - PERF_REG_PMU_MASK)
70+
/* Exclude MMCR3, SIER2, SIER3 for CPU_FTR_ARCH_300 */
71+
#define PERF_EXCLUDE_REG_EXT_300 (7ULL << PERF_REG_POWERPC_MMCR3)
6872

69-
#define PERF_REG_MAX_ISA_300 (PERF_REG_POWERPC_MMCR2 + 1)
70-
#define PERF_REG_MAX_ISA_31 (PERF_REG_POWERPC_SIER3 + 1)
73+
/*
74+
* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_300
75+
* includes 9 SPRS from MMCR0 to PMC6 excluding the
76+
* unsupported SPRS in PERF_EXCLUDE_REG_EXT_300.
77+
*/
78+
#define PERF_REG_PMU_MASK_300 ((0xfffULL << PERF_REG_POWERPC_MMCR0) - PERF_EXCLUDE_REG_EXT_300)
79+
80+
/*
81+
* PERF_REG_EXTENDED_MASK value for CPU_FTR_ARCH_31
82+
* includes 12 SPRs from MMCR0 to PMC6.
83+
*/
84+
#define PERF_REG_PMU_MASK_31 (0xfffULL << PERF_REG_POWERPC_MMCR0)
85+
86+
#define PERF_REG_EXTENDED_MAX (PERF_REG_POWERPC_PMC6 + 1)
7187
#endif /* _UAPI_ASM_POWERPC_PERF_REGS_H */

tools/bpf/bpftool/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
146146
/boot/vmlinux-$(shell uname -r)
147147
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
148148

149+
bootstrap: $(BPFTOOL_BOOTSTRAP)
150+
149151
ifneq ($(VMLINUX_BTF)$(VMLINUX_H),)
150152
ifeq ($(feature-clang-bpf-co-re),1)
151153

tools/build/Makefile.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ FEATURE_TESTS_EXTRA := \
9999
clang \
100100
libbpf \
101101
libpfm4 \
102-
libdebuginfod
102+
libdebuginfod \
103+
clang-bpf-co-re
104+
103105

104106
FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
105107

tools/build/feature/test-libopencsd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
/*
55
* Check OpenCSD library version is sufficient to provide required features
66
*/
7-
#define OCSD_MIN_VER ((0 << 16) | (14 << 8) | (0))
7+
#define OCSD_MIN_VER ((1 << 16) | (0 << 8) | (0))
88
#if !defined(OCSD_VER_NUM) || (OCSD_VER_NUM < OCSD_MIN_VER)
9-
#error "OpenCSD >= 0.14.0 is required"
9+
#error "OpenCSD >= 1.0.0 is required"
1010
#endif
1111

1212
int main(void)

tools/include/uapi/linux/perf_event.h

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ enum perf_event_sample_format {
145145
PERF_SAMPLE_CGROUP = 1U << 21,
146146
PERF_SAMPLE_DATA_PAGE_SIZE = 1U << 22,
147147
PERF_SAMPLE_CODE_PAGE_SIZE = 1U << 23,
148+
PERF_SAMPLE_WEIGHT_STRUCT = 1U << 24,
148149

149-
PERF_SAMPLE_MAX = 1U << 24, /* non-ABI */
150+
PERF_SAMPLE_MAX = 1U << 25, /* non-ABI */
150151

151152
__PERF_SAMPLE_CALLCHAIN_EARLY = 1ULL << 63, /* non-ABI; internal use */
152153
};
153154

155+
#define PERF_SAMPLE_WEIGHT_TYPE (PERF_SAMPLE_WEIGHT | PERF_SAMPLE_WEIGHT_STRUCT)
154156
/*
155157
* values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set
156158
*
@@ -386,7 +388,8 @@ struct perf_event_attr {
386388
aux_output : 1, /* generate AUX records instead of events */
387389
cgroup : 1, /* include cgroup events */
388390
text_poke : 1, /* include text poke events */
389-
__reserved_1 : 30;
391+
build_id : 1, /* use build id in mmap2 events */
392+
__reserved_1 : 29;
390393

391394
union {
392395
__u32 wakeup_events; /* wakeup every n events */
@@ -659,6 +662,22 @@ struct perf_event_mmap_page {
659662
__u64 aux_size;
660663
};
661664

665+
/*
666+
* The current state of perf_event_header::misc bits usage:
667+
* ('|' used bit, '-' unused bit)
668+
*
669+
* 012 CDEF
670+
* |||---------||||
671+
*
672+
* Where:
673+
* 0-2 CPUMODE_MASK
674+
*
675+
* C PROC_MAP_PARSE_TIMEOUT
676+
* D MMAP_DATA / COMM_EXEC / FORK_EXEC / SWITCH_OUT
677+
* E MMAP_BUILD_ID / EXACT_IP / SCHED_OUT_PREEMPT
678+
* F (reserved)
679+
*/
680+
662681
#define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
663682
#define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0)
664683
#define PERF_RECORD_MISC_KERNEL (1 << 0)
@@ -690,6 +709,7 @@ struct perf_event_mmap_page {
690709
*
691710
* PERF_RECORD_MISC_EXACT_IP - PERF_RECORD_SAMPLE of precise events
692711
* PERF_RECORD_MISC_SWITCH_OUT_PREEMPT - PERF_RECORD_SWITCH* events
712+
* PERF_RECORD_MISC_MMAP_BUILD_ID - PERF_RECORD_MMAP2 event
693713
*
694714
*
695715
* PERF_RECORD_MISC_EXACT_IP:
@@ -699,9 +719,13 @@ struct perf_event_mmap_page {
699719
*
700720
* PERF_RECORD_MISC_SWITCH_OUT_PREEMPT:
701721
* Indicates that thread was preempted in TASK_RUNNING state.
722+
*
723+
* PERF_RECORD_MISC_MMAP_BUILD_ID:
724+
* Indicates that mmap2 event carries build id data.
702725
*/
703726
#define PERF_RECORD_MISC_EXACT_IP (1 << 14)
704727
#define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
728+
#define PERF_RECORD_MISC_MMAP_BUILD_ID (1 << 14)
705729
/*
706730
* Reserve the last bit to indicate some extended misc field
707731
*/
@@ -890,7 +914,24 @@ enum perf_event_type {
890914
* char data[size];
891915
* u64 dyn_size; } && PERF_SAMPLE_STACK_USER
892916
*
893-
* { u64 weight; } && PERF_SAMPLE_WEIGHT
917+
* { union perf_sample_weight
918+
* {
919+
* u64 full; && PERF_SAMPLE_WEIGHT
920+
* #if defined(__LITTLE_ENDIAN_BITFIELD)
921+
* struct {
922+
* u32 var1_dw;
923+
* u16 var2_w;
924+
* u16 var3_w;
925+
* } && PERF_SAMPLE_WEIGHT_STRUCT
926+
* #elif defined(__BIG_ENDIAN_BITFIELD)
927+
* struct {
928+
* u16 var3_w;
929+
* u16 var2_w;
930+
* u32 var1_dw;
931+
* } && PERF_SAMPLE_WEIGHT_STRUCT
932+
* #endif
933+
* }
934+
* }
894935
* { u64 data_src; } && PERF_SAMPLE_DATA_SRC
895936
* { u64 transaction; } && PERF_SAMPLE_TRANSACTION
896937
* { u64 abi; # enum perf_sample_regs_abi
@@ -915,10 +956,20 @@ enum perf_event_type {
915956
* u64 addr;
916957
* u64 len;
917958
* u64 pgoff;
918-
* u32 maj;
919-
* u32 min;
920-
* u64 ino;
921-
* u64 ino_generation;
959+
* union {
960+
* struct {
961+
* u32 maj;
962+
* u32 min;
963+
* u64 ino;
964+
* u64 ino_generation;
965+
* };
966+
* struct {
967+
* u8 build_id_size;
968+
* u8 __reserved_1;
969+
* u16 __reserved_2;
970+
* u8 build_id[20];
971+
* };
972+
* };
922973
* u32 prot, flags;
923974
* char filename[];
924975
* struct sample_id sample_id;
@@ -1127,14 +1178,16 @@ union perf_mem_data_src {
11271178
mem_lvl_num:4, /* memory hierarchy level number */
11281179
mem_remote:1, /* remote */
11291180
mem_snoopx:2, /* snoop mode, ext */
1130-
mem_rsvd:24;
1181+
mem_blk:3, /* access blocked */
1182+
mem_rsvd:21;
11311183
};
11321184
};
11331185
#elif defined(__BIG_ENDIAN_BITFIELD)
11341186
union perf_mem_data_src {
11351187
__u64 val;
11361188
struct {
1137-
__u64 mem_rsvd:24,
1189+
__u64 mem_rsvd:21,
1190+
mem_blk:3, /* access blocked */
11381191
mem_snoopx:2, /* snoop mode, ext */
11391192
mem_remote:1, /* remote */
11401193
mem_lvl_num:4, /* memory hierarchy level number */
@@ -1217,6 +1270,12 @@ union perf_mem_data_src {
12171270
#define PERF_MEM_TLB_OS 0x40 /* OS fault handler */
12181271
#define PERF_MEM_TLB_SHIFT 26
12191272

1273+
/* Access blocked */
1274+
#define PERF_MEM_BLK_NA 0x01 /* not available */
1275+
#define PERF_MEM_BLK_DATA 0x02 /* data could not be forwarded */
1276+
#define PERF_MEM_BLK_ADDR 0x04 /* address conflict */
1277+
#define PERF_MEM_BLK_SHIFT 40
1278+
12201279
#define PERF_MEM_S(a, s) \
12211280
(((__u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT)
12221281

@@ -1248,4 +1307,23 @@ struct perf_branch_entry {
12481307
reserved:40;
12491308
};
12501309

1310+
union perf_sample_weight {
1311+
__u64 full;
1312+
#if defined(__LITTLE_ENDIAN_BITFIELD)
1313+
struct {
1314+
__u32 var1_dw;
1315+
__u16 var2_w;
1316+
__u16 var3_w;
1317+
};
1318+
#elif defined(__BIG_ENDIAN_BITFIELD)
1319+
struct {
1320+
__u16 var3_w;
1321+
__u16 var2_w;
1322+
__u32 var1_dw;
1323+
};
1324+
#else
1325+
#error "Unknown endianness"
1326+
#endif
1327+
};
1328+
12511329
#endif /* _UAPI_LINUX_PERF_EVENT_H */

tools/include/uapi/linux/prctl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,8 @@ struct prctl_mm_map {
251251
#define PR_SET_SYSCALL_USER_DISPATCH 59
252252
# define PR_SYS_DISPATCH_OFF 0
253253
# define PR_SYS_DISPATCH_ON 1
254+
/* The control values for the user space selector when dispatch is enabled */
255+
# define SYSCALL_DISPATCH_FILTER_ALLOW 0
256+
# define SYSCALL_DISPATCH_FILTER_BLOCK 1
254257

255258
#endif /* _LINUX_PRCTL_H */

tools/lib/api/fs/cgroup.c

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,29 @@
88
#include <string.h>
99
#include "fs.h"
1010

11+
struct cgroupfs_cache_entry {
12+
char subsys[32];
13+
char mountpoint[PATH_MAX];
14+
};
15+
16+
/* just cache last used one */
17+
static struct cgroupfs_cache_entry cached;
18+
1119
int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys)
1220
{
1321
FILE *fp;
14-
char mountpoint[PATH_MAX + 1], tokens[PATH_MAX + 1], type[PATH_MAX + 1];
15-
char path_v1[PATH_MAX + 1], path_v2[PATH_MAX + 2], *path;
16-
char *token, *saved_ptr = NULL;
22+
char *line = NULL;
23+
size_t len = 0;
24+
char *p, *path;
25+
char mountpoint[PATH_MAX];
26+
27+
if (!strcmp(cached.subsys, subsys)) {
28+
if (strlen(cached.mountpoint) < maxlen) {
29+
strcpy(buf, cached.mountpoint);
30+
return 0;
31+
}
32+
return -1;
33+
}
1734

1835
fp = fopen("/proc/mounts", "r");
1936
if (!fp)
@@ -22,45 +39,63 @@ int cgroupfs_find_mountpoint(char *buf, size_t maxlen, const char *subsys)
2239
/*
2340
* in order to handle split hierarchy, we need to scan /proc/mounts
2441
* and inspect every cgroupfs mount point to find one that has
25-
* perf_event subsystem
42+
* the given subsystem. If we found v1, just use it. If not we can
43+
* use v2 path as a fallback.
2644
*/
27-
path_v1[0] = '\0';
28-
path_v2[0] = '\0';
45+
mountpoint[0] = '\0';
2946

30-
while (fscanf(fp, "%*s %"__stringify(PATH_MAX)"s %"__stringify(PATH_MAX)"s %"
31-
__stringify(PATH_MAX)"s %*d %*d\n",
32-
mountpoint, type, tokens) == 3) {
47+
/*
48+
* The /proc/mounts has the follow format:
49+
*
50+
* <devname> <mount point> <fs type> <options> ...
51+
*
52+
*/
53+
while (getline(&line, &len, fp) != -1) {
54+
/* skip devname */
55+
p = strchr(line, ' ');
56+
if (p == NULL)
57+
continue;
58+
59+
/* save the mount point */
60+
path = ++p;
61+
p = strchr(p, ' ');
62+
if (p == NULL)
63+
continue;
3364

34-
if (!path_v1[0] && !strcmp(type, "cgroup")) {
65+
*p++ = '\0';
3566

36-
token = strtok_r(tokens, ",", &saved_ptr);
67+
/* check filesystem type */
68+
if (strncmp(p, "cgroup", 6))
69+
continue;
3770

38-
while (token != NULL) {
39-
if (subsys && !strcmp(token, subsys)) {
40-
strcpy(path_v1, mountpoint);
41-
break;
42-
}
43-
token = strtok_r(NULL, ",", &saved_ptr);
44-
}
71+
if (p[6] == '2') {
72+
/* save cgroup v2 path */
73+
strcpy(mountpoint, path);
74+
continue;
4575
}
4676

47-
if (!path_v2[0] && !strcmp(type, "cgroup2"))
48-
strcpy(path_v2, mountpoint);
77+
/* now we have cgroup v1, check the options for subsystem */
78+
p += 7;
4979

50-
if (path_v1[0] && path_v2[0])
51-
break;
80+
p = strstr(p, subsys);
81+
if (p == NULL)
82+
continue;
83+
84+
/* sanity check: it should be separated by a space or a comma */
85+
if (!strchr(" ,", p[-1]) || !strchr(" ,", p[strlen(subsys)]))
86+
continue;
87+
88+
strcpy(mountpoint, path);
89+
break;
5290
}
91+
free(line);
5392
fclose(fp);
5493

55-
if (path_v1[0])
56-
path = path_v1;
57-
else if (path_v2[0])
58-
path = path_v2;
59-
else
60-
return -1;
94+
strncpy(cached.subsys, subsys, sizeof(cached.subsys) - 1);
95+
strcpy(cached.mountpoint, mountpoint);
6196

62-
if (strlen(path) < maxlen) {
63-
strcpy(buf, path);
97+
if (mountpoint[0] && strlen(mountpoint) < maxlen) {
98+
strcpy(buf, mountpoint);
6499
return 0;
65100
}
66101
return -1;

0 commit comments

Comments
 (0)