From: "tip-bot2 for Namhyung Kim" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Namhyung Kim <namhyung@kernel.org>,
Ingo Molnar <mingo@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Song Liu <song@kernel.org>, Peter Zijlstra <peterz@infradead.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: perf/core] perf/core: Save the dynamic parts of sample data size
Date: Wed, 18 Jan 2023 11:37:53 -0000 [thread overview]
Message-ID: <167404187322.4906.2403100991800759318.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20230118060559.615653-2-namhyung@kernel.org>
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 4cf7a136115e96241f9f1089d2b53c47accf3823
Gitweb: https://git.kernel.org/tip/4cf7a136115e96241f9f1089d2b53c47accf3823
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Tue, 17 Jan 2023 22:05:52 -08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 18 Jan 2023 11:57:19 +01:00
perf/core: Save the dynamic parts of sample data size
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.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Tested-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Song Liu <song@kernel.org>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230118060559.615653-2-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 03949d0..16b9800 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 d56328e..827082d 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7586,7 +7586,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) {
@@ -7612,7 +7612,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) {
@@ -7624,7 +7624,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))
@@ -7639,7 +7639,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) {
@@ -7664,7 +7664,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)
@@ -7693,7 +7693,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 &&
@@ -7738,8 +7738,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
next prev parent reply other threads:[~2023-01-18 12:17 UTC|newest]
Thread overview: 21+ 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 ` [PATCH 1/8] perf/core: Save the dynamic parts of sample data size Namhyung Kim
2023-01-18 11:37 ` tip-bot2 for Namhyung Kim [this message]
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 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
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=167404187322.4906.2403100991800759318.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=song@kernel.org \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®