Skip to content

Commit 40c8432

Browse files
committed
Merge tag 'perf-tools-for-v5.17-2022-01-22' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull more perf tools updates from Arnaldo Carvalho de Melo: - Fix printing 'phys_addr' in 'perf script'. - Fix failure to add events with 'perf probe' in ppc64 due to not removing leading dot (ppc64 ABIv1). - Fix cpu_map__item() python binding building. - Support event alias in form foo-bar-baz, add pmu-events and parse-event tests for it. - No need to setup affinities when starting a workload or attaching to a pid. - Use path__join() to compose a path instead of ad-hoc snprintf() equivalent. - Override attr->sample_period for non-libpfm4 events. - Use libperf cpumap APIs instead of accessing the internal state directly. - Sync x86 arch prctl headers and files changed by the new set_mempolicy_home_node syscall with the kernel sources. - Remove duplicate include in cpumap.h. - Remove redundant err variable. * tag 'perf-tools-for-v5.17-2022-01-22' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: perf tools: Remove redundant err variable perf test: Add parse-events test for aliases with hyphens perf test: Add pmu-events test for aliases with hyphens perf parse-events: Support event alias in form foo-bar-baz perf evsel: Override attr->sample_period for non-libpfm4 events perf cpumap: Remove duplicate include in cpumap.h perf cpumap: Migrate to libperf cpumap api perf python: Fix cpu_map__item() building perf script: Fix printing 'phys_addr' failure issue tools headers UAPI: Sync files changed by new set_mempolicy_home_node syscall tools headers UAPI: Sync x86 arch prctl headers with the kernel sources perf machine: Use path__join() to compose a path instead of snprintf(dir, '/', filename) perf evlist: No need to setup affinities when disabling events for pid targets perf evlist: No need to setup affinities when enabling events for pid targets perf stat: No need to setup affinities when starting a workload perf affinity: Allow passing a NULL arg to affinity__cleanup() perf probe: Fix ppc64 'perf probe add events failed' case
2 parents 67bfce0 + f0ac5b8 commit 40c8432

Some content is hidden

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

51 files changed

+354
-149
lines changed

tools/arch/x86/include/uapi/asm/prctl.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
#ifndef _ASM_X86_PRCTL_H
33
#define _ASM_X86_PRCTL_H
44

5-
#define ARCH_SET_GS 0x1001
6-
#define ARCH_SET_FS 0x1002
7-
#define ARCH_GET_FS 0x1003
8-
#define ARCH_GET_GS 0x1004
5+
#define ARCH_SET_GS 0x1001
6+
#define ARCH_SET_FS 0x1002
7+
#define ARCH_GET_FS 0x1003
8+
#define ARCH_GET_GS 0x1004
99

10-
#define ARCH_GET_CPUID 0x1011
11-
#define ARCH_SET_CPUID 0x1012
10+
#define ARCH_GET_CPUID 0x1011
11+
#define ARCH_SET_CPUID 0x1012
1212

13-
#define ARCH_GET_XCOMP_SUPP 0x1021
14-
#define ARCH_GET_XCOMP_PERM 0x1022
15-
#define ARCH_REQ_XCOMP_PERM 0x1023
13+
#define ARCH_GET_XCOMP_SUPP 0x1021
14+
#define ARCH_GET_XCOMP_PERM 0x1022
15+
#define ARCH_REQ_XCOMP_PERM 0x1023
16+
#define ARCH_GET_XCOMP_GUEST_PERM 0x1024
17+
#define ARCH_REQ_XCOMP_GUEST_PERM 0x1025
1618

17-
#define ARCH_MAP_VDSO_X32 0x2001
18-
#define ARCH_MAP_VDSO_32 0x2002
19-
#define ARCH_MAP_VDSO_64 0x2003
19+
#define ARCH_MAP_VDSO_X32 0x2001
20+
#define ARCH_MAP_VDSO_32 0x2002
21+
#define ARCH_MAP_VDSO_64 0x2003
2022

2123
#endif /* _ASM_X86_PRCTL_H */

tools/include/uapi/asm-generic/unistd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,11 @@ __SYSCALL(__NR_process_mrelease, sys_process_mrelease)
883883
#define __NR_futex_waitv 449
884884
__SYSCALL(__NR_futex_waitv, sys_futex_waitv)
885885

886+
#define __NR_set_mempolicy_home_node 450
887+
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
888+
886889
#undef __NR_syscalls
887-
#define __NR_syscalls 450
890+
#define __NR_syscalls 451
888891

889892
/*
890893
* 32 bit systems traditionally used different

tools/lib/perf/evsel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
141141
}
142142

143143
if (evsel->fd == NULL &&
144-
perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0)
144+
perf_evsel__alloc_fd(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0)
145145
return -ENOMEM;
146146

147147
perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
@@ -384,7 +384,7 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
384384
{
385385
int err = 0, i;
386386

387-
for (i = 0; i < evsel->cpus->nr && !err; i++)
387+
for (i = 0; i < perf_cpu_map__nr(evsel->cpus) && !err; i++)
388388
err = perf_evsel__run_ioctl(evsel,
389389
PERF_EVENT_IOC_SET_FILTER,
390390
(void *)filter, i);

tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,4 @@
364364
# 447 reserved for memfd_secret
365365
448 n64 process_mrelease sys_process_mrelease
366366
449 n64 futex_waitv sys_futex_waitv
367+
450 common set_mempolicy_home_node sys_set_mempolicy_home_node

tools/perf/arch/powerpc/entry/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,4 @@
529529
# 447 reserved for memfd_secret
530530
448 common process_mrelease sys_process_mrelease
531531
449 common futex_waitv sys_futex_waitv
532+
450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node

tools/perf/arch/s390/entry/syscalls/syscall.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,4 @@
452452
# 447 reserved for memfd_secret
453453
448 common process_mrelease sys_process_mrelease sys_process_mrelease
454454
449 common futex_waitv sys_futex_waitv sys_futex_waitv
455+
450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node

tools/perf/arch/x86/entry/syscalls/syscall_64.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@
371371
447 common memfd_secret sys_memfd_secret
372372
448 common process_mrelease sys_process_mrelease
373373
449 common futex_waitv sys_futex_waitv
374+
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
374375

375376
#
376377
# Due to a historical design error, certain syscalls are numbered differently

tools/perf/bench/epoll-ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ int bench_epoll_ctl(int argc, const char **argv)
333333

334334
/* default to the number of CPUs */
335335
if (!nthreads)
336-
nthreads = cpu->nr;
336+
nthreads = perf_cpu_map__nr(cpu);
337337

338338
worker = calloc(nthreads, sizeof(*worker));
339339
if (!worker)

tools/perf/bench/epoll-wait.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ int bench_epoll_wait(int argc, const char **argv)
452452

453453
/* default to the number of CPUs and leave one for the writer pthread */
454454
if (!nthreads)
455-
nthreads = cpu->nr - 1;
455+
nthreads = perf_cpu_map__nr(cpu) - 1;
456456

457457
worker = calloc(nthreads, sizeof(*worker));
458458
if (!worker) {

tools/perf/bench/evlist-open-close.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int evlist__count_evsel_fds(struct evlist *evlist)
7171
int cnt = 0;
7272

7373
evlist__for_each_entry(evlist, evsel)
74-
cnt += evsel->core.threads->nr * evsel->core.cpus->nr;
74+
cnt += evsel->core.threads->nr * perf_cpu_map__nr(evsel->core.cpus);
7575

7676
return cnt;
7777
}
@@ -151,7 +151,7 @@ static int bench_evlist_open_close__run(char *evstr)
151151

152152
init_stats(&time_stats);
153153

154-
printf(" Number of cpus:\t%d\n", evlist->core.cpus->nr);
154+
printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.cpus));
155155
printf(" Number of threads:\t%d\n", evlist->core.threads->nr);
156156
printf(" Number of events:\t%d (%d fds)\n",
157157
evlist->core.nr_entries, evlist__count_evsel_fds(evlist));

tools/perf/bench/futex-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int bench_futex_hash(int argc, const char **argv)
150150
}
151151

152152
if (!params.nthreads) /* default to the number of CPUs */
153-
params.nthreads = cpu->nr;
153+
params.nthreads = perf_cpu_map__nr(cpu);
154154

155155
worker = calloc(params.nthreads, sizeof(*worker));
156156
if (!worker)

tools/perf/bench/futex-lock-pi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
173173
}
174174

175175
if (!params.nthreads)
176-
params.nthreads = cpu->nr;
176+
params.nthreads = perf_cpu_map__nr(cpu);
177177

178178
worker = calloc(params.nthreads, sizeof(*worker));
179179
if (!worker)

tools/perf/bench/futex-requeue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int bench_futex_requeue(int argc, const char **argv)
175175
}
176176

177177
if (!params.nthreads)
178-
params.nthreads = cpu->nr;
178+
params.nthreads = perf_cpu_map__nr(cpu);
179179

180180
worker = calloc(params.nthreads, sizeof(*worker));
181181
if (!worker)

tools/perf/bench/futex-wake-parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ int bench_futex_wake_parallel(int argc, const char **argv)
252252
err(EXIT_FAILURE, "calloc");
253253

254254
if (!params.nthreads)
255-
params.nthreads = cpu->nr;
255+
params.nthreads = perf_cpu_map__nr(cpu);
256256

257257
/* some sanity checks */
258258
if (params.nwakes > params.nthreads ||

tools/perf/bench/futex-wake.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int bench_futex_wake(int argc, const char **argv)
151151
}
152152

153153
if (!params.nthreads)
154-
params.nthreads = cpu->nr;
154+
params.nthreads = perf_cpu_map__nr(cpu);
155155

156156
worker = calloc(params.nthreads, sizeof(*worker));
157157
if (!worker)

tools/perf/builtin-ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap)
281281
int ret;
282282
int last_cpu;
283283

284-
last_cpu = perf_cpu_map__cpu(cpumap, cpumap->nr - 1).cpu;
284+
last_cpu = perf_cpu_map__cpu(cpumap, perf_cpu_map__nr(cpumap) - 1).cpu;
285285
mask_size = last_cpu / 4 + 2; /* one more byte for EOS */
286286
mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
287287

tools/perf/builtin-inject.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,9 @@ static int perf_event__repipe_exit(struct perf_tool *tool,
535535
static int perf_event__repipe_tracing_data(struct perf_session *session,
536536
union perf_event *event)
537537
{
538-
int err;
539-
540538
perf_event__repipe_synth(session->tool, event);
541-
err = perf_event__process_tracing_data(session, event);
542539

543-
return err;
540+
return perf_event__process_tracing_data(session, event);
544541
}
545542

546543
static int dso__read_build_id(struct dso *dso)

tools/perf/builtin-script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)
515515
return -EINVAL;
516516

517517
if (PRINT_FIELD(PHYS_ADDR) &&
518-
evsel__check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR", PERF_OUTPUT_PHYS_ADDR))
518+
evsel__do_check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR", PERF_OUTPUT_PHYS_ADDR, allow_user_set))
519519
return -EINVAL;
520520

521521
if (PRINT_FIELD(DATA_PAGE_SIZE) &&

tools/perf/builtin-stat.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,12 @@ static bool cpus_map_matched(struct evsel *a, struct evsel *b)
230230
if (!a->core.cpus || !b->core.cpus)
231231
return false;
232232

233-
if (a->core.cpus->nr != b->core.cpus->nr)
233+
if (perf_cpu_map__nr(a->core.cpus) != perf_cpu_map__nr(b->core.cpus))
234234
return false;
235235

236-
for (int i = 0; i < a->core.cpus->nr; i++) {
237-
if (a->core.cpus->map[i].cpu != b->core.cpus->map[i].cpu)
236+
for (int i = 0; i < perf_cpu_map__nr(a->core.cpus); i++) {
237+
if (perf_cpu_map__cpu(a->core.cpus, i).cpu !=
238+
perf_cpu_map__cpu(b->core.cpus, i).cpu)
238239
return false;
239240
}
240241

@@ -788,7 +789,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
788789
const bool forks = (argc > 0);
789790
bool is_pipe = STAT_RECORD ? perf_stat.data.is_pipe : false;
790791
struct evlist_cpu_iterator evlist_cpu_itr;
791-
struct affinity affinity;
792+
struct affinity saved_affinity, *affinity = NULL;
792793
int err;
793794
bool second_pass = false;
794795

@@ -803,8 +804,11 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
803804
if (group)
804805
evlist__set_leader(evsel_list);
805806

806-
if (affinity__setup(&affinity) < 0)
807-
return -1;
807+
if (!cpu_map__is_dummy(evsel_list->core.cpus)) {
808+
if (affinity__setup(&saved_affinity) < 0)
809+
return -1;
810+
affinity = &saved_affinity;
811+
}
808812

809813
evlist__for_each_entry(evsel_list, counter) {
810814
if (bpf_counter__load(counter, &target))
@@ -813,7 +817,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
813817
all_counters_use_bpf = false;
814818
}
815819

816-
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
820+
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
817821
counter = evlist_cpu_itr.evsel;
818822

819823
/*
@@ -869,7 +873,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
869873
*/
870874

871875
/* First close errored or weak retry */
872-
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
876+
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
873877
counter = evlist_cpu_itr.evsel;
874878

875879
if (!counter->reset_group && !counter->errored)
@@ -878,7 +882,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
878882
perf_evsel__close_cpu(&counter->core, evlist_cpu_itr.cpu_map_idx);
879883
}
880884
/* Now reopen weak */
881-
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
885+
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
882886
counter = evlist_cpu_itr.evsel;
883887

884888
if (!counter->reset_group && !counter->errored)
@@ -904,7 +908,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
904908
counter->supported = true;
905909
}
906910
}
907-
affinity__cleanup(&affinity);
911+
affinity__cleanup(affinity);
908912

909913
evlist__for_each_entry(evsel_list, counter) {
910914
if (!counter->supported) {

tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@
1818
"Invert": "0",
1919
"EdgeDetect": "0"
2020
},
21+
{
22+
"Unit": "CBO",
23+
"EventCode": "0xE0",
24+
"UMask": "0x00",
25+
"EventName": "event-hyphen",
26+
"BriefDescription": "UNC_CBO_HYPHEN",
27+
"PublicDescription": "UNC_CBO_HYPHEN"
28+
},
29+
{
30+
"Unit": "CBO",
31+
"EventCode": "0xC0",
32+
"UMask": "0x00",
33+
"EventName": "event-two-hyph",
34+
"BriefDescription": "UNC_CBO_TWO_HYPH",
35+
"PublicDescription": "UNC_CBO_TWO_HYPH"
36+
},
2137
{
2238
"EventCode": "0x7",
2339
"EventName": "uncore_hisi_l3c.rd_hit_cpipe",

tools/perf/tests/bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ static unsigned long *get_bitmap(const char *str, int nbits)
1717
bm = bitmap_zalloc(nbits);
1818

1919
if (map && bm) {
20-
for (i = 0; i < map->nr; i++)
21-
set_bit(map->map[i].cpu, bm);
20+
for (i = 0; i < perf_cpu_map__nr(map); i++)
21+
set_bit(perf_cpu_map__cpu(map, i).cpu, bm);
2222
}
2323

2424
if (map)

tools/perf/tests/event_update.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,
7575

7676
TEST_ASSERT_VAL("wrong id", ev->id == 123);
7777
TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
78-
TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
79-
TEST_ASSERT_VAL("wrong cpus", map->map[0].cpu == 1);
80-
TEST_ASSERT_VAL("wrong cpus", map->map[1].cpu == 2);
81-
TEST_ASSERT_VAL("wrong cpus", map->map[2].cpu == 3);
78+
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__nr(map) == 3);
79+
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 0).cpu == 1);
80+
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 1).cpu == 2);
81+
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 2).cpu == 3);
8282
perf_cpu_map__put(map);
8383
return 0;
8484
}

tools/perf/tests/mem2node.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ static unsigned long *get_bitmap(const char *str, int nbits)
2525
{
2626
struct perf_cpu_map *map = perf_cpu_map__new(str);
2727
unsigned long *bm = NULL;
28-
int i;
2928

3029
bm = bitmap_zalloc(nbits);
3130

3231
if (map && bm) {
33-
for (i = 0; i < map->nr; i++) {
34-
set_bit(map->map[i].cpu, bm);
35-
}
32+
struct perf_cpu cpu;
33+
int i;
34+
35+
perf_cpu_map__for_each_cpu(cpu, i, map)
36+
set_bit(cpu.cpu, bm);
3637
}
3738

3839
if (map)

tools/perf/tests/mmap-basic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest
5959
}
6060

6161
CPU_ZERO(&cpu_set);
62-
CPU_SET(cpus->map[0].cpu, &cpu_set);
62+
CPU_SET(perf_cpu_map__cpu(cpus, 0).cpu, &cpu_set);
6363
sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
6464
if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
6565
pr_debug("sched_setaffinity() failed on CPU %d: %s ",
66-
cpus->map[0].cpu, str_error_r(errno, sbuf, sizeof(sbuf)));
66+
perf_cpu_map__cpu(cpus, 0).cpu,
67+
str_error_r(errno, sbuf, sizeof(sbuf)));
6768
goto out_free_cpus;
6869
}
6970

0 commit comments

Comments
 (0)