Commit c81ca2ce authored by Yabin Cui's avatar Yabin Cui Committed by Luo Gengkun
Browse files

perf/core: Save raw sample data conditionally based on sample type

stable inclusion
from stable-v6.6.76
commit c0dbecb204cfb91999d0b785048be4a95bbc8c9c
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQXZY

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c0dbecb204cfb91999d0b785048be4a95bbc8c9c



--------------------------------

[ Upstream commit b9c44b91476b67327a521568a854babecc4070ab ]

Currently, space for raw sample data is always allocated within sample
records for both BPF output and tracepoint events. This leads to unused
space in sample records when raw sample data is not requested.

This patch enforces checking sample type of an event in
perf_sample_save_raw_data(). So raw sample data will only be saved if
explicitly requested, reducing overhead when it is not needed.

Fixes: 0a9081cf ("perf/core: Add perf_sample_save_raw_data() helper")
Signed-off-by: default avatarYabin Cui <yabinc@google.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240515193610.2350456-2-yabinc@google.com


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarLuo Gengkun <luogengkun2@huawei.com>
parent 9d22d5b7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -977,7 +977,7 @@ static int cfdiag_push_sample(struct perf_event *event,
	if (event->attr.sample_type & PERF_SAMPLE_RAW) {
		raw.frag.size = cpuhw->usedss;
		raw.frag.data = cpuhw->stop;
		perf_sample_save_raw_data(&data, &raw);
		perf_sample_save_raw_data(&data, event, &raw);
	}

	overflow = perf_event_overflow(event, &data, &regs);
+1 −1
Original line number Diff line number Diff line
@@ -365,7 +365,7 @@ static int paicrypt_push_sample(void)
	if (event->attr.sample_type & PERF_SAMPLE_RAW) {
		raw.frag.size = rawsize;
		raw.frag.data = cpump->save;
		perf_sample_save_raw_data(&data, &raw);
		perf_sample_save_raw_data(&data, event, &raw);
	}

	overflow = perf_event_overflow(event, &data, &regs);
+1 −1
Original line number Diff line number Diff line
@@ -454,7 +454,7 @@ static int paiext_push_sample(void)
	if (event->attr.sample_type & PERF_SAMPLE_RAW) {
		raw.frag.size = rawsize;
		raw.frag.data = cpump->save;
		perf_sample_save_raw_data(&data, &raw);
		perf_sample_save_raw_data(&data, event, &raw);
	}

	overflow = perf_event_overflow(event, &data, &regs);
+1 −1
Original line number Diff line number Diff line
@@ -1118,7 +1118,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
				.data = ibs_data.data,
			},
		};
		perf_sample_save_raw_data(&data, &raw);
		perf_sample_save_raw_data(&data, event, &raw);
	}

	if (perf_ibs == &perf_ibs_op)
+6 −0
Original line number Diff line number Diff line
@@ -1287,12 +1287,18 @@ static inline void perf_sample_save_callchain(struct perf_sample_data *data,
}

static inline void perf_sample_save_raw_data(struct perf_sample_data *data,
					     struct perf_event *event,
					     struct perf_raw_record *raw)
{
	struct perf_raw_frag *frag = &raw->frag;
	u32 sum = 0;
	int size;

	if (!(event->attr.sample_type & PERF_SAMPLE_RAW))
		return;
	if (WARN_ON_ONCE(data->sample_flags & PERF_SAMPLE_RAW))
		return;

	do {
		sum += frag->size;
		if (perf_raw_frag_last(frag))
Loading