From: Puranjay Mohan <puranjay@kernel•org>
To: bpf@vger•kernel.org
Cc: Puranjay Mohan <puranjay@kernel•org>,
Puranjay Mohan <puranjay12@gmail•com>,
Alexei Starovoitov <ast@kernel•org>,
Daniel Borkmann <daniel@iogearbox•net>,
John Fastabend <john.fastabend@gmail•com>,
Andrii Nakryiko <andrii@kernel•org>,
Martin KaFai Lau <martin.lau@linux•dev>,
Eduard Zingerman <eddyz87@gmail•com>, Song Liu <song@kernel•org>,
Yonghong Song <yonghong.song@linux•dev>,
Will Deacon <will@kernel•org>,
Mark Rutland <mark.rutland@arm•com>,
Catalin Marinas <catalin.marinas@arm•com>,
Leo Yan <leo.yan@arm•com>, Rob Herring <robh@kernel•org>,
Peter Zijlstra <peterz@infradead•org>,
Ingo Molnar <mingo@redhat•com>,
Arnaldo Carvalho de Melo <acme@kernel•org>,
Namhyung Kim <namhyung@kernel•org>,
James Clark <james.clark@linaro•org>,
Ian Rogers <irogers@google•com>,
Adrian Hunter <adrian.hunter@intel•com>,
Shuah Khan <shuah@kernel•org>, Breno Leitao <leitao@debian•org>,
Ravi Bangoria <ravi.bangoria@amd•com>,
Stephane Eranian <eranian@google•com>,
Kumar Kartikeya Dwivedi <memxor@gmail•com>,
Usama Arif <usama.arif@linux•dev>,
linux-arm-kernel@lists•infradead.org,
linux-perf-users@vger•kernel.org,
linux-kselftest@vger•kernel.org, linux-kernel@vger•kernel.org,
kernel-team@meta•com
Subject: [PATCH v4 2/4] perf: Use a union to clear branch entry bitfields
Date: Wed, 27 May 2026 05:11:58 -0700 [thread overview]
Message-ID: <20260527121207.2312181-3-puranjay@kernel.org> (raw)
In-Reply-To: <20260527121207.2312181-1-puranjay@kernel.org>
perf_clear_branch_entry_bitfields() zeroes individual bitfields of struct
perf_branch_entry but has repeatedly fallen out of sync when new fields
were added (new_type and priv were missed).
Wrap the bitfields in an anonymous struct inside a union with a u64
bitfields member, and clear them all with a single assignment. This
avoids having to update the clearing function every time a new bitfield
is added.
Fixes: bfe4daf850f4 ("perf/core: Add perf_clear_branch_entry_bitfields() helper")
Signed-off-by: Puranjay Mohan <puranjay@kernel•org>
---
include/linux/perf_event.h | 9 +--------
include/uapi/linux/perf_event.h | 25 +++++++++++++++----------
tools/include/uapi/linux/perf_event.h | 25 +++++++++++++++----------
3 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 48d851fbd8ea..f7360c43f902 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1474,14 +1474,7 @@ static inline u32 perf_sample_data_size(struct perf_sample_data *data,
*/
static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *br)
{
- br->mispred = 0;
- br->predicted = 0;
- br->in_tx = 0;
- br->abort = 0;
- br->cycles = 0;
- br->type = 0;
- br->spec = PERF_BR_SPEC_NA;
- br->reserved = 0;
+ br->bitfields = 0;
}
extern void perf_output_sample(struct perf_output_handle *handle,
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index fd10aa8d697f..c2e7b1b1c4fa 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -1491,16 +1491,21 @@ union perf_mem_data_src {
struct perf_branch_entry {
__u64 from;
__u64 to;
- __u64 mispred : 1, /* target mispredicted */
- predicted : 1, /* target predicted */
- in_tx : 1, /* in transaction */
- abort : 1, /* transaction abort */
- cycles : 16, /* cycle count to last branch */
- type : 4, /* branch type */
- spec : 2, /* branch speculation info */
- new_type : 4, /* additional branch type */
- priv : 3, /* privilege level */
- reserved : 31;
+ union {
+ struct {
+ __u64 mispred : 1, /* target mispredicted */
+ predicted : 1, /* target predicted */
+ in_tx : 1, /* in transaction */
+ abort : 1, /* transaction abort */
+ cycles : 16, /* cycle count to last branch */
+ type : 4, /* branch type */
+ spec : 2, /* branch speculation info */
+ new_type : 4, /* additional branch type */
+ priv : 3, /* privilege level */
+ reserved : 31;
+ };
+ __u64 bitfields;
+ };
};
/* Size of used info bits in struct perf_branch_entry */
diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index fd10aa8d697f..c2e7b1b1c4fa 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -1491,16 +1491,21 @@ union perf_mem_data_src {
struct perf_branch_entry {
__u64 from;
__u64 to;
- __u64 mispred : 1, /* target mispredicted */
- predicted : 1, /* target predicted */
- in_tx : 1, /* in transaction */
- abort : 1, /* transaction abort */
- cycles : 16, /* cycle count to last branch */
- type : 4, /* branch type */
- spec : 2, /* branch speculation info */
- new_type : 4, /* additional branch type */
- priv : 3, /* privilege level */
- reserved : 31;
+ union {
+ struct {
+ __u64 mispred : 1, /* target mispredicted */
+ predicted : 1, /* target predicted */
+ in_tx : 1, /* in transaction */
+ abort : 1, /* transaction abort */
+ cycles : 16, /* cycle count to last branch */
+ type : 4, /* branch type */
+ spec : 2, /* branch speculation info */
+ new_type : 4, /* additional branch type */
+ priv : 3, /* privilege level */
+ reserved : 31;
+ };
+ __u64 bitfields;
+ };
};
/* Size of used info bits in struct perf_branch_entry */
--
2.53.0-Meta
next prev parent reply other threads:[~2026-05-27 12:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 12:11 [PATCH v4 0/4] arm64: Add BRBE support for bpf_get_branch_snapshot() Puranjay Mohan
2026-05-27 12:11 ` [PATCH v4 1/4] perf/core: Fix sched_task callbacks for CPU-wide branch stack events Puranjay Mohan
2026-05-27 12:11 ` Puranjay Mohan [this message]
2026-05-27 13:00 ` [PATCH v4 2/4] perf: Use a union to clear branch entry bitfields bot+bpf-ci
2026-05-27 12:11 ` [PATCH v4 3/4] perf/arm64: Add BRBE support for bpf_get_branch_snapshot() Puranjay Mohan
2026-05-27 13:01 ` bot+bpf-ci
2026-05-27 12:12 ` [PATCH v4 4/4] selftests/bpf: Adjust wasted entries threshold for ARM64 BRBE Puranjay Mohan
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=20260527121207.2312181-3-puranjay@kernel.org \
--to=puranjay@kernel$(echo .)org \
--cc=acme@kernel$(echo .)org \
--cc=adrian.hunter@intel$(echo .)com \
--cc=andrii@kernel$(echo .)org \
--cc=ast@kernel$(echo .)org \
--cc=bpf@vger$(echo .)kernel.org \
--cc=catalin.marinas@arm$(echo .)com \
--cc=daniel@iogearbox$(echo .)net \
--cc=eddyz87@gmail$(echo .)com \
--cc=eranian@google$(echo .)com \
--cc=irogers@google$(echo .)com \
--cc=james.clark@linaro$(echo .)org \
--cc=john.fastabend@gmail$(echo .)com \
--cc=kernel-team@meta$(echo .)com \
--cc=leitao@debian$(echo .)org \
--cc=leo.yan@arm$(echo .)com \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-kselftest@vger$(echo .)kernel.org \
--cc=linux-perf-users@vger$(echo .)kernel.org \
--cc=mark.rutland@arm$(echo .)com \
--cc=martin.lau@linux$(echo .)dev \
--cc=memxor@gmail$(echo .)com \
--cc=mingo@redhat$(echo .)com \
--cc=namhyung@kernel$(echo .)org \
--cc=peterz@infradead$(echo .)org \
--cc=puranjay12@gmail$(echo .)com \
--cc=ravi.bangoria@amd$(echo .)com \
--cc=robh@kernel$(echo .)org \
--cc=shuah@kernel$(echo .)org \
--cc=song@kernel$(echo .)org \
--cc=usama.arif@linux$(echo .)dev \
--cc=will@kernel$(echo .)org \
--cc=yonghong.song@linux$(echo .)dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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