linux-stable/tools/perf
Thomas Richter e16b5f0779 perf stat: Fix forked applications enablement of counters
[ Upstream commit d0a0a51149 ]

I have run into the following issue:

 # perf stat -a -e new_pmu/INSTRUCTION_7/ --  mytest -c1 7

 Performance counter stats for 'system wide':

                 0      new_pmu/INSTRUCTION_7/

       0.000366428 seconds time elapsed
 #

The new PMU for s390 counts the execution of certain CPU instructions.
The root cause is the extremely small run time of the mytest program. It
just executes some assembly instructions and then exits.

In above invocation the instruction is executed exactly one time (-c1
option). The PMU is expected to report this one time execution by a
counter value of one, but fails to do so in some cases, not all.

Debugging reveals the invocation of the child process is done
*before* the counter events are installed and enabled.

Tracing reveals that sometimes the child process starts and exits before
the event is installed on all CPUs. The more CPUs the machine has, the
more often this miscount happens.

Fix this by reversing the start of the work load after the events have
been installed on the specified CPUs. Now the comment also matches the
code.

Output after:

 # perf stat -a -e new_pmu/INSTRUCTION_7/ --  mytest -c1 7

 Performance counter stats for 'system wide':

                 1      new_pmu/INSTRUCTION_7/

       0.000366428 seconds time elapsed
 #

Now the correct result is reported rock solid all the time regardless
how many CPUs are online.

Reviewers notes:

Jiri:

Right, without -a the event has enable_on_exec so the race does not
matter, but it's a problem for system wide with fork.

Namhyung:

Agreed. Also we may move the enable_counters() and the clock code out of
the if block to be shared with the else block.

Fixes: acf2892270 ("perf stat: Use perf_evlist__prepare/start_workload()")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Link: https://lore.kernel.org/r/20220317155346.577384-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-04-08 14:23:51 +02:00
..
arch perf callchain: Fix compilation on powerpc with gcc11+ 2021-10-31 12:51:41 -03:00
bench perf bench futex: Fix memory leak of perf_cpu_map__new() 2021-11-25 09:48:33 +01:00
dlfilters perf tests: Add dlfilter test 2021-08-11 09:35:44 -03:00
Documentation perf doc: Fix typos all over the place 2021-09-27 09:32:28 -03:00
examples/bpf
include perf build: Move perf_dlfilters.h in the source tree 2021-08-11 09:35:24 -03:00
jvmti
pmu-events perf jevents: Free the sys_event_tables list after processing entries 2021-10-05 14:48:10 -03:00
python
scripts perf scripts python: intel-pt-events.py: Fix printing of switch events 2022-01-05 12:42:40 +01:00
tests perf tests: Remove bash construct from record+zstd_comp_decomp.sh 2021-11-25 09:48:33 +01:00
trace perf beauty: Cover more flags in the move_mount syscall argument beautifier 2021-09-10 18:15:22 -03:00
ui perf annotate: Avoid TUI crash when navigating in the annotation of recursive functions 2022-01-20 09:13:15 +01:00
util perf symbols: Fix symbol size calculation condition 2022-03-23 09:16:43 +01:00
.gitignore perf tools: Ignore Documentation dependency file 2021-09-11 15:36:16 -03:00
Build
builtin-annotate.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-bench.c perf bench: Add benchmark for evlist open/close operations 2021-08-10 11:32:37 -03:00
builtin-buildid-cache.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-buildid-list.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-c2c.c Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
builtin-config.c
builtin-daemon.c
builtin-data.c perf data: Correct -h output 2021-08-31 15:12:00 -03:00
builtin-diff.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-evlist.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-ftrace.c
builtin-help.c
builtin-inject.c perf inject: Fix segfault due to perf_data__fd() without open 2021-12-22 09:32:48 +01:00
builtin-kallsyms.c
builtin-kmem.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-kvm.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-list.c
builtin-lock.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-mem.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-probe.c perf probe: Do not show @plt function by default 2021-07-07 10:28:10 -03:00
builtin-record.c Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
builtin-report.c perf report: Fix memory leaks around perf_tip() 2021-12-08 09:04:41 +01:00
builtin-sched.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-script.c perf script: Fix CPU filtering of a script's switch events 2022-01-05 12:42:39 +01:00
builtin-stat.c perf stat: Fix forked applications enablement of counters 2022-04-08 14:23:51 +02:00
builtin-timechart.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-top.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-trace.c perf tools: Remove repipe argument from perf_session__new() 2021-08-02 10:06:51 -03:00
builtin-version.c
builtin.h
check-headers.sh perf report: Add tools/arch/x86/include/asm/amd-ibs.h 2021-09-10 18:13:20 -03:00
command-list.txt
CREDITS
design.txt
Makefile
Makefile.config perf tools: Drop requirement for libstdc++.so for libopencsd check 2022-01-27 11:05:38 +01:00
Makefile.perf perf build: Suppress 'rm dlfilter' build message 2021-10-31 12:51:41 -03:00
MANIFEST
perf-archive.sh
perf-completion.sh
perf-iostat.sh
perf-read-vdso.c
perf-sys.h
perf-with-kcore.sh
perf.c perf debug: Move debug initialization earlier 2021-05-27 13:24:22 -03:00
perf.h