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 b70b39aa1b9 drivers/usrsock: run usrsock over rpmsg per CPU in BMP mode
b70b39aa1b9 is described below
commit b70b39aa1b98850e7728c525e45e5804225d6a13
Author: dongjiuzhu1 <[email protected]>
AuthorDate: Wed Nov 25 23:58:17 2026 +0800
drivers/usrsock: run usrsock over rpmsg per CPU in BMP mode
Under CONFIG_BMP every CPU runs its own kernel instance from the same
image:
- The usrsock rpmsg client state, g_usrsock_rpmsg, is per CPU, so each
CPU has its own connection to the server.
- Only one CPU may host the server. The new
NET_USRSOCK_RPMSG_SERVER_CPUID selects it, and
usrsock_rpmsg_server_initialize() fails with -EINVAL on the others.
Without BMP nothing changes.
Signed-off-by: dongjiuzhu1 <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
---
drivers/usrsock/Kconfig | 8 ++++++++
drivers/usrsock/usrsock_rpmsg.c | 4 +++-
drivers/usrsock/usrsock_rpmsg_server.c | 8 ++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/usrsock/Kconfig b/drivers/usrsock/Kconfig
index cfca31a2545..520cdd44d84 100644
--- a/drivers/usrsock/Kconfig
+++ b/drivers/usrsock/Kconfig
@@ -66,6 +66,14 @@ config NET_USRSOCK_RPMSG_SERVER
if NET_USRSOCK_RPMSG_SERVER
+config NET_USRSOCK_RPMSG_SERVER_CPUID
+ int "The CPU the usrsock RPMSG server runs on"
+ depends on BMP
+ ---help---
+ In BMP mode every CPU runs the same image, so only the CPU with
+ this ID starts the usrsock RPMSG server; the others are its
+ clients.
+
config NET_USRSOCK_RPMSG_SERVER_NSOCKS
int "The maximum number of socket descriptors for usrsock monitoring"
default 64
diff --git a/drivers/usrsock/usrsock_rpmsg.c b/drivers/usrsock/usrsock_rpmsg.c
index 08ebb8c6d73..0b8cd1b5b5d 100644
--- a/drivers/usrsock/usrsock_rpmsg.c
+++ b/drivers/usrsock/usrsock_rpmsg.c
@@ -26,6 +26,7 @@
#include <nuttx/net/dns.h>
#include <nuttx/net/net.h>
+#include <nuttx/percpu.h>
#include <nuttx/rpmsg/rpmsg.h>
#include <nuttx/semaphore.h>
#include <nuttx/usrsock/usrsock_rpmsg.h>
@@ -69,10 +70,11 @@ static void usrsock_rpmsg_device_destroy(FAR struct
rpmsg_device *rdev,
* Private Data
****************************************************************************/
-static struct usrsock_rpmsg_s g_usrsock_rpmsg =
+static DEFINE_PER_CPU_BMP(struct usrsock_rpmsg_s, g_usrsock_rpmsg) =
{
SEM_INITIALIZER(0)
};
+#define g_usrsock_rpmsg this_cpu_var_bmp(g_usrsock_rpmsg)
/****************************************************************************
* Private Functions
diff --git a/drivers/usrsock/usrsock_rpmsg_server.c
b/drivers/usrsock/usrsock_rpmsg_server.c
index 245bd2ee99b..b4f52fc4da6 100644
--- a/drivers/usrsock/usrsock_rpmsg_server.c
+++ b/drivers/usrsock/usrsock_rpmsg_server.c
@@ -39,6 +39,7 @@
#include <nuttx/mutex.h>
#include <nuttx/net/dns.h>
#include <nuttx/net/net.h>
+#include <nuttx/percpu.h>
#include <nuttx/poll.h>
#include <nuttx/queue.h>
#include <nuttx/rpmsg/rpmsg.h>
@@ -1357,6 +1358,13 @@ int usrsock_rpmsg_server_initialize(void)
int ret;
int i;
+#ifdef CONFIG_NET_USRSOCK_RPMSG_SERVER_CPUID
+ if (this_cpu() != CONFIG_NET_USRSOCK_RPMSG_SERVER_CPUID)
+ {
+ return -EINVAL;
+ }
+#endif
+
priv = kmm_calloc(1, sizeof(*priv));
if (priv == NULL)
{