From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Quentin Monnet <qmo@kernel.org>, Shuah Khan <shuah@kernel.org>,
Leon Hwang <leon.hwang@linux.dev>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH bpf-next 5/5] selftests/bpf: Improve readability in iter test for percpu data
Date: Sat, 15 Aug 2026 01:32:06 +0800 [thread overview]
Message-ID: <20260814173206.93082-6-leon.hwang@linux.dev> (raw)
In-Reply-To: <20260814173206.93082-1-leon.hwang@linux.dev>
The original 'offsetof()' + offset is equal to the new 'offsetof()'. Use
the new 'offsetof()' instead.
Rename two variables btw:
* offsetof_num -> num_off
* percpu_data_sum -> sum
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
tools/testing/selftests/bpf/prog_tests/global_data_init.c | 6 +++---
tools/testing/selftests/bpf/progs/test_global_percpu_data.c | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
index 2f0dbeb88934..c6d055b9457d 100644
--- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
+++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
@@ -348,8 +348,8 @@ static void test_global_percpu_data_iter(void)
return;
skel->rodata->num_cpus = num_cpus;
- skel->rodata->offsetof_num = offsetof(struct test_global_percpu_data__percpu, struct_data);
- skel->rodata->offsetof_num += sizeof(skel->percpu->struct_data) - sizeof(int);
+ skel->rodata->num_off = offsetof(struct test_global_percpu_data__percpu,
+ struct_data.nums[6]);
skel->rodata->elem_sz = roundup(sizeof(struct test_global_percpu_data__percpu), 8);
skel->percpu->struct_data.nums[6] = 0xc0de;
@@ -372,7 +372,7 @@ static void test_global_percpu_data_iter(void)
do { } while (0);
ASSERT_EQ(len, 0, "read iter");
ASSERT_TRUE(skel->bss->run_iter, "run_iter");
- ASSERT_EQ(skel->bss->percpu_data_sum, 0xc0de * num_cpus, "percpu_data_sum");
+ ASSERT_EQ(skel->bss->sum, 0xc0de * num_cpus, "sum");
close(fd);
out:
diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
index 12556590b647..175c44000753 100644
--- a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
+++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
@@ -64,9 +64,9 @@ int verifier_snprintf(void *ctx)
}
volatile const __u32 num_cpus = 0;
-volatile const int offsetof_num;
+volatile const int num_off;
volatile const int elem_sz;
-__u32 percpu_data_sum = 0;
+__u32 sum = 0;
bool run_iter = false;
SEC("iter/bpf_map_elem")
@@ -82,7 +82,7 @@ int dump_percpu_data(struct bpf_iter__bpf_map_elem *ctx)
run_iter = true;
for (i = 0; i < num_cpus; i++) {
- percpu_data_sum += *(int *) (pptr + offsetof_num);
+ sum += *(int *) (pptr + num_off);
pptr += elem_sz;
}
return 0;
--
2.55.0
next prev parent reply other threads:[~2026-08-14 17:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
2026-08-14 17:32 ` [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier Leon Hwang
2026-08-14 20:32 ` Andrii Nakryiko
2026-08-14 17:32 ` [PATCH bpf-next 2/5] libbpf: Avoid unnecessary mmap resize for percpu data maps Leon Hwang
2026-08-14 17:32 ` [PATCH bpf-next 3/5] bpftool: Update comments about skel " Leon Hwang
2026-08-14 20:32 ` Andrii Nakryiko
2026-08-14 17:32 ` [PATCH bpf-next 4/5] selftests/bpf: Avoid flaky resize value test for percpu data Leon Hwang
2026-08-14 18:24 ` bot+bpf-ci
2026-08-14 17:32 ` Leon Hwang [this message]
2026-08-14 20:37 ` [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Andrii Nakryiko
2026-08-14 20:40 ` patchwork-bot+netdevbpf
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=20260814173206.93082-6-leon.hwang@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=qmo@kernel.org \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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