Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Improve perf related BPF tests (sample_freq issue)

Linux kernel may automatically reduce kernel.perf_event_max_sample_rate
value when running tests in parallel on slow systems. Linux kernel checks
against this limit when opening perf event with freq=1 parameter set.
The lower bound is 1000. This patch reduces sample_freq value to 1000
in all BPF tests that use sample_freq to ensure they always can open
perf event.

Signed-off-by: Mykola Lysenko <mykolal@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20220308200449.1757478-2-mykolal@fb.com

authored by

Mykola Lysenko and committed by
Andrii Nakryiko
d4b54054 7fd9fd46

+5 -5
+1 -1
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
··· 199 199 attr.type = PERF_TYPE_SOFTWARE; 200 200 attr.config = PERF_COUNT_SW_CPU_CLOCK; 201 201 attr.freq = 1; 202 - attr.sample_freq = 4000; 202 + attr.sample_freq = 1000; 203 203 pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); 204 204 if (!ASSERT_GE(pfd, 0, "perf_fd")) 205 205 goto cleanup;
+1 -1
tools/testing/selftests/bpf/prog_tests/find_vma.c
··· 30 30 attr.type = PERF_TYPE_HARDWARE; 31 31 attr.config = PERF_COUNT_HW_CPU_CYCLES; 32 32 attr.freq = 1; 33 - attr.sample_freq = 4000; 33 + attr.sample_freq = 1000; 34 34 pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC); 35 35 36 36 return pfd >= 0 ? pfd : -errno;
+2 -2
tools/testing/selftests/bpf/prog_tests/perf_branches.c
··· 110 110 attr.type = PERF_TYPE_HARDWARE; 111 111 attr.config = PERF_COUNT_HW_CPU_CYCLES; 112 112 attr.freq = 1; 113 - attr.sample_freq = 4000; 113 + attr.sample_freq = 1000; 114 114 attr.sample_type = PERF_SAMPLE_BRANCH_STACK; 115 115 attr.branch_sample_type = PERF_SAMPLE_BRANCH_USER | PERF_SAMPLE_BRANCH_ANY; 116 116 pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); ··· 151 151 attr.type = PERF_TYPE_SOFTWARE; 152 152 attr.config = PERF_COUNT_SW_CPU_CLOCK; 153 153 attr.freq = 1; 154 - attr.sample_freq = 4000; 154 + attr.sample_freq = 1000; 155 155 pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); 156 156 if (CHECK(pfd < 0, "perf_event_open", "err %d\n", pfd)) 157 157 return;
+1 -1
tools/testing/selftests/bpf/prog_tests/perf_link.c
··· 39 39 attr.type = PERF_TYPE_SOFTWARE; 40 40 attr.config = PERF_COUNT_SW_CPU_CLOCK; 41 41 attr.freq = 1; 42 - attr.sample_freq = 4000; 42 + attr.sample_freq = 1000; 43 43 pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC); 44 44 if (!ASSERT_GE(pfd, 0, "perf_fd")) 45 45 goto cleanup;