Skip to content

Commit

Permalink
Merge tag 'perf-tools-for-v5.17-2022-01-22' of git://git.kernel.org/p…
Browse files Browse the repository at this point in the history
…ub/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
  • Loading branch information
torvalds committed Jan 23, 2022
2 parents 67bfce0 + f0ac5b8 commit 40c8432
Show file tree
Hide file tree
Showing 51 changed files with 354 additions and 149 deletions.
26 changes: 14 additions & 12 deletions tools/arch/x86/include/uapi/asm/prctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
#ifndef _ASM_X86_PRCTL_H
#define _ASM_X86_PRCTL_H

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004
#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004

#define ARCH_GET_CPUID 0x1011
#define ARCH_SET_CPUID 0x1012
#define ARCH_GET_CPUID 0x1011
#define ARCH_SET_CPUID 0x1012

#define ARCH_GET_XCOMP_SUPP 0x1021
#define ARCH_GET_XCOMP_PERM 0x1022
#define ARCH_REQ_XCOMP_PERM 0x1023
#define ARCH_GET_XCOMP_SUPP 0x1021
#define ARCH_GET_XCOMP_PERM 0x1022
#define ARCH_REQ_XCOMP_PERM 0x1023
#define ARCH_GET_XCOMP_GUEST_PERM 0x1024
#define ARCH_REQ_XCOMP_GUEST_PERM 0x1025

#define ARCH_MAP_VDSO_X32 0x2001
#define ARCH_MAP_VDSO_32 0x2002
#define ARCH_MAP_VDSO_64 0x2003
#define ARCH_MAP_VDSO_X32 0x2001
#define ARCH_MAP_VDSO_32 0x2002
#define ARCH_MAP_VDSO_64 0x2003

#endif /* _ASM_X86_PRCTL_H */
5 changes: 4 additions & 1 deletion tools/include/uapi/asm-generic/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,11 @@ __SYSCALL(__NR_process_mrelease, sys_process_mrelease)
#define __NR_futex_waitv 449
__SYSCALL(__NR_futex_waitv, sys_futex_waitv)

#define __NR_set_mempolicy_home_node 450
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)

#undef __NR_syscalls
#define __NR_syscalls 450
#define __NR_syscalls 451

/*
* 32 bit systems traditionally used different
Expand Down
4 changes: 2 additions & 2 deletions tools/lib/perf/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
}

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

perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
Expand Down Expand Up @@ -384,7 +384,7 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
{
int err = 0, i;

for (i = 0; i < evsel->cpus->nr && !err; i++)
for (i = 0; i < perf_cpu_map__nr(evsel->cpus) && !err; i++)
err = perf_evsel__run_ioctl(evsel,
PERF_EVENT_IOC_SET_FILTER,
(void *)filter, i);
Expand Down
1 change: 1 addition & 0 deletions tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,4 @@
# 447 reserved for memfd_secret
448 n64 process_mrelease sys_process_mrelease
449 n64 futex_waitv sys_futex_waitv
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
1 change: 1 addition & 0 deletions tools/perf/arch/powerpc/entry/syscalls/syscall.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,4 @@
# 447 reserved for memfd_secret
448 common process_mrelease sys_process_mrelease
449 common futex_waitv sys_futex_waitv
450 nospu set_mempolicy_home_node sys_set_mempolicy_home_node
1 change: 1 addition & 0 deletions tools/perf/arch/s390/entry/syscalls/syscall.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,4 @@
# 447 reserved for memfd_secret
448 common process_mrelease sys_process_mrelease sys_process_mrelease
449 common futex_waitv sys_futex_waitv sys_futex_waitv
450 common set_mempolicy_home_node sys_set_mempolicy_home_node sys_set_mempolicy_home_node
1 change: 1 addition & 0 deletions tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@
447 common memfd_secret sys_memfd_secret
448 common process_mrelease sys_process_mrelease
449 common futex_waitv sys_futex_waitv
450 common set_mempolicy_home_node sys_set_mempolicy_home_node

#
# Due to a historical design error, certain syscalls are numbered differently
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/epoll-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ int bench_epoll_ctl(int argc, const char **argv)

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

worker = calloc(nthreads, sizeof(*worker));
if (!worker)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/epoll-wait.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ int bench_epoll_wait(int argc, const char **argv)

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

worker = calloc(nthreads, sizeof(*worker));
if (!worker) {
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/bench/evlist-open-close.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int evlist__count_evsel_fds(struct evlist *evlist)
int cnt = 0;

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

return cnt;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ static int bench_evlist_open_close__run(char *evstr)

init_stats(&time_stats);

printf(" Number of cpus:\t%d\n", evlist->core.cpus->nr);
printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.cpus));
printf(" Number of threads:\t%d\n", evlist->core.threads->nr);
printf(" Number of events:\t%d (%d fds)\n",
evlist->core.nr_entries, evlist__count_evsel_fds(evlist));
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/futex-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int bench_futex_hash(int argc, const char **argv)
}

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

worker = calloc(params.nthreads, sizeof(*worker));
if (!worker)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/futex-lock-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
}

if (!params.nthreads)
params.nthreads = cpu->nr;
params.nthreads = perf_cpu_map__nr(cpu);

worker = calloc(params.nthreads, sizeof(*worker));
if (!worker)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/futex-requeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int bench_futex_requeue(int argc, const char **argv)
}

if (!params.nthreads)
params.nthreads = cpu->nr;
params.nthreads = perf_cpu_map__nr(cpu);

worker = calloc(params.nthreads, sizeof(*worker));
if (!worker)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/futex-wake-parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ int bench_futex_wake_parallel(int argc, const char **argv)
err(EXIT_FAILURE, "calloc");

if (!params.nthreads)
params.nthreads = cpu->nr;
params.nthreads = perf_cpu_map__nr(cpu);

/* some sanity checks */
if (params.nwakes > params.nthreads ||
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/bench/futex-wake.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int bench_futex_wake(int argc, const char **argv)
}

if (!params.nthreads)
params.nthreads = cpu->nr;
params.nthreads = perf_cpu_map__nr(cpu);

worker = calloc(params.nthreads, sizeof(*worker));
if (!worker)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap)
int ret;
int last_cpu;

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

Expand Down
5 changes: 1 addition & 4 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,9 @@ static int perf_event__repipe_exit(struct perf_tool *tool,
static int perf_event__repipe_tracing_data(struct perf_session *session,
union perf_event *event)
{
int err;

perf_event__repipe_synth(session->tool, event);
err = perf_event__process_tracing_data(session, event);

return err;
return perf_event__process_tracing_data(session, event);
}

static int dso__read_build_id(struct dso *dso)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)
return -EINVAL;

if (PRINT_FIELD(PHYS_ADDR) &&
evsel__check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR", PERF_OUTPUT_PHYS_ADDR))
evsel__do_check_stype(evsel, PERF_SAMPLE_PHYS_ADDR, "PHYS_ADDR", PERF_OUTPUT_PHYS_ADDR, allow_user_set))
return -EINVAL;

if (PRINT_FIELD(DATA_PAGE_SIZE) &&
Expand Down
24 changes: 14 additions & 10 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,12 @@ static bool cpus_map_matched(struct evsel *a, struct evsel *b)
if (!a->core.cpus || !b->core.cpus)
return false;

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

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

Expand Down Expand Up @@ -788,7 +789,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
const bool forks = (argc > 0);
bool is_pipe = STAT_RECORD ? perf_stat.data.is_pipe : false;
struct evlist_cpu_iterator evlist_cpu_itr;
struct affinity affinity;
struct affinity saved_affinity, *affinity = NULL;
int err;
bool second_pass = false;

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

if (affinity__setup(&affinity) < 0)
return -1;
if (!cpu_map__is_dummy(evsel_list->core.cpus)) {
if (affinity__setup(&saved_affinity) < 0)
return -1;
affinity = &saved_affinity;
}

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

evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
counter = evlist_cpu_itr.evsel;

/*
Expand Down Expand Up @@ -869,7 +873,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
*/

/* First close errored or weak retry */
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) {
evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) {
counter = evlist_cpu_itr.evsel;

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

if (!counter->reset_group && !counter->errored)
Expand All @@ -904,7 +908,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
counter->supported = true;
}
}
affinity__cleanup(&affinity);
affinity__cleanup(affinity);

evlist__for_each_entry(evsel_list, counter) {
if (!counter->supported) {
Expand Down
16 changes: 16 additions & 0 deletions tools/perf/pmu-events/arch/test/test_soc/cpu/uncore.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
"Invert": "0",
"EdgeDetect": "0"
},
{
"Unit": "CBO",
"EventCode": "0xE0",
"UMask": "0x00",
"EventName": "event-hyphen",
"BriefDescription": "UNC_CBO_HYPHEN",
"PublicDescription": "UNC_CBO_HYPHEN"
},
{
"Unit": "CBO",
"EventCode": "0xC0",
"UMask": "0x00",
"EventName": "event-two-hyph",
"BriefDescription": "UNC_CBO_TWO_HYPH",
"PublicDescription": "UNC_CBO_TWO_HYPH"
},
{
"EventCode": "0x7",
"EventName": "uncore_hisi_l3c.rd_hit_cpipe",
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/tests/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ static unsigned long *get_bitmap(const char *str, int nbits)
bm = bitmap_zalloc(nbits);

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

if (map)
Expand Down
8 changes: 4 additions & 4 deletions tools/perf/tests/event_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused,

TEST_ASSERT_VAL("wrong id", ev->id == 123);
TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
TEST_ASSERT_VAL("wrong cpus", map->map[0].cpu == 1);
TEST_ASSERT_VAL("wrong cpus", map->map[1].cpu == 2);
TEST_ASSERT_VAL("wrong cpus", map->map[2].cpu == 3);
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__nr(map) == 3);
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 0).cpu == 1);
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 1).cpu == 2);
TEST_ASSERT_VAL("wrong cpus", perf_cpu_map__cpu(map, 2).cpu == 3);
perf_cpu_map__put(map);
return 0;
}
Expand Down
9 changes: 5 additions & 4 deletions tools/perf/tests/mem2node.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ static unsigned long *get_bitmap(const char *str, int nbits)
{
struct perf_cpu_map *map = perf_cpu_map__new(str);
unsigned long *bm = NULL;
int i;

bm = bitmap_zalloc(nbits);

if (map && bm) {
for (i = 0; i < map->nr; i++) {
set_bit(map->map[i].cpu, bm);
}
struct perf_cpu cpu;
int i;

perf_cpu_map__for_each_cpu(cpu, i, map)
set_bit(cpu.cpu, bm);
}

if (map)
Expand Down
5 changes: 3 additions & 2 deletions tools/perf/tests/mmap-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest
}

CPU_ZERO(&cpu_set);
CPU_SET(cpus->map[0].cpu, &cpu_set);
CPU_SET(perf_cpu_map__cpu(cpus, 0).cpu, &cpu_set);
sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
pr_debug("sched_setaffinity() failed on CPU %d: %s ",
cpus->map[0].cpu, str_error_r(errno, sbuf, sizeof(sbuf)));
perf_cpu_map__cpu(cpus, 0).cpu,
str_error_r(errno, sbuf, sizeof(sbuf)));
goto out_free_cpus;
}

Expand Down
Loading

0 comments on commit 40c8432

Please sign in to comment.