From: Namhyung Kim <namhyung@kernel.org>
To: Ben Gainey <ben.gainey@arm.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
james.clark@arm.com, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 0/4] perf: Support PERF_SAMPLE_READ with inherit_stat
Date: Fri, 22 Mar 2024 18:22:36 -0700 [thread overview]
Message-ID: <CAM9d7chfXH0ynfT_PSPyjhE8ATa=fV-kbx_csgeQrWiv+1EiiQ@mail.gmail.com> (raw)
In-Reply-To: <20240322164237.203358-1-ben.gainey@arm.com>
On Fri, Mar 22, 2024 at 9:42 AM Ben Gainey <ben.gainey@arm.com> wrote:
>
> This change allows events to use PERF_SAMPLE READ with inherit so long
> as both inherit_stat and PERF_SAMPLE_TID are set.
>
> Currently it is not possible to use PERF_SAMPLE_READ with inherit. This
> restriction assumes the user is interested in collecting aggregate
> statistics as per `perf stat`. It prevents a user from collecting
> per-thread samples using counter groups from a multi-threaded or
> multi-process application, as with `perf record -e '{....}:S'`. Instead
> users must use system-wide mode, or forgo the ability to sample counter
> groups. System-wide mode is often problematic as it requires specific
> permissions (no CAP_PERFMON / root access), or may lead to capture of
> significant amounts of extra data from other processes running on the
> system.
>
> Perf already supports the ability to collect per-thread counts with
> `inherit` via the `inherit_stat` flag. This patch changes
I'm not sure about this part. IIUC inherit and inherit_stat is not for
per-thread counts, it only supports per-process (including children)
events.
> `perf_event_alloc` relaxing the restriction to combine `inherit` with
> `PERF_SAMPLE_READ` so that the combination will be allowed so long as
> `inherit_stat` and `PERF_SAMPLE_TID` are enabled.
Anyway, does it really need 'inherit_stat'? I think it's only for
counting use cases (e.g. 'perf stat') not for sampling.
Also technically, it can have PERF_SAMPLE_STREAM_ID instead
of PERF_SAMPLE_TID to distinguish the counter values.
>
> In this configuration stream ids (such as may appear in the read_format
> field of a PERF_RECORD_SAMPLE) are no longer globally unique, rather
> the pair of (stream id, tid) uniquely identify each event. Tools that
> rely on this, for example to calculate a delta between samples, would
> need updating to take this into account. Previously valid event
> configurations (system-wide, no-inherit and so on) where each stream id
> is the identifier are unaffected.
I think you meant PERF_SAMPLE_ID not PERF_SAMPLE_STREAM_ID.
IIUC the stream id is already unique.
Thanks,
Namhyung
>
>
> Changes since v3:
> - Cleaned up perf test data changes incorrectly included into this
> series from elsewhere.
>
> Changes since v2:
> - Rebase on v6.8
> - Respond to James Clarke's feedback; fixup some typos and move some
> repeated checks into a helper macro.
> - Cleaned up checkpatch lints.
> - Updated perf test; fixed evsel handling so that existing tests pass
> and added new tests to cover the new behaviour.
>
> Changes since v1:
> - Rebase on v6.8-rc1
> - Fixed value written into sample after child exists.
> - Modified handling of switch-out so that context with these events
> take the slow path, so that the per-event/per-thread PMU state is
> correctly switched.
> - Modified perf tools to support this mode of operation.
>
> Ben Gainey (4):
> perf: Support PERF_SAMPLE_READ with inherit_stat
> tools/perf: Track where perf_sample_ids need per-thread periods
> tools/perf: Correctly calculate sample period for inherited
> SAMPLE_READ values
> tools/perf: Allow inherit + inherit_stat + PERF_SAMPLE_READ when
> opening events
>
> include/linux/perf_event.h | 1 +
> kernel/events/core.c | 62 ++++++++++----
> tools/lib/perf/evlist.c | 1 +
> tools/lib/perf/evsel.c | 48 +++++++++++
> tools/lib/perf/include/internal/evsel.h | 55 ++++++++++++-
> .../test-record-group-sampling-inherit-stat | 62 ++++++++++++++
> tools/perf/util/evsel.c | 82 ++++++++++++++++++-
> tools/perf/util/evsel.h | 1 +
> tools/perf/util/session.c | 11 ++-
> 9 files changed, 301 insertions(+), 22 deletions(-)
> create mode 100644 tools/perf/tests/attr/test-record-group-sampling-inherit-stat
>
> --
> 2.44.0
>
next prev parent reply other threads:[~2024-03-23 1:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 16:42 [PATCH v4 0/4] perf: Support PERF_SAMPLE_READ with inherit_stat Ben Gainey
2024-03-22 16:42 ` [PATCH v4 1/4] " Ben Gainey
2024-03-22 16:42 ` [PATCH v4 2/4] tools/perf: Track where perf_sample_ids need per-thread periods Ben Gainey
2024-03-22 16:42 ` [PATCH v4 3/4] tools/perf: Correctly calculate sample period for inherited SAMPLE_READ values Ben Gainey
2024-03-22 16:42 ` [PATCH v4 4/4] tools/perf: Allow inherit + inherit_stat + PERF_SAMPLE_READ when opening events Ben Gainey
2024-03-23 1:22 ` Namhyung Kim [this message]
2024-03-25 10:12 ` [PATCH v4 0/4] perf: Support PERF_SAMPLE_READ with inherit_stat Ben Gainey
2024-03-27 20:34 ` Namhyung Kim
2024-04-02 10:17 ` Ben Gainey
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='CAM9d7chfXH0ynfT_PSPyjhE8ATa=fV-kbx_csgeQrWiv+1EiiQ@mail.gmail.com' \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=ben.gainey@arm.com \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--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).