Commit 4e59afbb authored by Ilya Leoshkevich's avatar Ilya Leoshkevich Committed by Alexei Starovoitov

selftests/bpf: skip nmi test when perf hw events are disabled

Some setups (e.g. virtual machines) might run with hardware perf events
disabled. If this is the case, skip the test_send_signal_nmi test.

Add a separate test involving a software perf event. This allows testing
the perf event path regardless of hardware perf event support.
Signed-off-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 3461a0a0
...@@ -173,6 +173,18 @@ static int test_send_signal_tracepoint(void) ...@@ -173,6 +173,18 @@ static int test_send_signal_tracepoint(void)
return test_send_signal_common(&attr, BPF_PROG_TYPE_TRACEPOINT, "tracepoint"); return test_send_signal_common(&attr, BPF_PROG_TYPE_TRACEPOINT, "tracepoint");
} }
static int test_send_signal_perf(void)
{
struct perf_event_attr attr = {
.sample_period = 1,
.type = PERF_TYPE_SOFTWARE,
.config = PERF_COUNT_SW_CPU_CLOCK,
};
return test_send_signal_common(&attr, BPF_PROG_TYPE_PERF_EVENT,
"perf_sw_event");
}
static int test_send_signal_nmi(void) static int test_send_signal_nmi(void)
{ {
struct perf_event_attr attr = { struct perf_event_attr attr = {
...@@ -181,8 +193,26 @@ static int test_send_signal_nmi(void) ...@@ -181,8 +193,26 @@ static int test_send_signal_nmi(void)
.type = PERF_TYPE_HARDWARE, .type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES, .config = PERF_COUNT_HW_CPU_CYCLES,
}; };
int pmu_fd;
/* Some setups (e.g. virtual machines) might run with hardware
* perf events disabled. If this is the case, skip this test.
*/
pmu_fd = syscall(__NR_perf_event_open, &attr, 0 /* pid */,
-1 /* cpu */, -1 /* group_fd */, 0 /* flags */);
if (pmu_fd == -1) {
if (errno == ENOENT) {
printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
__func__);
return 0;
}
/* Let the test fail with a more informative message */
} else {
close(pmu_fd);
}
return test_send_signal_common(&attr, BPF_PROG_TYPE_PERF_EVENT, "perf_event"); return test_send_signal_common(&attr, BPF_PROG_TYPE_PERF_EVENT,
"perf_hw_event");
} }
void test_send_signal(void) void test_send_signal(void)
...@@ -190,6 +220,7 @@ void test_send_signal(void) ...@@ -190,6 +220,7 @@ void test_send_signal(void)
int ret = 0; int ret = 0;
ret |= test_send_signal_tracepoint(); ret |= test_send_signal_tracepoint();
ret |= test_send_signal_perf();
ret |= test_send_signal_nmi(); ret |= test_send_signal_nmi();
if (!ret) if (!ret)
printf("test_send_signal:OK\n"); printf("test_send_signal:OK\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment