提交 a271336f 编写于 作者: Y Yauheni Kaliuta 提交者: Zheng Zengkai

selftests/bpf: ringbuf: Use runtime page size

mainline inclusion
from mainline-5.13-rc1
commit 23a65766
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=23a65766066bb6e42a44e9097ddf79f72292a19f

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

Replace hardcoded 4096 with runtime value in the userspace part of
the test and set bpf table sizes dynamically according to the value.

Do not switch to ASSERT macros, keep CHECK, for consistency with the
rest of the test. Can be a separate cleanup patch.
Signed-off-by: NYauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210408061310.95877-6-yauheni.kaliuta@redhat.com
(cherry picked from commit 23a65766)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 6fb4ae46
...@@ -87,11 +87,20 @@ void test_ringbuf(void) ...@@ -87,11 +87,20 @@ void test_ringbuf(void)
pthread_t thread; pthread_t thread;
long bg_ret = -1; long bg_ret = -1;
int err, cnt; int err, cnt;
int page_size = getpagesize();
skel = test_ringbuf__open_and_load(); skel = test_ringbuf__open();
if (CHECK(!skel, "skel_open_load", "skeleton open&load failed\n")) if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
return; return;
err = bpf_map__set_max_entries(skel->maps.ringbuf, page_size);
if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
goto cleanup;
err = test_ringbuf__load(skel);
if (CHECK(err != 0, "skel_load", "skeleton load failed\n"))
goto cleanup;
/* only trigger BPF program for current process */ /* only trigger BPF program for current process */
skel->bss->pid = getpid(); skel->bss->pid = getpid();
...@@ -110,9 +119,9 @@ void test_ringbuf(void) ...@@ -110,9 +119,9 @@ void test_ringbuf(void)
CHECK(skel->bss->avail_data != 3 * rec_sz, CHECK(skel->bss->avail_data != 3 * rec_sz,
"err_avail_size", "exp %ld, got %ld\n", "err_avail_size", "exp %ld, got %ld\n",
3L * rec_sz, skel->bss->avail_data); 3L * rec_sz, skel->bss->avail_data);
CHECK(skel->bss->ring_size != 4096, CHECK(skel->bss->ring_size != page_size,
"err_ring_size", "exp %ld, got %ld\n", "err_ring_size", "exp %ld, got %ld\n",
4096L, skel->bss->ring_size); (long)page_size, skel->bss->ring_size);
CHECK(skel->bss->cons_pos != 0, CHECK(skel->bss->cons_pos != 0,
"err_cons_pos", "exp %ld, got %ld\n", "err_cons_pos", "exp %ld, got %ld\n",
0L, skel->bss->cons_pos); 0L, skel->bss->cons_pos);
......
...@@ -15,7 +15,6 @@ struct sample { ...@@ -15,7 +15,6 @@ struct sample {
struct { struct {
__uint(type, BPF_MAP_TYPE_RINGBUF); __uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 12);
} ringbuf SEC(".maps"); } ringbuf SEC(".maps");
/* inputs */ /* inputs */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册