perf tools: Don't set inherit bit for system wide evsel
v2 cover perf tools: Don't set inherit bit for system wide evsel
Previous version can be found from [1].
To make bpf_perf_event_output() and bpf_perf_event_read() easier to be used, these two patches set inherit to 0 for system wide evsels. After applying them, users are possible to pass system wide events to BPF programs in following command, and don't need to consider the setting of inherit:
# perf record -a -e evt=cycles -e ./test__map.c/maps.pmu_map.event=evt/ ...
Patch 1/2 set evsel->system_wide for system wide target. I have checked in current evlist.c and evsel.c. The only behavior change I found is in evlist.c:
/*
* The system_wide flag causes a selected event to be opened
* always without a pid. Consequently it will never get a
* POLLHUP, but it is used for tracking in combination with
* other events, so it should not need to be polled anyway.
* Therefore don't add it for polling.
*/
if (!evsel->system_wide &&
__perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
perf_evlist__mmap_put(evlist, idx);
return -1;
}With patch 1/2, __perf_evlist__add_pollfd() won't be called. From the comment I pasted this modification looks harmless.
[1] http://lkml.kernel.org/r/[email protected]
Wang Nan (2):
perf tools: Set evsel->system_wide field for global system wide
recording
perf tools: Don't set inherit bit for system wide evsel
tools/perf/util/evsel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.3.4
RFC PATCH v2 1/2 perf tools: Set evsel->system_wide field for global system wide recording
evsel->system_wide is introduced by commit bf8e8f4b832972c76d64ab2e2837 (perf evlist: Add 'system_wide' option), which is used for mixing evsels that aren't system-wide with ones that are [1]. However, for global system wide recording (perf record -a ...), evsel->system_wide is set to false, which is confusion.
This patch set evsel->system_wide to true if the target.system_wide is set, which makes evsel->system_wide a reliable way to describe whether itself is system_wide or not.
[1] http://lkml.kernel.org/r/[email protected]
--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
@@ -734,6 +734,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)int track = evsel->tracking;bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread; + evsel->system_wide = opts->target.system_wide; attr->sample_id_all = perf_missing_features.sample_id_all ?0 :1 ; attr->inherit = !opts->no_inherit;
Signature · 1 line
1.8.3.4
Adrian Hunter
reviewerRe: [RFC PATCH v2 1/2] perf tools: Set evsel->system_wide field for global system wide recording
Quoted 29 lines · Wang Nan
evsel->system_wideis introduced by commitbf8e8f4b832972c76d64ab2e2837(perf evlist: Add 'system_wide' option), which is used for mixing evsels that aren't system-wide with ones that are [1]. However, for global system wide recording (perf record -a ...),evsel->system_wideis set to false, which is confusion.This patch set
evsel->system_wideto true if the target.system_wide is set, which makesevsel->system_widea reliable way to describe whether itself issystem_wideor not.[1] http://lkml.kernel.org/r/[email protected]
Signed-off-by Wang Nan <[email protected]>Cc Adrian Hunter <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)tools/perf/util/evsel.c +0
-0
tools/perf/util/evsel.c void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) · line 737
Quoted 4 lines
tools/perf/util/evsel.c +1
-0@@ -734,6 +734,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)int track = evsel->tracking;bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread; + evsel->system_wide = opts->target.system_wide;
Well that breaks the way evsel->system_wide is used i.e. it is a parameter to the evsel and here you just overwrote it.
Quoted 4 lines
tools/perf/util/evsel.c +0
-0attr->sample_id_all = perf_missing_features.sample_id_all ?0 :1 ; attr->inherit = !opts->no_inherit;
Re: [RFC PATCH v2 1/2] perf tools: Set evsel->system_wide field for global system wide recording
Quoted 33 lines · Adrian Hunter
Quoted 32 lines · Wang Nan
evsel->system_wideis introduced by commitbf8e8f4b832972c76d64ab2e2837(perf evlist: Add 'system_wide' option), which is used for mixing evsels that aren't system-wide with ones that are [1]. However, for global system wide recording (perf record -a ...),evsel->system_wideis set to false, which is confusion.This patch set
evsel->system_wideto true if the target.system_wide is set, which makesevsel->system_widea reliable way to describe whether itself issystem_wideor not.[1] http://lkml.kernel.org/r/[email protected]
Signed-off-by Wang Nan <[email protected]>Cc Adrian Hunter <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)tools/perf/util/evsel.c +0
-0@@ -734,6 +734,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)int track = evsel->tracking;bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread;
Quoted 3 lines
tools/perf/util/evsel.c void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) · line 737
Quoted 1 line
tools/perf/util/evsel.c +1
-0+ evsel->system_wide = opts->target.system_wide;Well that breaks the way
evsel->system_wideis used i.e. it is a parameter to the evsel and here you just overwrote it.
Currently the only user of evsel->system_wide is IPT:
auxtrace_record__options -> intel_pt_recording_options
and it only set it to true.
So I think changing to this should make it safe:
evsel->system_wide = (evsel->system_wide || opt->target.system_wide);
Thought?
If we want to add further config terms we can put it to apply_config_terms(), where we can implement something like:
# perf record -e cycles/system-wide/ -e instruction/no-system-wide/ ...
But currently I don't have such requirement.
Thank you.
Adrian Hunter
reviewerRe: [RFC PATCH v2 1/2] perf tools: Set evsel->system_wide field for global system wide recording
Quoted 45 lines · Wangnan (F)
Quoted 25 lines · Adrian Hunter
Quoted 24 lines · Wang Nan
evsel->system_wideis introduced by commitbf8e8f4b832972c76d64ab2e2837(perf evlist: Add 'system_wide' option), which is used for mixing evsels that aren't system-wide with ones that are [1]. However, for global system wide recording (perf record -a ...),evsel->system_wideis set to false, which is confusion.This patch set
evsel->system_wideto true if the target.system_wide is set, which makesevsel->system_widea reliable way to describe whether itself issystem_wideor not.[1] http://lkml.kernel.org/r/[email protected]
Signed-off-by Wang Nan <[email protected]>Cc Adrian Hunter <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)Quoted 12 lines
tools/perf/util/evsel.c void perf_evsel__config(struct perf_evsel *evsel, · line 738
Quoted 10 lines
tools/perf/util/evsel.c +0
-0@@ -734,6 +734,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)int track = evsel->tracking;bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread; + evsel->system_wide = opts->target.system_wide;Well that breaks the way
evsel->system_wideis used i.e. it is a parameter to the evsel and here you just overwrote it.Currently the only user of
evsel->system_wideis IPT:
auxtrace_record__options->intel_pt_recording_options
Quoted 7 lines
and it only set it to true.
So I think changing to this should make it safe:
evsel->system_wide= (evsel->system_wide||opt->target.system_wide);Thought?
That would work although it looks like a kludge.
Have you looked at properly validating opts->no_inherit ?
Also, aren't you neglecting target->cpu_list ?
Quoted 11 lines
If we want to add further config terms we can put it to
apply_config_terms(), where we can implement something like:# perf record -e cycles/system-wide/ -e instruction/no-system-wide/ ...But currently I don't have such requirement.
Thank you.
Re: [RFC PATCH v2 1/2] perf tools: Set evsel->system_wide field for global system wide recording
Quoted 48 lines · Adrian Hunter
Quoted 47 lines · Wangnan (F)
Quoted 25 lines · Adrian Hunter
Quoted 24 lines · Wang Nan
evsel->system_wideis introduced by commitbf8e8f4b832972c76d64ab2e2837(perf evlist: Add 'system_wide' option), which is used for mixing evsels that aren't system-wide with ones that are [1]. However, for global system wide recording (perf record -a ...),evsel->system_wideis set to false, which is confusion.This patch set
evsel->system_wideto true if the target.system_wide is set, which makesevsel->system_widea reliable way to describe whether itself issystem_wideor not.[1] http://lkml.kernel.org/r/[email protected]
Signed-off-by Wang Nan <[email protected]>Cc Adrian Hunter <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Li Zefan <[email protected]>--- tools/perf/util/evsel.c | 1 + 1 file changed, 1 insertion(+)Quoted 12 lines
tools/perf/util/evsel.c void perf_evsel__config(struct perf_evsel *evsel, · line 738
Quoted 10 lines
tools/perf/util/evsel.c +0
-0@@ -734,6 +734,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)int track = evsel->tracking;bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread; + evsel->system_wide = opts->target.system_wide;Well that breaks the way
evsel->system_wideis used i.e. it is a parameter to the evsel and here you just overwrote it.Currently the only user of
evsel->system_wideis IPT:
auxtrace_record__options->intel_pt_recording_optionsand it only set it to true.
So I think changing to this should make it safe:
Quoted 8 lines
Quoted 3 lines
evsel->system_wide= (evsel->system_wide||opt->target.system_wide);Thought?
That would work although it looks like a kludge.
Have you looked at properly validating
opts->no_inherit?Also, aren't you neglecting
target->cpu_list?
I need this because Alexei's bpf_perf_event_output() helper needs perf side support, and it only accept no-inherit perf event. I have already made a patch[1] to support setting inherit bit per-event, so even without this and next patch I can continue my work on bpf output. I'd like to rethink this patch after I finish perf support for bpf output.
Thank you.
RFC PATCH v2 2/2 perf tools: Don't set inherit bit for system wide evsel
In reply to Wang NanInherit bit is useless for a system wide evsel [1]. Further kernel improvements are giving more constrain [2] on inherit events. This patch set inherit bit to 0 for system wide evsels to avoid potential constrains.
[1] http://lkml.kernel.org/r/[email protected]
[2] http://lkml.kernel.org/r/[email protected]
--- tools/perf/util/evsel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evsel.c +1 -1
@@ -736,7 +736,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) evsel->system_wide = opts->target.system_wide; attr->sample_id_all = perf_missing_features.sample_id_all ?0 :1 ; - attr->inherit = !opts->no_inherit; + attr->inherit = !opts->no_inherit && !evsel->system_wide;perf_evsel__set_sample_bit (evsel,IP );perf_evsel__set_sample_bit (evsel,TID );
Signature · 1 line
1.8.3.4