BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Skip test when perf_event_open returns EOPNOTSUPP
@ 2024-04-01 12:33 Pu Lehui
  2024-04-01 15:29 ` Yonghong Song
  0 siblings, 1 reply; 5+ messages in thread
From: Pu Lehui @ 2024-04-01 12:33 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Mykola Lysenko, Pu Lehui, Pu Lehui

From: Pu Lehui <pulehui@huawei.com>

For the bpf selftest, the semantics of perf_event_open returning ENOENT
and EOPNOTSUPP imply that continuing the test is meaningless. Let’s skip
test when perf_event_open returns EOPNOTSUPP, which has already been
skipped in other test cases.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
 tools/testing/selftests/bpf/prog_tests/send_signal.c            | 2 +-
 .../testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c
index b15b343ebb6b..920aee41bd58 100644
--- a/tools/testing/selftests/bpf/prog_tests/send_signal.c
+++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c
@@ -179,7 +179,7 @@ static void test_send_signal_nmi(bool signal_thread)
 	pmu_fd = syscall(__NR_perf_event_open, &attr, 0 /* pid */,
 			 -1 /* cpu */, -1 /* group_fd */, 0 /* flags */);
 	if (pmu_fd == -1) {
-		if (errno == ENOENT) {
+		if (errno == ENOENT || errno == EOPNOTSUPP) {
 			printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
 			       __func__);
 			test__skip();
diff --git a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
index 5db9eec24b5b..0832fd787457 100644
--- a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
+++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
@@ -35,7 +35,7 @@ void test_stacktrace_build_id_nmi(void)
 	pmu_fd = syscall(__NR_perf_event_open, &attr, -1 /* pid */,
 			 0 /* cpu 0 */, -1 /* group id */,
 			 0 /* flags */);
-	if (pmu_fd < 0 && errno == ENOENT) {
+	if (pmu_fd < 0 && (errno == ENOENT || errno == EOPNOTSUPP)) {
 		printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__);
 		test__skip();
 		goto cleanup;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Skip test when perf_event_open returns EOPNOTSUPP
  2024-04-01 12:33 [PATCH bpf-next] selftests/bpf: Skip test when perf_event_open returns EOPNOTSUPP Pu Lehui
@ 2024-04-01 15:29 ` Yonghong Song
  2024-04-02  2:22   ` Pu Lehui
  0 siblings, 1 reply; 5+ messages in thread
From: Yonghong Song @ 2024-04-01 15:29 UTC (permalink / raw)
  To: Pu Lehui, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Mykola Lysenko,
	Pu Lehui


On 4/1/24 5:33 AM, Pu Lehui wrote:
> From: Pu Lehui <pulehui@huawei.com>
>
> For the bpf selftest, the semantics of perf_event_open returning ENOENT
> and EOPNOTSUPP imply that continuing the test is meaningless. Let’s skip
> test when perf_event_open returns EOPNOTSUPP, which has already been
> skipped in other test cases.

Could you explain when EOPNOTSUPP is returned for these two tests?
Is this riscv specific? If the EOPNOTSUPP is returned due to missing
config in tools/testing/selftests/bpf/config, we should add that to
ensure the test can execute properly.

>
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> ---
>   tools/testing/selftests/bpf/prog_tests/send_signal.c            | 2 +-
>   .../testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c  | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c
> index b15b343ebb6b..920aee41bd58 100644
> --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c
> +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c
> @@ -179,7 +179,7 @@ static void test_send_signal_nmi(bool signal_thread)
>   	pmu_fd = syscall(__NR_perf_event_open, &attr, 0 /* pid */,
>   			 -1 /* cpu */, -1 /* group_fd */, 0 /* flags */);
>   	if (pmu_fd == -1) {
> -		if (errno == ENOENT) {
> +		if (errno == ENOENT || errno == EOPNOTSUPP) {
>   			printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
>   			       __func__);
>   			test__skip();
> diff --git a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
> index 5db9eec24b5b..0832fd787457 100644
> --- a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
> +++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
> @@ -35,7 +35,7 @@ void test_stacktrace_build_id_nmi(void)
>   	pmu_fd = syscall(__NR_perf_event_open, &attr, -1 /* pid */,
>   			 0 /* cpu 0 */, -1 /* group id */,
>   			 0 /* flags */);
> -	if (pmu_fd < 0 && errno == ENOENT) {
> +	if (pmu_fd < 0 && (errno == ENOENT || errno == EOPNOTSUPP)) {
>   		printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__);
>   		test__skip();
>   		goto cleanup;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Skip test when perf_event_open returns EOPNOTSUPP
  2024-04-01 15:29 ` Yonghong Song
@ 2024-04-02  2:22   ` Pu Lehui
  2024-04-02  6:16     ` Yonghong Song
  0 siblings, 1 reply; 5+ messages in thread
From: Pu Lehui @ 2024-04-02  2:22 UTC (permalink / raw)
  To: Yonghong Song, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Mykola Lysenko,
	Pu Lehui



On 2024/4/1 23:29, Yonghong Song wrote:
> 
> On 4/1/24 5:33 AM, Pu Lehui wrote:
>> From: Pu Lehui <pulehui@huawei.com>
>>
>> For the bpf selftest, the semantics of perf_event_open returning ENOENT
>> and EOPNOTSUPP imply that continuing the test is meaningless. Let’s skip
>> test when perf_event_open returns EOPNOTSUPP, which has already been
>> skipped in other test cases.
> 
> Could you explain when EOPNOTSUPP is returned for these two tests?
> Is this riscv specific? If the EOPNOTSUPP is returned due to missing
> config in tools/testing/selftests/bpf/config, we should add that to
> ensure the test can execute properly.
> 

Hello Yonghong, I tested on riscv but it is not unique to riscv. When 
the perf driver does not support sampling events, perf_event_open will 
return EOPNOTSUPP, that is, PERF_PMU_CAP_NO_INTERRUPT is set to the pmu 
capabilities. This is no problem with riscv with sscofpmf extension and 
sbi pmu driver. I found that PERF_PMU_CAP_NO_INTERRUPT is set not only 
in the riscv-related perf driver. At the same time, it is possible to 
return EOPNOTSUPP about PERF_PMU_CAP_AUX_OUTPUT on the path of 
perf_event_open. I think it resonable to skip such use cases for 
functions not supported by non-bpf modules, what do you think?

>>
>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>> ---
>>   tools/testing/selftests/bpf/prog_tests/send_signal.c            | 2 +-
>>   .../testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c  | 2 +-
>>   2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c 
>> b/tools/testing/selftests/bpf/prog_tests/send_signal.c
>> index b15b343ebb6b..920aee41bd58 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c
>> @@ -179,7 +179,7 @@ static void test_send_signal_nmi(bool signal_thread)
>>       pmu_fd = syscall(__NR_perf_event_open, &attr, 0 /* pid */,
>>                -1 /* cpu */, -1 /* group_fd */, 0 /* flags */);
>>       if (pmu_fd == -1) {
>> -        if (errno == ENOENT) {
>> +        if (errno == ENOENT || errno == EOPNOTSUPP) {
>>               printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
>>                      __func__);
>>               test__skip();
>> diff --git 
>> a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c 
>> b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>> index 5db9eec24b5b..0832fd787457 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>> @@ -35,7 +35,7 @@ void test_stacktrace_build_id_nmi(void)
>>       pmu_fd = syscall(__NR_perf_event_open, &attr, -1 /* pid */,
>>                0 /* cpu 0 */, -1 /* group id */,
>>                0 /* flags */);
>> -    if (pmu_fd < 0 && errno == ENOENT) {
>> +    if (pmu_fd < 0 && (errno == ENOENT || errno == EOPNOTSUPP)) {
>>           printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__);
>>           test__skip();
>>           goto cleanup;


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Skip test when perf_event_open returns EOPNOTSUPP
  2024-04-02  2:22   ` Pu Lehui
@ 2024-04-02  6:16     ` Yonghong Song
  2024-04-02  6:32       ` Pu Lehui
  0 siblings, 1 reply; 5+ messages in thread
From: Yonghong Song @ 2024-04-02  6:16 UTC (permalink / raw)
  To: Pu Lehui, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Mykola Lysenko,
	Pu Lehui


On 4/1/24 7:22 PM, Pu Lehui wrote:
>
>
> On 2024/4/1 23:29, Yonghong Song wrote:
>>
>> On 4/1/24 5:33 AM, Pu Lehui wrote:
>>> From: Pu Lehui <pulehui@huawei.com>
>>>
>>> For the bpf selftest, the semantics of perf_event_open returning ENOENT
>>> and EOPNOTSUPP imply that continuing the test is meaningless. Let’s 
>>> skip
>>> test when perf_event_open returns EOPNOTSUPP, which has already been
>>> skipped in other test cases.
>>
>> Could you explain when EOPNOTSUPP is returned for these two tests?
>> Is this riscv specific? If the EOPNOTSUPP is returned due to missing
>> config in tools/testing/selftests/bpf/config, we should add that to
>> ensure the test can execute properly.
>>
>
> Hello Yonghong, I tested on riscv but it is not unique to riscv. When 
> the perf driver does not support sampling events, perf_event_open will 
> return EOPNOTSUPP, that is, PERF_PMU_CAP_NO_INTERRUPT is set to the 
> pmu capabilities. This is no problem with riscv with sscofpmf 
> extension and sbi pmu driver. I found that PERF_PMU_CAP_NO_INTERRUPT 
> is set not only in the riscv-related perf driver. At the same time, it 
> is possible to return EOPNOTSUPP about PERF_PMU_CAP_AUX_OUTPUT on the 
> path of perf_event_open. I think it resonable to skip such use cases 
> for functions not supported by non-bpf modules, what do you think?

Thanks for explanation. I checked kernel/events/core.c and arch/x86/.... I agree that if hardware has capabilities PERF_PMU_CAP_NO_INTERRUPT
or PERF_PMU_CAP_AUX_OUTPUT, EOPNOTSUPP could be returned, although I think this should be extremely rare for x86 cpu's (probably only really old ones).
Several other arch's also have hardware which has capability PERF_PMU_CAP_NO_INTERRUPT, so may indeed hit this issue.

In bpf-next/arch/riscv, I didn't find usage of PERF_PMU_CAP_NO_INTERRUPT though.

Your patch looks good to me. Since you hit the issue with riscv so please describe how EOPNOTSUPP could be returned in your test. It would be a good
justification for your patch.

>
>>>
>>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>>> ---
>>> tools/testing/selftests/bpf/prog_tests/send_signal.c | 2 +-
>>> .../testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c | 2 +-
>>>   2 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c 
>>> b/tools/testing/selftests/bpf/prog_tests/send_signal.c
>>> index b15b343ebb6b..920aee41bd58 100644
>>> --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c
>>> +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c
>>> @@ -179,7 +179,7 @@ static void test_send_signal_nmi(bool 
>>> signal_thread)
>>>       pmu_fd = syscall(__NR_perf_event_open, &attr, 0 /* pid */,
>>>                -1 /* cpu */, -1 /* group_fd */, 0 /* flags */);
>>>       if (pmu_fd == -1) {
>>> -        if (errno == ENOENT) {
>>> +        if (errno == ENOENT || errno == EOPNOTSUPP) {
>>>               printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
>>>                      __func__);
>>>               test__skip();
>>> diff --git 
>>> a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c 
>>> b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>>> index 5db9eec24b5b..0832fd787457 100644
>>> --- a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>>> +++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>>> @@ -35,7 +35,7 @@ void test_stacktrace_build_id_nmi(void)
>>>       pmu_fd = syscall(__NR_perf_event_open, &attr, -1 /* pid */,
>>>                0 /* cpu 0 */, -1 /* group id */,
>>>                0 /* flags */);
>>> -    if (pmu_fd < 0 && errno == ENOENT) {
>>> +    if (pmu_fd < 0 && (errno == ENOENT || errno == EOPNOTSUPP)) {
>>>           printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__);
>>>           test__skip();
>>>           goto cleanup;
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Skip test when perf_event_open returns EOPNOTSUPP
  2024-04-02  6:16     ` Yonghong Song
@ 2024-04-02  6:32       ` Pu Lehui
  0 siblings, 0 replies; 5+ messages in thread
From: Pu Lehui @ 2024-04-02  6:32 UTC (permalink / raw)
  To: Yonghong Song, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Song Liu, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Mykola Lysenko,
	Pu Lehui



On 2024/4/2 14:16, Yonghong Song wrote:
> 
> On 4/1/24 7:22 PM, Pu Lehui wrote:
>>
>>
>> On 2024/4/1 23:29, Yonghong Song wrote:
>>>
>>> On 4/1/24 5:33 AM, Pu Lehui wrote:
>>>> From: Pu Lehui <pulehui@huawei.com>
>>>>
>>>> For the bpf selftest, the semantics of perf_event_open returning ENOENT
>>>> and EOPNOTSUPP imply that continuing the test is meaningless. Let’s 
>>>> skip
>>>> test when perf_event_open returns EOPNOTSUPP, which has already been
>>>> skipped in other test cases.
>>>
>>> Could you explain when EOPNOTSUPP is returned for these two tests?
>>> Is this riscv specific? If the EOPNOTSUPP is returned due to missing
>>> config in tools/testing/selftests/bpf/config, we should add that to
>>> ensure the test can execute properly.
>>>
>>
>> Hello Yonghong, I tested on riscv but it is not unique to riscv. When 
>> the perf driver does not support sampling events, perf_event_open will 
>> return EOPNOTSUPP, that is, PERF_PMU_CAP_NO_INTERRUPT is set to the 
>> pmu capabilities. This is no problem with riscv with sscofpmf 
>> extension and sbi pmu driver. I found that PERF_PMU_CAP_NO_INTERRUPT 
>> is set not only in the riscv-related perf driver. At the same time, it 
>> is possible to return EOPNOTSUPP about PERF_PMU_CAP_AUX_OUTPUT on the 
>> path of perf_event_open. I think it resonable to skip such use cases 
>> for functions not supported by non-bpf modules, what do you think?
> 
> Thanks for explanation. I checked kernel/events/core.c and arch/x86/.... 
> I agree that if hardware has capabilities PERF_PMU_CAP_NO_INTERRUPT
> or PERF_PMU_CAP_AUX_OUTPUT, EOPNOTSUPP could be returned, although I 
> think this should be extremely rare for x86 cpu's (probably only really 
> old ones).
> Several other arch's also have hardware which has capability 
> PERF_PMU_CAP_NO_INTERRUPT, so may indeed hit this issue.
> 
> In bpf-next/arch/riscv, I didn't find usage of PERF_PMU_CAP_NO_INTERRUPT 
> though.
> 

The riscv pmu driver is located in drivers/perf/riscv_pmu*. Sampling 
events are not supported in legacy mode, nor in sbi mode without the 
sscofpmf extension.

> Your patch looks good to me. Since you hit the issue with riscv so 
> please describe how EOPNOTSUPP could be returned in your test. It would 
> be a good
> justification for your patch.

Alright, I will patch that in next version.

> 
>>
>>>>
>>>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>>>> ---
>>>> tools/testing/selftests/bpf/prog_tests/send_signal.c | 2 +-
>>>> .../testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c | 2 +-
>>>>   2 files changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c 
>>>> b/tools/testing/selftests/bpf/prog_tests/send_signal.c
>>>> index b15b343ebb6b..920aee41bd58 100644
>>>> --- a/tools/testing/selftests/bpf/prog_tests/send_signal.c
>>>> +++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c
>>>> @@ -179,7 +179,7 @@ static void test_send_signal_nmi(bool 
>>>> signal_thread)
>>>>       pmu_fd = syscall(__NR_perf_event_open, &attr, 0 /* pid */,
>>>>                -1 /* cpu */, -1 /* group_fd */, 0 /* flags */);
>>>>       if (pmu_fd == -1) {
>>>> -        if (errno == ENOENT) {
>>>> +        if (errno == ENOENT || errno == EOPNOTSUPP) {
>>>>               printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n",
>>>>                      __func__);
>>>>               test__skip();
>>>> diff --git 
>>>> a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c 
>>>> b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>>>> index 5db9eec24b5b..0832fd787457 100644
>>>> --- a/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>>>> +++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_build_id_nmi.c
>>>> @@ -35,7 +35,7 @@ void test_stacktrace_build_id_nmi(void)
>>>>       pmu_fd = syscall(__NR_perf_event_open, &attr, -1 /* pid */,
>>>>                0 /* cpu 0 */, -1 /* group id */,
>>>>                0 /* flags */);
>>>> -    if (pmu_fd < 0 && errno == ENOENT) {
>>>> +    if (pmu_fd < 0 && (errno == ENOENT || errno == EOPNOTSUPP)) {
>>>>           printf("%s:SKIP:no PERF_COUNT_HW_CPU_CYCLES\n", __func__);
>>>>           test__skip();
>>>>           goto cleanup;
>>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-02  6:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-01 12:33 [PATCH bpf-next] selftests/bpf: Skip test when perf_event_open returns EOPNOTSUPP Pu Lehui
2024-04-01 15:29 ` Yonghong Song
2024-04-02  2:22   ` Pu Lehui
2024-04-02  6:16     ` Yonghong Song
2024-04-02  6:32       ` Pu Lehui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox