Skip to contentSkip to conversation

selftests/bpf: Add powerpc support for get_preempt_count() in selftest

PATCH Superseded Saket Kumar Bhaskar 3 participants 3 messages Jan 29 – Jan 30

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: Add powerpc support for get_preempt_count() in selftest

get_preempt_count() is enabled to return preempt_count for powerpc, so that bpf_in_interrupt()/get_preempt_count() works for powerpc as well.

---
 tools/testing/selftests/bpf/bpf_experimental.h | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/bpf_experimental.h +2 -0
index 2cd9165c7348..c3f039a878f3 100644
@@ -630,6 +630,8 @@ static inline int get_preempt_count(void)
 	return *(int *) bpf_this_cpu_ptr(&__preempt_count);
 #elif defined(bpf_target_arm64)
 	return bpf_get_current_task_btf()->thread_info.preempt.count;
+#elif defined(bpf_target_powerpc)
+	return bpf_get_current_task_btf()->thread_info.preempt_count;
 #endif
 	return 0;
 }
Signature · 1 line
2.52.0
#1 lore raw
Now that get_preempt_count() supports PowerPC, should the documentation comments for bpf_in_interrupt(), bpf_in_nmi(), bpf_in_hardirq(), bpf_in_serving_softirq(), and bpf_in_task() be updated to…

tools/testing/selftests/bpf/bpf_experimental.h static inline int get_preempt_count(void) · line 634

Quoted 13 lines
tools/testing/selftests/bpf/bpf_experimental.h +2 -0
index a39576c8ba..147bbf6cd3 100644
@@ -627,6 +627,8 @@ static inline int get_preempt_count(void)
 	return *(int *) bpf_this_cpu_ptr(&__preempt_count);
 #elif defined(bpf_target_arm64)
 	return bpf_get_current_task_btf()->thread_info.preempt.count;
+#elif defined(bpf_target_powerpc)
+	return bpf_get_current_task_btf()->thread_info.preempt_count;
 #endif
 	return 0;
 }

Now that get_preempt_count() supports PowerPC, should the documentation comments for bpf_in_interrupt(), bpf_in_nmi(), bpf_in_hardirq(), bpf_in_serving_softirq(), and bpf_in_task() be updated to include PowerPC in their supported architecture lists? Currently these comments still say "Only works on the following archs: x86, arm64" but they now also work on PowerPC via this change to get_preempt_count().

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21467281843

AI-authorship-score: low
AI-authorship-explanation: Straightforward kernel patch with natural technical writing style and minimal code changes consistent with human-authored commits.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Documentation comments not updated to reflect PowerPC support in helper functions; minor documentation mismatch in test code.

Tested-by on v1 1/1
#2 lore raw
In reply to Saket Kumar Bhaskar
Quoted 14 lines · Saket Kumar Bhaskar

get_preempt_count() is enabled to return preempt_count for powerpc, so that bpf_in_interrupt()/get_preempt_count() works for powerpc as well.

---
  tools/testing/selftests/bpf/bpf_experimental.h | 2 ++
  1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/bpf_experimental.h +0 -0
index 2cd9165c7348..c3f039a878f3 100644

tools/testing/selftests/bpf/bpf_experimental.h static inline int get_preempt_count(void) · line 637

Quoted 8 lines
tools/testing/selftests/bpf/bpf_experimental.h +2 -0
@@ -630,6 +630,8 @@ static inline int get_preempt_count(void)
  	return *(int *) bpf_this_cpu_ptr(&__preempt_count);
  #elif defined(bpf_target_arm64)
  	return bpf_get_current_task_btf()->thread_info.preempt.count;
+#elif defined(bpf_target_powerpc)
+	return bpf_get_current_task_btf()->thread_info.preempt_count;
  #endif
  	return 0;
  }

Tested this patch by applying on mainline kernel and it passes the below selftest.

./test_progs -t timer_interrupt
#481     timer_interrupt:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Please add below tag.

Regards,

Venkat.