This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e468d2c8bba734beea58d60f36ae19a53177609d
Author: buxiasen <[email protected]>
AuthorDate: Mon Nov 10 11:39:09 2025 +0800

    percpu: always use this_cpu() for current logic cpuid
    
    this_cpu() returned 0 whenever CONFIG_SMP was off, which is wrong for
    BMP, where every CPU runs its own kernel instance. Use the logical CPU
    index unless CONFIG_UP is set, and use this_cpu() in the
    PERCPU_SECTION version of this_cpu_var() too.
    
    Signed-off-by: buxiasen <[email protected]>
---
 include/nuttx/percpu.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/include/nuttx/percpu.h b/include/nuttx/percpu.h
index dcaba008de4..00c39ee9334 100644
--- a/include/nuttx/percpu.h
+++ b/include/nuttx/percpu.h
@@ -63,7 +63,7 @@
  * These macros are intended to support a future SMP implementation.
  */
 
-#ifdef CONFIG_SMP
+#ifndef CONFIG_UP
 #  define this_cpu()                   up_this_cpu()
 #else
 #  define this_cpu()                   (0)
@@ -88,7 +88,7 @@ extern char _percpu_offset[];
 /* For BMP case per_cpu_var is not supported */
 
 #  define per_cpu_var_smp(v, c)        (*(FAR typeof(v) *)((unsigned long)&(v) 
+ PERCPU_OFFSET * (c)))
-#  define this_cpu_var(v)              (*(FAR typeof(v) *)((unsigned long)&(v) 
+ PERCPU_OFFSET * up_cpu_index()))
+#  define this_cpu_var(v)              (*(FAR typeof(v) *)((unsigned long)&(v) 
+ PERCPU_OFFSET * this_cpu()))
 #endif
 
 #ifdef CONFIG_SMP
@@ -115,4 +115,15 @@ extern char _percpu_offset[];
 #  define this_cpu_var_bmp(v)          v
 #endif
 
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/* The up_cpu_index possible a inline function, we should include to avoid
+ * dependency issue, g_interrupt_context needs percpu.h, have to put irq.h at
+ * tail of percpu.h
+ */
+
+#include <nuttx/irq.h>
+
 #endif

Reply via email to