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 21b3a6db6c8 drivers/virtio, drivers/vhost: keep the bus per CPU in BMP 
mode
21b3a6db6c8 is described below

commit 21b3a6db6c8edccb79fc050b1d78526ad2909be2
Author: Bowen Wang <[email protected]>
AuthorDate: Wed Nov 25 23:48:45 2026 +0800

    drivers/virtio, drivers/vhost: keep the bus per CPU in BMP mode
    
    Under CONFIG_BMP every CPU runs its own kernel instance and probes its
    own virtio and vhost devices, so g_virtio_bus and g_vhost_bus, with
    their device and driver lists and lock, must be private to each CPU.
    Define them with DEFINE_PER_CPU_BMP(), which leaves them plain globals
    when BMP is off. The lists are dq_queue_t, valid when zeroed, so each
    CPU copy needs no run-time initialisation.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/vhost/vhost.c   | 4 +++-
 drivers/virtio/virtio.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 42bc6d492c9..653387e4882 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -34,6 +34,7 @@
 #include <nuttx/kmalloc.h>
 #include <nuttx/mutex.h>
 #include <nuttx/nuttx.h>
+#include <nuttx/percpu.h>
 #include <nuttx/queue.h>
 #include <nuttx/wqueue.h>
 #include <nuttx/vhost/vhost.h>
@@ -104,10 +105,11 @@ static const struct file_operations g_vhost_dev_ops =
   vhost_dev_ioctl,  /* ioctl */
 };
 
-static struct vhost_bus_s g_vhost_bus =
+static DEFINE_PER_CPU_BMP(struct vhost_bus_s, g_vhost_bus) =
 {
   .lock = NXMUTEX_INITIALIZER,
 };
+#define g_vhost_bus this_cpu_var_bmp(g_vhost_bus)
 
 /****************************************************************************
  * Private Functions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 3f097288d29..702709b560c 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -35,6 +35,7 @@
 #include <nuttx/nuttx.h>
 #include <nuttx/mutex.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
 #include <nuttx/virtio/virtio.h>
 #include <nuttx/virtio/virtio-ping.h>
 
@@ -102,10 +103,11 @@ static const struct file_operations g_virtio_dev_ops =
   virtio_dev_ioctl,  /* ioctl */
 };
 
-static struct virtio_bus_s g_virtio_bus =
+static DEFINE_PER_CPU_BMP(struct virtio_bus_s, g_virtio_bus) =
 {
   .lock = NXMUTEX_INITIALIZER,
 };
+#define g_virtio_bus this_cpu_var_bmp(g_virtio_bus)
 
 /****************************************************************************
  * Private Functions

Reply via email to