* [PATCH v2] perf record: Ensure space for lost samples
@ 2024-06-11 5:06 Ian Rogers
2024-06-11 16:03 ` Namhyung Kim
2024-06-14 13:31 ` Namhyung Kim
0 siblings, 2 replies; 3+ messages in thread
From: Ian Rogers @ 2024-06-11 5:06 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, Kan Liang, linux-perf-users,
linux-kernel
Cc: Milian Wolff
Previous allocation didn't account for sample ID written after the
lost samples event. Switch from malloc/free to a stack allocation.
Reported-by: Milian Wolff <milian.wolff@kdab.com>
Closes: https://lore.kernel.org/linux-perf-users/23879991.0LEYPuXRzz@milian-workstation/
Signed-off-by: Ian Rogers <irogers@google.com>
---
v2. Switch from union to struct and place struct in header to clearly
tie it to the MAX_ID_HDR_ENTRIES.
---
tools/lib/perf/include/perf/event.h | 6 +++++
tools/perf/builtin-record.c | 34 ++++++++---------------------
2 files changed, 15 insertions(+), 25 deletions(-)
diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h
index ae64090184d3..37bb7771d914 100644
--- a/tools/lib/perf/include/perf/event.h
+++ b/tools/lib/perf/include/perf/event.h
@@ -77,6 +77,12 @@ struct perf_record_lost_samples {
__u64 lost;
};
+#define MAX_ID_HDR_ENTRIES 6
+struct perf_record_lost_samples_and_ids {
+ struct perf_record_lost_samples lost;
+ __u64 sample_ids[MAX_ID_HDR_ENTRIES];
+};
+
/*
* PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID | PERF_FORMAT_LOST
*/
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 66a3de8ac661..019305b94e5f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1926,7 +1926,7 @@ static void __record__save_lost_samples(struct record *rec, struct evsel *evsel,
static void record__read_lost_samples(struct record *rec)
{
struct perf_session *session = rec->session;
- struct perf_record_lost_samples *lost = NULL;
+ struct perf_record_lost_samples_and_ids lost;
struct evsel *evsel;
/* there was an error during record__open */
@@ -1951,20 +1951,13 @@ static void record__read_lost_samples(struct record *rec)
if (perf_evsel__read(&evsel->core, x, y, &count) < 0) {
pr_debug("read LOST count failed\n");
- goto out;
+ return;
}
if (count.lost) {
- if (!lost) {
- lost = zalloc(sizeof(*lost) +
- session->machines.host.id_hdr_size);
- if (!lost) {
- pr_debug("Memory allocation failed\n");
- return;
- }
- lost->header.type = PERF_RECORD_LOST_SAMPLES;
- }
- __record__save_lost_samples(rec, evsel, lost,
+ memset(&lost.lost, 0, sizeof(lost));
+ lost.lost.header.type = PERF_RECORD_LOST_SAMPLES;
+ __record__save_lost_samples(rec, evsel, &lost.lost,
x, y, count.lost, 0);
}
}
@@ -1972,21 +1965,12 @@ static void record__read_lost_samples(struct record *rec)
lost_count = perf_bpf_filter__lost_count(evsel);
if (lost_count) {
- if (!lost) {
- lost = zalloc(sizeof(*lost) +
- session->machines.host.id_hdr_size);
- if (!lost) {
- pr_debug("Memory allocation failed\n");
- return;
- }
- lost->header.type = PERF_RECORD_LOST_SAMPLES;
- }
- __record__save_lost_samples(rec, evsel, lost, 0, 0, lost_count,
+ memset(&lost.lost, 0, sizeof(lost));
+ lost.lost.header.type = PERF_RECORD_LOST_SAMPLES;
+ __record__save_lost_samples(rec, evsel, &lost.lost, 0, 0, lost_count,
PERF_RECORD_MISC_LOST_SAMPLES_BPF);
}
}
-out:
- free(lost);
}
static volatile sig_atomic_t workload_exec_errno;
@@ -3198,7 +3182,7 @@ static int switch_output_setup(struct record *rec)
unsigned long val;
/*
- * If we're using --switch-output-events, then we imply its
+ * If we're using --switch-output-events, then we imply its
* --switch-output=signal, as we'll send a SIGUSR2 from the side band
* thread to its parent.
*/
--
2.45.2.505.gda0bf45e8d-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] perf record: Ensure space for lost samples
2024-06-11 5:06 [PATCH v2] perf record: Ensure space for lost samples Ian Rogers
@ 2024-06-11 16:03 ` Namhyung Kim
2024-06-14 13:31 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-06-11 16:03 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Kan Liang, linux-perf-users, linux-kernel, Milian Wolff
Hi Ian,
On Mon, Jun 10, 2024 at 10:06 PM Ian Rogers <irogers@google.com> wrote:
>
> Previous allocation didn't account for sample ID written after the
> lost samples event. Switch from malloc/free to a stack allocation.
>
> Reported-by: Milian Wolff <milian.wolff@kdab.com>
> Closes: https://lore.kernel.org/linux-perf-users/23879991.0LEYPuXRzz@milian-workstation/
> Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] perf record: Ensure space for lost samples
2024-06-11 5:06 [PATCH v2] perf record: Ensure space for lost samples Ian Rogers
2024-06-11 16:03 ` Namhyung Kim
@ 2024-06-14 13:31 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-06-14 13:31 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Kan Liang, linux-perf-users, linux-kernel, Ian Rogers
Cc: Milian Wolff
On Mon, 10 Jun 2024 22:06:26 -0700, Ian Rogers wrote:
> Previous allocation didn't account for sample ID written after the
> lost samples event. Switch from malloc/free to a stack allocation.
>
>
Applied to perf-tools-next, thanks!
Arnaldo, I'll resolve the conflict when I merge perf-tools later which
has the revert.
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-14 13:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-11 5:06 [PATCH v2] perf record: Ensure space for lost samples Ian Rogers
2024-06-11 16:03 ` Namhyung Kim
2024-06-14 13:31 ` Namhyung Kim
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).