This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a3d839ea7d8355181c1153639a6d8ad50c47646c Author: yintao <[email protected]> AuthorDate: Wed Nov 25 23:26:39 2026 +0800 drivers/rpmsg: keep the global state per CPU in BMP mode Under CONFIG_BMP every CPU runs its own kernel instance, so the rpmsg device and callback lists, their lock, the global work queues, the procfs filter and the trace lock must be private to each CPU. Define them with DEFINE_PER_CPU_BMP(), which leaves them plain globals when BMP is off. A per-CPU copy cannot be initialised statically to point at itself, so the two list heads are initialised from the new rpmsg_early_initialize(), called by drivers_early_initialize(). Signed-off-by: yintao <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- drivers/drivers_initialize.c | 4 ++++ drivers/rpmsg/rpmsg.c | 21 +++++++++++++++++---- drivers/rpmsg/rpmsg_procfs.c | 5 ++++- drivers/rpmsg/rpmsg_trace.c | 4 +++- include/nuttx/rpmsg/rpmsg.h | 1 + 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/drivers_initialize.c b/drivers/drivers_initialize.c index 2c302e8e60c..b089da099c3 100644 --- a/drivers/drivers_initialize.c +++ b/drivers/drivers_initialize.c @@ -101,6 +101,10 @@ void drivers_early_initialize(void) { +#ifdef CONFIG_RPMSG + rpmsg_early_initialize(); +#endif + #ifdef CONFIG_DRIVERS_NOTE note_early_initialize(); #endif diff --git a/drivers/rpmsg/rpmsg.c b/drivers/rpmsg/rpmsg.c index 723784ab6a6..4a1a2052499 100644 --- a/drivers/rpmsg/rpmsg.c +++ b/drivers/rpmsg/rpmsg.c @@ -41,6 +41,7 @@ #include <nuttx/mm/mempool.h> #include <nuttx/mutex.h> #include <nuttx/nuttx.h> +#include <nuttx/percpu.h> #include <nuttx/rwsem.h> #include <nuttx/semaphore.h> #include <nuttx/spinlock.h> @@ -102,10 +103,14 @@ static int rpmsg_dev_ioctl(FAR struct file *filep, int cmd, * Private Data ****************************************************************************/ -static struct list_node g_rpmsg_cb = LIST_INITIAL_VALUE(g_rpmsg_cb); -static struct list_node g_rpmsg = LIST_INITIAL_VALUE(g_rpmsg); +static DEFINE_PER_CPU_BSS_BMP(struct list_node, g_rpmsg_cb); +#define g_rpmsg_cb this_cpu_var_bmp(g_rpmsg_cb) -static rw_semaphore_t g_rpmsg_lock = RWSEM_INITIALIZER; +static DEFINE_PER_CPU_BSS_BMP(struct list_node, g_rpmsg); +#define g_rpmsg this_cpu_var_bmp(g_rpmsg) + +static DEFINE_PER_CPU_BMP(rw_semaphore_t, g_rpmsg_lock) = RWSEM_INITIALIZER; +#define g_rpmsg_lock this_cpu_var_bmp(g_rpmsg_lock) #if CONFIG_RPMSG_POOL_COUNT > 0 MEMPOOL_DEFINE(g_rpmsg_pool, CONFIG_RPMSG_POOL_SIZE, @@ -113,7 +118,9 @@ MEMPOOL_DEFINE(g_rpmsg_pool, CONFIG_RPMSG_POOL_SIZE, #endif #ifdef CONFIG_RPMSG_WQUEUE_GLOBAL -static struct rpmsg_wqueue_s g_rpmsg_wqueues[CONFIG_RPMSG_WQUEUE_NUMBER]; +static DEFINE_PER_CPU_BSS_BMP(struct rpmsg_wqueue_s, + g_rpmsg_wqueues[CONFIG_RPMSG_WQUEUE_NUMBER]); +#define g_rpmsg_wqueues this_cpu_var_bmp(g_rpmsg_wqueues) static spinlock_t g_rpmsg_wqueue_lock = SP_UNLOCKED; #endif @@ -392,6 +399,12 @@ void rpmsg_rx_worker(FAR void *arg) worker(rpmsg, arg); } +void rpmsg_early_initialize(void) +{ + list_initialize(&g_rpmsg); + list_initialize(&g_rpmsg_cb); +} + void rpmsg_initialize(void) { rpmsg_procfs_initialize(); diff --git a/drivers/rpmsg/rpmsg_procfs.c b/drivers/rpmsg/rpmsg_procfs.c index 49b7f2b6bbf..7e6ddebd3ff 100644 --- a/drivers/rpmsg/rpmsg_procfs.c +++ b/drivers/rpmsg/rpmsg_procfs.c @@ -39,6 +39,7 @@ #include <nuttx/fs/procfs.h> #include <nuttx/kmalloc.h> #include <nuttx/nuttx.h> +#include <nuttx/percpu.h> #include <nuttx/rpmsg/rpmsg.h> #include "rpmsg.h" @@ -123,7 +124,9 @@ static const struct procfs_entry_s g_rpmsg_procfs_root = /* Endpoint name pattern rpmsg_trace() records, empty to record all */ -static char g_rpmsg_procfs_filter[RPMSG_PROCFS_LINELEN]; +static DEFINE_PER_CPU_BSS_BMP(char, + g_rpmsg_procfs_filter[RPMSG_PROCFS_LINELEN]); +#define g_rpmsg_procfs_filter this_cpu_var_bmp(g_rpmsg_procfs_filter) /**************************************************************************** * Private Functions diff --git a/drivers/rpmsg/rpmsg_trace.c b/drivers/rpmsg/rpmsg_trace.c index f48bdd8eba3..3391b2e24f6 100644 --- a/drivers/rpmsg/rpmsg_trace.c +++ b/drivers/rpmsg/rpmsg_trace.c @@ -33,6 +33,7 @@ #include <stdio.h> #include <execinfo.h> +#include <nuttx/percpu.h> #include <nuttx/sched_note.h> #include <nuttx/spinlock.h> #include <nuttx/streams.h> @@ -58,7 +59,8 @@ * note stream when several CPUs trace at the same time. */ -static spinlock_t g_rpmsg_trace_lock = SP_UNLOCKED; +static DEFINE_PER_CPU_BMP(spinlock_t, g_rpmsg_trace_lock) = SP_UNLOCKED; +#define g_rpmsg_trace_lock this_cpu_var_bmp(g_rpmsg_trace_lock) /**************************************************************************** * Public Functions diff --git a/include/nuttx/rpmsg/rpmsg.h b/include/nuttx/rpmsg/rpmsg.h index 1b1608373d0..a650fb52acf 100644 --- a/include/nuttx/rpmsg/rpmsg.h +++ b/include/nuttx/rpmsg/rpmsg.h @@ -132,6 +132,7 @@ extern "C" { #endif +void rpmsg_early_initialize(void); void rpmsg_initialize(void); int rpmsg_tickwait(FAR struct rpmsg_endpoint *ept, FAR sem_t *sem,
