[PATCH RFC bpf-next 1/2] selftests/bpf: Add riscv support for get_preempt_count()
Pu Lehui
pulehui at huawei.com
Tue Jun 16 20:43:37 PDT 2026
On 2026/4/20 19:15, Tiezhu Yang wrote:
> There is no riscv support for get_preempt_count() currently and its
> fallback path always returns 0, just add it so that bpf_in_interrupt(),
> bpf_in_nmi(), bpf_in_hardirq(), bpf_in_serving_softirq(), bpf_in_task()
> works for riscv as well. With this patch, "./test_progs -t exe_ctx"
> should pass on riscv.
>
> Signed-off-by: Tiezhu Yang <yangtiezhu at loongson.cn>
> ---
> tools/testing/selftests/bpf/bpf_experimental.h | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
> index 2234bd6bc9d3..e5c039bc44cb 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -505,6 +505,8 @@ static inline int get_preempt_count(void)
> return bpf_get_current_task_btf()->thread_info.preempt_count;
> #elif defined(bpf_target_s390)
> return bpf_get_lowcore()->preempt_count;
> +#elif defined(bpf_target_riscv)
> + return bpf_get_current_task_btf()->thread_info.preempt_count;
> #endif
> return 0;
> }
> @@ -515,6 +517,7 @@ static inline int get_preempt_count(void)
> * * arm64
> * * powerpc64
> * * s390x
> + * * riscv
> */
> static inline int bpf_in_interrupt(void)
> {
> @@ -536,6 +539,7 @@ static inline int bpf_in_interrupt(void)
> * * arm64
> * * powerpc64
> * * s390x
> + * * riscv
> */
> static inline int bpf_in_nmi(void)
> {
> @@ -548,6 +552,7 @@ static inline int bpf_in_nmi(void)
> * * arm64
> * * powerpc64
> * * s390x
> + * * riscv
> */
> static inline int bpf_in_hardirq(void)
> {
> @@ -560,6 +565,7 @@ static inline int bpf_in_hardirq(void)
> * * arm64
> * * powerpc64
> * * s390x
> + * * riscv
> */
> static inline int bpf_in_serving_softirq(void)
> {
> @@ -580,6 +586,7 @@ static inline int bpf_in_serving_softirq(void)
> * * arm64
> * * powerpc64
> * * s390x
> + * * riscv
> */
> static inline int bpf_in_task(void)
> {
Hi Tiezhu,
Thanks for doing this, feel free to add:
Tested-by: Pu Lehui <pulehui at huawei.com>
Reviewed-by: Pu Lehui <pulehui at huawei.com>
More information about the linux-riscv
mailing list