Skip to content

Commit

Permalink
perf: Use sample_flags for raw_data
Browse files Browse the repository at this point in the history
Use the new sample_flags to indicate whether the raw data field is
filled by the PMU driver.  Although it could check with the NULL,
follow the same rule with other fields.

Remove the raw field from the perf_sample_data_init() to minimize
the number of cache lines touched.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220921220032.2858517-2-namhyung@kernel.org
  • Loading branch information
Namhyung Kim authored and Peter Zijlstra committed Sep 27, 2022
1 parent 7b08463 commit 838d9bb
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions arch/s390/kernel/perf_cpum_cf.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ static int cfdiag_push_sample(struct perf_event *event,
raw.frag.data = cpuhw->stop;
raw.size = raw.frag.size;
data.raw = &raw;
data.sample_flags |= PERF_SAMPLE_RAW;
}

overflow = perf_event_overflow(event, &data, &regs);
Expand Down
1 change: 1 addition & 0 deletions arch/s390/kernel/perf_pai_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ static int paicrypt_push_sample(void)
raw.frag.data = cpump->save;
raw.size = raw.frag.size;
data.raw = &raw;
data.sample_flags |= PERF_SAMPLE_RAW;
}

overflow = perf_event_overflow(event, &data, &regs);
Expand Down
1 change: 1 addition & 0 deletions arch/x86/events/amd/ibs.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
},
};
data.raw = &raw;
data.sample_flags |= PERF_SAMPLE_RAW;
}

/*
Expand Down
5 changes: 2 additions & 3 deletions include/linux/perf_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,6 @@ struct perf_sample_data {
* minimize the cachelines touched.
*/
u64 sample_flags;
struct perf_raw_record *raw;
u64 period;

/*
Expand All @@ -1040,6 +1039,7 @@ struct perf_sample_data {
union perf_mem_data_src data_src;
u64 txn;
u64 addr;
struct perf_raw_record *raw;

u64 type;
u64 ip;
Expand Down Expand Up @@ -1078,8 +1078,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data,
u64 addr, u64 period)
{
/* remaining struct members initialized in perf_prepare_sample() */
data->sample_flags = 0;
data->raw = NULL;
data->sample_flags = PERF_SAMPLE_PERIOD;
data->period = period;

if (addr) {
Expand Down
3 changes: 2 additions & 1 deletion kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7332,7 +7332,7 @@ void perf_prepare_sample(struct perf_event_header *header,
struct perf_raw_record *raw = data->raw;
int size;

if (raw) {
if (raw && (data->sample_flags & PERF_SAMPLE_RAW)) {
struct perf_raw_frag *frag = &raw->frag;
u32 sum = 0;

Expand All @@ -7348,6 +7348,7 @@ void perf_prepare_sample(struct perf_event_header *header,
frag->pad = raw->size - sum;
} else {
size = sizeof(u64);
data->raw = NULL;
}

header->size += size;
Expand Down

0 comments on commit 838d9bb

Please sign in to comment.