]> www.infradead.org Git - users/jedix/linux-maple.git/commit
selftests/bpf: Add test case for atomic update of fd htab
authorHou Tao <houtao1@huawei.com>
Tue, 1 Apr 2025 06:22:50 +0000 (14:22 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 10 Apr 2025 03:12:54 +0000 (20:12 -0700)
commit7c6fb1cf33fb9a7b89a0d9feada957d0fe56de6f
treee9e00761dd4013c0d79131ba93ab6993c30d6260
parent6704b1e8cfc5eed264065735fe00a1dd8a0bffef
selftests/bpf: Add test case for atomic update of fd htab

Add a test case to verify the atomic update of existing elements in the
htab of maps. The test proceeds in three steps:

1) fill the outer map with keys in the range [0, 8]
For each inner array map, the value of its first element is set as the
key used to lookup the inner map.

2) create 16 threads to lookup these keys concurrently
Each lookup thread first lookups the inner map, then it checks whether
the first value of the inner array map is the same as the key used to
lookup the inner map.

3) create 8 threads to overwrite these keys concurrently
Each update thread first creates an inner array, it sets the first value
of the array to the key used to update the outer map, then it uses the
key and the inner map to update the outer map.

Without atomic update support, the lookup operation may return -ENOENT
during the lookup of outer map, or return -EINVAL during the comparison
of the first value in the inner map and the key used for inner map, and
the test will fail. After the atomic update change, both the lookup and
the comparison will succeed.

Given that the update of outer map is slow, the test case sets the loop
number for each thread as 5 to reduce the total running time. However,
the loop number could also be adjusted through FD_HTAB_LOOP_NR
environment variable.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20250401062250.543403-7-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/fd_htab_lookup.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/fd_htab_lookup.c [new file with mode: 0644]