OSDN Git Service

Improve perf related BPF tests (sample_freq issue)
authorMykola Lysenko <mykolal@fb.com>
Tue, 8 Mar 2022 20:04:47 +0000 (12:04 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 9 Mar 2022 01:39:28 +0000 (17:39 -0800)
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
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
tools/testing/selftests/bpf/prog_tests/find_vma.c
tools/testing/selftests/bpf/prog_tests/perf_branches.c
tools/testing/selftests/bpf/prog_tests/perf_link.c

index cd10df6..0612e79 100644 (file)
@@ -199,7 +199,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
        attr.type = PERF_TYPE_SOFTWARE;
        attr.config = PERF_COUNT_SW_CPU_CLOCK;
        attr.freq = 1;
-       attr.sample_freq = 4000;
+       attr.sample_freq = 1000;
        pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
        if (!ASSERT_GE(pfd, 0, "perf_fd"))
                goto cleanup;
index b74b3c0..743a094 100644 (file)
@@ -30,7 +30,7 @@ static int open_pe(void)
        attr.type = PERF_TYPE_HARDWARE;
        attr.config = PERF_COUNT_HW_CPU_CYCLES;
        attr.freq = 1;
-       attr.sample_freq = 4000;
+       attr.sample_freq = 1000;
        pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC);
 
        return pfd >= 0 ? pfd : -errno;
index 12c4f45..bc24f83 100644 (file)
@@ -110,7 +110,7 @@ static void test_perf_branches_hw(void)
        attr.type = PERF_TYPE_HARDWARE;
        attr.config = PERF_COUNT_HW_CPU_CYCLES;
        attr.freq = 1;
-       attr.sample_freq = 4000;
+       attr.sample_freq = 1000;
        attr.sample_type = PERF_SAMPLE_BRANCH_STACK;
        attr.branch_sample_type = PERF_SAMPLE_BRANCH_USER | PERF_SAMPLE_BRANCH_ANY;
        pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
@@ -151,7 +151,7 @@ static void test_perf_branches_no_hw(void)
        attr.type = PERF_TYPE_SOFTWARE;
        attr.config = PERF_COUNT_SW_CPU_CLOCK;
        attr.freq = 1;
-       attr.sample_freq = 4000;
+       attr.sample_freq = 1000;
        pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
        if (CHECK(pfd < 0, "perf_event_open", "err %d\n", pfd))
                return;
index ede0734..224eba6 100644 (file)
@@ -39,7 +39,7 @@ void serial_test_perf_link(void)
        attr.type = PERF_TYPE_SOFTWARE;
        attr.config = PERF_COUNT_SW_CPU_CLOCK;
        attr.freq = 1;
-       attr.sample_freq = 4000;
+       attr.sample_freq = 1000;
        pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
        if (!ASSERT_GE(pfd, 0, "perf_fd"))
                goto cleanup;