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 21:07:57 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2011-01-04 01:39:04 +07:00
|
|
|
#ifndef __PERF_EVSEL_H
|
|
|
|
#define __PERF_EVSEL_H 1
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2011-01-04 02:45:52 +07:00
|
|
|
#include <stdbool.h>
|
2019-08-22 02:39:29 +07:00
|
|
|
#include <sys/types.h>
|
2012-11-20 05:21:03 +07:00
|
|
|
#include <linux/perf_event.h>
|
2014-04-26 02:31:02 +07:00
|
|
|
#include <linux/types.h>
|
2019-07-21 18:24:22 +07:00
|
|
|
#include <internal/evsel.h>
|
2019-08-22 00:09:54 +07:00
|
|
|
#include <perf/evsel.h>
|
2019-01-28 06:06:16 +07:00
|
|
|
#include "symbol_conf.h"
|
2019-08-22 02:39:29 +07:00
|
|
|
#include <internal/cpumap.h>
|
2011-01-04 01:39:04 +07:00
|
|
|
|
2019-09-25 01:41:51 +07:00
|
|
|
struct bpf_object;
|
|
|
|
struct cgroup;
|
|
|
|
struct perf_counts;
|
2017-10-27 00:22:34 +07:00
|
|
|
struct perf_stat_evsel;
|
2019-09-25 01:41:51 +07:00
|
|
|
union perf_event;
|
2017-10-27 00:22:34 +07:00
|
|
|
|
2019-03-12 12:30:50 +07:00
|
|
|
typedef int (perf_evsel__sb_cb_t)(union perf_event *event, void *data);
|
|
|
|
|
2019-03-27 05:18:21 +07:00
|
|
|
enum perf_tool_event {
|
|
|
|
PERF_TOOL_NONE = 0,
|
|
|
|
PERF_TOOL_DURATION_TIME = 1,
|
|
|
|
};
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
/** struct evsel - event selector
|
2011-02-16 20:10:01 +07:00
|
|
|
*
|
2015-08-27 19:07:40 +07:00
|
|
|
* @evlist - evlist this evsel is in, if it is in one.
|
2019-07-21 18:24:22 +07:00
|
|
|
* @core - libperf evsel object
|
2011-02-16 20:10:01 +07: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 15:23:09 +07: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 05:02:31 +07:00
|
|
|
* struct perf_record_sample
|
2013-08-27 15:23:09 +07: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 17:45:13 +07:00
|
|
|
* @priv: And what is in its containing unnamed union are tool specific
|
2011-02-16 20:10:01 +07:00
|
|
|
*/
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel {
|
2019-07-21 18:24:22 +07:00
|
|
|
struct perf_evsel core;
|
2019-07-21 18:23:52 +07:00
|
|
|
struct evlist *evlist;
|
2011-01-04 01:39:04 +07:00
|
|
|
char *filter;
|
2011-01-04 02:45:52 +07:00
|
|
|
struct perf_counts *counts;
|
2013-01-29 18:47:43 +07:00
|
|
|
struct perf_counts *prev_raw_counts;
|
2011-01-04 01:39:04 +07:00
|
|
|
int idx;
|
perf evsel: Introduce per event max_events property
This simply adds the field to 'struct perf_evsel' and allows setting
it via the event parser, to test it lets trace trace:
First look at where in a function that receives an evsel we can put a probe
to read how evsel->max_events was setup:
# perf probe -x ~/bin/perf -L trace__event_handler
<trace__event_handler@/home/acme/git/perf/tools/perf/builtin-trace.c:0>
0 static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel,
union perf_event *event __maybe_unused,
struct perf_sample *sample)
3 {
4 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
5 int callchain_ret = 0;
7 if (sample->callchain) {
8 callchain_ret = trace__resolve_callchain(trace, evsel, sample, &callchain_cursor);
9 if (callchain_ret == 0) {
10 if (callchain_cursor.nr < trace->min_stack)
11 goto out;
12 callchain_ret = 1;
}
}
See what variables we can probe at line 7:
# perf probe -x ~/bin/perf -V trace__event_handler:7
Available variables at trace__event_handler:7
@<trace__event_handler+89>
int callchain_ret
struct perf_evsel* evsel
struct perf_sample* sample
struct thread* thread
struct trace* trace
union perf_event* event
Add a probe at that line asking for evsel->max_events to be collected and named
as "max_events":
# perf probe -x ~/bin/perf trace__event_handler:7 'max_events=evsel->max_events'
Added new event:
probe_perf:trace__event_handler (on trace__event_handler:7 in /home/acme/bin/perf with max_events=evsel->max_events)
You can now use it in all perf tools, such as:
perf record -e probe_perf:trace__event_handler -aR sleep 1
Now use 'perf trace', here aliased to just 'trace' and trace trace, i.e.
the first 'trace' is tracing just that 'probe_perf:trace__event_handler' event,
while the traced trace is tracing all scheduler tracepoints, will stop at two
events (--max-events 2) and will just set evsel->max_events for all the sched
tracepoints to 9, we will see the output of both traces intermixed:
# trace -e *perf:*event_handler trace --max-events 2 -e sched:*/nr=9/
0.000 :0/0 sched:sched_waking:comm=rcu_sched pid=10 prio=120 target_cpu=000
0.009 :0/0 sched:sched_wakeup:comm=rcu_sched pid=10 prio=120 target_cpu=000
0.000 trace/23949 probe_perf:trace__event_handler:(48c34a) max_events=0x9
0.046 trace/23949 probe_perf:trace__event_handler:(48c34a) max_events=0x9
#
Now, if the traced trace sends its output to /dev/null, we'll see just
what the first level trace outputs: that evsel->max_events is indeed
being set to 9:
# trace -e *perf:*event_handler trace -o /dev/null --max-events 2 -e sched:*/nr=9/
0.000 trace/23961 probe_perf:trace__event_handler:(48c34a) max_events=0x9
0.030 trace/23961 probe_perf:trace__event_handler:(48c34a) max_events=0x9
#
Now that we can set evsel->max_events, we can go to the next step, honour that
per-event property in 'perf trace'.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-og00yasj276joem6e14l1eas@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-10-20 01:47:34 +07:00
|
|
|
unsigned long max_events;
|
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 00:14:16 +07:00
|
|
|
unsigned long nr_events_printed;
|
2011-02-16 20:10:01 +07:00
|
|
|
char *name;
|
2013-11-12 23:58:49 +07:00
|
|
|
double scale;
|
|
|
|
const char *unit;
|
2018-11-30 22:44:07 +07:00
|
|
|
struct tep_event *tp_format;
|
2015-10-25 21:51:44 +07:00
|
|
|
off_t id_offset;
|
2017-10-27 00:22:34 +07:00
|
|
|
struct perf_stat_evsel *stats;
|
2016-03-09 12:11:54 +07:00
|
|
|
void *priv;
|
|
|
|
u64 db_id;
|
2018-03-06 19:51:48 +07:00
|
|
|
struct cgroup *cgrp;
|
2013-11-06 20:17:38 +07:00
|
|
|
void *handler;
|
2012-08-02 04:53:11 +07:00
|
|
|
unsigned int sample_size;
|
2013-08-27 15:23:09 +07:00
|
|
|
int id_pos;
|
|
|
|
int is_pos;
|
2019-03-27 05:18:21 +07:00
|
|
|
enum perf_tool_event tool_event;
|
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 01:20:14 +07:00
|
|
|
bool uniquified_name;
|
perf tools: Elliminate alignment holes
perf_evsel:
Before:
/* size: 320, cachelines: 5, members: 35 */
/* sum members: 304, holes: 3, sum holes: 16 */
After:
/* size: 304, cachelines: 5, members: 35 */
/* last cacheline: 48 bytes */
perf_evlist:
Before:
/* size: 2544, cachelines: 40, members: 17 */
/* sum members: 2533, holes: 2, sum holes: 11 */
/* last cacheline: 48 bytes */
After:
/* size: 2536, cachelines: 40, members: 17 */
/* sum members: 2533, holes: 1, sum holes: 3 */
/* last cacheline: 40 bytes */
timechart:
Before:
/* size: 288, cachelines: 5, members: 21 */
/* sum members: 271, holes: 2, sum holes: 10 */
/* padding: 7 */
/* last cacheline: 32 bytes */
After:
/* size: 272, cachelines: 5, members: 21 */
/* sum members: 271, holes: 1, sum holes: 1 */
/* last cacheline: 16 bytes */
thread:
Before:
/* size: 112, cachelines: 2, members: 15 */
/* sum members: 101, holes: 2, sum holes: 11 */
/* last cacheline: 48 bytes */
After:
/* size: 104, cachelines: 2, members: 15 */
/* sum members: 101, holes: 1, sum holes: 3 */
/* last cacheline: 40 bytes */
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-a543w7zjl9yyrg9nkf1teukp@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-05-16 03:29:56 +07:00
|
|
|
bool snapshot;
|
2011-05-30 21:55:59 +07:00
|
|
|
bool supported;
|
2012-09-26 22:48:18 +07:00
|
|
|
bool needs_swap;
|
2018-10-20 19:04:41 +07:00
|
|
|
bool disabled;
|
2014-07-14 17:02:56 +07:00
|
|
|
bool no_aux_samples;
|
2014-07-14 17:02:57 +07:00
|
|
|
bool immediate;
|
2014-07-31 13:00:52 +07:00
|
|
|
bool tracking;
|
2014-11-21 16:31:12 +07:00
|
|
|
bool per_pkg;
|
perf tools: Introduce 'P' modifier to request max precision
The 'P' will cause the event to get maximum possible detected precise
level.
Following record:
$ perf record -e cycles:P ...
will detect maximum precise level for 'cycles' event and use it.
Commiter note:
Testing it:
$ perf record -e cycles:P usleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.013 MB perf.data (9 samples) ]
$ perf evlist
cycles:P
$ perf evlist -v
cycles:P: 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, precise_ip: 2, sample_id_all: 1, mmap2: 1,
comm_exec: 1
$
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1444068369-20978-6-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-10-06 01:06:05 +07:00
|
|
|
bool precise_max;
|
2016-12-13 14:46:22 +07:00
|
|
|
bool ignore_missing_thread;
|
2018-03-07 22:50:02 +07:00
|
|
|
bool forced_leader;
|
perf parse-events: Handle uncore event aliases in small groups properly
Perf stat doesn't count the uncore event aliases from the same uncore
block in a group, for example:
perf stat -e '{unc_m_cas_count.all,unc_m_clockticks}' -a -I 1000
# time counts unit events
1.000447342 <not counted> unc_m_cas_count.all
1.000447342 <not counted> unc_m_clockticks
2.000740654 <not counted> unc_m_cas_count.all
2.000740654 <not counted> unc_m_clockticks
The output is very misleading. It gives a wrong impression that the
uncore event doesn't work.
An uncore block could be composed by several PMUs. An uncore event alias
is a joint name which means the same event runs on all PMUs of a block.
Perf doesn't support mixed events from different PMUs in the same group.
It is wrong to put uncore event aliases in a big group.
The right way is to split the big group into multiple small groups which
only include the events from the same PMU.
Only uncore event aliases from the same uncore block should be specially
handled here. It doesn't make sense to mix the uncore events with other
uncore events from different blocks or even core events in a group.
With the patch:
# time counts unit events
1.001557653 140,833 unc_m_cas_count.all
1.001557653 1,330,231,332 unc_m_clockticks
2.002709483 85,007 unc_m_cas_count.all
2.002709483 1,429,494,563 unc_m_clockticks
Reported-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Agustin Vega-Frias <agustinv@codeaurora.org>
Cc: Ganapatrao Kulkarni <ganapatrao.kulkarni@cavium.com>
Cc: Jin Yao <yao.jin@linux.intel.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>
Link: http://lkml.kernel.org/r/1525727623-19768-1-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2018-05-08 04:13:43 +07:00
|
|
|
bool use_uncore_alias;
|
2012-08-08 17:21:54 +07:00
|
|
|
/* parse modifier helper */
|
|
|
|
int exclude_GH;
|
2012-10-10 22:39:03 +07:00
|
|
|
int sample_read;
|
perf tools: Elliminate alignment holes
perf_evsel:
Before:
/* size: 320, cachelines: 5, members: 35 */
/* sum members: 304, holes: 3, sum holes: 16 */
After:
/* size: 304, cachelines: 5, members: 35 */
/* last cacheline: 48 bytes */
perf_evlist:
Before:
/* size: 2544, cachelines: 40, members: 17 */
/* sum members: 2533, holes: 2, sum holes: 11 */
/* last cacheline: 48 bytes */
After:
/* size: 2536, cachelines: 40, members: 17 */
/* sum members: 2533, holes: 1, sum holes: 3 */
/* last cacheline: 40 bytes */
timechart:
Before:
/* size: 288, cachelines: 5, members: 21 */
/* sum members: 271, holes: 2, sum holes: 10 */
/* padding: 7 */
/* last cacheline: 32 bytes */
After:
/* size: 272, cachelines: 5, members: 21 */
/* sum members: 271, holes: 1, sum holes: 1 */
/* last cacheline: 16 bytes */
thread:
Before:
/* size: 112, cachelines: 2, members: 15 */
/* sum members: 101, holes: 2, sum holes: 11 */
/* last cacheline: 48 bytes */
After:
/* size: 104, cachelines: 2, members: 15 */
/* sum members: 101, holes: 1, sum holes: 3 */
/* last cacheline: 40 bytes */
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-a543w7zjl9yyrg9nkf1teukp@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-05-16 03:29:56 +07:00
|
|
|
unsigned long *per_pkg_mask;
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel *leader;
|
perf tools: Enable grouping logic for parsed events
This patch adds a functionality that allows to create event groups
based on the way they are specified on the command line. Adding
functionality to the '{}' group syntax introduced in earlier patch.
The current '--group/-g' option behaviour remains intact. If you
specify it for record/stat/top command, all the specified events
become members of a single group with the first event as a group
leader.
With the new '{}' group syntax you can create group like:
# perf record -e '{cycles,faults}' ls
resulting in single event group containing 'cycles' and 'faults'
events, with cycles event as group leader.
All groups are created with regards to threads and cpus. Thus
recording an event group within a 2 threads on server with
4 CPUs will create 8 separate groups.
Examples (first event in brackets is group leader):
# 1 group (cpu-clock,task-clock)
perf record --group -e cpu-clock,task-clock ls
perf record -e '{cpu-clock,task-clock}' ls
# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
perf record -e '{cpu-clock,task-clock},{minor-faults,major-faults}' ls
# 1 group (cpu-clock,task-clock,minor-faults,major-faults)
perf record --group -e cpu-clock,task-clock -e minor-faults,major-faults ls
perf record -e '{cpu-clock,task-clock,minor-faults,major-faults}' ls
# 2 groups (cpu-clock,task-clock) (minor-faults,major-faults)
perf record -e '{cpu-clock,task-clock} -e '{minor-faults,major-faults}' \
-e instructions ls
# 1 group
# (cpu-clock,task-clock,minor-faults,major-faults,instructions)
perf record --group -e cpu-clock,task-clock \
-e minor-faults,major-faults -e instructions ls perf record -e
'{cpu-clock,task-clock,minor-faults,major-faults,instructions}' ls
It's possible to use standard event modifier for a group, which spans
over all events in the group and updates each event modifier settings,
for example:
# perf record -r '{faults:k,cache-references}:p'
resulting in ':kp' modifier being used for 'faults' and ':p' modifier
being used for 'cache-references' event.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ulrich Drepper <drepper@gmail.com>
Link: http://lkml.kernel.org/n/tip-ho42u0wcr8mn1otkalqi13qp@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-08 17:22:36 +07:00
|
|
|
char *group_name;
|
2015-07-10 14:36:09 +07:00
|
|
|
bool cmdline_group_boundary;
|
2015-07-29 16:42:10 +07:00
|
|
|
struct list_head config_terms;
|
2019-07-16 02:22:57 +07:00
|
|
|
struct bpf_object *bpf_obj;
|
perf bpf: Attach eBPF filter to perf event
This is the final patch which makes basic BPF filter work. After
applying this patch, users are allowed to use BPF filter like:
# perf record --event ./hello_world.o ls
A bpf_fd field is appended to 'struct evsel', and setup during the
callback function add_bpf_event() for each 'probe_trace_event'.
PERF_EVENT_IOC_SET_BPF ioctl is used to attach eBPF program to a newly
created perf event. The file descriptor of the eBPF program is passed to
perf record using previous patches, and stored into evsel->bpf_fd.
It is possible that different perf event are created for one kprobe
events for different CPUs. In this case, when trying to call the ioctl,
EEXIST will be return. This patch doesn't treat it as an error.
Committer note:
The bpf proggie used so far:
__attribute__((section("fork=_do_fork"), used))
int fork(void *ctx)
{
return 0;
}
char _license[] __attribute__((section("license"), used)) = "GPL";
int _version __attribute__((section("version"), used)) = 0x40300;
failed to produce any samples, even with forks happening and it being
running in system wide mode.
That is because now the filter is being associated, and the code above
always returns zero, meaning that all forks will be probed but filtered
away ;-/
Change it to 'return 1;' instead and after that:
# trace --no-syscalls --event /tmp/foo.o
0.000 perf_bpf_probe:fork:(ffffffff8109be30))
2.333 perf_bpf_probe:fork:(ffffffff8109be30))
3.725 perf_bpf_probe:fork:(ffffffff8109be30))
4.550 perf_bpf_probe:fork:(ffffffff8109be30))
^C#
And it works with all tools, including 'perf trace'.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1444826502-49291-8-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-10-14 19:41:18 +07:00
|
|
|
int bpf_fd;
|
2019-11-21 07:15:20 +07:00
|
|
|
int err;
|
perf stat: Only auto-merge events that are PMU aliases
Peter reported that when he explicitely asked for multiple events with
the same name on the command line it got coalesced into just one line,
i.e.:
# perf stat -e cycles -e cycles -e cycles usleep 1
Performance counter stats for 'usleep 1':
3,269,652 cycles
0.000884123 seconds time elapsed
#
And while there is the --no-merges option to disable that auto-merging,
this is a blunt change in behaviour for such explicit request, so change
the code so that this auto merging is done only when handling the multi
PMU aliases with the same name that introduced this coalescing,
restoring the previous behaviour for the explicit case:
# perf stat -e cycles -e cycles -e cycles usleep 1
Performance counter stats for 'usleep 1':
1,472,837 cycles
1,472,837 cycles
1,472,837 cycles
0.001764870 seconds time elapsed
#
Reported-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Fixes: 430daf2dc7af ("perf stat: Collapse identically named events")
Link: http://lkml.kernel.org/r/20170831184122.GK4831@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-09-01 01:32:18 +07:00
|
|
|
bool auto_merge_stats;
|
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 03:17:00 +07:00
|
|
|
bool merged_stat;
|
perf stat: Output JSON MetricExpr metric
Add generic infrastructure to perf stat to output ratios for
"MetricExpr" entries in the event lists. Many events are more useful as
ratios than in raw form, typically some count in relation to total
ticks.
Transfer the MetricExpr information from the alias to the evsel.
We mark the events that need to be collected for MetricExpr, and also
link the events using them with a pointer. The code is careful to always
prefer the right event in the same group to minimize multiplexing
errors. At the moment only a single relation is supported.
Then add a rblist to the stat shadow code that remembers stats based on
the cpu and context.
Then finally update and retrieve and print these values similarly to the
existing hardcoded perf metrics. We use the simple expression parser
added earlier to evaluate the expression.
Normally we just output the result without further commentary, but for
--metric-only this would lead to empty columns. So for this case use the
original event as description.
There is no attempt to automatically add the MetricExpr event, if it is
missing, however we suggest it to the user, because the user tool
doesn't have enough information to reliably construct a group that is
guaranteed to schedule. So we leave that to the user.
% perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}'
1.000147889 800,085,181 unc_p_clockticks
1.000147889 93,126,241 unc_p_freq_max_os_cycles # 11.6
2.000448381 800,218,217 unc_p_clockticks
2.000448381 142,516,095 unc_p_freq_max_os_cycles # 17.8
3.000639852 800,243,057 unc_p_clockticks
3.000639852 162,292,689 unc_p_freq_max_os_cycles # 20.3
% perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}' --metric-only
# time freq_max_os_cycles %
1.000127077 0.9
2.000301436 0.7
3.000456379 0.0
v2: Change from DivideBy to MetricExpr
v3: Use expr__ prefix. Support more than one other event.
v4: Update description
v5: Only print warning message once for multiple PMUs.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-11-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-03-21 03:17:08 +07:00
|
|
|
const char * metric_expr;
|
2017-03-21 03:17:10 +07:00
|
|
|
const char * metric_name;
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel **metric_events;
|
2019-08-28 12:59:32 +07:00
|
|
|
struct evsel *metric_leader;
|
perf stat: Output JSON MetricExpr metric
Add generic infrastructure to perf stat to output ratios for
"MetricExpr" entries in the event lists. Many events are more useful as
ratios than in raw form, typically some count in relation to total
ticks.
Transfer the MetricExpr information from the alias to the evsel.
We mark the events that need to be collected for MetricExpr, and also
link the events using them with a pointer. The code is careful to always
prefer the right event in the same group to minimize multiplexing
errors. At the moment only a single relation is supported.
Then add a rblist to the stat shadow code that remembers stats based on
the cpu and context.
Then finally update and retrieve and print these values similarly to the
existing hardcoded perf metrics. We use the simple expression parser
added earlier to evaluate the expression.
Normally we just output the result without further commentary, but for
--metric-only this would lead to empty columns. So for this case use the
original event as description.
There is no attempt to automatically add the MetricExpr event, if it is
missing, however we suggest it to the user, because the user tool
doesn't have enough information to reliably construct a group that is
guaranteed to schedule. So we leave that to the user.
% perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}'
1.000147889 800,085,181 unc_p_clockticks
1.000147889 93,126,241 unc_p_freq_max_os_cycles # 11.6
2.000448381 800,218,217 unc_p_clockticks
2.000448381 142,516,095 unc_p_freq_max_os_cycles # 17.8
3.000639852 800,243,057 unc_p_clockticks
3.000639852 162,292,689 unc_p_freq_max_os_cycles # 20.3
% perf stat -a -I 1000 -e '{unc_p_clockticks,unc_p_freq_max_os_cycles}' --metric-only
# time freq_max_os_cycles %
1.000127077 0.9
2.000301436 0.7
3.000456379 0.0
v2: Change from DivideBy to MetricExpr
v3: Use expr__ prefix. Support more than one other event.
v4: Update description
v5: Only print warning message once for multiple PMUs.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170320201711.14142-11-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-03-21 03:17:08 +07:00
|
|
|
bool collect_stat;
|
perf tools: Support weak groups in 'perf stat'
Setting up groups can be complicated due to the complicated scheduling
restrictions of different PMUs.
User tools usually don't understand all these restrictions.
Still in many cases it is useful to set up groups and they work most of
the time. However if the group is set up wrong some members will not
report any value because they never get scheduled.
Add a concept of a 'weak group': try to set up a group, but if it's not
schedulable fallback to not using a group. That gives us the best of
both worlds: groups if they work, but still a usable fallback if they
don't.
In theory it would be possible to have more complex fallback strategies
(e.g. try to split the group in half), but the simple fallback of not
using a group seems to work for now.
So far the weak group is only implemented for perf stat, not for record.
Here's an unschedulable group (on IvyBridge with SMT on)
% perf stat -e '{branches,branch-misses,l1d.replacement,l2_lines_in.all,l2_rqsts.all_code_rd}' -a sleep 1
73,806,067 branches
4,848,144 branch-misses # 6.57% of all branches
14,754,458 l1d.replacement
24,905,558 l2_lines_in.all
<not supported> l2_rqsts.all_code_rd <------- will never report anything
With the weak group:
% perf stat -e '{branches,branch-misses,l1d.replacement,l2_lines_in.all,l2_rqsts.all_code_rd}:W' -a sleep 1
125,366,055 branches (80.02%)
9,208,402 branch-misses # 7.35% of all branches (80.01%)
24,560,249 l1d.replacement (80.00%)
43,174,971 l2_lines_in.all (80.05%)
31,891,457 l2_rqsts.all_code_rd (79.92%)
The extra event scheduled with some extra multiplexing
v2: Move fallback code to separate function.
Add comment on for_each_group_member
Adjust to new perf_evsel__close interface
v3: Fix debug print out.
Committer testing:
Before:
# perf stat -e '{branches,branch-misses,l1d.replacement,l2_lines_in.all,l2_rqsts.all_code_rd}' -a sleep 1
Performance counter stats for 'system wide':
<not counted> branches
<not counted> branch-misses
<not counted> l1d.replacement
<not counted> l2_lines_in.all
<not supported> l2_rqsts.all_code_rd
1.002147212 seconds time elapsed
# perf stat -e '{branches,l1d.replacement,l2_lines_in.all,l2_rqsts.all_code_rd}' -a sleep 1
Performance counter stats for 'system wide':
83,207,892 branches
11,065,444 l1d.replacement
28,484,024 l2_lines_in.all
12,186,179 l2_rqsts.all_code_rd
1.001739493 seconds time elapsed
After:
# perf stat -e '{branches,branch-misses,l1d.replacement,l2_lines_in.all,l2_rqsts.all_code_rd}':W -a sleep 1
Performance counter stats for 'system wide':
543,323,909 branches (80.01%)
27,100,512 branch-misses # 4.99% of all branches (80.02%)
50,402,905 l1d.replacement (80.03%)
67,385,892 l2_lines_in.all (80.01%)
21,352,885 l2_rqsts.all_code_rd (79.94%)
1.001086658 seconds time elapsed
#
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: http://lkml.kernel.org/r/20170831194036.30146-2-andi@firstfloor.org
[ Add a "'perf stat' only, for now" comment in the man page, suggested by Jiri ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-09-01 02:40:26 +07:00
|
|
|
bool weak_group;
|
2019-11-21 07:15:19 +07:00
|
|
|
bool reset_group;
|
|
|
|
bool errored;
|
2019-04-12 20:59:47 +07:00
|
|
|
bool percore;
|
2019-11-21 07:15:15 +07:00
|
|
|
int cpu_iter;
|
2018-03-06 21:04:43 +07:00
|
|
|
const char *pmu_name;
|
2019-03-12 12:30:50 +07:00
|
|
|
struct {
|
|
|
|
perf_evsel__sb_cb_t *cb;
|
|
|
|
void *data;
|
|
|
|
} side_band;
|
2011-01-04 01:39:04 +07:00
|
|
|
};
|
|
|
|
|
2018-02-02 21:27:25 +07: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-17 23:15:17 +07:00
|
|
|
bool ksymbol;
|
2019-08-27 05:31:06 +07:00
|
|
|
bool bpf;
|
2019-08-13 21:06:38 +07: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-28 23:30:01 +07:00
|
|
|
bool branch_hw_idx;
|
2020-03-25 19:45:34 +07:00
|
|
|
bool cgroup;
|
2018-02-02 21:27:25 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct perf_missing_features perf_missing_features;
|
|
|
|
|
2019-07-21 18:23:49 +07:00
|
|
|
struct perf_cpu_map;
|
2014-10-13 20:29:50 +07:00
|
|
|
struct target;
|
2011-01-04 08:09:46 +07:00
|
|
|
struct thread_map;
|
2013-12-20 00:43:45 +07:00
|
|
|
struct record_opts;
|
2011-01-04 08:09:46 +07:00
|
|
|
|
2019-07-21 18:24:05 +07:00
|
|
|
static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel)
|
2015-06-23 05:36:08 +07:00
|
|
|
{
|
2019-07-21 18:24:54 +07:00
|
|
|
return perf_evsel__cpus(&evsel->core);
|
2015-06-23 05:36:08 +07:00
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline int perf_evsel__nr_cpus(struct evsel *evsel)
|
2015-06-23 05:36:08 +07:00
|
|
|
{
|
2019-07-21 18:24:05 +07:00
|
|
|
return evsel__cpus(evsel)->nr;
|
2015-06-23 05:36:08 +07:00
|
|
|
}
|
|
|
|
|
2014-11-21 16:31:06 +07:00
|
|
|
void perf_counts_values__scale(struct perf_counts_values *count,
|
|
|
|
bool scale, s8 *pscaled);
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
void perf_evsel__compute_deltas(struct evsel *evsel, int cpu, int thread,
|
2014-11-21 16:31:05 +07:00
|
|
|
struct perf_counts_values *count);
|
|
|
|
|
2014-10-10 01:29:51 +07:00
|
|
|
int perf_evsel__object_config(size_t object_size,
|
2019-07-21 18:23:51 +07:00
|
|
|
int (*init)(struct evsel *evsel),
|
|
|
|
void (*fini)(struct evsel *evsel));
|
2014-10-10 01:29:51 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
|
2013-11-08 02:41:19 +07:00
|
|
|
|
2019-07-21 18:23:58 +07:00
|
|
|
static inline struct evsel *evsel__new(struct perf_event_attr *attr)
|
2013-11-08 02:41:19 +07:00
|
|
|
{
|
|
|
|
return perf_evsel__new_idx(attr, 0);
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
|
2013-11-08 02:41:19 +07:00
|
|
|
|
2015-09-07 15:38:06 +07:00
|
|
|
/*
|
|
|
|
* Returns pointer with encoded error via <linux/err.h> interface.
|
|
|
|
*/
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline struct evsel *perf_evsel__newtp(const char *sys, const char *name)
|
2013-11-08 02:41:19 +07:00
|
|
|
{
|
|
|
|
return perf_evsel__newtp_idx(sys, name, 0);
|
|
|
|
}
|
2012-09-27 06:24:19 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
struct evsel *perf_evsel__new_cycles(bool precise);
|
2016-07-29 04:33:20 +07:00
|
|
|
|
2018-11-30 22:44:07 +07:00
|
|
|
struct tep_event *event_format__new(const char *sys, const char *name);
|
2012-09-27 06:24:19 +07:00
|
|
|
|
2019-07-21 18:23:53 +07:00
|
|
|
void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int idx);
|
2019-07-21 18:23:51 +07:00
|
|
|
void perf_evsel__exit(struct evsel *evsel);
|
2019-07-21 18:23:57 +07:00
|
|
|
void evsel__delete(struct evsel *evsel);
|
2011-01-04 01:39:04 +07:00
|
|
|
|
2016-04-12 04:15:29 +07:00
|
|
|
struct callchain_param;
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
void perf_evsel__config(struct evsel *evsel,
|
2016-04-12 04:15:29 +07:00
|
|
|
struct record_opts *opts,
|
|
|
|
struct callchain_param *callchain);
|
2019-07-21 18:23:51 +07:00
|
|
|
void perf_evsel__config_callchain(struct evsel *evsel,
|
2016-04-12 04:39:37 +07:00
|
|
|
struct record_opts *opts,
|
|
|
|
struct callchain_param *callchain);
|
2011-11-08 23:41:57 +07:00
|
|
|
|
2013-08-27 15:23:09 +07:00
|
|
|
int __perf_evsel__sample_size(u64 sample_type);
|
2019-07-21 18:23:51 +07:00
|
|
|
void perf_evsel__calc_id_pos(struct evsel *evsel);
|
2013-08-27 15:23:09 +07:00
|
|
|
|
2012-06-12 00:08:07 +07:00
|
|
|
bool perf_evsel__is_cache_op_valid(u8 type, u8 op);
|
|
|
|
|
|
|
|
#define PERF_EVSEL__MAX_ALIASES 8
|
|
|
|
|
|
|
|
extern const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX]
|
|
|
|
[PERF_EVSEL__MAX_ALIASES];
|
|
|
|
extern const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX]
|
|
|
|
[PERF_EVSEL__MAX_ALIASES];
|
2012-09-06 23:11:18 +07:00
|
|
|
extern const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX]
|
|
|
|
[PERF_EVSEL__MAX_ALIASES];
|
|
|
|
extern const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX];
|
|
|
|
extern const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX];
|
2012-06-12 00:08:07 +07:00
|
|
|
int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result,
|
|
|
|
char *bf, size_t size);
|
2019-07-21 18:23:51 +07:00
|
|
|
const char *perf_evsel__name(struct evsel *evsel);
|
2013-11-12 23:58:49 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
const char *perf_evsel__group_name(struct evsel *evsel);
|
|
|
|
int perf_evsel__group_desc(struct evsel *evsel, char *buf, size_t size);
|
2012-05-26 02:38:11 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
void __perf_evsel__set_sample_bit(struct evsel *evsel,
|
2012-12-11 00:53:43 +07:00
|
|
|
enum perf_event_sample_format bit);
|
2019-07-21 18:23:51 +07:00
|
|
|
void __perf_evsel__reset_sample_bit(struct evsel *evsel,
|
2012-12-11 00:53:43 +07:00
|
|
|
enum perf_event_sample_format bit);
|
|
|
|
|
|
|
|
#define perf_evsel__set_sample_bit(evsel, bit) \
|
|
|
|
__perf_evsel__set_sample_bit(evsel, PERF_SAMPLE_##bit)
|
|
|
|
|
|
|
|
#define perf_evsel__reset_sample_bit(evsel, bit) \
|
|
|
|
__perf_evsel__reset_sample_bit(evsel, PERF_SAMPLE_##bit)
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
void perf_evsel__set_sample_id(struct evsel *evsel,
|
2013-08-27 15:23:09 +07:00
|
|
|
bool use_sample_identifier);
|
2012-12-11 01:21:30 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
int perf_evsel__set_filter(struct evsel *evsel, const char *filter);
|
|
|
|
int perf_evsel__append_tp_filter(struct evsel *evsel, const char *filter);
|
|
|
|
int perf_evsel__append_addr_filter(struct evsel *evsel,
|
2016-09-16 21:44:05 +07:00
|
|
|
const char *filter);
|
2019-11-21 07:15:21 +07:00
|
|
|
int evsel__enable_cpu(struct evsel *evsel, int cpu);
|
2019-07-21 18:24:02 +07:00
|
|
|
int evsel__enable(struct evsel *evsel);
|
2019-07-21 18:24:03 +07:00
|
|
|
int evsel__disable(struct evsel *evsel);
|
2019-11-21 07:15:21 +07:00
|
|
|
int evsel__disable_cpu(struct evsel *evsel, int cpu);
|
2012-09-27 01:07:39 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
int perf_evsel__open_per_cpu(struct evsel *evsel,
|
2019-11-21 07:15:19 +07:00
|
|
|
struct perf_cpu_map *cpus,
|
|
|
|
int cpu);
|
2019-07-21 18:23:51 +07:00
|
|
|
int perf_evsel__open_per_thread(struct evsel *evsel,
|
2019-07-21 18:23:50 +07:00
|
|
|
struct perf_thread_map *threads);
|
2019-07-21 18:24:01 +07:00
|
|
|
int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
|
|
|
|
struct perf_thread_map *threads);
|
2019-07-21 18:24:50 +07:00
|
|
|
void evsel__close(struct evsel *evsel);
|
2011-01-04 02:48:12 +07:00
|
|
|
|
2012-09-12 05:24:23 +07:00
|
|
|
struct perf_sample;
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
void *perf_evsel__rawptr(struct evsel *evsel, struct perf_sample *sample,
|
2012-09-12 05:24:23 +07:00
|
|
|
const char *name);
|
2019-07-21 18:23:51 +07:00
|
|
|
u64 perf_evsel__intval(struct evsel *evsel, struct perf_sample *sample,
|
2012-09-12 05:24:23 +07:00
|
|
|
const char *name);
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline char *perf_evsel__strval(struct evsel *evsel,
|
2012-09-27 06:22:00 +07:00
|
|
|
struct perf_sample *sample,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
return perf_evsel__rawptr(evsel, sample, name);
|
|
|
|
}
|
|
|
|
|
2018-09-20 01:56:45 +07:00
|
|
|
struct tep_format_field;
|
2012-09-18 21:21:50 +07:00
|
|
|
|
2018-09-20 01:56:45 +07:00
|
|
|
u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap);
|
2016-05-31 22:47:46 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
struct tep_format_field *perf_evsel__field(struct evsel *evsel, const char *name);
|
2012-09-18 21:21:50 +07:00
|
|
|
|
2011-01-04 01:49:44 +07:00
|
|
|
#define perf_evsel__match(evsel, t, c) \
|
2019-07-21 18:24:29 +07:00
|
|
|
(evsel->core.attr.type == PERF_TYPE_##t && \
|
|
|
|
evsel->core.attr.config == PERF_COUNT_##c)
|
2011-01-04 01:49:44 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline bool perf_evsel__match2(struct evsel *e1,
|
|
|
|
struct evsel *e2)
|
2012-09-06 22:46:55 +07:00
|
|
|
{
|
2019-07-21 18:24:29 +07:00
|
|
|
return (e1->core.attr.type == e2->core.attr.type) &&
|
|
|
|
(e1->core.attr.config == e2->core.attr.config);
|
2012-09-06 22:46:55 +07:00
|
|
|
}
|
|
|
|
|
2013-08-22 06:47:26 +07:00
|
|
|
#define perf_evsel__cmp(a, b) \
|
|
|
|
((a) && \
|
|
|
|
(b) && \
|
2019-07-21 18:24:29 +07:00
|
|
|
(a)->core.attr.type == (b)->core.attr.type && \
|
|
|
|
(a)->core.attr.config == (b)->core.attr.config)
|
2013-08-22 06:47:26 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
int perf_evsel__read_counter(struct evsel *evsel, int cpu, int thread);
|
2017-07-26 19:02:05 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
int __perf_evsel__read_on_cpu(struct evsel *evsel,
|
2011-01-04 02:45:52 +07:00
|
|
|
int cpu, int thread, bool scale);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* perf_evsel__read_on_cpu - Read out the results on a CPU and thread
|
|
|
|
*
|
|
|
|
* @evsel - event selector to read value
|
|
|
|
* @cpu - CPU of interest
|
|
|
|
* @thread - thread of interest
|
|
|
|
*/
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline int perf_evsel__read_on_cpu(struct evsel *evsel,
|
2011-01-04 02:45:52 +07:00
|
|
|
int cpu, int thread)
|
|
|
|
{
|
|
|
|
return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
|
|
|
|
*
|
|
|
|
* @evsel - event selector to read value
|
|
|
|
* @cpu - CPU of interest
|
|
|
|
* @thread - thread of interest
|
|
|
|
*/
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline int perf_evsel__read_on_cpu_scaled(struct evsel *evsel,
|
2011-01-04 02:45:52 +07:00
|
|
|
int cpu, int thread)
|
|
|
|
{
|
|
|
|
return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
int perf_evsel__parse_sample(struct evsel *evsel, union perf_event *event,
|
2012-09-26 22:48:18 +07:00
|
|
|
struct perf_sample *sample);
|
2012-08-15 02:42:15 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
int perf_evsel__parse_sample_timestamp(struct evsel *evsel,
|
2017-08-03 18:10:28 +07:00
|
|
|
union perf_event *event,
|
|
|
|
u64 *timestamp);
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline struct evsel *perf_evsel__next(struct evsel *evsel)
|
2012-08-15 02:42:15 +07:00
|
|
|
{
|
2019-07-21 18:24:22 +07:00
|
|
|
return list_entry(evsel->core.node.next, struct evsel, core.node);
|
2012-08-15 02:42:15 +07:00
|
|
|
}
|
2012-11-14 03:27:28 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline struct evsel *perf_evsel__prev(struct evsel *evsel)
|
2013-11-14 01:56:40 +07:00
|
|
|
{
|
2019-07-21 18:24:22 +07:00
|
|
|
return list_entry(evsel->core.node.prev, struct evsel, core.node);
|
2013-11-14 01:56:40 +07:00
|
|
|
}
|
|
|
|
|
2013-03-05 12:53:26 +07:00
|
|
|
/**
|
|
|
|
* perf_evsel__is_group_leader - Return whether given evsel is a leader event
|
|
|
|
*
|
|
|
|
* @evsel - evsel selector to be tested
|
|
|
|
*
|
|
|
|
* Return %true if @evsel is a group leader or a stand-alone event
|
|
|
|
*/
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline bool perf_evsel__is_group_leader(const struct evsel *evsel)
|
2012-11-14 03:27:28 +07:00
|
|
|
{
|
2012-11-29 13:38:30 +07:00
|
|
|
return evsel->leader == evsel;
|
2012-11-14 03:27:28 +07:00
|
|
|
}
|
2012-12-11 04:17:08 +07:00
|
|
|
|
2013-03-05 12:53:26 +07:00
|
|
|
/**
|
|
|
|
* perf_evsel__is_group_event - Return whether given evsel is a group event
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline bool perf_evsel__is_group_event(struct evsel *evsel)
|
2013-03-05 12:53:26 +07:00
|
|
|
{
|
|
|
|
if (!symbol_conf.event_group)
|
|
|
|
return false;
|
|
|
|
|
2019-07-21 18:24:46 +07:00
|
|
|
return perf_evsel__is_group_leader(evsel) && evsel->core.nr_members > 1;
|
2013-03-05 12:53:26 +07:00
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
bool perf_evsel__is_function_event(struct evsel *evsel);
|
2014-03-02 22:56:40 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline bool perf_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 16:10:37 +07:00
|
|
|
{
|
2018-07-20 18:00:33 +07:00
|
|
|
return perf_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 16:10:37 +07:00
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline bool perf_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 18:00:34 +07:00
|
|
|
{
|
|
|
|
return perf_evsel__match(evsel, SOFTWARE, SW_CPU_CLOCK) ||
|
|
|
|
perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK);
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
bool perf_evsel__fallback(struct evsel *evsel, int err,
|
2012-12-14 00:16:30 +07:00
|
|
|
char *msg, size_t msgsize);
|
2019-07-21 18:23:51 +07:00
|
|
|
int perf_evsel__open_strerror(struct evsel *evsel, struct target *target,
|
2012-12-14 01:10:58 +07:00
|
|
|
int err, char *msg, size_t size);
|
2013-01-22 16:09:29 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline int perf_evsel__group_idx(struct evsel *evsel)
|
2013-01-22 16:09:29 +07:00
|
|
|
{
|
|
|
|
return evsel->idx - evsel->leader->idx;
|
|
|
|
}
|
2013-01-22 16:09:44 +07:00
|
|
|
|
2018-08-04 20:05:08 +07:00
|
|
|
/* Iterates group WITHOUT the leader. */
|
2013-01-22 16:09:44 +07:00
|
|
|
#define for_each_group_member(_evsel, _leader) \
|
2019-07-21 18:24:22 +07:00
|
|
|
for ((_evsel) = list_entry((_leader)->core.node.next, struct evsel, core.node); \
|
2013-01-22 16:09:44 +07:00
|
|
|
(_evsel) && (_evsel)->leader == (_leader); \
|
2019-07-21 18:24:22 +07:00
|
|
|
(_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
|
2013-01-22 16:09:44 +07:00
|
|
|
|
2018-08-04 20:05:08 +07:00
|
|
|
/* Iterates group WITH the leader. */
|
|
|
|
#define for_each_group_evsel(_evsel, _leader) \
|
|
|
|
for ((_evsel) = _leader; \
|
|
|
|
(_evsel) && (_evsel)->leader == (_leader); \
|
2019-07-21 18:24:22 +07:00
|
|
|
(_evsel) = list_entry((_evsel)->core.node.next, struct evsel, core.node))
|
2018-08-04 20:05:08 +07:00
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline bool perf_evsel__has_branch_callstack(const struct evsel *evsel)
|
2015-01-06 01:23:05 +07:00
|
|
|
{
|
2019-07-21 18:24:29 +07:00
|
|
|
return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
|
2015-01-06 01:23:05 +07: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 16:09:54 +07:00
|
|
|
|
2020-02-28 23:30:00 +07:00
|
|
|
static inline bool perf_evsel__has_branch_hw_idx(const struct evsel *evsel)
|
|
|
|
{
|
|
|
|
return evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX;
|
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
static inline bool evsel__has_callchain(const struct evsel *evsel)
|
2018-05-29 02:00:29 +07:00
|
|
|
{
|
2019-07-21 18:24:29 +07:00
|
|
|
return (evsel->core.attr.sample_type & PERF_SAMPLE_CALLCHAIN) != 0;
|
2018-05-29 02:00:29 +07:00
|
|
|
}
|
|
|
|
|
2019-07-21 18:23:51 +07:00
|
|
|
struct perf_env *perf_evsel__env(struct evsel *evsel);
|
2016-06-30 13:14:19 +07:00
|
|
|
|
2019-07-21 18:23:52 +07:00
|
|
|
int perf_evsel__store_ids(struct evsel *evsel, struct evlist *evlist);
|
2011-01-04 01:39:04 +07:00
|
|
|
#endif /* __PERF_EVSEL_H */
|