License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2011-01-04 02:39:04 +08:00
|
|
|
#ifndef __PERF_EVSEL_H
|
|
|
|
#define __PERF_EVSEL_H 1
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2011-01-04 03:45:52 +08:00
|
|
|
#include <stdbool.h>
|
2019-08-22 03:39:29 +08:00
|
|
|
#include <sys/types.h>
|
2012-11-20 06:21:03 +08:00
|
|
|
#include <linux/perf_event.h>
|
2014-04-26 03:31:02 +08:00
|
|
|
#include <linux/types.h>
|
2019-07-21 19:24:22 +08:00
|
|
|
#include <internal/evsel.h>
|
2019-08-22 01:09:54 +08:00
|
|
|
#include <perf/evsel.h>
|
2019-01-28 07:06:16 +08:00
|
|
|
#include "symbol_conf.h"
|
2019-08-22 03:39:29 +08:00
|
|
|
#include <internal/cpumap.h>
|
2011-01-04 02:39:04 +08:00
|
|
|
|
2019-09-25 02:41:51 +08:00
|
|
|
struct bpf_object;
|
|
|
|
struct cgroup;
|
|
|
|
struct perf_counts;
|
2017-10-27 01:22:34 +08:00
|
|
|
struct perf_stat_evsel;
|
2019-09-25 02:41:51 +08:00
|
|
|
union perf_event;
|
perf stat: Enable counting events for BPF programs
Introduce 'perf stat -b' option, which counts events for BPF programs, like:
[root@localhost ~]# ~/perf stat -e ref-cycles,cycles -b 254 -I 1000
1.487903822 115,200 ref-cycles
1.487903822 86,012 cycles
2.489147029 80,560 ref-cycles
2.489147029 73,784 cycles
3.490341825 60,720 ref-cycles
3.490341825 37,797 cycles
4.491540887 37,120 ref-cycles
4.491540887 31,963 cycles
The example above counts 'cycles' and 'ref-cycles' of BPF program of id
254. This is similar to bpftool-prog-profile command, but more
flexible.
'perf stat -b' creates per-cpu perf_event and loads fentry/fexit BPF
programs (monitor-progs) to the target BPF program (target-prog). The
monitor-progs read perf_event before and after the target-prog, and
aggregate the difference in a BPF map. Then the user space reads data
from these maps.
A new 'struct bpf_counter' is introduced to provide a common interface
that uses BPF programs/maps to count perf events.
Committer notes:
Removed all but bpf_counter.h includes from evsel.h, not needed at all.
Also BPF map lookups for PERCPU_ARRAYs need to have as its value receive
buffer passed to the kernel libbpf_num_possible_cpus() entries, not
evsel__nr_cpus(evsel), as the former uses
/sys/devices/system/cpu/possible while the later uses
/sys/devices/system/cpu/online, which may be less than the 'possible'
number making the bpf map lookup overwrite memory and cause hard to
debug memory corruption.
We need to continue using evsel__nr_cpus(evsel) when accessing the
perf_counts array tho, not to overwrite another are of memory :-)
Signed-off-by: Song Liu <songliubraving@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/lkml/20210120163031.GU12699@kernel.org/
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: kernel-team@fb.com
Link: http://lore.kernel.org/lkml/20201229214214.3413833-4-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-12-30 05:42:14 +08:00
|
|
|
struct bpf_counter_ops;
|
|
|
|
struct target;
|
perf stat: Fix wrong skipping for per-die aggregation
Uncore becomes die-scope on Xeon Cascade Lake-AP and perf has supported
--per-die aggregation yet.
One issue is found in check_per_pkg() for uncore events running on AP
system. On cascade Lake-AP, we have:
S0-D0
S0-D1
S1-D0
S1-D1
But in check_per_pkg(), S0-D1 and S1-D1 are skipped because the mask
bits for S0 and S1 have been set for S0-D0 and S1-D0. It doesn't check
die_id. So the counting for S0-D1 and S1-D1 are set to zero. That's not
correct.
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001460963 S0-D0 1 1317376 Bytes llc_misses.mem_read
1.001460963 S0-D1 1 998016 Bytes llc_misses.mem_read
1.001460963 S1-D0 1 970496 Bytes llc_misses.mem_read
1.001460963 S1-D1 1 1291264 Bytes llc_misses.mem_read
2.003488021 S0-D0 1 1082048 Bytes llc_misses.mem_read
2.003488021 S0-D1 1 1919040 Bytes llc_misses.mem_read
2.003488021 S1-D0 1 890752 Bytes llc_misses.mem_read
2.003488021 S1-D1 1 2380800 Bytes llc_misses.mem_read
3.005613270 S0-D0 1 1126080 Bytes llc_misses.mem_read
3.005613270 S0-D1 1 2898176 Bytes llc_misses.mem_read
3.005613270 S1-D0 1 870912 Bytes llc_misses.mem_read
3.005613270 S1-D1 1 3388608 Bytes llc_misses.mem_read
4.007627598 S0-D0 1 1124608 Bytes llc_misses.mem_read
4.007627598 S0-D1 1 3884416 Bytes llc_misses.mem_read
4.007627598 S1-D0 1 921088 Bytes llc_misses.mem_read
4.007627598 S1-D1 1 4451840 Bytes llc_misses.mem_read
5.001479927 S0-D0 1 963328 Bytes llc_misses.mem_read
5.001479927 S0-D1 1 4831936 Bytes llc_misses.mem_read
5.001479927 S1-D0 1 895104 Bytes llc_misses.mem_read
5.001479927 S1-D1 1 5496640 Bytes llc_misses.mem_read
From above output, we can see S0-D1 and S1-D1 don't report the interval
values, they are continued to grow. That's because check_per_pkg()
wrongly decides to use zero counts for S0-D1 and S1-D1.
So in check_per_pkg(), we should use hashmap(socket,die) to decide if
the cpu counts needs to skip. Only considering socket is not enough.
Now with this patch,
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001586691 S0-D0 1 1229440 Bytes llc_misses.mem_read
1.001586691 S0-D1 1 976832 Bytes llc_misses.mem_read
1.001586691 S1-D0 1 938304 Bytes llc_misses.mem_read
1.001586691 S1-D1 1 1227328 Bytes llc_misses.mem_read
2.003776312 S0-D0 1 1586752 Bytes llc_misses.mem_read
2.003776312 S0-D1 1 875392 Bytes llc_misses.mem_read
2.003776312 S1-D0 1 855616 Bytes llc_misses.mem_read
2.003776312 S1-D1 1 949376 Bytes llc_misses.mem_read
3.006512788 S0-D0 1 1338880 Bytes llc_misses.mem_read
3.006512788 S0-D1 1 920064 Bytes llc_misses.mem_read
3.006512788 S1-D0 1 877184 Bytes llc_misses.mem_read
3.006512788 S1-D1 1 1020736 Bytes llc_misses.mem_read
4.008895291 S0-D0 1 926592 Bytes llc_misses.mem_read
4.008895291 S0-D1 1 906368 Bytes llc_misses.mem_read
4.008895291 S1-D0 1 892224 Bytes llc_misses.mem_read
4.008895291 S1-D1 1 987712 Bytes llc_misses.mem_read
5.001590993 S0-D0 1 962624 Bytes llc_misses.mem_read
5.001590993 S0-D1 1 912512 Bytes llc_misses.mem_read
5.001590993 S1-D0 1 891200 Bytes llc_misses.mem_read
5.001590993 S1-D1 1 978432 Bytes llc_misses.mem_read
On no-die system, die_id is 0, actually it's hashmap(socket,0), original behavior
is not changed.
Reported-by: Ying Huang <ying.huang@intel.com>
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ying Huang <ying.huang@intel.com>
Link: http://lore.kernel.org/lkml/20210128013417.25597-1-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-28 09:34:17 +08:00
|
|
|
struct hashmap;
|
perf stat: Introduce 'bperf' to share hardware PMCs with BPF
The perf tool uses performance monitoring counters (PMCs) to monitor
system performance. The PMCs are limited hardware resources. For
example, Intel CPUs have 3x fixed PMCs and 4x programmable PMCs per cpu.
Modern data center systems use these PMCs in many different ways: system
level monitoring, (maybe nested) container level monitoring, per process
monitoring, profiling (in sample mode), etc. In some cases, there are
more active perf_events than available hardware PMCs. To allow all
perf_events to have a chance to run, it is necessary to do expensive
time multiplexing of events.
On the other hand, many monitoring tools count the common metrics
(cycles, instructions). It is a waste to have multiple tools create
multiple perf_events of "cycles" and occupy multiple PMCs.
bperf tries to reduce such wastes by allowing multiple perf_events of
"cycles" or "instructions" (at different scopes) to share PMUs. Instead
of having each perf-stat session to read its own perf_events, bperf uses
BPF programs to read the perf_events and aggregate readings to BPF maps.
Then, the perf-stat session(s) reads the values from these BPF maps.
Please refer to the comment before the definition of bperf_ops for the
description of bperf architecture.
bperf is off by default. To enable it, pass --bpf-counters option to
perf-stat. bperf uses a BPF hashmap to share information about BPF
programs and maps used by bperf. This map is pinned to bpffs. The
default path is /sys/fs/bpf/perf_attr_map. The user could change the
path with option --bpf-attr-map.
Committer testing:
# dmesg|grep "Performance Events" -A5
[ 0.225277] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[ 0.225280] ... version: 0
[ 0.225280] ... bit width: 48
[ 0.225281] ... generic registers: 6
[ 0.225281] ... value mask: 0000ffffffffffff
[ 0.225281] ... max period: 00007fffffffffff
#
# for a in $(seq 6) ; do perf stat -a -e cycles,instructions sleep 100000 & done
[1] 2436231
[2] 2436232
[3] 2436233
[4] 2436234
[5] 2436235
[6] 2436236
# perf stat -a -e cycles,instructions sleep 0.1
Performance counter stats for 'system wide':
310,326,987 cycles (41.87%)
236,143,290 instructions # 0.76 insn per cycle (41.87%)
0.100800885 seconds time elapsed
#
We can see that the counters were enabled for this workload 41.87% of
the time.
Now with --bpf-counters:
# for a in $(seq 32) ; do perf stat --bpf-counters -a -e cycles,instructions sleep 100000 & done
[1] 2436514
[2] 2436515
[3] 2436516
[4] 2436517
[5] 2436518
[6] 2436519
[7] 2436520
[8] 2436521
[9] 2436522
[10] 2436523
[11] 2436524
[12] 2436525
[13] 2436526
[14] 2436527
[15] 2436528
[16] 2436529
[17] 2436530
[18] 2436531
[19] 2436532
[20] 2436533
[21] 2436534
[22] 2436535
[23] 2436536
[24] 2436537
[25] 2436538
[26] 2436539
[27] 2436540
[28] 2436541
[29] 2436542
[30] 2436543
[31] 2436544
[32] 2436545
#
# ls -la /sys/fs/bpf/perf_attr_map
-rw-------. 1 root root 0 Mar 23 14:53 /sys/fs/bpf/perf_attr_map
# bpftool map | grep bperf | wc -l
64
#
# bpftool map | tail
1265: percpu_array name accum_readings flags 0x0
key 4B value 24B max_entries 1 memlock 4096B
1266: hash name filter flags 0x0
key 4B value 4B max_entries 1 memlock 4096B
1267: array name bperf_fo.bss flags 0x400
key 4B value 8B max_entries 1 memlock 4096B
btf_id 996
pids perf(2436545)
1268: percpu_array name accum_readings flags 0x0
key 4B value 24B max_entries 1 memlock 4096B
1269: hash name filter flags 0x0
key 4B value 4B max_entries 1 memlock 4096B
1270: array name bperf_fo.bss flags 0x400
key 4B value 8B max_entries 1 memlock 4096B
btf_id 997
pids perf(2436541)
1285: array name pid_iter.rodata flags 0x480
key 4B value 4B max_entries 1 memlock 4096B
btf_id 1017 frozen
pids bpftool(2437504)
1286: array flags 0x0
key 4B value 32B max_entries 1 memlock 4096B
#
# bpftool map dump id 1268 | tail
value (CPU 21):
8f f3 bc ca 00 00 00 00 80 fd 2a d1 4d 00 00 00
80 fd 2a d1 4d 00 00 00
value (CPU 22):
7e d5 64 4d 00 00 00 00 a4 8a 2e ee 4d 00 00 00
a4 8a 2e ee 4d 00 00 00
value (CPU 23):
a7 78 3e 06 01 00 00 00 b2 34 94 f6 4d 00 00 00
b2 34 94 f6 4d 00 00 00
Found 1 element
# bpftool map dump id 1268 | tail
value (CPU 21):
c6 8b d9 ca 00 00 00 00 20 c6 fc 83 4e 00 00 00
20 c6 fc 83 4e 00 00 00
value (CPU 22):
9c b4 d2 4d 00 00 00 00 3e 0c df 89 4e 00 00 00
3e 0c df 89 4e 00 00 00
value (CPU 23):
18 43 66 06 01 00 00 00 5b 69 ed 83 4e 00 00 00
5b 69 ed 83 4e 00 00 00
Found 1 element
# bpftool map dump id 1268 | tail
value (CPU 21):
f2 6e db ca 00 00 00 00 92 67 4c ba 4e 00 00 00
92 67 4c ba 4e 00 00 00
value (CPU 22):
dc 8e e1 4d 00 00 00 00 d9 32 7a c5 4e 00 00 00
d9 32 7a c5 4e 00 00 00
value (CPU 23):
bd 2b 73 06 01 00 00 00 7c 73 87 bf 4e 00 00 00
7c 73 87 bf 4e 00 00 00
Found 1 element
#
# perf stat --bpf-counters -a -e cycles,instructions sleep 0.1
Performance counter stats for 'system wide':
119,410,122 cycles
152,105,479 instructions # 1.27 insn per cycle
0.101395093 seconds time elapsed
#
See? We had the counters enabled all the time.
Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: kernel-team@fb.com
Link: http://lore.kernel.org/lkml/20210316211837.910506-2-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-03-17 05:18:35 +08:00
|
|
|
struct bperf_leader_bpf;
|
|
|
|
struct bperf_follower_bpf;
|
2017-10-27 01:22:34 +08:00
|
|
|
|
2020-04-30 02:42:16 +08:00
|
|
|
typedef int (evsel__sb_cb_t)(union perf_event *event, void *data);
|
2019-03-12 13:30:50 +08:00
|
|
|
|
2019-03-27 06:18:21 +08:00
|
|
|
enum perf_tool_event {
|
|
|
|
PERF_TOOL_NONE = 0,
|
|
|
|
PERF_TOOL_DURATION_TIME = 1,
|
|
|
|
};
|
|
|
|
|
2019-07-21 19:23:51 +08:00
|
|
|
/** struct evsel - event selector
|
2011-02-16 21:10:01 +08:00
|
|
|
*
|
2015-08-27 20:07:40 +08:00
|
|
|
* @evlist - evlist this evsel is in, if it is in one.
|
2019-07-21 19:24:22 +08:00
|
|
|
* @core - libperf evsel object
|
2011-02-16 21:10:01 +08:00
|
|
|
* @name - Can be set to retain the original event name passed by the user,
|
|
|
|
* so that when showing results in tools such as 'perf stat', we
|
|
|
|
* show the name used, not some alias.
|
2013-08-27 16:23:09 +08:00
|
|
|
* @id_pos: the position of the event id (PERF_SAMPLE_ID or
|
|
|
|
* PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of
|
2019-08-27 06:02:31 +08:00
|
|
|
* struct perf_record_sample
|
2013-08-27 16:23:09 +08:00
|
|
|
* @is_pos: the position (counting backwards) of the event id (PERF_SAMPLE_ID or
|
|
|
|
* PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
|
|
|
|
* is used there is an id sample appended to non-sample events
|
2014-10-23 18:45:13 +08:00
|
|
|
* @priv: And what is in its containing unnamed union are tool specific
|
2011-02-16 21:10:01 +08:00
|
|
|
*/
|
2019-07-21 19:23:51 +08:00
|
|
|
struct evsel {
|
2019-07-21 19:24:22 +08:00
|
|
|
struct perf_evsel core;
|
2020-09-24 20:44:51 +08:00
|
|
|
struct evlist *evlist;
|
|
|
|
off_t id_offset;
|
|
|
|
int id_pos;
|
|
|
|
int is_pos;
|
|
|
|
unsigned int sample_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These fields can be set in the parse-events code or similar.
|
|
|
|
* Please check evsel__clone() to copy them properly so that
|
|
|
|
* they can be released properly.
|
|
|
|
*/
|
|
|
|
struct {
|
|
|
|
char *name;
|
|
|
|
char *group_name;
|
|
|
|
const char *pmu_name;
|
|
|
|
struct tep_event *tp_format;
|
|
|
|
char *filter;
|
|
|
|
unsigned long max_events;
|
|
|
|
double scale;
|
|
|
|
const char *unit;
|
|
|
|
struct cgroup *cgrp;
|
|
|
|
enum perf_tool_event tool_event;
|
|
|
|
/* parse modifier helper */
|
|
|
|
int exclude_GH;
|
|
|
|
int sample_read;
|
|
|
|
bool snapshot;
|
|
|
|
bool per_pkg;
|
|
|
|
bool percore;
|
|
|
|
bool precise_max;
|
|
|
|
bool use_uncore_alias;
|
|
|
|
bool is_libpfm_event;
|
|
|
|
bool auto_merge_stats;
|
|
|
|
bool collect_stat;
|
|
|
|
bool weak_group;
|
2021-04-26 05:43:32 +08:00
|
|
|
bool bpf_counter;
|
2021-06-03 05:22:40 +08:00
|
|
|
bool use_config_name;
|
2020-09-24 20:44:51 +08:00
|
|
|
int bpf_fd;
|
|
|
|
struct bpf_object *bpf_obj;
|
2021-06-03 05:22:40 +08:00
|
|
|
struct list_head config_terms;
|
2020-09-24 20:44:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* metric fields are similar, but needs more care as they can have
|
|
|
|
* references to other metric (evsel).
|
|
|
|
*/
|
|
|
|
const char * metric_expr;
|
|
|
|
const char * metric_name;
|
|
|
|
struct evsel **metric_events;
|
|
|
|
struct evsel *metric_leader;
|
|
|
|
|
|
|
|
void *handler;
|
2011-01-04 03:45:52 +08:00
|
|
|
struct perf_counts *counts;
|
2013-01-29 19:47:43 +08:00
|
|
|
struct perf_counts *prev_raw_counts;
|
perf trace: Introduce per-event maximum number of events property
Call it 'nr', as in this context it should be expressive enough, i.e.:
# perf trace -e sched:*waking/nr=8,call-graph=fp/
0.000 :0/0 sched:sched_waking:comm=rcu_sched pid=10 prio=120 target_cpu=001
try_to_wake_up ([kernel.kallsyms])
sched_clock ([kernel.kallsyms])
3.933 :0/0 sched:sched_waking:comm=rcu_sched pid=10 prio=120 target_cpu=001
try_to_wake_up ([kernel.kallsyms])
sched_clock ([kernel.kallsyms])
3.970 IPDL Backgroun/3622 sched:sched_waking:comm=Gecko_IOThread pid=3569 prio=120 target_cpu=003
try_to_wake_up ([kernel.kallsyms])
__libc_write (/usr/lib64/libpthread-2.26.so)
20.069 IPDL Backgroun/3622 sched:sched_waking:comm=Gecko_IOThread pid=3569 prio=120 target_cpu=003
try_to_wake_up ([kernel.kallsyms])
__libc_write (/usr/lib64/libpthread-2.26.so)
37.170 IPDL Backgroun/3622 sched:sched_waking:comm=Gecko_IOThread pid=3569 prio=120 target_cpu=003
try_to_wake_up ([kernel.kallsyms])
__libc_write (/usr/lib64/libpthread-2.26.so)
53.267 IPDL Backgroun/3622 sched:sched_waking:comm=Gecko_IOThread pid=3569 prio=120 target_cpu=003
try_to_wake_up ([kernel.kallsyms])
__libc_write (/usr/lib64/libpthread-2.26.so)
70.365 IPDL Backgroun/3622 sched:sched_waking:comm=Gecko_IOThread pid=3569 prio=120 target_cpu=003
try_to_wake_up ([kernel.kallsyms])
__libc_write (/usr/lib64/libpthread-2.26.so)
75.781 Web Content/3649 sched:sched_waking:comm=JS Helper pid=3670 prio=120 target_cpu=000
try_to_wake_up ([kernel.kallsyms])
try_to_wake_up ([kernel.kallsyms])
wake_up_q ([kernel.kallsyms])
futex_wake ([kernel.kallsyms])
do_futex ([kernel.kallsyms])
__x64_sys_futex ([kernel.kallsyms])
do_syscall_64 ([kernel.kallsyms])
entry_SYSCALL_64_after_hwframe ([kernel.kallsyms])
pthread_cond_signal@@GLIBC_2.3.2 (/usr/lib64/libpthread-2.26.so)
#
# perf trace -e sched:*switch/nr=2/,block:*_plug/nr=4/,block:*_unplug/nr=1/,net:*dev_queue/nr=3,max-stack=16/
0.000 :0/0 sched:sched_switch:swapper/0:0 [120] S ==> trace:3367 [120]
0.046 :0/0 sched:sched_switch:swapper/1:0 [120] S ==> kworker/u16:58:2722 [120]
570.670 irq/50-iwlwifi/680 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff93498051ef00 len=66
__dev_queue_xmit ([kernel.kallsyms])
1106.141 jbd2/dm-0-8/476 block:block_plug:[jbd2/dm-0-8]
1106.175 jbd2/dm-0-8/476 block:block_unplug:[jbd2/dm-0-8] 1
1618.088 kworker/u16:30/2694 block:block_plug:[kworker/u16:30]
1810.000 :0/0 net:net_dev_queue:dev=vnet0 skbaddr=0xffff93498051ef00 len=52
__dev_queue_xmit ([kernel.kallsyms])
3857.974 :0/0 net:net_dev_queue:dev=vnet0 skbaddr=0xffff93498051f900 len=52
__dev_queue_xmit ([kernel.kallsyms])
4790.277 jbd2/dm-2-8/748 block:block_plug:[jbd2/dm-2-8]
4790.448 jbd2/dm-2-8/748 block:block_plug:[jbd2/dm-2-8]
#
The global --max-events has precendence:
# trace --max-events 3 -e sched:*switch/nr=2/,block:*_plug/nr=4/,block:*_unplug/nr=1/,net:*dev_queue/nr=3,max-stack=16/
0.000 :0/0 sched:sched_switch:swapper/0:0 [120] S ==> qemu-system-x86:2252 [120]
0.029 qemu-system-x8/2252 sched:sched_switch:qemu-system-x86:2252 [120] D ==> swapper/0:0 [120]
58.047 DNS Res~er #14/31661 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff9346966af100 len=84
__dev_queue_xmit ([kernel.kallsyms])
__libc_send (/usr/lib64/libpthread-2.26.so)
#
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-s4jswltvh660ughvg9nwngah@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-10-23 01:14:16 +08:00
|
|
|
unsigned long nr_events_printed;
|
2017-10-27 01:22:34 +08:00
|
|
|
struct perf_stat_evsel *stats;
|
2016-03-09 13:11:54 +08:00
|
|
|
void *priv;
|
|
|
|
u64 db_id;
|
perf stat: Fix duplicate PMU name for interval print
PMU name is printed repeatedly for interval print, for example:
perf stat --no-merge -e 'unc_m_clockticks' -a -I 1000
# time counts unit events
1.001053069 243,702,144 unc_m_clockticks [uncore_imc_4]
1.001053069 244,268,304 unc_m_clockticks [uncore_imc_2]
1.001053069 244,427,386 unc_m_clockticks [uncore_imc_0]
1.001053069 244,583,760 unc_m_clockticks [uncore_imc_5]
1.001053069 244,738,971 unc_m_clockticks [uncore_imc_3]
1.001053069 244,880,309 unc_m_clockticks [uncore_imc_1]
2.002024821 240,818,200 unc_m_clockticks [uncore_imc_4] [uncore_imc_4]
2.002024821 240,767,812 unc_m_clockticks [uncore_imc_2] [uncore_imc_2]
2.002024821 240,764,215 unc_m_clockticks [uncore_imc_0] [uncore_imc_0]
2.002024821 240,759,504 unc_m_clockticks [uncore_imc_5] [uncore_imc_5]
2.002024821 240,755,992 unc_m_clockticks [uncore_imc_3] [uncore_imc_3]
2.002024821 240,750,403 unc_m_clockticks [uncore_imc_1] [uncore_imc_1]
For each print, the PMU name is unconditionally appended to the
counter->name.
Need to check the counter->name first. If the PMU name is already
appended, do nothing.
Committer notes:
Add and use perf_evsel->uniquified_name bool instead of doing the more
expensive strstr(event->name, pmu->name).
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Agustin Vega-Frias <agustinv@codeaurora.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shaokun Zhang <zhangshaokun@hisilicon.com>
Cc: Will Deacon <will.deacon@arm.com>
Fixes: 8c5421c016a4 ("perf pmu: Display pmu name when printing unmerged events in stat")
Link: http://lkml.kernel.org/r/1524594014-79243-5-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-04-25 02:20:14 +08:00
|
|
|
bool uniquified_name;
|
2011-05-30 22:55:59 +08:00
|
|
|
bool supported;
|
2012-09-26 23:48:18 +08:00
|
|
|
bool needs_swap;
|
2018-10-20 20:04:41 +08:00
|
|
|
bool disabled;
|
2014-07-14 18:02:56 +08:00
|
|
|
bool no_aux_samples;
|
2014-07-14 18:02:57 +08:00
|
|
|
bool immediate;
|
2014-07-31 14:00:52 +08:00
|
|
|
bool tracking;
|
2016-12-13 15:46:22 +08:00
|
|
|
bool ignore_missing_thread;
|
2018-03-07 23:50:02 +08:00
|
|
|
bool forced_leader;
|
2015-07-10 15:36:09 +08:00
|
|
|
bool cmdline_group_boundary;
|
perf stat: Collapse identically named events
The uncore PMU has a lot of duplicated PMUs for different subsystems.
When expanding an uncore alias we usually end up with a large
number of identically named aliases, which makes perf stat
output difficult to read.
Automatically sum them up in perf stat, unless --no-merge is specified.
This can be default because only the uncores generally have duplicated
aliases. Other PMUs have unique names.
Before:
% perf stat --no-merge -a -e unc_c_llc_lookup.any sleep 1
Performance counter stats for 'system wide':
694,976 Bytes unc_c_llc_lookup.any
706,304 Bytes unc_c_llc_lookup.any
956,608 Bytes unc_c_llc_lookup.any
782,720 Bytes unc_c_llc_lookup.any
605,696 Bytes unc_c_llc_lookup.any
442,816 Bytes unc_c_llc_lookup.any
659,328 Bytes unc_c_llc_lookup.any
509,312 Bytes unc_c_llc_lookup.any
263,936 Bytes unc_c_llc_lookup.any
592,448 Bytes unc_c_llc_lookup.any
672,448 Bytes unc_c_llc_lookup.any
608,640 Bytes unc_c_llc_lookup.any
641,024 Bytes unc_c_llc_lookup.any
856,896 Bytes unc_c_llc_lookup.any
808,832 Bytes unc_c_llc_lookup.any
684,864 Bytes unc_c_llc_lookup.any
710,464 Bytes unc_c_llc_lookup.any
538,304 Bytes unc_c_llc_lookup.any
1.002577660 seconds time elapsed
After:
% perf stat -a -e unc_c_llc_lookup.any sleep 1
Performance counter stats for 'system wide':
2,685,120 Bytes unc_c_llc_lookup.any
1.002648032 seconds time elapsed
v2: Split collect_aliases. Rename alias flag.
v3: Make sure unsupported/not counted is always printed.
v4: Factor out callback change into separate patch.
v5: Move check for bad results here
Move merged check into collect_data
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-3-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-03-21 04:17:00 +08:00
|
|
|
bool merged_stat;
|
2019-11-21 08:15:19 +08:00
|
|
|
bool reset_group;
|
|
|
|
bool errored;
|
perf stat: Fix wrong skipping for per-die aggregation
Uncore becomes die-scope on Xeon Cascade Lake-AP and perf has supported
--per-die aggregation yet.
One issue is found in check_per_pkg() for uncore events running on AP
system. On cascade Lake-AP, we have:
S0-D0
S0-D1
S1-D0
S1-D1
But in check_per_pkg(), S0-D1 and S1-D1 are skipped because the mask
bits for S0 and S1 have been set for S0-D0 and S1-D0. It doesn't check
die_id. So the counting for S0-D1 and S1-D1 are set to zero. That's not
correct.
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001460963 S0-D0 1 1317376 Bytes llc_misses.mem_read
1.001460963 S0-D1 1 998016 Bytes llc_misses.mem_read
1.001460963 S1-D0 1 970496 Bytes llc_misses.mem_read
1.001460963 S1-D1 1 1291264 Bytes llc_misses.mem_read
2.003488021 S0-D0 1 1082048 Bytes llc_misses.mem_read
2.003488021 S0-D1 1 1919040 Bytes llc_misses.mem_read
2.003488021 S1-D0 1 890752 Bytes llc_misses.mem_read
2.003488021 S1-D1 1 2380800 Bytes llc_misses.mem_read
3.005613270 S0-D0 1 1126080 Bytes llc_misses.mem_read
3.005613270 S0-D1 1 2898176 Bytes llc_misses.mem_read
3.005613270 S1-D0 1 870912 Bytes llc_misses.mem_read
3.005613270 S1-D1 1 3388608 Bytes llc_misses.mem_read
4.007627598 S0-D0 1 1124608 Bytes llc_misses.mem_read
4.007627598 S0-D1 1 3884416 Bytes llc_misses.mem_read
4.007627598 S1-D0 1 921088 Bytes llc_misses.mem_read
4.007627598 S1-D1 1 4451840 Bytes llc_misses.mem_read
5.001479927 S0-D0 1 963328 Bytes llc_misses.mem_read
5.001479927 S0-D1 1 4831936 Bytes llc_misses.mem_read
5.001479927 S1-D0 1 895104 Bytes llc_misses.mem_read
5.001479927 S1-D1 1 5496640 Bytes llc_misses.mem_read
From above output, we can see S0-D1 and S1-D1 don't report the interval
values, they are continued to grow. That's because check_per_pkg()
wrongly decides to use zero counts for S0-D1 and S1-D1.
So in check_per_pkg(), we should use hashmap(socket,die) to decide if
the cpu counts needs to skip. Only considering socket is not enough.
Now with this patch,
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001586691 S0-D0 1 1229440 Bytes llc_misses.mem_read
1.001586691 S0-D1 1 976832 Bytes llc_misses.mem_read
1.001586691 S1-D0 1 938304 Bytes llc_misses.mem_read
1.001586691 S1-D1 1 1227328 Bytes llc_misses.mem_read
2.003776312 S0-D0 1 1586752 Bytes llc_misses.mem_read
2.003776312 S0-D1 1 875392 Bytes llc_misses.mem_read
2.003776312 S1-D0 1 855616 Bytes llc_misses.mem_read
2.003776312 S1-D1 1 949376 Bytes llc_misses.mem_read
3.006512788 S0-D0 1 1338880 Bytes llc_misses.mem_read
3.006512788 S0-D1 1 920064 Bytes llc_misses.mem_read
3.006512788 S1-D0 1 877184 Bytes llc_misses.mem_read
3.006512788 S1-D1 1 1020736 Bytes llc_misses.mem_read
4.008895291 S0-D0 1 926592 Bytes llc_misses.mem_read
4.008895291 S0-D1 1 906368 Bytes llc_misses.mem_read
4.008895291 S1-D0 1 892224 Bytes llc_misses.mem_read
4.008895291 S1-D1 1 987712 Bytes llc_misses.mem_read
5.001590993 S0-D0 1 962624 Bytes llc_misses.mem_read
5.001590993 S0-D1 1 912512 Bytes llc_misses.mem_read
5.001590993 S1-D0 1 891200 Bytes llc_misses.mem_read
5.001590993 S1-D1 1 978432 Bytes llc_misses.mem_read
On no-die system, die_id is 0, actually it's hashmap(socket,0), original behavior
is not changed.
Reported-by: Ying Huang <ying.huang@intel.com>
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ying Huang <ying.huang@intel.com>
Link: http://lore.kernel.org/lkml/20210128013417.25597-1-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-28 09:34:17 +08:00
|
|
|
struct hashmap *per_pkg_mask;
|
2020-09-24 20:44:51 +08:00
|
|
|
int err;
|
2019-11-21 08:15:15 +08:00
|
|
|
int cpu_iter;
|
2019-03-12 13:30:50 +08:00
|
|
|
struct {
|
2020-04-30 02:42:16 +08:00
|
|
|
evsel__sb_cb_t *cb;
|
|
|
|
void *data;
|
2019-03-12 13:30:50 +08:00
|
|
|
} side_band;
|
2020-04-01 18:16:07 +08:00
|
|
|
/*
|
|
|
|
* For reporting purposes, an evsel sample can have a callchain
|
|
|
|
* synthesized from AUX area data. Keep track of synthesized sample
|
|
|
|
* types here. Note, the recorded sample_type cannot be changed because
|
|
|
|
* it is needed to continue to parse events.
|
|
|
|
* See also evsel__has_callchain().
|
|
|
|
*/
|
|
|
|
__u64 synth_sample_type;
|
perf stat: Introduce 'bperf' to share hardware PMCs with BPF
The perf tool uses performance monitoring counters (PMCs) to monitor
system performance. The PMCs are limited hardware resources. For
example, Intel CPUs have 3x fixed PMCs and 4x programmable PMCs per cpu.
Modern data center systems use these PMCs in many different ways: system
level monitoring, (maybe nested) container level monitoring, per process
monitoring, profiling (in sample mode), etc. In some cases, there are
more active perf_events than available hardware PMCs. To allow all
perf_events to have a chance to run, it is necessary to do expensive
time multiplexing of events.
On the other hand, many monitoring tools count the common metrics
(cycles, instructions). It is a waste to have multiple tools create
multiple perf_events of "cycles" and occupy multiple PMCs.
bperf tries to reduce such wastes by allowing multiple perf_events of
"cycles" or "instructions" (at different scopes) to share PMUs. Instead
of having each perf-stat session to read its own perf_events, bperf uses
BPF programs to read the perf_events and aggregate readings to BPF maps.
Then, the perf-stat session(s) reads the values from these BPF maps.
Please refer to the comment before the definition of bperf_ops for the
description of bperf architecture.
bperf is off by default. To enable it, pass --bpf-counters option to
perf-stat. bperf uses a BPF hashmap to share information about BPF
programs and maps used by bperf. This map is pinned to bpffs. The
default path is /sys/fs/bpf/perf_attr_map. The user could change the
path with option --bpf-attr-map.
Committer testing:
# dmesg|grep "Performance Events" -A5
[ 0.225277] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[ 0.225280] ... version: 0
[ 0.225280] ... bit width: 48
[ 0.225281] ... generic registers: 6
[ 0.225281] ... value mask: 0000ffffffffffff
[ 0.225281] ... max period: 00007fffffffffff
#
# for a in $(seq 6) ; do perf stat -a -e cycles,instructions sleep 100000 & done
[1] 2436231
[2] 2436232
[3] 2436233
[4] 2436234
[5] 2436235
[6] 2436236
# perf stat -a -e cycles,instructions sleep 0.1
Performance counter stats for 'system wide':
310,326,987 cycles (41.87%)
236,143,290 instructions # 0.76 insn per cycle (41.87%)
0.100800885 seconds time elapsed
#
We can see that the counters were enabled for this workload 41.87% of
the time.
Now with --bpf-counters:
# for a in $(seq 32) ; do perf stat --bpf-counters -a -e cycles,instructions sleep 100000 & done
[1] 2436514
[2] 2436515
[3] 2436516
[4] 2436517
[5] 2436518
[6] 2436519
[7] 2436520
[8] 2436521
[9] 2436522
[10] 2436523
[11] 2436524
[12] 2436525
[13] 2436526
[14] 2436527
[15] 2436528
[16] 2436529
[17] 2436530
[18] 2436531
[19] 2436532
[20] 2436533
[21] 2436534
[22] 2436535
[23] 2436536
[24] 2436537
[25] 2436538
[26] 2436539
[27] 2436540
[28] 2436541
[29] 2436542
[30] 2436543
[31] 2436544
[32] 2436545
#
# ls -la /sys/fs/bpf/perf_attr_map
-rw-------. 1 root root 0 Mar 23 14:53 /sys/fs/bpf/perf_attr_map
# bpftool map | grep bperf | wc -l
64
#
# bpftool map | tail
1265: percpu_array name accum_readings flags 0x0
key 4B value 24B max_entries 1 memlock 4096B
1266: hash name filter flags 0x0
key 4B value 4B max_entries 1 memlock 4096B
1267: array name bperf_fo.bss flags 0x400
key 4B value 8B max_entries 1 memlock 4096B
btf_id 996
pids perf(2436545)
1268: percpu_array name accum_readings flags 0x0
key 4B value 24B max_entries 1 memlock 4096B
1269: hash name filter flags 0x0
key 4B value 4B max_entries 1 memlock 4096B
1270: array name bperf_fo.bss flags 0x400
key 4B value 8B max_entries 1 memlock 4096B
btf_id 997
pids perf(2436541)
1285: array name pid_iter.rodata flags 0x480
key 4B value 4B max_entries 1 memlock 4096B
btf_id 1017 frozen
pids bpftool(2437504)
1286: array flags 0x0
key 4B value 32B max_entries 1 memlock 4096B
#
# bpftool map dump id 1268 | tail
value (CPU 21):
8f f3 bc ca 00 00 00 00 80 fd 2a d1 4d 00 00 00
80 fd 2a d1 4d 00 00 00
value (CPU 22):
7e d5 64 4d 00 00 00 00 a4 8a 2e ee 4d 00 00 00
a4 8a 2e ee 4d 00 00 00
value (CPU 23):
a7 78 3e 06 01 00 00 00 b2 34 94 f6 4d 00 00 00
b2 34 94 f6 4d 00 00 00
Found 1 element
# bpftool map dump id 1268 | tail
value (CPU 21):
c6 8b d9 ca 00 00 00 00 20 c6 fc 83 4e 00 00 00
20 c6 fc 83 4e 00 00 00
value (CPU 22):
9c b4 d2 4d 00 00 00 00 3e 0c df 89 4e 00 00 00
3e 0c df 89 4e 00 00 00
value (CPU 23):
18 43 66 06 01 00 00 00 5b 69 ed 83 4e 00 00 00
5b 69 ed 83 4e 00 00 00
Found 1 element
# bpftool map dump id 1268 | tail
value (CPU 21):
f2 6e db ca 00 00 00 00 92 67 4c ba 4e 00 00 00
92 67 4c ba 4e 00 00 00
value (CPU 22):
dc 8e e1 4d 00 00 00 00 d9 32 7a c5 4e 00 00 00
d9 32 7a c5 4e 00 00 00
value (CPU 23):
bd 2b 73 06 01 00 00 00 7c 73 87 bf 4e 00 00 00
7c 73 87 bf 4e 00 00 00
Found 1 element
#
# perf stat --bpf-counters -a -e cycles,instructions sleep 0.1
Performance counter stats for 'system wide':
119,410,122 cycles
152,105,479 instructions # 1.27 insn per cycle
0.101395093 seconds time elapsed
#
See? We had the counters enabled all the time.
Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: kernel-team@fb.com
Link: http://lore.kernel.org/lkml/20210316211837.910506-2-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-03-17 05:18:35 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* bpf_counter_ops serves two use cases:
|
|
|
|
* 1. perf-stat -b counting events used byBPF programs
|
|
|
|
* 2. perf-stat --use-bpf use BPF programs to aggregate counts
|
|
|
|
*/
|
perf stat: Enable counting events for BPF programs
Introduce 'perf stat -b' option, which counts events for BPF programs, like:
[root@localhost ~]# ~/perf stat -e ref-cycles,cycles -b 254 -I 1000
1.487903822 115,200 ref-cycles
1.487903822 86,012 cycles
2.489147029 80,560 ref-cycles
2.489147029 73,784 cycles
3.490341825 60,720 ref-cycles
3.490341825 37,797 cycles
4.491540887 37,120 ref-cycles
4.491540887 31,963 cycles
The example above counts 'cycles' and 'ref-cycles' of BPF program of id
254. This is similar to bpftool-prog-profile command, but more
flexible.
'perf stat -b' creates per-cpu perf_event and loads fentry/fexit BPF
programs (monitor-progs) to the target BPF program (target-prog). The
monitor-progs read perf_event before and after the target-prog, and
aggregate the difference in a BPF map. Then the user space reads data
from these maps.
A new 'struct bpf_counter' is introduced to provide a common interface
that uses BPF programs/maps to count perf events.
Committer notes:
Removed all but bpf_counter.h includes from evsel.h, not needed at all.
Also BPF map lookups for PERCPU_ARRAYs need to have as its value receive
buffer passed to the kernel libbpf_num_possible_cpus() entries, not
evsel__nr_cpus(evsel), as the former uses
/sys/devices/system/cpu/possible while the later uses
/sys/devices/system/cpu/online, which may be less than the 'possible'
number making the bpf map lookup overwrite memory and cause hard to
debug memory corruption.
We need to continue using evsel__nr_cpus(evsel) when accessing the
perf_counts array tho, not to overwrite another are of memory :-)
Signed-off-by: Song Liu <songliubraving@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/lkml/20210120163031.GU12699@kernel.org/
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: kernel-team@fb.com
Link: http://lore.kernel.org/lkml/20201229214214.3413833-4-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-12-30 05:42:14 +08:00
|
|
|
struct bpf_counter_ops *bpf_counter_ops;
|
perf stat: Introduce 'bperf' to share hardware PMCs with BPF
The perf tool uses performance monitoring counters (PMCs) to monitor
system performance. The PMCs are limited hardware resources. For
example, Intel CPUs have 3x fixed PMCs and 4x programmable PMCs per cpu.
Modern data center systems use these PMCs in many different ways: system
level monitoring, (maybe nested) container level monitoring, per process
monitoring, profiling (in sample mode), etc. In some cases, there are
more active perf_events than available hardware PMCs. To allow all
perf_events to have a chance to run, it is necessary to do expensive
time multiplexing of events.
On the other hand, many monitoring tools count the common metrics
(cycles, instructions). It is a waste to have multiple tools create
multiple perf_events of "cycles" and occupy multiple PMCs.
bperf tries to reduce such wastes by allowing multiple perf_events of
"cycles" or "instructions" (at different scopes) to share PMUs. Instead
of having each perf-stat session to read its own perf_events, bperf uses
BPF programs to read the perf_events and aggregate readings to BPF maps.
Then, the perf-stat session(s) reads the values from these BPF maps.
Please refer to the comment before the definition of bperf_ops for the
description of bperf architecture.
bperf is off by default. To enable it, pass --bpf-counters option to
perf-stat. bperf uses a BPF hashmap to share information about BPF
programs and maps used by bperf. This map is pinned to bpffs. The
default path is /sys/fs/bpf/perf_attr_map. The user could change the
path with option --bpf-attr-map.
Committer testing:
# dmesg|grep "Performance Events" -A5
[ 0.225277] Performance Events: Fam17h+ core perfctr, AMD PMU driver.
[ 0.225280] ... version: 0
[ 0.225280] ... bit width: 48
[ 0.225281] ... generic registers: 6
[ 0.225281] ... value mask: 0000ffffffffffff
[ 0.225281] ... max period: 00007fffffffffff
#
# for a in $(seq 6) ; do perf stat -a -e cycles,instructions sleep 100000 & done
[1] 2436231
[2] 2436232
[3] 2436233
[4] 2436234
[5] 2436235
[6] 2436236
# perf stat -a -e cycles,instructions sleep 0.1
Performance counter stats for 'system wide':
310,326,987 cycles (41.87%)
236,143,290 instructions # 0.76 insn per cycle (41.87%)
0.100800885 seconds time elapsed
#
We can see that the counters were enabled for this workload 41.87% of
the time.
Now with --bpf-counters:
# for a in $(seq 32) ; do perf stat --bpf-counters -a -e cycles,instructions sleep 100000 & done
[1] 2436514
[2] 2436515
[3] 2436516
[4] 2436517
[5] 2436518
[6] 2436519
[7] 2436520
[8] 2436521
[9] 2436522
[10] 2436523
[11] 2436524
[12] 2436525
[13] 2436526
[14] 2436527
[15] 2436528
[16] 2436529
[17] 2436530
[18] 2436531
[19] 2436532
[20] 2436533
[21] 2436534
[22] 2436535
[23] 2436536
[24] 2436537
[25] 2436538
[26] 2436539
[27] 2436540
[28] 2436541
[29] 2436542
[30] 2436543
[31] 2436544
[32] 2436545
#
# ls -la /sys/fs/bpf/perf_attr_map
-rw-------. 1 root root 0 Mar 23 14:53 /sys/fs/bpf/perf_attr_map
# bpftool map | grep bperf | wc -l
64
#
# bpftool map | tail
1265: percpu_array name accum_readings flags 0x0
key 4B value 24B max_entries 1 memlock 4096B
1266: hash name filter flags 0x0
key 4B value 4B max_entries 1 memlock 4096B
1267: array name bperf_fo.bss flags 0x400
key 4B value 8B max_entries 1 memlock 4096B
btf_id 996
pids perf(2436545)
1268: percpu_array name accum_readings flags 0x0
key 4B value 24B max_entries 1 memlock 4096B
1269: hash name filter flags 0x0
key 4B value 4B max_entries 1 memlock 4096B
1270: array name bperf_fo.bss flags 0x400
key 4B value 8B max_entries 1 memlock 4096B
btf_id 997
pids perf(2436541)
1285: array name pid_iter.rodata flags 0x480
key 4B value 4B max_entries 1 memlock 4096B
btf_id 1017 frozen
pids bpftool(2437504)
1286: array flags 0x0
key 4B value 32B max_entries 1 memlock 4096B
#
# bpftool map dump id 1268 | tail
value (CPU 21):
8f f3 bc ca 00 00 00 00 80 fd 2a d1 4d 00 00 00
80 fd 2a d1 4d 00 00 00
value (CPU 22):
7e d5 64 4d 00 00 00 00 a4 8a 2e ee 4d 00 00 00
a4 8a 2e ee 4d 00 00 00
value (CPU 23):
a7 78 3e 06 01 00 00 00 b2 34 94 f6 4d 00 00 00
b2 34 94 f6 4d 00 00 00
Found 1 element
# bpftool map dump id 1268 | tail
value (CPU 21):
c6 8b d9 ca 00 00 00 00 20 c6 fc 83 4e 00 00 00
20 c6 fc 83 4e 00 00 00
value (CPU 22):
9c b4 d2 4d 00 00 00 00 3e 0c df 89 4e 00 00 00
3e 0c df 89 4e 00 00 00
value (CPU 23):
18 43 66 06 01 00 00 00 5b 69 ed 83 4e 00 00 00
5b 69 ed 83 4e 00 00 00
Found 1 element
# bpftool map dump id 1268 | tail
value (CPU 21):
f2 6e db ca 00 00 00 00 92 67 4c ba 4e 00 00 00
92 67 4c ba 4e 00 00 00
value (CPU 22):
dc 8e e1 4d 00 00 00 00 d9 32 7a c5 4e 00 00 00
d9 32 7a c5 4e 00 00 00
value (CPU 23):
bd 2b 73 06 01 00 00 00 7c 73 87 bf 4e 00 00 00
7c 73 87 bf 4e 00 00 00
Found 1 element
#
# perf stat --bpf-counters -a -e cycles,instructions sleep 0.1
Performance counter stats for 'system wide':
119,410,122 cycles
152,105,479 instructions # 1.27 insn per cycle
0.101395093 seconds time elapsed
#
See? We had the counters enabled all the time.
Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: kernel-team@fb.com
Link: http://lore.kernel.org/lkml/20210316211837.910506-2-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-03-17 05:18:35 +08:00
|
|
|
|
|
|
|
/* for perf-stat -b */
|
|
|
|
struct list_head bpf_counter_list;
|
|
|
|
|
|
|
|
/* for perf-stat --use-bpf */
|
|
|
|
int bperf_leader_prog_fd;
|
|
|
|
int bperf_leader_link_fd;
|
|
|
|
union {
|
|
|
|
struct bperf_leader_bpf *leader_skel;
|
|
|
|
struct bperf_follower_bpf *follower_skel;
|
|
|
|
};
|
2021-08-21 17:19:22 +08:00
|
|
|
unsigned long open_flags;
|
2021-08-21 17:19:30 +08:00
|
|
|
int precise_ip_original;
|
2011-01-04 02:39:04 +08:00
|
|
|
};
|
|
|
|
|
2018-02-02 22:27:25 +08:00
|
|
|
struct perf_missing_features {
|
|
|
|
bool sample_id_all;
|
|
|
|
bool exclude_guest;
|
|
|
|
bool mmap2;
|
|
|
|
bool cloexec;
|
|
|
|
bool clockid;
|
|
|
|
bool clockid_wrong;
|
|
|
|
bool lbr_flags;
|
|
|
|
bool write_backward;
|
|
|
|
bool group_read;
|
2019-01-18 00:15:17 +08:00
|
|
|
bool ksymbol;
|
2019-08-27 06:31:06 +08:00
|
|
|
bool bpf;
|
2019-08-13 22:06:38 +08:00
|
|
|
bool aux_output;
|
perf evsel: Support PERF_SAMPLE_BRANCH_HW_INDEX
A new branch sample type PERF_SAMPLE_BRANCH_HW_INDEX has been introduced
in latest kernel.
Enable HW_INDEX by default in LBR call stack mode.
If kernel doesn't support the sample type, switching it off.
Add HW_INDEX in attr_fprintf as well. User can check whether the branch
sample type is set via debug information or header.
Committer testing:
First collect some samples with LBR callchains, system wide, for a few
seconds:
# perf record --call-graph lbr -a sleep 5
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.625 MB perf.data (224 samples) ]
#
Now lets use 'perf evlist -v' to look at the branch_sample_type:
# perf evlist -v
cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: USER|CALL_STACK|NO_FLAGS|NO_CYCLES|HW_INDEX
#
So the machine has the kernel feature, and it was correctly added to
perf_event_attr.branch_sample_type, for the default 'cycles' event.
If we do it in another machine, where the kernel lacks the HW_INDEX
feature, we get:
# perf record --call-graph lbr -a sleep 2s
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 1.690 MB perf.data (499 samples) ]
# perf evlist -v
cycles: size: 120, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|BRANCH_STACK, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, ksymbol: 1, bpf_event: 1, branch_sample_type: USER|CALL_STACK|NO_FLAGS|NO_CYCLES
#
No HW_INDEX in attr.branch_sample_type.
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Pavel Gerasimov <pavel.gerasimov@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Vitaly Slobodskoy <vitaly.slobodskoy@intel.com>
Link: http://lore.kernel.org/lkml/20200228163011.19358-3-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-02-29 00:30:01 +08:00
|
|
|
bool branch_hw_idx;
|
2020-03-25 20:45:34 +08:00
|
|
|
bool cgroup;
|
2020-12-08 01:04:05 +08:00
|
|
|
bool data_page_size;
|
2021-01-06 03:57:49 +08:00
|
|
|
bool code_page_size;
|
2021-02-03 04:09:09 +08:00
|
|
|
bool weight_struct;
|
2018-02-02 22:27:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct perf_missing_features perf_missing_features;
|
|
|
|
|
2019-07-21 19:23:49 +08:00
|
|
|
struct perf_cpu_map;
|
2011-01-04 09:09:46 +08:00
|
|
|
struct thread_map;
|
2013-12-20 01:43:45 +08:00
|
|
|
struct record_opts;
|
2011-01-04 09:09:46 +08:00
|
|
|
|
2019-07-21 19:24:05 +08:00
|
|
|
static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel)
|
2015-06-23 06:36:08 +08:00
|
|
|
{
|
2019-07-21 19:24:54 +08:00
|
|
|
return perf_evsel__cpus(&evsel->core);
|
2015-06-23 06:36:08 +08:00
|
|
|
}
|
|
|
|
|
2020-04-30 02:45:09 +08:00
|
|
|
static inline int evsel__nr_cpus(struct evsel *evsel)
|
2015-06-23 06:36:08 +08:00
|
|
|
{
|
2019-07-21 19:24:05 +08:00
|
|
|
return evsel__cpus(evsel)->nr;
|
2015-06-23 06:36:08 +08:00
|
|
|
}
|
|
|
|
|
2014-11-21 17:31:06 +08:00
|
|
|
void perf_counts_values__scale(struct perf_counts_values *count,
|
|
|
|
bool scale, s8 *pscaled);
|
|
|
|
|
2020-04-30 02:47:38 +08:00
|
|
|
void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
|
|
|
|
struct perf_counts_values *count);
|
2014-11-21 17:31:05 +08:00
|
|
|
|
2020-05-06 23:55:06 +08:00
|
|
|
int evsel__object_config(size_t object_size,
|
|
|
|
int (*init)(struct evsel *evsel),
|
|
|
|
void (*fini)(struct evsel *evsel));
|
2014-10-10 02:29:51 +08:00
|
|
|
|
2020-04-30 02:50:10 +08:00
|
|
|
struct perf_pmu *evsel__find_pmu(struct evsel *evsel);
|
2020-04-30 02:51:38 +08:00
|
|
|
bool evsel__is_aux_event(struct evsel *evsel);
|
2020-04-01 18:16:09 +08:00
|
|
|
|
2020-05-07 00:27:04 +08:00
|
|
|
struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx);
|
2013-11-08 03:41:19 +08:00
|
|
|
|
2019-07-21 19:23:58 +08:00
|
|
|
static inline struct evsel *evsel__new(struct perf_event_attr *attr)
|
2013-11-08 03:41:19 +08:00
|
|
|
{
|
2020-05-07 00:27:04 +08:00
|
|
|
return evsel__new_idx(attr, 0);
|
2013-11-08 03:41:19 +08:00
|
|
|
}
|
|
|
|
|
2020-09-24 20:44:51 +08:00
|
|
|
struct evsel *evsel__clone(struct evsel *orig);
|
2020-05-07 00:27:04 +08:00
|
|
|
struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx);
|
2013-11-08 03:41:19 +08:00
|
|
|
|
2021-09-09 20:55:07 +08:00
|
|
|
int copy_config_terms(struct list_head *dst, struct list_head *src);
|
|
|
|
void free_config_terms(struct list_head *config_terms);
|
|
|
|
|
2015-09-07 16:38:06 +08:00
|
|
|
/*
|
|
|
|
* Returns pointer with encoded error via <linux/err.h> interface.
|
|
|
|
*/
|
2020-05-07 00:27:04 +08:00
|
|
|
static inline struct evsel *evsel__newtp(const char *sys, const char *name)
|
2013-11-08 03:41:19 +08:00
|
|
|
{
|
2020-05-07 00:27:04 +08:00
|
|
|
return evsel__newtp_idx(sys, name, 0);
|
2013-11-08 03:41:19 +08:00
|
|
|
}
|
2012-09-27 07:24:19 +08:00
|
|
|
|
2021-04-27 15:01:26 +08:00
|
|
|
struct evsel *evsel__new_cycles(bool precise, __u32 type, __u64 config);
|
2016-07-29 05:33:20 +08:00
|
|
|
|
2018-11-30 23:44:07 +08:00
|
|
|
struct tep_event *event_format__new(const char *sys, const char *name);
|
2012-09-27 07:24:19 +08:00
|
|
|
|
2019-07-21 19:23:53 +08:00
|
|
|
void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int idx);
|
2020-04-30 02:53:17 +08:00
|
|
|
void evsel__exit(struct evsel *evsel);
|
2019-07-21 19:23:57 +08:00
|
|
|
void evsel__delete(struct evsel *evsel);
|
2011-01-04 02:39:04 +08:00
|
|
|
|
2016-04-12 05:15:29 +08:00
|
|
|
struct callchain_param;
|
|
|
|
|
2020-04-30 02:57:01 +08:00
|
|
|
void evsel__config(struct evsel *evsel, struct record_opts *opts,
|
|
|
|
struct callchain_param *callchain);
|
|
|
|
void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts,
|
|
|
|
struct callchain_param *callchain);
|
2011-11-09 00:41:57 +08:00
|
|
|
|
2020-04-30 03:00:27 +08:00
|
|
|
int __evsel__sample_size(u64 sample_type);
|
2020-04-30 02:58:40 +08:00
|
|
|
void evsel__calc_id_pos(struct evsel *evsel);
|
2013-08-27 16:23:09 +08:00
|
|
|
|
2020-04-30 21:51:16 +08:00
|
|
|
bool evsel__is_cache_op_valid(u8 type, u8 op);
|
2012-06-12 01:08:07 +08:00
|
|
|
|
2021-04-26 05:43:31 +08:00
|
|
|
static inline bool evsel__is_bpf(struct evsel *evsel)
|
|
|
|
{
|
|
|
|
return evsel->bpf_counter_ops != NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-07 00:32:23 +08:00
|
|
|
#define EVSEL__MAX_ALIASES 8
|
|
|
|
|
|
|
|
extern const char *evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX][EVSEL__MAX_ALIASES];
|
|
|
|
extern const char *evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX][EVSEL__MAX_ALIASES];
|
|
|
|
extern const char *evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX][EVSEL__MAX_ALIASES];
|
|
|
|
extern const char *evsel__hw_names[PERF_COUNT_HW_MAX];
|
|
|
|
extern const char *evsel__sw_names[PERF_COUNT_SW_MAX];
|
2021-04-26 05:43:31 +08:00
|
|
|
extern char *evsel__bpf_counter_events;
|
|
|
|
bool evsel__match_bpf_counter_events(const char *name);
|
|
|
|
|
2020-04-30 03:07:09 +08:00
|
|
|
int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size);
|
|
|
|
const char *evsel__name(struct evsel *evsel);
|
2013-11-13 00:58:49 +08:00
|
|
|
|
2020-04-30 03:07:09 +08:00
|
|
|
const char *evsel__group_name(struct evsel *evsel);
|
2020-04-30 03:09:12 +08:00
|
|
|
int evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
|
2012-05-26 03:38:11 +08:00
|
|
|
|
2020-04-30 03:12:15 +08:00
|
|
|
void __evsel__set_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit);
|
|
|
|
void __evsel__reset_sample_bit(struct evsel *evsel, enum perf_event_sample_format bit);
|
2012-12-11 01:53:43 +08:00
|
|
|
|
2020-04-30 03:12:15 +08:00
|
|
|
#define evsel__set_sample_bit(evsel, bit) \
|
|
|
|
__evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
|
2012-12-11 01:53:43 +08:00
|
|
|
|
2020-04-30 03:12:15 +08:00
|
|
|
#define evsel__reset_sample_bit(evsel, bit) \
|
|
|
|
__evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
|
2012-12-11 01:53:43 +08:00
|
|
|
|
2020-04-30 03:12:15 +08:00
|
|
|
void evsel__set_sample_id(struct evsel *evsel, bool use_sample_identifier);
|
2012-12-11 02:21:30 +08:00
|
|
|
|
2021-02-03 04:09:09 +08:00
|
|
|
void arch_evsel__set_sample_weight(struct evsel *evsel);
|
|
|
|
|
2020-04-30 03:19:05 +08:00
|
|
|
int evsel__set_filter(struct evsel *evsel, const char *filter);
|
|
|
|
int evsel__append_tp_filter(struct evsel *evsel, const char *filter);
|
|
|
|
int evsel__append_addr_filter(struct evsel *evsel, const char *filter);
|
2019-11-21 08:15:21 +08:00
|
|
|
int evsel__enable_cpu(struct evsel *evsel, int cpu);
|
2019-07-21 19:24:02 +08:00
|
|
|
int evsel__enable(struct evsel *evsel);
|
2019-07-21 19:24:03 +08:00
|
|
|
int evsel__disable(struct evsel *evsel);
|
2019-11-21 08:15:21 +08:00
|
|
|
int evsel__disable_cpu(struct evsel *evsel, int cpu);
|
2012-09-27 02:07:39 +08:00
|
|
|
|
2020-04-30 03:21:03 +08:00
|
|
|
int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu);
|
|
|
|
int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads);
|
2019-07-21 19:24:01 +08:00
|
|
|
int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
|
|
|
|
struct perf_thread_map *threads);
|
2019-07-21 19:24:50 +08:00
|
|
|
void evsel__close(struct evsel *evsel);
|
2021-08-21 17:19:24 +08:00
|
|
|
int evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
|
|
|
|
struct perf_thread_map *threads);
|
2021-08-21 17:19:25 +08:00
|
|
|
bool evsel__detect_missing_features(struct evsel *evsel);
|
2011-01-04 03:48:12 +08:00
|
|
|
|
2021-08-21 17:19:26 +08:00
|
|
|
enum rlimit_action { NO_CHANGE, SET_TO_MAX, INCREASED_MAX };
|
|
|
|
bool evsel__increase_rlimit(enum rlimit_action *set_rlimit);
|
|
|
|
|
2021-08-21 17:19:27 +08:00
|
|
|
bool evsel__ignore_missing_thread(struct evsel *evsel,
|
|
|
|
int nr_cpus, int cpu,
|
|
|
|
struct perf_thread_map *threads,
|
|
|
|
int thread, int err);
|
2021-08-21 17:19:30 +08:00
|
|
|
bool evsel__precise_ip_fallback(struct evsel *evsel);
|
2021-08-21 17:19:27 +08:00
|
|
|
|
2012-09-12 06:24:23 +08:00
|
|
|
struct perf_sample;
|
|
|
|
|
2020-04-30 03:26:57 +08:00
|
|
|
void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name);
|
|
|
|
u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name);
|
|
|
|
|
|
|
|
static inline char *evsel__strval(struct evsel *evsel, struct perf_sample *sample, const char *name)
|
2012-09-27 07:22:00 +08:00
|
|
|
{
|
2020-04-30 03:26:57 +08:00
|
|
|
return evsel__rawptr(evsel, sample, name);
|
2012-09-27 07:22:00 +08:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
struct tep_format_field;
|
2012-09-18 22:21:50 +08:00
|
|
|
|
2018-09-20 02:56:45 +08:00
|
|
|
u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap);
|
2016-05-31 23:47:46 +08:00
|
|
|
|
2020-04-30 03:26:57 +08:00
|
|
|
struct tep_format_field *evsel__field(struct evsel *evsel, const char *name);
|
2012-09-18 22:21:50 +08:00
|
|
|
|
2020-04-30 21:51:16 +08:00
|
|
|
#define evsel__match(evsel, t, c) \
|
2019-07-21 19:24:29 +08:00
|
|
|
(evsel->core.attr.type == PERF_TYPE_##t && \
|
|
|
|
evsel->core.attr.config == PERF_COUNT_##c)
|
2011-01-04 02:49:44 +08:00
|
|
|
|
2020-04-30 21:51:16 +08:00
|
|
|
static inline bool evsel__match2(struct evsel *e1, struct evsel *e2)
|
2012-09-06 23:46:55 +08:00
|
|
|
{
|
2019-07-21 19:24:29 +08:00
|
|
|
return (e1->core.attr.type == e2->core.attr.type) &&
|
|
|
|
(e1->core.attr.config == e2->core.attr.config);
|
2012-09-06 23:46:55 +08:00
|
|
|
}
|
|
|
|
|
2020-04-30 22:00:53 +08:00
|
|
|
int evsel__read_counter(struct evsel *evsel, int cpu, int thread);
|
2017-07-26 20:02:05 +08:00
|
|
|
|
2020-04-30 22:00:53 +08:00
|
|
|
int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale);
|
2011-01-04 03:45:52 +08:00
|
|
|
|
|
|
|
/**
|
2020-04-30 22:00:53 +08:00
|
|
|
* evsel__read_on_cpu - Read out the results on a CPU and thread
|
2011-01-04 03:45:52 +08:00
|
|
|
*
|
|
|
|
* @evsel - event selector to read value
|
|
|
|
* @cpu - CPU of interest
|
|
|
|
* @thread - thread of interest
|
|
|
|
*/
|
2020-04-30 22:00:53 +08:00
|
|
|
static inline int evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread)
|
2011-01-04 03:45:52 +08:00
|
|
|
{
|
2020-04-30 22:00:53 +08:00
|
|
|
return __evsel__read_on_cpu(evsel, cpu, thread, false);
|
2011-01-04 03:45:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-30 22:00:53 +08:00
|
|
|
* evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
|
2011-01-04 03:45:52 +08:00
|
|
|
*
|
|
|
|
* @evsel - event selector to read value
|
|
|
|
* @cpu - CPU of interest
|
|
|
|
* @thread - thread of interest
|
|
|
|
*/
|
2020-04-30 22:00:53 +08:00
|
|
|
static inline int evsel__read_on_cpu_scaled(struct evsel *evsel, int cpu, int thread)
|
2011-01-04 03:45:52 +08:00
|
|
|
{
|
2020-04-30 22:00:53 +08:00
|
|
|
return __evsel__read_on_cpu(evsel, cpu, thread, true);
|
2011-01-04 03:45:52 +08:00
|
|
|
}
|
|
|
|
|
2020-04-30 22:03:49 +08:00
|
|
|
int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
|
|
|
|
struct perf_sample *sample);
|
2012-08-15 03:42:15 +08:00
|
|
|
|
2020-04-30 22:03:49 +08:00
|
|
|
int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event,
|
|
|
|
u64 *timestamp);
|
2017-08-03 19:10:28 +08:00
|
|
|
|
2020-04-30 22:06:45 +08:00
|
|
|
static inline struct evsel *evsel__next(struct evsel *evsel)
|
2012-08-15 03:42:15 +08:00
|
|
|
{
|
2019-07-21 19:24:22 +08:00
|
|
|
return list_entry(evsel->core.node.next, struct evsel, core.node);
|
2012-08-15 03:42:15 +08:00
|
|
|
}
|
2012-11-14 04:27:28 +08:00
|
|
|
|
2020-04-30 22:06:45 +08:00
|
|
|
static inline struct evsel *evsel__prev(struct evsel *evsel)
|
2013-11-14 02:56:40 +08:00
|
|
|
{
|
2019-07-21 19:24:22 +08:00
|
|
|
return list_entry(evsel->core.node.prev, struct evsel, core.node);
|
2013-11-14 02:56:40 +08:00
|
|
|
}
|
|
|
|
|
2013-03-05 13:53:26 +08:00
|
|
|
/**
|
2020-04-30 21:51:16 +08:00
|
|
|
* evsel__is_group_leader - Return whether given evsel is a leader event
|
2013-03-05 13:53:26 +08:00
|
|
|
*
|
|
|
|
* @evsel - evsel selector to be tested
|
|
|
|
*
|
|
|
|
* Return %true if @evsel is a group leader or a stand-alone event
|
|
|
|
*/
|
2020-04-30 21:51:16 +08:00
|
|
|
static inline bool evsel__is_group_leader(const struct evsel *evsel)
|
2012-11-14 04:27:28 +08:00
|
|
|
{
|
2021-07-06 23:17:00 +08:00
|
|
|
return evsel->core.leader == &evsel->core;
|
2012-11-14 04:27:28 +08:00
|
|
|
}
|
2012-12-11 05:17:08 +08:00
|
|
|
|
2013-03-05 13:53:26 +08:00
|
|
|
/**
|
2020-04-30 21:51:16 +08:00
|
|
|
* evsel__is_group_event - Return whether given evsel is a group event
|
2013-03-05 13:53:26 +08:00
|
|
|
*
|
|
|
|
* @evsel - evsel selector to be tested
|
|
|
|
*
|
|
|
|
* Return %true iff event group view is enabled and @evsel is a actual group
|
|
|
|
* leader which has other members in the group
|
|
|
|
*/
|
2020-04-30 21:51:16 +08:00
|
|
|
static inline bool evsel__is_group_event(struct evsel *evsel)
|
2013-03-05 13:53:26 +08:00
|
|
|
{
|
|
|
|
if (!symbol_conf.event_group)
|
|
|
|
return false;
|
|
|
|
|
2020-04-30 21:51:16 +08:00
|
|
|
return evsel__is_group_leader(evsel) && evsel->core.nr_members > 1;
|
2013-03-05 13:53:26 +08:00
|
|
|
}
|
|
|
|
|
2020-04-30 21:51:16 +08:00
|
|
|
bool evsel__is_function_event(struct evsel *evsel);
|
2014-03-02 23:56:40 +08:00
|
|
|
|
2020-04-30 21:51:16 +08:00
|
|
|
static inline bool evsel__is_bpf_output(struct evsel *evsel)
|
perf tools: Introduce bpf-output event
Commit a43eec304259 ("bpf: introduce bpf_perf_event_output() helper")
adds a helper to enable a BPF program to output data to a perf ring
buffer through a new type of perf event, PERF_COUNT_SW_BPF_OUTPUT. This
patch enables perf to create events of that type. Now a perf user can
use the following cmdline to receive output data from BPF programs:
# perf record -a -e bpf-output/no-inherit,name=evt/ \
-e ./test_bpf_output.c/map:channel.event=evt/ ls /
# perf script
perf 1560 [004] 347747.086295: evt: ffffffff811fd201 sys_write ...
perf 1560 [004] 347747.086300: evt: ffffffff811fd201 sys_write ...
perf 1560 [004] 347747.086315: evt: ffffffff811fd201 sys_write ...
...
Test result:
# cat test_bpf_output.c
/************************ BEGIN **************************/
#include <uapi/linux/bpf.h>
struct bpf_map_def {
unsigned int type;
unsigned int key_size;
unsigned int value_size;
unsigned int max_entries;
};
#define SEC(NAME) __attribute__((section(NAME), used))
static u64 (*ktime_get_ns)(void) =
(void *)BPF_FUNC_ktime_get_ns;
static int (*trace_printk)(const char *fmt, int fmt_size, ...) =
(void *)BPF_FUNC_trace_printk;
static int (*get_smp_processor_id)(void) =
(void *)BPF_FUNC_get_smp_processor_id;
static int (*perf_event_output)(void *, struct bpf_map_def *, int, void *, unsigned long) =
(void *)BPF_FUNC_perf_event_output;
struct bpf_map_def SEC("maps") channel = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(u32),
.max_entries = __NR_CPUS__,
};
SEC("func_write=sys_write")
int func_write(void *ctx)
{
struct {
u64 ktime;
int cpuid;
} __attribute__((packed)) output_data;
char error_data[] = "Error: failed to output: %d\n";
output_data.cpuid = get_smp_processor_id();
output_data.ktime = ktime_get_ns();
int err = perf_event_output(ctx, &channel, get_smp_processor_id(),
&output_data, sizeof(output_data));
if (err)
trace_printk(error_data, sizeof(error_data), err);
return 0;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
/************************ END ***************************/
# perf record -a -e bpf-output/no-inherit,name=evt/ \
-e ./test_bpf_output.c/map:channel.event=evt/ ls /
# perf script | grep ls
ls 2242 [003] 347851.557563: evt: ffffffff811fd201 sys_write ...
ls 2242 [003] 347851.557571: evt: ffffffff811fd201 sys_write ...
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Cody P Schafer <dev@codyps.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kirill Smelkov <kirr@nexedi.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1456132275-98875-11-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-02-22 17:10:37 +08:00
|
|
|
{
|
2020-04-30 21:51:16 +08:00
|
|
|
return evsel__match(evsel, SOFTWARE, SW_BPF_OUTPUT);
|
perf tools: Introduce bpf-output event
Commit a43eec304259 ("bpf: introduce bpf_perf_event_output() helper")
adds a helper to enable a BPF program to output data to a perf ring
buffer through a new type of perf event, PERF_COUNT_SW_BPF_OUTPUT. This
patch enables perf to create events of that type. Now a perf user can
use the following cmdline to receive output data from BPF programs:
# perf record -a -e bpf-output/no-inherit,name=evt/ \
-e ./test_bpf_output.c/map:channel.event=evt/ ls /
# perf script
perf 1560 [004] 347747.086295: evt: ffffffff811fd201 sys_write ...
perf 1560 [004] 347747.086300: evt: ffffffff811fd201 sys_write ...
perf 1560 [004] 347747.086315: evt: ffffffff811fd201 sys_write ...
...
Test result:
# cat test_bpf_output.c
/************************ BEGIN **************************/
#include <uapi/linux/bpf.h>
struct bpf_map_def {
unsigned int type;
unsigned int key_size;
unsigned int value_size;
unsigned int max_entries;
};
#define SEC(NAME) __attribute__((section(NAME), used))
static u64 (*ktime_get_ns)(void) =
(void *)BPF_FUNC_ktime_get_ns;
static int (*trace_printk)(const char *fmt, int fmt_size, ...) =
(void *)BPF_FUNC_trace_printk;
static int (*get_smp_processor_id)(void) =
(void *)BPF_FUNC_get_smp_processor_id;
static int (*perf_event_output)(void *, struct bpf_map_def *, int, void *, unsigned long) =
(void *)BPF_FUNC_perf_event_output;
struct bpf_map_def SEC("maps") channel = {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(u32),
.max_entries = __NR_CPUS__,
};
SEC("func_write=sys_write")
int func_write(void *ctx)
{
struct {
u64 ktime;
int cpuid;
} __attribute__((packed)) output_data;
char error_data[] = "Error: failed to output: %d\n";
output_data.cpuid = get_smp_processor_id();
output_data.ktime = ktime_get_ns();
int err = perf_event_output(ctx, &channel, get_smp_processor_id(),
&output_data, sizeof(output_data));
if (err)
trace_printk(error_data, sizeof(error_data), err);
return 0;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
/************************ END ***************************/
# perf record -a -e bpf-output/no-inherit,name=evt/ \
-e ./test_bpf_output.c/map:channel.event=evt/ ls /
# perf script | grep ls
ls 2242 [003] 347851.557563: evt: ffffffff811fd201 sys_write ...
ls 2242 [003] 347851.557571: evt: ffffffff811fd201 sys_write ...
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Cody P Schafer <dev@codyps.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kirill Smelkov <kirr@nexedi.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1456132275-98875-11-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-02-22 17:10:37 +08:00
|
|
|
}
|
|
|
|
|
2020-04-30 21:51:16 +08:00
|
|
|
static inline bool evsel__is_clock(struct evsel *evsel)
|
perf stat: Get rid of extra clock display function
There's no reason to have separate function to display clock events.
It's only purpose was to convert the nanosecond value into microseconds.
We do that now in generic code, if the unit and scale values are
properly set, which this patch do for clock events.
The output differs in the unit field being displayed in its columns
rather than having it added as a suffix of the event name. Plus the
value is rounded into 2 decimal numbers as for any other event.
Before:
# perf stat -e cpu-clock,task-clock -C 0 sleep 3
Performance counter stats for 'CPU(s) 0':
3001.123137 cpu-clock (msec) # 1.000 CPUs utilized
3001.133250 task-clock (msec) # 1.000 CPUs utilized
3.001159813 seconds time elapsed
Now:
# perf stat -e cpu-clock,task-clock -C 0 sleep 3
Performance counter stats for 'CPU(s) 0':
3,001.05 msec cpu-clock # 1.000 CPUs utilized
3,001.05 msec task-clock # 1.000 CPUs utilized
3.001077794 seconds time elapsed
There's a small difference in csv output, as we now output the unit
field, which was empty before. It's in the proper spot, so there's no
compatibility issue.
Before:
# perf stat -e cpu-clock,task-clock -C 0 -x, sleep 3
3001.065177,,cpu-clock,3001064187,100.00,1.000,CPUs utilized
3001.077085,,task-clock,3001077085,100.00,1.000,CPUs utilized
# perf stat -e cpu-clock,task-clock -C 0 -x, sleep 3
3000.80,msec,cpu-clock,3000799026,100.00,1.000,CPUs utilized
3000.80,msec,task-clock,3000799550,100.00,1.000,CPUs utilized
Add perf_evsel__is_clock to replace nsec_counter.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180720110036.32251-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-07-20 19:00:34 +08:00
|
|
|
{
|
2020-04-30 21:51:16 +08:00
|
|
|
return evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) ||
|
|
|
|
evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK);
|
perf stat: Get rid of extra clock display function
There's no reason to have separate function to display clock events.
It's only purpose was to convert the nanosecond value into microseconds.
We do that now in generic code, if the unit and scale values are
properly set, which this patch do for clock events.
The output differs in the unit field being displayed in its columns
rather than having it added as a suffix of the event name. Plus the
value is rounded into 2 decimal numbers as for any other event.
Before:
# perf stat -e cpu-clock,task-clock -C 0 sleep 3
Performance counter stats for 'CPU(s) 0':
3001.123137 cpu-clock (msec) # 1.000 CPUs utilized
3001.133250 task-clock (msec) # 1.000 CPUs utilized
3.001159813 seconds time elapsed
Now:
# perf stat -e cpu-clock,task-clock -C 0 sleep 3
Performance counter stats for 'CPU(s) 0':
3,001.05 msec cpu-clock # 1.000 CPUs utilized
3,001.05 msec task-clock # 1.000 CPUs utilized
3.001077794 seconds time elapsed
There's a small difference in csv output, as we now output the unit
field, which was empty before. It's in the proper spot, so there's no
compatibility issue.
Before:
# perf stat -e cpu-clock,task-clock -C 0 -x, sleep 3
3001.065177,,cpu-clock,3001064187,100.00,1.000,CPUs utilized
3001.077085,,task-clock,3001077085,100.00,1.000,CPUs utilized
# perf stat -e cpu-clock,task-clock -C 0 -x, sleep 3
3000.80,msec,cpu-clock,3000799026,100.00,1.000,CPUs utilized
3000.80,msec,task-clock,3000799550,100.00,1.000,CPUs utilized
Add perf_evsel__is_clock to replace nsec_counter.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180720110036.32251-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-07-20 19:00:34 +08:00
|
|
|
}
|
|
|
|
|
2020-04-30 22:46:15 +08:00
|
|
|
bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize);
|
2020-05-05 00:43:03 +08:00
|
|
|
int evsel__open_strerror(struct evsel *evsel, struct target *target,
|
|
|
|
int err, char *msg, size_t size);
|
2013-01-22 17:09:29 +08:00
|
|
|
|
2020-05-05 00:43:03 +08:00
|
|
|
static inline int evsel__group_idx(struct evsel *evsel)
|
2013-01-22 17:09:29 +08:00
|
|
|
{
|
2021-07-06 23:17:00 +08:00
|
|
|
return evsel->core.idx - evsel->core.leader->idx;
|
2013-01-22 17:09:29 +08:00
|
|
|
}
|
2013-01-22 17:09:44 +08:00
|
|
|
|
2018-08-04 21:05:08 +08:00
|
|
|
/* Iterates group WITHOUT the leader. */
|
2013-01-22 17:09:44 +08:00
|
|
|
#define for_each_group_member(_evsel, _leader) \
|
2019-07-21 19:24:22 +08:00
|
|
|
for ((_evsel) = list_entry((_leader)->core.node.next, struct evsel, core.node); \
|
2021-07-06 23:17:00 +08:00
|
|
|
(_evsel) && (_evsel)->core.leader == (&_leader->core); \
|
2019-07-21 19:24:22 +08:00
|
|
|
(_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
|
2013-01-22 17:09:44 +08:00
|
|
|
|
2018-08-04 21:05:08 +08:00
|
|
|
/* Iterates group WITH the leader. */
|
|
|
|
#define for_each_group_evsel(_evsel, _leader) \
|
|
|
|
for ((_evsel) = _leader; \
|
2021-07-06 23:17:00 +08:00
|
|
|
(_evsel) && (_evsel)->core.leader == (&_leader->core); \
|
2019-07-21 19:24:22 +08:00
|
|
|
(_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
|
2018-08-04 21:05:08 +08:00
|
|
|
|
2020-04-30 22:19:45 +08:00
|
|
|
static inline bool evsel__has_branch_callstack(const struct evsel *evsel)
|
2015-01-06 02:23:05 +08:00
|
|
|
{
|
2019-07-21 19:24:29 +08:00
|
|
|
return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
|
2015-01-06 02:23:05 +08:00
|
|
|
}
|
perf tools: Merge all perf_event_attr print functions
Currently there's 3 (that I found) different and incomplete
implementations of printing perf_event_attr.
This is quite silly. Merge the lot.
While this patch does not retain the exact form all printing that I
found is debug output and thus it should not be critical.
Also, I cannot find a single print_event_desc() caller.
Pre:
$ perf record -vv -e cycles -- sleep 1
------------------------------------------------------------
perf_event_attr:
type 0
size 104
config 0
sample_period 4000
sample_freq 4000
sample_type 0x107
read_format 0
disabled 1 inherit 1
pinned 0 exclusive 0
exclude_user 0 exclude_kernel 0
exclude_hv 0 exclude_idle 0
mmap 1 comm 1
mmap2 1 comm_exec 1
freq 1 inherit_stat 0
enable_on_exec 1 task 1
watermark 0 precise_ip 0
mmap_data 0 sample_id_all 1
exclude_host 0 exclude_guest 1
excl.callchain_kern 0 excl.callchain_user 0
wakeup_events 0
wakeup_watermark 0
bp_type 0
bp_addr 0
config1 0
bp_len 0
config2 0
branch_sample_type 0
sample_regs_user 0
sample_stack_user 0
sample_regs_intr 0
------------------------------------------------------------
$ perf evlist -vv
cycles: sample_freq=4000, size: 104, sample_type: IP|TID|TIME|PERIOD,
disabled: 1, inherit: 1, mmap: 1, mmap2: 1, comm: 1, comm_exec: 1,
freq: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1
Post:
$ ./perf record -vv -e cycles -- sleep 1
------------------------------------------------------------
perf_event_attr:
size 112
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|PERIOD
disabled 1
inherit 1
mmap 1
comm 1
freq 1
enable_on_exec 1
task 1
sample_id_all 1
exclude_guest 1
mmap2 1
comm_exec 1
------------------------------------------------------------
$ ./perf evlist -vv
cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type:
IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq:
1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1,
mmap2: 1, comm_exec: 1
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20150407091150.644238729@infradead.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-04-07 17:09:54 +08:00
|
|
|
|
2020-04-30 22:19:45 +08:00
|
|
|
static inline bool evsel__has_branch_hw_idx(const struct evsel *evsel)
|
2020-02-29 00:30:00 +08:00
|
|
|
{
|
|
|
|
return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX;
|
|
|
|
}
|
|
|
|
|
2019-07-21 19:23:51 +08:00
|
|
|
static inline bool evsel__has_callchain(const struct evsel *evsel)
|
2018-05-29 03:00:29 +08:00
|
|
|
{
|
2020-04-01 18:16:07 +08:00
|
|
|
/*
|
|
|
|
* For reporting purposes, an evsel sample can have a recorded callchain
|
|
|
|
* or a callchain synthesized from AUX area data.
|
|
|
|
*/
|
|
|
|
return evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN ||
|
|
|
|
evsel->synth_sample_type & PERF_SAMPLE_CALLCHAIN;
|
2018-05-29 03:00:29 +08:00
|
|
|
}
|
|
|
|
|
2020-04-29 23:07:47 +08:00
|
|
|
static inline bool evsel__has_br_stack(const struct evsel *evsel)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For reporting purposes, an evsel sample can have a recorded branch
|
|
|
|
* stack or a branch stack synthesized from AUX area data.
|
|
|
|
*/
|
|
|
|
return evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK ||
|
|
|
|
evsel->synth_sample_type & PERF_SAMPLE_BRANCH_STACK;
|
|
|
|
}
|
|
|
|
|
2020-06-29 17:19:51 +08:00
|
|
|
static inline bool evsel__is_dummy_event(struct evsel *evsel)
|
|
|
|
{
|
|
|
|
return (evsel->core.attr.type == PERF_TYPE_SOFTWARE) &&
|
|
|
|
(evsel->core.attr.config == PERF_COUNT_SW_DUMMY);
|
|
|
|
}
|
|
|
|
|
2020-05-05 00:44:03 +08:00
|
|
|
struct perf_env *evsel__env(struct evsel *evsel);
|
2016-06-30 14:14:19 +08:00
|
|
|
|
2020-05-05 00:45:19 +08:00
|
|
|
int evsel__store_ids(struct evsel *evsel, struct evlist *evlist);
|
perf stat: Enable counting events for BPF programs
Introduce 'perf stat -b' option, which counts events for BPF programs, like:
[root@localhost ~]# ~/perf stat -e ref-cycles,cycles -b 254 -I 1000
1.487903822 115,200 ref-cycles
1.487903822 86,012 cycles
2.489147029 80,560 ref-cycles
2.489147029 73,784 cycles
3.490341825 60,720 ref-cycles
3.490341825 37,797 cycles
4.491540887 37,120 ref-cycles
4.491540887 31,963 cycles
The example above counts 'cycles' and 'ref-cycles' of BPF program of id
254. This is similar to bpftool-prog-profile command, but more
flexible.
'perf stat -b' creates per-cpu perf_event and loads fentry/fexit BPF
programs (monitor-progs) to the target BPF program (target-prog). The
monitor-progs read perf_event before and after the target-prog, and
aggregate the difference in a BPF map. Then the user space reads data
from these maps.
A new 'struct bpf_counter' is introduced to provide a common interface
that uses BPF programs/maps to count perf events.
Committer notes:
Removed all but bpf_counter.h includes from evsel.h, not needed at all.
Also BPF map lookups for PERCPU_ARRAYs need to have as its value receive
buffer passed to the kernel libbpf_num_possible_cpus() entries, not
evsel__nr_cpus(evsel), as the former uses
/sys/devices/system/cpu/possible while the later uses
/sys/devices/system/cpu/online, which may be less than the 'possible'
number making the bpf map lookup overwrite memory and cause hard to
debug memory corruption.
We need to continue using evsel__nr_cpus(evsel) when accessing the
perf_counts array tho, not to overwrite another are of memory :-)
Signed-off-by: Song Liu <songliubraving@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/lkml/20210120163031.GU12699@kernel.org/
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: kernel-team@fb.com
Link: http://lore.kernel.org/lkml/20201229214214.3413833-4-songliubraving@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-12-30 05:42:14 +08:00
|
|
|
|
perf stat: Fix wrong skipping for per-die aggregation
Uncore becomes die-scope on Xeon Cascade Lake-AP and perf has supported
--per-die aggregation yet.
One issue is found in check_per_pkg() for uncore events running on AP
system. On cascade Lake-AP, we have:
S0-D0
S0-D1
S1-D0
S1-D1
But in check_per_pkg(), S0-D1 and S1-D1 are skipped because the mask
bits for S0 and S1 have been set for S0-D0 and S1-D0. It doesn't check
die_id. So the counting for S0-D1 and S1-D1 are set to zero. That's not
correct.
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001460963 S0-D0 1 1317376 Bytes llc_misses.mem_read
1.001460963 S0-D1 1 998016 Bytes llc_misses.mem_read
1.001460963 S1-D0 1 970496 Bytes llc_misses.mem_read
1.001460963 S1-D1 1 1291264 Bytes llc_misses.mem_read
2.003488021 S0-D0 1 1082048 Bytes llc_misses.mem_read
2.003488021 S0-D1 1 1919040 Bytes llc_misses.mem_read
2.003488021 S1-D0 1 890752 Bytes llc_misses.mem_read
2.003488021 S1-D1 1 2380800 Bytes llc_misses.mem_read
3.005613270 S0-D0 1 1126080 Bytes llc_misses.mem_read
3.005613270 S0-D1 1 2898176 Bytes llc_misses.mem_read
3.005613270 S1-D0 1 870912 Bytes llc_misses.mem_read
3.005613270 S1-D1 1 3388608 Bytes llc_misses.mem_read
4.007627598 S0-D0 1 1124608 Bytes llc_misses.mem_read
4.007627598 S0-D1 1 3884416 Bytes llc_misses.mem_read
4.007627598 S1-D0 1 921088 Bytes llc_misses.mem_read
4.007627598 S1-D1 1 4451840 Bytes llc_misses.mem_read
5.001479927 S0-D0 1 963328 Bytes llc_misses.mem_read
5.001479927 S0-D1 1 4831936 Bytes llc_misses.mem_read
5.001479927 S1-D0 1 895104 Bytes llc_misses.mem_read
5.001479927 S1-D1 1 5496640 Bytes llc_misses.mem_read
From above output, we can see S0-D1 and S1-D1 don't report the interval
values, they are continued to grow. That's because check_per_pkg()
wrongly decides to use zero counts for S0-D1 and S1-D1.
So in check_per_pkg(), we should use hashmap(socket,die) to decide if
the cpu counts needs to skip. Only considering socket is not enough.
Now with this patch,
root@lkp-csl-2ap4 ~# ./perf stat -a -I 1000 -e llc_misses.mem_read --per-die -- sleep 5
1.001586691 S0-D0 1 1229440 Bytes llc_misses.mem_read
1.001586691 S0-D1 1 976832 Bytes llc_misses.mem_read
1.001586691 S1-D0 1 938304 Bytes llc_misses.mem_read
1.001586691 S1-D1 1 1227328 Bytes llc_misses.mem_read
2.003776312 S0-D0 1 1586752 Bytes llc_misses.mem_read
2.003776312 S0-D1 1 875392 Bytes llc_misses.mem_read
2.003776312 S1-D0 1 855616 Bytes llc_misses.mem_read
2.003776312 S1-D1 1 949376 Bytes llc_misses.mem_read
3.006512788 S0-D0 1 1338880 Bytes llc_misses.mem_read
3.006512788 S0-D1 1 920064 Bytes llc_misses.mem_read
3.006512788 S1-D0 1 877184 Bytes llc_misses.mem_read
3.006512788 S1-D1 1 1020736 Bytes llc_misses.mem_read
4.008895291 S0-D0 1 926592 Bytes llc_misses.mem_read
4.008895291 S0-D1 1 906368 Bytes llc_misses.mem_read
4.008895291 S1-D0 1 892224 Bytes llc_misses.mem_read
4.008895291 S1-D1 1 987712 Bytes llc_misses.mem_read
5.001590993 S0-D0 1 962624 Bytes llc_misses.mem_read
5.001590993 S0-D1 1 912512 Bytes llc_misses.mem_read
5.001590993 S1-D0 1 891200 Bytes llc_misses.mem_read
5.001590993 S1-D1 1 978432 Bytes llc_misses.mem_read
On no-die system, die_id is 0, actually it's hashmap(socket,0), original behavior
is not changed.
Reported-by: Ying Huang <ying.huang@intel.com>
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ying Huang <ying.huang@intel.com>
Link: http://lore.kernel.org/lkml/20210128013417.25597-1-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-28 09:34:17 +08:00
|
|
|
void evsel__zero_per_pkg(struct evsel *evsel);
|
2021-04-27 15:01:29 +08:00
|
|
|
bool evsel__is_hybrid(struct evsel *evsel);
|
2021-07-06 23:17:00 +08:00
|
|
|
struct evsel *evsel__leader(struct evsel *evsel);
|
|
|
|
bool evsel__has_leader(struct evsel *evsel, struct evsel *leader);
|
|
|
|
bool evsel__is_leader(struct evsel *evsel);
|
|
|
|
void evsel__set_leader(struct evsel *evsel, struct evsel *leader);
|
2011-01-04 02:39:04 +08:00
|
|
|
#endif /* __PERF_EVSEL_H */
|