linux-stable/tools
Namhyung Kim 314f50ce4e perf stat: Fix handling of --for-each-cgroup with --bpf-counters to match non BPF mode
[ Upstream commit 54b353a20c ]

The --for-each-cgroup can have the same cgroup multiple times, but this
confuses BPF counters (since they have the same cgroup id), making only
the last cgroup events to be counted.

Let's check the cgroup name before adding a new entry to the cgroups
list.

Before:

  $ sudo ./perf stat -a --bpf-counters --for-each-cgroup /,/ sleep 1

   Performance counter stats for 'system wide':

       <not counted> msec cpu-clock                        /
       <not counted>      context-switches                 /
       <not counted>      cpu-migrations                   /
       <not counted>      page-faults                      /
       <not counted>      cycles                           /
       <not counted>      instructions                     /
       <not counted>      branches                         /
       <not counted>      branch-misses                    /
            8,016.04 msec cpu-clock                        /                #    7.998 CPUs utilized
               6,152      context-switches                 /                #  767.461 /sec
                 250      cpu-migrations                   /                #   31.187 /sec
                 442      page-faults                      /                #   55.139 /sec
         613,111,487      cycles                           /                #    0.076 GHz
         280,599,604      instructions                     /                #    0.46  insn per cycle
          57,692,724      branches                         /                #    7.197 M/sec
           3,385,168      branch-misses                    /                #    5.87% of all branches

         1.002220125 seconds time elapsed

After it becomes similar to the non-BPF mode:

  $ sudo ./perf stat -a --bpf-counters --for-each-cgroup /,/  sleep 1

   Performance counter stats for 'system wide':

            8,013.38 msec cpu-clock                        /                #    7.998 CPUs utilized
               6,859      context-switches                 /                #  855.944 /sec
                 334      cpu-migrations                   /                #   41.680 /sec
                 345      page-faults                      /                #   43.053 /sec
         782,326,119      cycles                           /                #    0.098 GHz
         471,645,724      instructions                     /                #    0.60  insn per cycle
          94,963,430      branches                         /                #   11.851 M/sec
           3,685,511      branch-misses                    /                #    3.88% of all branches

         1.001864539 seconds time elapsed

Committer notes:

As a reminder, to test with BPF counters one has to use BUILD_BPF_SKEL=1
in the make command line and have clang/llvm installed when building
perf, otherwise the --bpf-counters option will not be available:

  # perf stat -a --bpf-counters --for-each-cgroup /,/ sleep 1
  Error: unknown option `bpf-counters'

   Usage: perf stat [<options>] [<command>]

      -a, --all-cpus        system-wide collection from all CPUs
  <SNIP>
  #

Fixes: bb1c15b60b ("perf stat: Support regex pattern in --for-each-cgroup")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: bpf@vger.kernel.org
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/r/20230104064402.1551516-5-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-01-12 12:00:41 +01:00
..
accounting delayacct: remove some unused variables 2022-06-16 19:58:21 -07:00
arch x86/cpu: Restore AMD's DE_CFG MSR after resume 2022-11-16 10:04:14 +01:00
bootconfig
bpf bpftool: Fix memory leak in do_build_table_cb 2022-12-31 13:26:09 +01:00
build tools build: Switch to new openssl API for test-libcrypto 2022-08-10 10:44:02 -03:00
certs tools/certs: Add print-cert-tbs-hash.sh 2022-05-23 18:47:49 +03:00
cgroup tools: add memcg_shrinker.py 2022-07-03 18:08:40 -07:00
counter
debugging tools: Add new "test" taint to kernel-chktaint 2022-09-07 14:51:12 -06:00
edid
firewire
firmware
gpio
hv tools: hv: kvp: remove unnecessary (void*) conversions 2022-09-05 16:55:20 +00:00
iio tools: iio: iio_generic_buffer: Fix read size 2022-12-02 17:43:14 +01:00
include tools/nolibc/string: Fix memcmp() implementation 2022-11-10 18:17:33 +01:00
io_uring
kvm/kvm_stat tools/kvm_stat: fix display of error when multiple processes are found 2022-06-15 08:14:20 -04:00
laptop
leds
lib libbpf: Avoid enum forward-declarations in public API in C++ mode 2022-12-31 13:26:46 +01:00
memory-model
objtool objtool: Fix SEGFAULT 2023-01-04 11:26:27 +01:00
pci
pcmcia
perf perf stat: Fix handling of --for-each-cgroup with --bpf-counters to match non BPF mode 2023-01-12 12:00:41 +01:00
power tools/power turbostat: Use standard Energy Unit for SPR Dram RAPL domain 2022-10-21 12:39:02 +02:00
rcu
scripts
spi spi: spidev_test: Warn when the mode is not the requested mode 2022-06-13 15:56:03 +01:00
testing selftests: net: return non-zero for failures reported in arp_ndisc_evict_nocarrier 2023-01-12 12:00:38 +01:00
thermal tools/thermal: Fix possible path truncations 2022-08-03 19:28:46 +02:00
time
tracing rtla: Consolidate and show all necessary libraries that failed for building 2022-08-10 12:03:02 -04:00
usb tools: usb: testusb: Add super-plus speed reporting 2022-07-08 14:54:49 +02:00
verification rv/dot2c: Make automaton definition static 2022-10-29 10:08:35 +02:00
virtio virtio_test: fixup for vq reset 2022-09-27 18:30:49 -04:00
vm tools/vm/slabinfo-gnuplot: use "grep -E" instead of "egrep" 2022-12-08 11:30:19 +01:00
wmi
Makefile tools/nolibc: make the default target build the headers 2022-06-20 09:43:19 -07:00