2021-11-09 16:30:39

by German Gomez

[permalink] [raw]
Subject: [PATCH v2 0/3] perf arm-spe: Add snapshot mode support

This patchset adds snapshot mode support for arm-spe.

- [PATCH 1/3] implements the minimal callbacks to support recording in
snapshot mode.
- [PATCH 2/3] implements the find_snapshot callback in order to handle
wrap-arounds in the AUX buffer.
- [PATCH 3/3] adds a test for spe snapshot mode.

---

Changes since v1:
- Added [email protected] to the recipients list as I forgot to include
him in the original patchset [1].
- Removed [PATCH 1/5] and [PATCH 2/5] in order to keep patches
semantically relevant.
- Updated test script test_arm_spe.sh because it wasn't working on
distributions that use dash shell v0.5.10 (ubuntu 20) [2].

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

German Gomez (3):
perf arm-spe: Add snapshot mode support
perf arm-spe: Implement find_snapshot callback
perf arm-spe: Snapshot mode test

tools/perf/arch/arm64/util/arm-spe.c | 275 +++++++++++++++++++++++++
tools/perf/tests/shell/test_arm_spe.sh | 89 ++++++++
2 files changed, 364 insertions(+)
create mode 100755 tools/perf/tests/shell/test_arm_spe.sh

--
2.25.1



2021-11-09 16:30:47

by German Gomez

[permalink] [raw]
Subject: [PATCH v2 1/3] perf arm-spe: Add snapshot mode support

This patch enables support for snapshot mode of arm_spe events,
including the implementation of the necessary callbacks (excluding
find_snapshot, which is to be included in a followup commit).

Reviewed-by: James Clark <[email protected]>
Signed-off-by: German Gomez <[email protected]>
Reviewed-by: Leo Yan <[email protected]>
Tested-by: Leo Yan <[email protected]>
---
tools/perf/arch/arm64/util/arm-spe.c | 130 +++++++++++++++++++++++++++
1 file changed, 130 insertions(+)

diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c
index a4420d4df..f8b03d164 100644
--- a/tools/perf/arch/arm64/util/arm-spe.c
+++ b/tools/perf/arch/arm64/util/arm-spe.c
@@ -84,6 +84,55 @@ static int arm_spe_info_fill(struct auxtrace_record *itr,
return 0;
}

+static void
+arm_spe_snapshot_resolve_auxtrace_defaults(struct record_opts *opts,
+ bool privileged)
+{
+ /*
+ * The default snapshot size is the auxtrace mmap size. If neither auxtrace mmap size nor
+ * snapshot size is specified, then the default is 4MiB for privileged users, 128KiB for
+ * unprivileged users.
+ *
+ * The default auxtrace mmap size is 4MiB/page_size for privileged users, 128KiB for
+ * unprivileged users. If an unprivileged user does not specify mmap pages, the mmap pages
+ * will be reduced from the default 512KiB/page_size to 256KiB/page_size, otherwise the
+ * user is likely to get an error as they exceed their mlock limmit.
+ */
+
+ /*
+ * No size were given to '-S' or '-m,', so go with the default
+ */
+ if (!opts->auxtrace_snapshot_size && !opts->auxtrace_mmap_pages) {
+ if (privileged) {
+ opts->auxtrace_mmap_pages = MiB(4) / page_size;
+ } else {
+ opts->auxtrace_mmap_pages = KiB(128) / page_size;
+ if (opts->mmap_pages == UINT_MAX)
+ opts->mmap_pages = KiB(256) / page_size;
+ }
+ } else if (!opts->auxtrace_mmap_pages && !privileged && opts->mmap_pages == UINT_MAX) {
+ opts->mmap_pages = KiB(256) / page_size;
+ }
+
+ /*
+ * '-m,xyz' was specified but no snapshot size, so make the snapshot size as big as the
+ * auxtrace mmap area.
+ */
+ if (!opts->auxtrace_snapshot_size)
+ opts->auxtrace_snapshot_size = opts->auxtrace_mmap_pages * (size_t)page_size;
+
+ /*
+ * '-Sxyz' was specified but no auxtrace mmap area, so make the auxtrace mmap area big
+ * enough to fit the requested snapshot size.
+ */
+ if (!opts->auxtrace_mmap_pages) {
+ size_t sz = opts->auxtrace_snapshot_size;
+
+ sz = round_up(sz, page_size) / page_size;
+ opts->auxtrace_mmap_pages = roundup_pow_of_two(sz);
+ }
+}
+
static int arm_spe_recording_options(struct auxtrace_record *itr,
struct evlist *evlist,
struct record_opts *opts)
@@ -115,6 +164,36 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
if (!opts->full_auxtrace)
return 0;

+ /*
+ * we are in snapshot mode.
+ */
+ if (opts->auxtrace_snapshot_mode) {
+ /*
+ * Command arguments '-Sxyz' and/or '-m,xyz' are missing, so fill those in with
+ * default values.
+ */
+ if (!opts->auxtrace_snapshot_size || !opts->auxtrace_mmap_pages)
+ arm_spe_snapshot_resolve_auxtrace_defaults(opts, privileged);
+
+ /*
+ * Snapshot size can't be bigger than the auxtrace area.
+ */
+ if (opts->auxtrace_snapshot_size > opts->auxtrace_mmap_pages * (size_t)page_size) {
+ pr_err("Snapshot size %zu must not be greater than AUX area tracing mmap size %zu\n",
+ opts->auxtrace_snapshot_size,
+ opts->auxtrace_mmap_pages * (size_t)page_size);
+ return -EINVAL;
+ }
+
+ /*
+ * Something went wrong somewhere - this shouldn't happen.
+ */
+ if (!opts->auxtrace_snapshot_size || !opts->auxtrace_mmap_pages) {
+ pr_err("Failed to calculate default snapshot size and/or AUX area tracing mmap pages\n");
+ return -EINVAL;
+ }
+ }
+
/* We are in full trace mode but '-m,xyz' wasn't specified */
if (!opts->auxtrace_mmap_pages) {
if (privileged) {
@@ -138,6 +217,9 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
}
}

+ if (opts->auxtrace_snapshot_mode)
+ pr_debug2("%sx snapshot size: %zu\n", ARM_SPE_PMU_NAME,
+ opts->auxtrace_snapshot_size);

/*
* To obtain the auxtrace buffer file descriptor, the auxtrace event
@@ -172,6 +254,51 @@ static int arm_spe_recording_options(struct auxtrace_record *itr,
return 0;
}

+static int arm_spe_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused,
+ struct record_opts *opts,
+ const char *str)
+{
+ unsigned long long snapshot_size = 0;
+ char *endptr;
+
+ if (str) {
+ snapshot_size = strtoull(str, &endptr, 0);
+ if (*endptr || snapshot_size > SIZE_MAX)
+ return -1;
+ }
+
+ opts->auxtrace_snapshot_mode = true;
+ opts->auxtrace_snapshot_size = snapshot_size;
+
+ return 0;
+}
+
+static int arm_spe_snapshot_start(struct auxtrace_record *itr)
+{
+ struct arm_spe_recording *ptr =
+ container_of(itr, struct arm_spe_recording, itr);
+ struct evsel *evsel;
+
+ evlist__for_each_entry(ptr->evlist, evsel) {
+ if (evsel->core.attr.type == ptr->arm_spe_pmu->type)
+ return evsel__disable(evsel);
+ }
+ return -EINVAL;
+}
+
+static int arm_spe_snapshot_finish(struct auxtrace_record *itr)
+{
+ struct arm_spe_recording *ptr =
+ container_of(itr, struct arm_spe_recording, itr);
+ struct evsel *evsel;
+
+ evlist__for_each_entry(ptr->evlist, evsel) {
+ if (evsel->core.attr.type == ptr->arm_spe_pmu->type)
+ return evsel__enable(evsel);
+ }
+ return -EINVAL;
+}
+
static u64 arm_spe_reference(struct auxtrace_record *itr __maybe_unused)
{
struct timespec ts;
@@ -207,6 +334,9 @@ struct auxtrace_record *arm_spe_recording_init(int *err,

sper->arm_spe_pmu = arm_spe_pmu;
sper->itr.pmu = arm_spe_pmu;
+ sper->itr.snapshot_start = arm_spe_snapshot_start;
+ sper->itr.snapshot_finish = arm_spe_snapshot_finish;
+ sper->itr.parse_snapshot_options = arm_spe_parse_snapshot_options;
sper->itr.recording_options = arm_spe_recording_options;
sper->itr.info_priv_size = arm_spe_info_priv_size;
sper->itr.info_fill = arm_spe_info_fill;
--
2.25.1


2021-11-10 23:52:17

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] perf arm-spe: Add snapshot mode support

Hello,

On Tue, Nov 9, 2021 at 8:30 AM German Gomez <[email protected]> wrote:
>
> This patchset adds snapshot mode support for arm-spe.
>
> - [PATCH 1/3] implements the minimal callbacks to support recording in
> snapshot mode.
> - [PATCH 2/3] implements the find_snapshot callback in order to handle
> wrap-arounds in the AUX buffer.
> - [PATCH 3/3] adds a test for spe snapshot mode.
>
> ---
>
> Changes since v1:
> - Added [email protected] to the recipients list as I forgot to include
> him in the original patchset [1].
> - Removed [PATCH 1/5] and [PATCH 2/5] in order to keep patches
> semantically relevant.
> - Updated test script test_arm_spe.sh because it wasn't working on
> distributions that use dash shell v0.5.10 (ubuntu 20) [2].
>
> [1] https://lore.kernel.org/all/[email protected]/
> [2] https://lore.kernel.org/all/[email protected]/
>
> German Gomez (3):
> perf arm-spe: Add snapshot mode support
> perf arm-spe: Implement find_snapshot callback
> perf arm-spe: Snapshot mode test

Acked-by: Namhyung Kim <[email protected]>

Thanks,
Namhyung

>
> tools/perf/arch/arm64/util/arm-spe.c | 275 +++++++++++++++++++++++++
> tools/perf/tests/shell/test_arm_spe.sh | 89 ++++++++
> 2 files changed, 364 insertions(+)
> create mode 100755 tools/perf/tests/shell/test_arm_spe.sh
>
> --
> 2.25.1
>

2021-11-11 08:46:39

by Leo Yan

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] perf arm-spe: Add snapshot mode support

Hi Arnaldo,

On Tue, Nov 09, 2021 at 04:30:06PM +0000, German Gomez wrote:
> This patchset adds snapshot mode support for arm-spe.
>
> - [PATCH 1/3] implements the minimal callbacks to support recording in
> snapshot mode.
> - [PATCH 2/3] implements the find_snapshot callback in order to handle
> wrap-arounds in the AUX buffer.
> - [PATCH 3/3] adds a test for spe snapshot mode.

I have verified this patch set on Hisilicon D06 board, please consider
to pick up:

root@ubuntu:/home/leoy/linux/tools/perf# ./perf test -v 85
85: Check Arm SPE trace data recording and synthesized samples :
--- start ---
test child forked, pid 17083
Recording trace with snapshot mode /tmp/__perf_test.perf.data.MI2iX
Looking at perf.data file for dumping samples:
Looking at perf.data file for reporting samples:
SPE snapshot testing: PASS
test child finished with 0
---- end ----
Check Arm SPE trace data recording and synthesized samples: Ok

BTW, you could see German has another patch set for enabling pid/tid
for Arm SPE tracing [1]. I confirmed that the pid/tid patch set and
current patch set have no conflit, and don't need worry the dependency
between these two patch sets (so you could apply two patch sets in any
ordering).

Thanks,
Leo

[1] https://lore.kernel.org/lkml/20211111072714.GB102075@leoy-ThinkPad-X240s/T/#m932fd26d54278208331d4e3c32597cf63b6d4341

2021-11-11 14:54:41

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] perf arm-spe: Add snapshot mode support

Em Thu, Nov 11, 2021 at 04:46:21PM +0800, Leo Yan escreveu:
> Hi Arnaldo,
>
> On Tue, Nov 09, 2021 at 04:30:06PM +0000, German Gomez wrote:
> > This patchset adds snapshot mode support for arm-spe.
> >
> > - [PATCH 1/3] implements the minimal callbacks to support recording in
> > snapshot mode.
> > - [PATCH 2/3] implements the find_snapshot callback in order to handle
> > wrap-arounds in the AUX buffer.
> > - [PATCH 3/3] adds a test for spe snapshot mode.
>
> I have verified this patch set on Hisilicon D06 board, please consider
> to pick up:
>
> root@ubuntu:/home/leoy/linux/tools/perf# ./perf test -v 85
> 85: Check Arm SPE trace data recording and synthesized samples :
> --- start ---
> test child forked, pid 17083
> Recording trace with snapshot mode /tmp/__perf_test.perf.data.MI2iX
> Looking at perf.data file for dumping samples:
> Looking at perf.data file for reporting samples:
> SPE snapshot testing: PASS
> test child finished with 0
> ---- end ----
> Check Arm SPE trace data recording and synthesized samples: Ok
>
> BTW, you could see German has another patch set for enabling pid/tid
> for Arm SPE tracing [1]. I confirmed that the pid/tid patch set and
> current patch set have no conflit, and don't need worry the dependency
> between these two patch sets (so you could apply two patch sets in any
> ordering).

Thanks for the clarifications, applied, its out in my tmp.perf/core
branch, that still needs some fixes for buiding on arm related to a
recent patchset for 'perf test' from Ian Rogers, as soon as that is
fixed it will be set in stone in perf/core.

- Arnaldo