From: Ben Gainey <Ben.Gainey@arm.com>
To: "namhyung@kernel.org" <namhyung@kernel.org>
Cc: "alexander.shishkin@linux.intel.com"
<alexander.shishkin@linux.intel.com>,
"peterz@infradead.org" <peterz@infradead.org>,
"acme@kernel.org" <acme@kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
James Clark <James.Clark@arm.com>,
"adrian.hunter@intel.com" <adrian.hunter@intel.com>,
"irogers@google.com" <irogers@google.com>,
"jolsa@kernel.org" <jolsa@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-perf-users@vger.kernel.org"
<linux-perf-users@vger.kernel.org>,
Mark Rutland <Mark.Rutland@arm.com>
Subject: Re: [PATCH v9 4/4] tools/perf: Allow inherit + PERF_SAMPLE_READ when opening events
Date: Thu, 1 Aug 2024 12:28:25 +0000 [thread overview]
Message-ID: <7b8da3f40cbc30a25fe5fa856627245dc2b6a991.camel@arm.com> (raw)
In-Reply-To: <Zqp_vqCn0FEfGFwX@google.com>
On Wed, 2024-07-31 at 11:17 -0700, Namhyung Kim wrote:
> Hello,
>
> On Tue, Jul 30, 2024 at 09:44:17AM +0100, Ben Gainey wrote:
> > The "perf record" tool will now default to this new mode if the
> > user
> > specifies a sampling group when not in system-wide mode, and when
> > "--no-inherit" is not specified.
> >
> > This change updates evsel to allow the combination of inherit
> > and PERF_SAMPLE_READ.
> >
> > A fallback is implemented for kernel versions where this feature is
> > not
> > supported.
> >
> > Signed-off-by: Ben Gainey <ben.gainey@arm.com>
> > ---
> >
snip
> > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> > index bc603193c477..ceb09b6a8c2f 100644
> > --- a/tools/perf/util/evsel.c
> > +++ b/tools/perf/util/evsel.c
> > @@ -1171,7 +1171,15 @@ void evsel__config(struct evsel *evsel,
> > struct record_opts *opts,
> > */
> > if (leader->core.nr_members > 1) {
> > attr->read_format |= PERF_FORMAT_GROUP;
> > - attr->inherit = 0;
> > + }
> > +
> > + /*
> > + * Inherit + SAMPLE_READ requires SAMPLE_TID in the read_format
> > + */
> > + if (attr->inherit) {
> > + evsel__set_sample_bit(evsel, TID);
> > + evsel->core.attr.read_format |=
> > + PERF_FORMAT_ID;
> > }
>
> Also I think we should reset the inherit bit for system-wide events.
>
> $ perf record -a --synth=no true
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.042 MB perf.data (51 samples) ]
>
> $ perf evlist -v | tr ',' '\n' | grep inherit
> inherit: 1
> inherit: 1
>
> Maybe something like this:
>
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index bc603193c477..9423cd65c3c4 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -1149,7 +1149,7 @@ void evsel__config(struct evsel *evsel, struct
> record_opts *opts,
> bool per_cpu = opts->target.default_per_cpu && !opts-
> >target.per_thread;
>
> attr->sample_id_all = perf_missing_features.sample_id_all ? 0
> : 1;
> - attr->inherit = !opts->no_inherit;
> + attr->inherit = target__has_cpu(&opts->target) ? 0 :
> !opts->no_inherit;
> attr->write_backward = opts->overwrite ? 1 : 0;
> attr->read_format = PERF_FORMAT_LOST;
>
>
> Thanks,
> Namhyung
>
Done, though this looks benign; the current tools appear to do this,
and there are a couple of files in tests/attr that assumed inherit=1
for system wide mode that I've had to update.
# perf --version
perf version 6.10-1
# perf record -vvv -a --synth=no true
...
------------------------------------------------------------
perf_event_attr:
type 0 (PERF_TYPE_HARDWARE)
size 136
config 0 (PERF_COUNT_HW_CPU_CYCLES)
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID|LOST
disabled 1
inherit 1
freq 1
precise_ip 3
sample_id_all 1
------------------------------------------------------------
Testing your fix with -a, -C <n> as well as with application profiling
appears to do the right thing.
Regards
Ben
>
> > }
> >
> > @@ -2020,6 +2028,8 @@ static int __evsel__prepare_open(struct evsel
> > *evsel, struct perf_cpu_map *cpus,
> >
> > static void evsel__disable_missing_features(struct evsel *evsel)
> > {
> > + if (perf_missing_features.inherit_sample_read)
> > + evsel->core.attr.inherit = 0;
> > if (perf_missing_features.branch_counters)
> > evsel->core.attr.branch_sample_type &=
> > ~PERF_SAMPLE_BRANCH_COUNTERS;
> > if (perf_missing_features.read_lost)
> > @@ -2075,7 +2085,12 @@ bool evsel__detect_missing_features(struct
> > evsel *evsel)
> > * Must probe features in the order they were added to the
> > * perf_event_attr interface.
> > */
> > - if (!perf_missing_features.branch_counters &&
> > + if (!perf_missing_features.inherit_sample_read &&
> > + evsel->core.attr.inherit && (evsel->core.attr.sample_type &
> > PERF_SAMPLE_READ)) {
> > + perf_missing_features.inherit_sample_read = true;
> > + pr_debug2("Using PERF_SAMPLE_READ / :S modifier is not compatible
> > with inherit, falling back to no-inherit.\n");
> > + return true;
> > + } else if (!perf_missing_features.branch_counters &&
> > (evsel->core.attr.branch_sample_type &
> > PERF_SAMPLE_BRANCH_COUNTERS)) {
> > perf_missing_features.branch_counters = true;
> > pr_debug2("switching off branch counters support\n");
> > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> > index 80b5f6dd868e..bb0c91c23679 100644
> > --- a/tools/perf/util/evsel.h
> > +++ b/tools/perf/util/evsel.h
> > @@ -206,6 +206,7 @@ struct perf_missing_features {
> > bool weight_struct;
> > bool read_lost;
> > bool branch_counters;
> > + bool inherit_sample_read;
> > };
> >
> > extern struct perf_missing_features perf_missing_features;
> > --
> > 2.45.2
> >
next prev parent reply other threads:[~2024-08-01 12:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 8:44 [PATCH v9 0/4] perf: Support PERF_SAMPLE_READ with inherit Ben Gainey
2024-07-30 8:44 ` [PATCH v9 1/4] perf: Rename perf_event_context.nr_pending to nr_no_switch_fast Ben Gainey
2024-07-30 8:44 ` [PATCH v9 2/4] perf: Support PERF_SAMPLE_READ with inherit Ben Gainey
2024-07-30 8:44 ` [PATCH v9 3/4] tools/perf: Correctly calculate sample period for inherited SAMPLE_READ values Ben Gainey
2024-07-30 8:44 ` [PATCH v9 4/4] tools/perf: Allow inherit + PERF_SAMPLE_READ when opening events Ben Gainey
2024-07-31 18:17 ` Namhyung Kim
2024-08-01 12:28 ` Ben Gainey [this message]
2024-07-30 12:25 ` [PATCH v9 0/4] perf: Support PERF_SAMPLE_READ with inherit Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7b8da3f40cbc30a25fe5fa856627245dc2b6a991.camel@arm.com \
--to=ben.gainey@arm.com \
--cc=James.Clark@arm.com \
--cc=Mark.Rutland@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).