Skip to content

Commit 105eb5d

Browse files
mykyta5anakryiko
authored andcommitted
selftests/bpf: Fix flaky bpf_cookie selftest
bpf_cookie can fail on perf_event_open(), when it runs after the task_work selftest. The task_work test causes perf to lower sysctl_perf_event_sample_rate, and bpf_cookie uses sample_freq, which is validated against that sysctl. As a result, perf_event_open() rejects the attr if the (now tighter) limit is exceeded. >From perf_event_open(): if (attr.freq) { if (attr.sample_freq > sysctl_perf_event_sample_rate) return -EINVAL; } else { if (attr.sample_period & (1ULL << 63)) return -EINVAL; } Switch bpf_cookie to use sample_period, which is not checked against sysctl_perf_event_sample_rate. Signed-off-by: Mykyta Yatsenko <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 1193c46 commit 105eb5d

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_cookie.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
450450
attr.size = sizeof(attr);
451451
attr.type = PERF_TYPE_SOFTWARE;
452452
attr.config = PERF_COUNT_SW_CPU_CLOCK;
453-
attr.freq = 1;
454-
attr.sample_freq = 10000;
453+
attr.sample_period = 100000;
455454
pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
456455
if (!ASSERT_GE(pfd, 0, "perf_fd"))
457456
goto cleanup;

0 commit comments

Comments
 (0)