From: Namhyung Kim <namhyung@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
Song Liu <song@kernel.org>,
bpf@vger.kernel.org
Subject: [PATCH 1/8] perf/core: Save the dynamic parts of sample data size
Date: Tue, 17 Jan 2023 22:05:52 -0800 [thread overview]
Message-ID: <20230118060559.615653-2-namhyung@kernel.org> (raw)
In-Reply-To: <20230118060559.615653-1-namhyung@kernel.org>
The perf sample data can be divided into parts. The event->header_size
and event->id_header_size keep the static part of the sample data which
is determined by the sample_type flags.
But other parts like CALLCHAIN and BRANCH_STACK are changing dynamically
so it needs to see the actual data. In preparation of handling repeated
calls for perf_prepare_sample(), it can save the dynamic size to the
perf sample data to avoid the duplicate work.
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Tested-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
include/linux/perf_event.h | 2 ++
kernel/events/core.c | 17 ++++++++++-------
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 03949d017ac9..16b980014449 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1103,6 +1103,7 @@ struct perf_sample_data {
*/
u64 sample_flags;
u64 period;
+ u64 dyn_size;
/*
* Fields commonly set by __perf_event_header__init_id(),
@@ -1158,6 +1159,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
/* remaining struct members initialized in perf_prepare_sample() */
data->sample_flags = PERF_SAMPLE_PERIOD;
data->period = period;
+ data->dyn_size = 0;
if (addr) {
data->addr = addr;
diff --git a/kernel/events/core.c b/kernel/events/core.c
index eacc3702654d..8c8de26f04ab 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7593,7 +7593,7 @@ void perf_prepare_sample(struct perf_event_header *header,
size += data->callchain->nr;
- header->size += size * sizeof(u64);
+ data->dyn_size += size * sizeof(u64);
}
if (sample_type & PERF_SAMPLE_RAW) {
@@ -7619,7 +7619,7 @@ void perf_prepare_sample(struct perf_event_header *header,
data->raw = NULL;
}
- header->size += size;
+ data->dyn_size += size;
}
if (sample_type & PERF_SAMPLE_BRANCH_STACK) {
@@ -7631,7 +7631,7 @@ void perf_prepare_sample(struct perf_event_header *header,
size += data->br_stack->nr
* sizeof(struct perf_branch_entry);
}
- header->size += size;
+ data->dyn_size += size;
}
if (sample_type & (PERF_SAMPLE_REGS_USER | PERF_SAMPLE_STACK_USER))
@@ -7646,7 +7646,7 @@ void perf_prepare_sample(struct perf_event_header *header,
size += hweight64(mask) * sizeof(u64);
}
- header->size += size;
+ data->dyn_size += size;
}
if (sample_type & PERF_SAMPLE_STACK_USER) {
@@ -7671,7 +7671,7 @@ void perf_prepare_sample(struct perf_event_header *header,
size += sizeof(u64) + stack_size;
data->stack_user_size = stack_size;
- header->size += size;
+ data->dyn_size += size;
}
if (filtered_sample_type & PERF_SAMPLE_WEIGHT_TYPE)
@@ -7700,7 +7700,7 @@ void perf_prepare_sample(struct perf_event_header *header,
size += hweight64(mask) * sizeof(u64);
}
- header->size += size;
+ data->dyn_size += size;
}
if (sample_type & PERF_SAMPLE_PHYS_ADDR &&
@@ -7745,8 +7745,11 @@ void perf_prepare_sample(struct perf_event_header *header,
size = perf_prepare_sample_aux(event, data, size);
WARN_ON_ONCE(size + header->size > U16_MAX);
- header->size += size;
+ data->dyn_size += size + sizeof(u64); /* size above */
}
+
+ header->size += data->dyn_size;
+
/*
* If you're adding more sample types here, you likely need to do
* something about the overflowing header::size, like repurpose the
--
2.39.0.314.g84b9a713c41-goog
next prev parent reply other threads:[~2023-01-18 6:20 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-18 6:05 [PATCHSET 0/8] perf/core: Prepare sample data for BPF (v3) Namhyung Kim
2023-01-18 6:05 ` Namhyung Kim [this message]
2023-01-18 11:37 ` [tip: perf/core] perf/core: Save the dynamic parts of sample data size tip-bot2 for Namhyung Kim
2023-01-18 6:05 ` [PATCH 2/8] perf/core: Add perf_sample_save_callchain() helper Namhyung Kim
2023-01-18 11:37 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2023-01-18 6:05 ` [PATCH 3/8] perf/core: Add perf_sample_save_raw_data() helper Namhyung Kim
2023-01-18 11:37 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2023-01-18 6:05 ` [PATCH 4/8] perf/core: Add perf_sample_save_brstack() helper Namhyung Kim
2023-01-18 6:05 ` Namhyung Kim
2023-01-18 9:06 ` Athira Rajeev
2023-01-18 9:06 ` Athira Rajeev
2023-01-18 11:37 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2023-01-18 6:05 ` [PATCH 5/8] perf/core: Set data->sample_flags in perf_prepare_sample() Namhyung Kim
2023-01-18 11:37 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2023-01-18 6:05 ` [PATCH 6/8] perf/core: Do not pass header for sample id init Namhyung Kim
2023-01-18 11:37 ` [tip: perf/core] perf/core: Do not pass header for sample ID init tip-bot2 for Namhyung Kim
2023-01-18 6:05 ` [PATCH 7/8] perf/core: Introduce perf_prepare_header() Namhyung Kim
2023-01-18 11:37 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2023-01-18 6:05 ` [PATCH 8/8] perf/core: Call perf_prepare_sample() before running BPF Namhyung Kim
2023-01-18 11:37 ` [tip: perf/core] " tip-bot2 for Namhyung Kim
2023-01-18 10:50 ` [PATCHSET 0/8] perf/core: Prepare sample data for BPF (v3) Peter Zijlstra
2023-01-18 19:42 ` Alexei Starovoitov
2023-01-18 22:08 ` Namhyung Kim
-- strict thread matches above, loose matches on Subject: below --
2023-01-12 21:40 [PATCHSET 0/8] perf/core: Prepare sample data for BPF Namhyung Kim
2023-01-12 21:40 ` [PATCH 1/8] perf/core: Save the dynamic parts of sample data size Namhyung Kim
2023-01-13 20:44 ` Song Liu
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=20230118060559.615653-2-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=bpf@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=song@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.