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
The following commit(s) were added to refs/heads/master by this push:
new f6c6e5846e8 drivers/reset: make the controller list per-CPU under BMP
f6c6e5846e8 is described below
commit f6c6e5846e8c44bae2f3abd070c87eb251a990c4
Author: wangshaoxin <[email protected]>
AuthorDate: Tue Sep 8 19:26:21 2026 +0800
drivers/reset: make the controller list per-CPU under BMP
Under BMP every core runs its own scheduler out of one shared image, so a
plain global is shared between cores. That is wrong for both the reset
controller list and its lock: a controller is registered by, and belongs
to, one core, and a NuttX mutex belongs to one scheduler instance, so
blocking on it across cores is not something the kernel supports.
Move both into per-CPU storage. The controller list becomes a dq queue on
the way: a circular list_node head cannot keep a static initialiser in
per-CPU storage, where that initialiser would point every core's copy at
the first core's head, while a zeroed dq head is already a valid empty
queue and needs no initialisation at all.
Convert the other framework list too, of the reset controls requested from
one controller, so the framework uses one list flavour throughout and
reset-controller.h no longer pulls in both list.h and queue.h. A dq head
has to be handed to dq_rem(), which reset_control_put_internal() takes from
rstc->rcdev, the same pointer it already uses for the release op on the
next line. Insertion moves from the head of the list to the tail, which
nothing depends on: this list is only ever walked to match a line id.
Nothing changes for AMP or UP builds, where the per-CPU macros collapse
to plain globals, one per image.
Signed-off-by: wangshaoxin <[email protected]>
---
drivers/reset/core.c | 46 ++++++++++++++++++++++------------
include/nuttx/reset/reset-controller.h | 8 +++---
include/nuttx/reset/reset.h | 4 +--
3 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index f313cca67dc..db581460296 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -30,6 +30,9 @@
#include <nuttx/nuttx.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/mutex.h>
+#include <nuttx/percpu.h>
+#include <nuttx/queue.h>
#include <nuttx/reset/reset.h>
#include <nuttx/reset/reset-controller.h>
@@ -46,9 +49,20 @@
* Private Data
****************************************************************************/
-static struct list_node
-g_reset_controller_list = LIST_INITIAL_VALUE(g_reset_controller_list);
-static mutex_t g_reset_list_mutex = NXMUTEX_INITIALIZER;
+/* The controller list and its lock are per-CPU: under BMP each core runs its
+ * own scheduler off a shared image, so a controller belongs to the core that
+ * registered it and the lock must not be shared across cores either.
+ *
+ * The list is a dq queue rather than a list_node: a circular head cannot be
+ * initialised statically in per-CPU storage, where the initialiser would
+ * point every core's copy at the first core's head, while a zeroed dq head
+ * is already a valid empty queue.
+ */
+
+static DEFINE_PER_CPU_BSS_BMP(dq_queue_t, g_reset_controller_list);
+#define g_reset_controller_list this_cpu_var_bmp(g_reset_controller_list)
+static DEFINE_PER_CPU_BMP(mutex_t, g_reset_list_mutex) = NXMUTEX_INITIALIZER;
+#define g_reset_list_mutex this_cpu_var_bmp(g_reset_list_mutex)
/****************************************************************************
* Private Types
@@ -272,8 +286,8 @@ reset_control_get_internal(FAR struct reset_controller_dev
*rcdev,
DEBUGASSERT(nxmutex_is_locked(&g_reset_list_mutex));
- list_for_every_entry(&rcdev->reset_control_head, rstc,
- struct reset_control, list)
+ dq_for_every_entry(&rcdev->reset_control_head, rstc,
+ struct reset_control, list)
{
if (rstc->id == index)
{
@@ -323,7 +337,7 @@ reset_control_get_internal(FAR struct reset_controller_dev
*rcdev,
#endif
rstc->rcdev = rcdev;
- list_add_after(&rcdev->reset_control_head, &rstc->list);
+ dq_addlast(&rstc->list, &rcdev->reset_control_head);
rstc->id = index;
atomic_set(&rstc->refcnt, 1);
rstc->acquired = acquired;
@@ -350,7 +364,7 @@ static void reset_control_put_internal(FAR struct
reset_control *rstc)
if (atomic_sub(&rstc->refcnt, 1) == 1)
{
DEBUGASSERT(nxmutex_is_locked(&g_reset_list_mutex));
- list_delete(&rstc->list);
+ dq_rem(&rstc->list, &rstc->rcdev->reset_control_head);
#if defined(CONFIG_RESET_RPMSG)
@@ -412,8 +426,8 @@ reset_controller_get_by_name(FAR const char *name)
FAR struct reset_controller_dev *rcdev;
nxmutex_lock(&g_reset_list_mutex);
- list_for_every_entry(&g_reset_controller_list, rcdev,
- struct reset_controller_dev, list)
+ dq_for_every_entry(&g_reset_controller_list, rcdev,
+ struct reset_controller_dev, list)
{
if (!strcmp(name, rcdev->name))
{
@@ -625,8 +639,8 @@ static ssize_t reset_procfs_read(FAR struct file *filep,
return ret;
}
- list_for_every_entry(&g_reset_controller_list, rcdev,
- struct reset_controller_dev, list)
+ dq_for_every_entry(&g_reset_controller_list, rcdev,
+ struct reset_controller_dev, list)
{
if (remaining == 0)
{
@@ -1151,8 +1165,8 @@ int reset_control_acquire(FAR struct reset_control *rstc)
return 0;
}
- list_for_every_entry(&rstc->rcdev->reset_control_head, rc,
- struct reset_control, list)
+ dq_for_every_entry(&rstc->rcdev->reset_control_head, rc,
+ struct reset_control, list)
{
if (rstc != rc && rstc->id == rc->id)
{
@@ -1348,7 +1362,7 @@ int reset_controller_register(FAR struct
reset_controller_dev *rcdev)
return -EINVAL;
}
- list_initialize(&rcdev->reset_control_head);
+ dq_init(&rcdev->reset_control_head);
nxmutex_lock(&g_reset_list_mutex);
@@ -1366,7 +1380,7 @@ int reset_controller_register(FAR struct
reset_controller_dev *rcdev)
}
#endif
- list_add_after(&g_reset_controller_list, &rcdev->list);
+ dq_addlast(&rcdev->list, &g_reset_controller_list);
nxmutex_unlock(&g_reset_list_mutex);
return 0;
@@ -1385,7 +1399,7 @@ int reset_controller_register(FAR struct
reset_controller_dev *rcdev)
void reset_controller_unregister(FAR struct reset_controller_dev *rcdev)
{
nxmutex_lock(&g_reset_list_mutex);
- list_delete(&rcdev->list);
+ dq_rem(&rcdev->list, &g_reset_controller_list);
nxmutex_unlock(&g_reset_list_mutex);
}
diff --git a/include/nuttx/reset/reset-controller.h
b/include/nuttx/reset/reset-controller.h
index 24e3d4ecf13..4f634587058 100644
--- a/include/nuttx/reset/reset-controller.h
+++ b/include/nuttx/reset/reset-controller.h
@@ -30,7 +30,7 @@
#include <nuttx/config.h>
#include <stdbool.h>
-#include <nuttx/list.h>
+#include <nuttx/queue.h>
#include <nuttx/compiler.h>
/****************************************************************************
@@ -105,7 +105,7 @@ struct reset_control_ops
* provide multiple reset controls
* name a reset controller device name
* ops: a pointer to device specific struct reset_control_ops
- * list: internal list of reset controller devices
+ * list: node in the per-CPU list of reset controller devices
* reset_control_head: head of internal list of requested reset controls
* nlines: the id space, so get_line() is asked about 0 to nlines - 1.
* Controllers commonly leave gaps, which get_line() reports, so
@@ -117,8 +117,8 @@ struct reset_controller_dev
{
FAR const char *name;
FAR const struct reset_control_ops *ops;
- struct list_node list;
- struct list_node reset_control_head;
+ dq_entry_t list;
+ dq_queue_t reset_control_head;
unsigned int nlines;
};
diff --git a/include/nuttx/reset/reset.h b/include/nuttx/reset/reset.h
index be5f2718569..550e673cb8b 100644
--- a/include/nuttx/reset/reset.h
+++ b/include/nuttx/reset/reset.h
@@ -31,7 +31,7 @@
#include <stdbool.h>
#include <nuttx/atomic.h>
-#include <nuttx/list.h>
+#include <nuttx/queue.h>
/****************************************************************************
* Public Types
@@ -58,7 +58,7 @@ struct reset_controller_dev;
struct reset_control
{
FAR struct reset_controller_dev *rcdev;
- struct list_node list;
+ dq_entry_t list;
unsigned int id;
atomic_t refcnt;
bool acquired;