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 87b036eea0229c6092d651cf7c7c24eb4cd75988
Author: hujun5 <[email protected]>
AuthorDate: Fri Nov 21 22:10:48 2025 +0800

    percpu: remove irq.h and include arch.h to access up_cpu_index
    
    percpu.h includes arch/arch.h for up_cpu_index() instead of including
    irq.h at the end of the file. An architecture that keeps the per-CPU
    base in a register can override this_cpu_var() and this_cpu_var_user().
    
    Signed-off-by: buxiasen <[email protected]>
    Signed-off-by: hujun5 <[email protected]>
---
 include/nuttx/percpu.h    | 21 ++++++++-------------
 include/nuttx/userspace.h | 12 ++++++++++--
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/include/nuttx/percpu.h b/include/nuttx/percpu.h
index 00c39ee9334..683007b18e3 100644
--- a/include/nuttx/percpu.h
+++ b/include/nuttx/percpu.h
@@ -30,6 +30,8 @@
 #include <nuttx/config.h>
 #include <nuttx/compiler.h>
 
+#include <arch/arch.h>
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
@@ -87,8 +89,12 @@ 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 * this_cpu()))
+#  define per_cpu_var_smp(v, c)        (*(FAR typeof(v) *)((uintptr_t)&(v) + 
PERCPU_OFFSET * (c)))
+#  ifndef up_this_cpu_var
+#    define this_cpu_var(v)              (*(FAR typeof(v) *)((uintptr_t)&(v) + 
PERCPU_OFFSET * this_cpu()))
+#  else
+#    define this_cpu_var(v)              up_this_cpu_var(v)
+#endif
 #endif
 
 #ifdef CONFIG_SMP
@@ -115,15 +121,4 @@ 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
diff --git a/include/nuttx/userspace.h b/include/nuttx/userspace.h
index af510171af8..4d4b66b9d6e 100644
--- a/include/nuttx/userspace.h
+++ b/include/nuttx/userspace.h
@@ -76,10 +76,18 @@
 #  define this_cpu_var_user(v)       v[this_cpu()]
 #elif defined(__KERNEL__)
 #  define per_cpu_var_user_smp(v, c) (*(FAR typeof(v) *)((uintptr_t)&(v) + 
USERSPACE->us_offset_percpu * (c)))
-#  define this_cpu_var_user(v)       (*(FAR typeof(v) *)((uintptr_t)&(v) + 
USERSPACE->us_offset_percpu * this_cpu()))
+#  ifndef up_this_cpu_var_user
+#    define this_cpu_var_user(v)       (*(FAR typeof(v) *)((uintptr_t)&(v) + 
USERSPACE->us_offset_percpu * this_cpu()))
+#  else
+#    define this_cpu_var_user(v)       up_this_cpu_var_user(v)
+#  endif
 #else
 #  define per_cpu_var_user_smp(v, c) (*(FAR typeof(v) *)((uintptr_t)&(v) + 
PERCPU_OFFSET * (c)))
-#  define this_cpu_var_user(v)       (*(FAR typeof(v) *)((uintptr_t)&(v) + 
PERCPU_OFFSET * this_cpu()))
+#  ifndef up_this_cpu_var_user
+#    define this_cpu_var_user(v)       (*(FAR typeof(v) *)((uintptr_t)&(v) + 
PERCPU_OFFSET * this_cpu()))
+#  else
+#    define this_cpu_var_user(v)       up_this_cpu_var_user(v)
+#  endif
 #endif
 
 #ifdef CONFIG_SMP

Reply via email to