Skip to content

Commit 18118a4

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.17-2022-02-06' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Fix display of grouped aliased events in 'perf stat'. - Add missing branch_sample_type to perf_event_attr__fprintf(). - Apply correct label to user/kernel symbols in branch mode. - Fix 'perf ftrace' system_wide tracing, it has to be set before creating the maps. - Return error if procfs isn't mounted for PID namespaces when synthesizing records for pre-existing processes. - Set error stream of objdump process for 'perf annotate' TUI, to avoid garbling the screen. - Add missing arm64 support to perf_mmap__read_self(), the kernel part got into 5.17. - Check for NULL pointer before dereference writing debug info about a sample. - Update UAPI copies for asound, perf_event, prctl and kvm headers. - Fix a typo in bpf_counter_cgroup.c. * tag 'perf-tools-fixes-for-v5.17-2022-02-06' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf ftrace: system_wide collection is not effective by default libperf: Add arm64 support to perf_mmap__read_self() tools include UAPI: Sync sound/asound.h copy with the kernel sources perf stat: Fix display of grouped aliased events perf tools: Apply correct label to user/kernel symbols in branch mode perf bpf: Fix a typo in bpf_counter_cgroup.c perf synthetic-events: Return error if procfs isn't mounted for PID namespaces perf session: Check for NULL pointer before dereference perf annotate: Set error stream of objdump process for TUI perf tools: Add missing branch_sample_type to perf_event_attr__fprintf() tools headers UAPI: Sync linux/kvm.h with the kernel sources tools headers UAPI: Sync linux/prctl.h with the kernel sources perf beauty: Make the prctl arg regexp more strict to cope with PR_SET_VMA tools headers cpufeatures: Sync with the kernel sources tools headers UAPI: Sync linux/perf_event.h with the kernel sources tools include UAPI: Sync sound/asound.h copy with the kernel sources
2 parents c3bf8a1 + fceb621 commit 18118a4

18 files changed

+186
-45
lines changed

tools/arch/x86/include/asm/cpufeatures.h

+2
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@
299299
/* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */
300300
#define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */
301301
#define X86_FEATURE_AVX512_BF16 (12*32+ 5) /* AVX512 BFLOAT16 instructions */
302+
#define X86_FEATURE_AMX_BF16 (18*32+22) /* AMX bf16 Support */
302303
#define X86_FEATURE_AMX_TILE (18*32+24) /* AMX tile Support */
304+
#define X86_FEATURE_AMX_INT8 (18*32+25) /* AMX int8 Support */
303305

304306
/* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */
305307
#define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */

tools/include/uapi/linux/kvm.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1624,9 +1624,6 @@ struct kvm_enc_region {
16241624
#define KVM_S390_NORMAL_RESET _IO(KVMIO, 0xc3)
16251625
#define KVM_S390_CLEAR_RESET _IO(KVMIO, 0xc4)
16261626

1627-
/* Available with KVM_CAP_XSAVE2 */
1628-
#define KVM_GET_XSAVE2 _IOR(KVMIO, 0xcf, struct kvm_xsave)
1629-
16301627
struct kvm_s390_pv_sec_parm {
16311628
__u64 origin;
16321629
__u64 length;
@@ -2048,4 +2045,7 @@ struct kvm_stats_desc {
20482045

20492046
#define KVM_GET_STATS_FD _IO(KVMIO, 0xce)
20502047

2048+
/* Available with KVM_CAP_XSAVE2 */
2049+
#define KVM_GET_XSAVE2 _IOR(KVMIO, 0xcf, struct kvm_xsave)
2050+
20512051
#endif /* __LINUX_KVM_H */

tools/include/uapi/linux/perf_event.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,9 @@ union perf_mem_data_src {
13321332

13331333
/* hop level */
13341334
#define PERF_MEM_HOPS_0 0x01 /* remote core, same node */
1335-
#define PERF_MEM_HOPS_1 0x02 /* remote node, same socket */
1336-
#define PERF_MEM_HOPS_2 0x03 /* remote socket, same board */
1337-
#define PERF_MEM_HOPS_3 0x04 /* remote board */
1335+
#define PERF_MEM_HOPS_1 0x02 /* remote node, same socket */
1336+
#define PERF_MEM_HOPS_2 0x03 /* remote socket, same board */
1337+
#define PERF_MEM_HOPS_3 0x04 /* remote board */
13381338
/* 5-7 available */
13391339
#define PERF_MEM_HOPS_SHIFT 43
13401340

tools/include/uapi/linux/prctl.h

+3
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,7 @@ struct prctl_mm_map {
272272
# define PR_SCHED_CORE_SCOPE_THREAD_GROUP 1
273273
# define PR_SCHED_CORE_SCOPE_PROCESS_GROUP 2
274274

275+
#define PR_SET_VMA 0x53564d41
276+
# define PR_SET_VMA_ANON_NAME 0
277+
275278
#endif /* _LINUX_PRCTL_H */

tools/include/uapi/sound/asound.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@
5656
* *
5757
****************************************************************************/
5858

59+
#define AES_IEC958_STATUS_SIZE 24
60+
5961
struct snd_aes_iec958 {
60-
unsigned char status[24]; /* AES/IEC958 channel status bits */
62+
unsigned char status[AES_IEC958_STATUS_SIZE]; /* AES/IEC958 channel status bits */
6163
unsigned char subcode[147]; /* AES/IEC958 subcode bits */
6264
unsigned char pad; /* nothing */
6365
unsigned char dig_subframe[4]; /* AES/IEC958 subframe bits */
@@ -202,6 +204,11 @@ typedef int __bitwise snd_pcm_format_t;
202204
#define SNDRV_PCM_FORMAT_S24_BE ((__force snd_pcm_format_t) 7) /* low three bytes */
203205
#define SNDRV_PCM_FORMAT_U24_LE ((__force snd_pcm_format_t) 8) /* low three bytes */
204206
#define SNDRV_PCM_FORMAT_U24_BE ((__force snd_pcm_format_t) 9) /* low three bytes */
207+
/*
208+
* For S32/U32 formats, 'msbits' hardware parameter is often used to deliver information about the
209+
* available bit count in most significant bit. It's for the case of so-called 'left-justified' or
210+
* `right-padding` sample which has less width than 32 bit.
211+
*/
205212
#define SNDRV_PCM_FORMAT_S32_LE ((__force snd_pcm_format_t) 10)
206213
#define SNDRV_PCM_FORMAT_S32_BE ((__force snd_pcm_format_t) 11)
207214
#define SNDRV_PCM_FORMAT_U32_LE ((__force snd_pcm_format_t) 12)
@@ -300,7 +307,7 @@ typedef int __bitwise snd_pcm_subformat_t;
300307
#define SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME 0x04000000 /* report estimated link audio time */
301308
#define SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME 0x08000000 /* report synchronized audio/system time */
302309
#define SNDRV_PCM_INFO_EXPLICIT_SYNC 0x10000000 /* needs explicit sync of pointers and data */
303-
310+
#define SNDRV_PCM_INFO_NO_REWINDS 0x20000000 /* hardware can only support monotonic changes of appl_ptr */
304311
#define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */
305312
#define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */
306313

tools/lib/perf/mmap.c

+98
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <internal/lib.h>
1414
#include <linux/kernel.h>
1515
#include <linux/math64.h>
16+
#include <linux/stringify.h>
1617
#include "internal.h"
1718

1819
void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev,
@@ -294,6 +295,103 @@ static u64 read_timestamp(void)
294295

295296
return low | ((u64)high) << 32;
296297
}
298+
#elif defined(__aarch64__)
299+
#define read_sysreg(r) ({ \
300+
u64 __val; \
301+
asm volatile("mrs %0, " __stringify(r) : "=r" (__val)); \
302+
__val; \
303+
})
304+
305+
static u64 read_pmccntr(void)
306+
{
307+
return read_sysreg(pmccntr_el0);
308+
}
309+
310+
#define PMEVCNTR_READ(idx) \
311+
static u64 read_pmevcntr_##idx(void) { \
312+
return read_sysreg(pmevcntr##idx##_el0); \
313+
}
314+
315+
PMEVCNTR_READ(0);
316+
PMEVCNTR_READ(1);
317+
PMEVCNTR_READ(2);
318+
PMEVCNTR_READ(3);
319+
PMEVCNTR_READ(4);
320+
PMEVCNTR_READ(5);
321+
PMEVCNTR_READ(6);
322+
PMEVCNTR_READ(7);
323+
PMEVCNTR_READ(8);
324+
PMEVCNTR_READ(9);
325+
PMEVCNTR_READ(10);
326+
PMEVCNTR_READ(11);
327+
PMEVCNTR_READ(12);
328+
PMEVCNTR_READ(13);
329+
PMEVCNTR_READ(14);
330+
PMEVCNTR_READ(15);
331+
PMEVCNTR_READ(16);
332+
PMEVCNTR_READ(17);
333+
PMEVCNTR_READ(18);
334+
PMEVCNTR_READ(19);
335+
PMEVCNTR_READ(20);
336+
PMEVCNTR_READ(21);
337+
PMEVCNTR_READ(22);
338+
PMEVCNTR_READ(23);
339+
PMEVCNTR_READ(24);
340+
PMEVCNTR_READ(25);
341+
PMEVCNTR_READ(26);
342+
PMEVCNTR_READ(27);
343+
PMEVCNTR_READ(28);
344+
PMEVCNTR_READ(29);
345+
PMEVCNTR_READ(30);
346+
347+
/*
348+
* Read a value direct from PMEVCNTR<idx>
349+
*/
350+
static u64 read_perf_counter(unsigned int counter)
351+
{
352+
static u64 (* const read_f[])(void) = {
353+
read_pmevcntr_0,
354+
read_pmevcntr_1,
355+
read_pmevcntr_2,
356+
read_pmevcntr_3,
357+
read_pmevcntr_4,
358+
read_pmevcntr_5,
359+
read_pmevcntr_6,
360+
read_pmevcntr_7,
361+
read_pmevcntr_8,
362+
read_pmevcntr_9,
363+
read_pmevcntr_10,
364+
read_pmevcntr_11,
365+
read_pmevcntr_13,
366+
read_pmevcntr_12,
367+
read_pmevcntr_14,
368+
read_pmevcntr_15,
369+
read_pmevcntr_16,
370+
read_pmevcntr_17,
371+
read_pmevcntr_18,
372+
read_pmevcntr_19,
373+
read_pmevcntr_20,
374+
read_pmevcntr_21,
375+
read_pmevcntr_22,
376+
read_pmevcntr_23,
377+
read_pmevcntr_24,
378+
read_pmevcntr_25,
379+
read_pmevcntr_26,
380+
read_pmevcntr_27,
381+
read_pmevcntr_28,
382+
read_pmevcntr_29,
383+
read_pmevcntr_30,
384+
read_pmccntr
385+
};
386+
387+
if (counter < ARRAY_SIZE(read_f))
388+
return (read_f[counter])();
389+
390+
return 0;
391+
}
392+
393+
static u64 read_timestamp(void) { return read_sysreg(cntvct_el0); }
394+
297395
#else
298396
static u64 read_perf_counter(unsigned int counter __maybe_unused) { return 0; }
299397
static u64 read_timestamp(void) { return 0; }

tools/lib/perf/tests/test-evsel.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ static int test_stat_user_read(int event)
130130
struct perf_event_attr attr = {
131131
.type = PERF_TYPE_HARDWARE,
132132
.config = event,
133+
#ifdef __aarch64__
134+
.config1 = 0x2, /* Request user access */
135+
#endif
133136
};
134137
int err, i;
135138

@@ -150,7 +153,7 @@ static int test_stat_user_read(int event)
150153
pc = perf_evsel__mmap_base(evsel, 0, 0);
151154
__T("failed to get mmapped address", pc);
152155

153-
#if defined(__i386__) || defined(__x86_64__)
156+
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
154157
__T("userspace counter access not supported", pc->cap_user_rdpmc);
155158
__T("userspace counter access not enabled", pc->index);
156159
__T("userspace counter width not set", pc->pmc_width >= 32);

tools/perf/builtin-ftrace.c

+24-21
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ enum perf_ftrace_subcommand {
11151115
int cmd_ftrace(int argc, const char **argv)
11161116
{
11171117
int ret;
1118+
int (*cmd_func)(struct perf_ftrace *) = NULL;
11181119
struct perf_ftrace ftrace = {
11191120
.tracer = DEFAULT_TRACER,
11201121
.target = { .uid = UINT_MAX, },
@@ -1221,6 +1222,28 @@ int cmd_ftrace(int argc, const char **argv)
12211222
goto out_delete_filters;
12221223
}
12231224

1225+
switch (subcmd) {
1226+
case PERF_FTRACE_TRACE:
1227+
if (!argc && target__none(&ftrace.target))
1228+
ftrace.target.system_wide = true;
1229+
cmd_func = __cmd_ftrace;
1230+
break;
1231+
case PERF_FTRACE_LATENCY:
1232+
if (list_empty(&ftrace.filters)) {
1233+
pr_err("Should provide a function to measure\n");
1234+
parse_options_usage(ftrace_usage, options, "T", 1);
1235+
ret = -EINVAL;
1236+
goto out_delete_filters;
1237+
}
1238+
cmd_func = __cmd_latency;
1239+
break;
1240+
case PERF_FTRACE_NONE:
1241+
default:
1242+
pr_err("Invalid subcommand\n");
1243+
ret = -EINVAL;
1244+
goto out_delete_filters;
1245+
}
1246+
12241247
ret = target__validate(&ftrace.target);
12251248
if (ret) {
12261249
char errbuf[512];
@@ -1248,27 +1271,7 @@ int cmd_ftrace(int argc, const char **argv)
12481271
goto out_delete_evlist;
12491272
}
12501273

1251-
switch (subcmd) {
1252-
case PERF_FTRACE_TRACE:
1253-
if (!argc && target__none(&ftrace.target))
1254-
ftrace.target.system_wide = true;
1255-
ret = __cmd_ftrace(&ftrace);
1256-
break;
1257-
case PERF_FTRACE_LATENCY:
1258-
if (list_empty(&ftrace.filters)) {
1259-
pr_err("Should provide a function to measure\n");
1260-
parse_options_usage(ftrace_usage, options, "T", 1);
1261-
ret = -EINVAL;
1262-
goto out_delete_evlist;
1263-
}
1264-
ret = __cmd_latency(&ftrace);
1265-
break;
1266-
case PERF_FTRACE_NONE:
1267-
default:
1268-
pr_err("Invalid subcommand\n");
1269-
ret = -EINVAL;
1270-
break;
1271-
}
1274+
ret = cmd_func(&ftrace);
12721275

12731276
out_delete_evlist:
12741277
evlist__delete(ftrace.evlist);

tools/perf/trace/beauty/prctl_option.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[ $# -eq 1 ] && header_dir=$1 || header_dir=tools/include/uapi/linux/
55

66
printf "static const char *prctl_options[] = {\n"
7-
regex='^#define[[:space:]]+PR_(\w+)[[:space:]]*([[:xdigit:]]+).*'
7+
regex='^#define[[:space:]]{1}PR_(\w+)[[:space:]]*([[:xdigit:]]+)([[:space:]]*\/.*)?$'
88
egrep $regex ${header_dir}/prctl.h | grep -v PR_SET_PTRACER | \
99
sed -r "s/$regex/\2 \1/g" | \
1010
sort -n | xargs printf "\t[%s] = \"%s\",\n"

tools/perf/util/annotate.c

+1
Original file line numberDiff line numberDiff line change
@@ -2036,6 +2036,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
20362036
memset(&objdump_process, 0, sizeof(objdump_process));
20372037
objdump_process.argv = objdump_argv;
20382038
objdump_process.out = -1;
2039+
objdump_process.err = -1;
20392040
if (start_command(&objdump_process)) {
20402041
pr_err("Failure starting to run %s\n", command);
20412042
err = -1;

tools/perf/util/bpf_counter_cgroup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int bperf_cgrp__read(struct evsel *evsel)
266266
idx = evsel->core.idx;
267267
err = bpf_map_lookup_elem(reading_map_fd, &idx, values);
268268
if (err) {
269-
pr_err("bpf map lookup falied: idx=%u, event=%s, cgrp=%s\n",
269+
pr_err("bpf map lookup failed: idx=%u, event=%s, cgrp=%s\n",
270270
idx, evsel__name(evsel), evsel->cgrp->name);
271271
goto out;
272272
}

tools/perf/util/machine.c

+2
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,7 @@ static void ip__resolve_ams(struct thread *thread,
20732073

20742074
ams->addr = ip;
20752075
ams->al_addr = al.addr;
2076+
ams->al_level = al.level;
20762077
ams->ms.maps = al.maps;
20772078
ams->ms.sym = al.sym;
20782079
ams->ms.map = al.map;
@@ -2092,6 +2093,7 @@ static void ip__resolve_data(struct thread *thread,
20922093

20932094
ams->addr = addr;
20942095
ams->al_addr = al.addr;
2096+
ams->al_level = al.level;
20952097
ams->ms.maps = al.maps;
20962098
ams->ms.sym = al.sym;
20972099
ams->ms.map = al.map;

tools/perf/util/map_symbol.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct addr_map_symbol {
1818
struct map_symbol ms;
1919
u64 addr;
2020
u64 al_addr;
21+
char al_level;
2122
u64 phys_addr;
2223
u64 data_page_size;
2324
};

tools/perf/util/perf_event_attr_fprintf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void __p_branch_sample_type(char *buf, size_t size, u64 value)
5252
bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX),
5353
bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP),
5454
bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES),
55-
bit_name(HW_INDEX),
55+
bit_name(TYPE_SAVE), bit_name(HW_INDEX),
5656
{ .name = NULL, }
5757
};
5858
#undef bit_name

tools/perf/util/session.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1503,11 +1503,12 @@ static int machines__deliver_event(struct machines *machines,
15031503
++evlist->stats.nr_unknown_id;
15041504
return 0;
15051505
}
1506-
dump_sample(evsel, event, sample, perf_env__arch(machine->env));
15071506
if (machine == NULL) {
15081507
++evlist->stats.nr_unprocessable_samples;
1508+
dump_sample(evsel, event, sample, perf_env__arch(NULL));
15091509
return 0;
15101510
}
1511+
dump_sample(evsel, event, sample, perf_env__arch(machine->env));
15111512
return evlist__deliver_sample(evlist, tool, event, sample, evsel, machine);
15121513
case PERF_RECORD_MMAP:
15131514
return tool->mmap(tool, event, sample, machine);

tools/perf/util/sort.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ static int hist_entry__sym_from_snprintf(struct hist_entry *he, char *bf,
915915
struct addr_map_symbol *from = &he->branch_info->from;
916916

917917
return _hist_entry__sym_snprintf(&from->ms, from->al_addr,
918-
he->level, bf, size, width);
918+
from->al_level, bf, size, width);
919919
}
920920

921921
return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A");
@@ -928,7 +928,7 @@ static int hist_entry__sym_to_snprintf(struct hist_entry *he, char *bf,
928928
struct addr_map_symbol *to = &he->branch_info->to;
929929

930930
return _hist_entry__sym_snprintf(&to->ms, to->al_addr,
931-
he->level, bf, size, width);
931+
to->al_level, bf, size, width);
932932
}
933933

934934
return repsep_snprintf(bf, size, "%-*.*s", width, width, "N/A");

tools/perf/util/stat-display.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,16 @@ static void collect_all_aliases(struct perf_stat_config *config, struct evsel *c
585585

586586
alias = list_prepare_entry(counter, &(evlist->core.entries), core.node);
587587
list_for_each_entry_continue (alias, &evlist->core.entries, core.node) {
588-
if (strcmp(evsel__name(alias), evsel__name(counter)) ||
589-
alias->scale != counter->scale ||
590-
alias->cgrp != counter->cgrp ||
591-
strcmp(alias->unit, counter->unit) ||
592-
evsel__is_clock(alias) != evsel__is_clock(counter) ||
593-
!strcmp(alias->pmu_name, counter->pmu_name))
594-
break;
595-
alias->merged_stat = true;
596-
cb(config, alias, data, false);
588+
/* Merge events with the same name, etc. but on different PMUs. */
589+
if (!strcmp(evsel__name(alias), evsel__name(counter)) &&
590+
alias->scale == counter->scale &&
591+
alias->cgrp == counter->cgrp &&
592+
!strcmp(alias->unit, counter->unit) &&
593+
evsel__is_clock(alias) == evsel__is_clock(counter) &&
594+
strcmp(alias->pmu_name, counter->pmu_name)) {
595+
alias->merged_stat = true;
596+
cb(config, alias, data, false);
597+
}
597598
}
598599
}
599600

0 commit comments

Comments
 (0)