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 52df5e8fad0 drivers/virtio: keep the driver state per CPU in BMP mode
52df5e8fad0 is described below
commit 52df5e8fad084fe3ee15a54fb41351b09a9085ff
Author: Bowen Wang <[email protected]>
AuthorDate: Wed Nov 25 23:50:50 2026 +0800
drivers/virtio: keep the driver state per CPU in BMP mode
With the virtio bus per CPU in BMP mode, every CPU registers its own
virtio drivers, and a virtio_driver is linked into its bus through its
own node, so the driver structures must be per CPU too, as must the
counters and tables the drivers use to name and track their devices
(blk, input, net, rng and serial indices, the gpu table, the gpio, i2c
and spi bus state, the serial console). Define them with
DEFINE_PER_CPU_BMP(), which leaves them plain globals when BMP is off.
Signed-off-by: Bowen Wang <[email protected]>
---
drivers/virtio/virtio-blk.c | 7 +++++--
drivers/virtio/virtio-crypto.c | 4 +++-
drivers/virtio/virtio-gpio.c | 7 +++++--
drivers/virtio/virtio-gpu.c | 8 ++++++--
drivers/virtio/virtio-i2c.c | 7 +++++--
drivers/virtio/virtio-input.c | 15 +++++++++++----
drivers/virtio/virtio-net.c | 7 +++++--
drivers/virtio/virtio-ping.c | 4 +++-
drivers/virtio/virtio-rng.c | 7 +++++--
drivers/virtio/virtio-rpmb.c | 4 +++-
drivers/virtio/virtio-rpmsg.c | 4 +++-
drivers/virtio/virtio-serial.c | 15 +++++++++++----
drivers/virtio/virtio-snd.c | 4 +++-
drivers/virtio/virtio-spi.c | 7 +++++--
14 files changed, 73 insertions(+), 27 deletions(-)
diff --git a/drivers/virtio/virtio-blk.c b/drivers/virtio/virtio-blk.c
index c252c95e8c8..810fbfa18ee 100644
--- a/drivers/virtio/virtio-blk.c
+++ b/drivers/virtio/virtio-blk.c
@@ -31,6 +31,7 @@
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
+#include <nuttx/percpu.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
#include <nuttx/virtio/virtio.h>
@@ -94,13 +95,14 @@ static void virtio_blk_dump(FAR struct virtio_device *vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_blk_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_blk_driver) =
{
VIRTIO_ID_BLOCK, /* device id */
virtio_blk_probe, /* probe */
virtio_blk_remove, /* remove */
virtio_blk_dump, /* dump */
};
+#define g_virtio_blk_driver this_cpu_var_bmp(g_virtio_blk_driver)
static const struct block_operations g_virtio_blk_bops =
{
@@ -112,7 +114,8 @@ static const struct block_operations g_virtio_blk_bops =
virtio_blk_ioctl /* ioctl */
};
-static int g_virtio_blk_idx = 0;
+static DEFINE_PER_CPU_BMP(int, g_virtio_blk_idx);
+#define g_virtio_blk_idx this_cpu_var_bmp(g_virtio_blk_idx)
/****************************************************************************
* Private Functions
diff --git a/drivers/virtio/virtio-crypto.c b/drivers/virtio/virtio-crypto.c
index 1c1730aa1fa..eee049fd83c 100644
--- a/drivers/virtio/virtio-crypto.c
+++ b/drivers/virtio/virtio-crypto.c
@@ -28,6 +28,7 @@
#include <inttypes.h>
#include <crypto/virtio_crypto.h>
+#include <nuttx/percpu.h>
#include <nuttx/spinlock.h>
#include <nuttx/virtio/virtio.h>
#include <nuttx/virtio/virtio-crypto.h>
@@ -160,12 +161,13 @@ static void virtio_crypto_remove(FAR struct virtio_device
*vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_crypto_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_crypto_driver) =
{
VIRTIO_ID_CRYPTO, /* device id */
virtio_crypto_probe, /* probe */
virtio_crypto_remove, /* remove */
};
+#define g_virtio_crypto_driver this_cpu_var_bmp(g_virtio_crypto_driver)
/****************************************************************************
* Private Functions
diff --git a/drivers/virtio/virtio-gpio.c b/drivers/virtio/virtio-gpio.c
index 5c4d4e7622d..6651921ae8f 100644
--- a/drivers/virtio/virtio-gpio.c
+++ b/drivers/virtio/virtio-gpio.c
@@ -33,6 +33,7 @@
#include <nuttx/ioexpander/ioexpander.h>
#include <nuttx/ioexpander/gpio_virtio.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
#include <nuttx/wqueue.h>
@@ -145,12 +146,13 @@ static void virtio_gpio_remove(FAR struct virtio_device
*vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_gpio_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_gpio_driver) =
{
VIRTIO_ID_GPIO, /* Device id */
virtio_gpio_probe, /* Probe */
virtio_gpio_remove, /* Remove */
};
+#define g_virtio_gpio_driver this_cpu_var_bmp(g_virtio_gpio_driver)
static const struct ioexpander_ops_s g_virtio_gpio_ops =
{
@@ -172,10 +174,11 @@ static const struct ioexpander_ops_s g_virtio_gpio_ops =
/* Lower-halves published to board code, indexed by probe order. */
-static struct virtio_gpio_bus_s g_virtio_gpio_bus =
+static DEFINE_PER_CPU_BMP(struct virtio_gpio_bus_s, g_virtio_gpio_bus) =
{
SP_UNLOCKED,
};
+#define g_virtio_gpio_bus this_cpu_var_bmp(g_virtio_gpio_bus)
/****************************************************************************
* Private Functions
diff --git a/drivers/virtio/virtio-gpu.c b/drivers/virtio/virtio-gpu.c
index 0fcfab50d1f..6ecf4598c59 100644
--- a/drivers/virtio/virtio-gpu.c
+++ b/drivers/virtio/virtio-gpu.c
@@ -28,6 +28,7 @@
#include <nuttx/clock.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
#include <nuttx/semaphore.h>
#include <nuttx/video/fb.h>
#include <nuttx/virtio/virtio.h>
@@ -150,15 +151,18 @@ static int virtio_gpu_flush_output(FAR struct fb_vtable_s
*vtable,
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_gpu_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_gpu_driver) =
{
.device = VIRTIO_ID_GPU, /* device id */
.probe = virtio_gpu_probe, /* probe */
.remove = virtio_gpu_remove, /* remove */
.dump = virtio_gpu_dump, /* dump */
};
+#define g_virtio_gpu_driver this_cpu_var_bmp(g_virtio_gpu_driver)
-static FAR struct virtio_gpu_priv_s *g_virtio_gpu[VIRTIO_GPU_MAX_DISP];
+static DEFINE_PER_CPU_BMP(FAR struct virtio_gpu_priv_s *,
+ g_virtio_gpu[VIRTIO_GPU_MAX_DISP]);
+#define g_virtio_gpu this_cpu_var_bmp(g_virtio_gpu)
/****************************************************************************
* Private Functions
diff --git a/drivers/virtio/virtio-i2c.c b/drivers/virtio/virtio-i2c.c
index 5d9f3ebc61d..b101aaa27c6 100644
--- a/drivers/virtio/virtio-i2c.c
+++ b/drivers/virtio/virtio-i2c.c
@@ -36,6 +36,7 @@
#include <nuttx/i2c/i2c_virtio.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
+#include <nuttx/percpu.h>
#include <nuttx/queue.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
@@ -82,22 +83,24 @@ static void virtio_i2c_dump(FAR struct virtio_device *vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_i2c_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_i2c_driver) =
{
VIRTIO_ID_I2C_ADAPTER, /* device id */
virtio_i2c_probe, /* probe */
virtio_i2c_remove, /* remove */
virtio_i2c_dump, /* dump */
};
+#define g_virtio_i2c_driver this_cpu_var_bmp(g_virtio_i2c_driver)
/* Registry of probed VirtIO I2C frontends, so board/in-kernel code can
* obtain the I2C lower-half through virtio_i2c_get_master().
*/
-static struct virtio_i2c_bus_s g_virtio_i2c_bus =
+static DEFINE_PER_CPU_BMP(struct virtio_i2c_bus_s, g_virtio_i2c_bus) =
{
SP_UNLOCKED,
};
+#define g_virtio_i2c_bus this_cpu_var_bmp(g_virtio_i2c_bus)
static const struct i2c_ops_s g_virtio_i2c_ops =
{
diff --git a/drivers/virtio/virtio-input.c b/drivers/virtio/virtio-input.c
index d2e678fc8c3..5926d1b5983 100644
--- a/drivers/virtio/virtio-input.c
+++ b/drivers/virtio/virtio-input.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <sys/param.h>
+#include <nuttx/percpu.h>
#include <nuttx/queue.h>
#include <nuttx/kmalloc.h>
#include <nuttx/virtio/virtio.h>
@@ -93,17 +94,23 @@ static void virtio_input_dump(FAR struct virtio_device
*vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_input_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_input_driver) =
{
.device = VIRTIO_ID_INPUT, /* device id */
.probe = virtio_input_probe, /* probe */
.remove = virtio_input_remove, /* remove */
.dump = virtio_input_dump, /* dump */
};
+#define g_virtio_input_driver this_cpu_var_bmp(g_virtio_input_driver)
-static int g_virtio_mouse_idx = 0;
-static int g_virtio_touch_idx = 0;
-static int g_virtio_keyboard_idx = 0;
+static DEFINE_PER_CPU_BMP(int, g_virtio_mouse_idx);
+#define g_virtio_mouse_idx this_cpu_var_bmp(g_virtio_mouse_idx)
+
+static DEFINE_PER_CPU_BMP(int, g_virtio_touch_idx);
+#define g_virtio_touch_idx this_cpu_var_bmp(g_virtio_touch_idx)
+
+static DEFINE_PER_CPU_BMP(int, g_virtio_keyboard_idx);
+#define g_virtio_keyboard_idx this_cpu_var_bmp(g_virtio_keyboard_idx)
/****************************************************************************
* Private Functions
diff --git a/drivers/virtio/virtio-net.c b/drivers/virtio/virtio-net.c
index 932bda0bd61..02bafaace8c 100644
--- a/drivers/virtio/virtio-net.c
+++ b/drivers/virtio/virtio-net.c
@@ -36,6 +36,7 @@
#include <nuttx/mm/iob.h>
#include <nuttx/net/ip.h>
#include <nuttx/net/netdev_lowerhalf.h>
+#include <nuttx/percpu.h>
#include <nuttx/virtio/virtio.h>
#include <nuttx/net/wifi_sim.h>
@@ -186,13 +187,14 @@ static void virtio_net_dump(FAR struct virtio_device
*vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_net_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_net_driver) =
{
VIRTIO_ID_NETWORK, /* device id */
virtio_net_probe, /* probe */
virtio_net_remove, /* remove */
virtio_net_dump, /* dump */
};
+#define g_virtio_net_driver this_cpu_var_bmp(g_virtio_net_driver)
static const struct netdev_ops_s g_virtio_net_ops =
{
@@ -213,7 +215,8 @@ static const struct netdev_ops_s g_virtio_net_ops =
};
#ifdef CONFIG_DRIVERS_WIFI_SIM
-static uint8_t g_netdev_num = 0;
+static DEFINE_PER_CPU_BMP(uint8_t, g_netdev_num);
+#define g_netdev_num this_cpu_var_bmp(g_netdev_num)
#endif
/****************************************************************************
diff --git a/drivers/virtio/virtio-ping.c b/drivers/virtio/virtio-ping.c
index 7ffe48b278c..07278f65b84 100644
--- a/drivers/virtio/virtio-ping.c
+++ b/drivers/virtio/virtio-ping.c
@@ -32,6 +32,7 @@
#include <nuttx/clock.h>
#include <nuttx/debug.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
#include <nuttx/semaphore.h>
#include <nuttx/signal.h>
#include <nuttx/spinlock.h>
@@ -92,13 +93,14 @@ static void virtio_ping_dump(FAR struct virtio_device
*vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_ping_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_ping_driver) =
{
VIRTIO_ID_PING, /* device id */
virtio_ping_probe, /* probe */
virtio_ping_remove, /* remove */
virtio_ping_dump, /* dump */
};
+#define g_virtio_ping_driver this_cpu_var_bmp(g_virtio_ping_driver)
/****************************************************************************
* Private Functions
diff --git a/drivers/virtio/virtio-rng.c b/drivers/virtio/virtio-rng.c
index bdc68460c4e..57a1c798722 100644
--- a/drivers/virtio/virtio-rng.c
+++ b/drivers/virtio/virtio-rng.c
@@ -29,6 +29,7 @@
#include <nuttx/debug.h>
#include <nuttx/fs/fs.h>
+#include <nuttx/percpu.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
#include <nuttx/virtio/virtio.h>
@@ -78,13 +79,14 @@ static void virtio_rng_dump(FAR struct virtio_device *vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_rng_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_rng_driver) =
{
VIRTIO_ID_ENTROPY, /* device id */
virtio_rng_probe, /* probe */
virtio_rng_remove, /* remove */
virtio_rng_dump, /* dump */
};
+#define g_virtio_rng_driver this_cpu_var_bmp(g_virtio_rng_driver)
static const struct file_operations g_virtio_rng_ops =
{
@@ -104,7 +106,8 @@ static const struct file_operations g_virtio_rng_ops =
#endif
};
-static int g_virtio_rng_idx = 0;
+static DEFINE_PER_CPU_BMP(int, g_virtio_rng_idx);
+#define g_virtio_rng_idx this_cpu_var_bmp(g_virtio_rng_idx)
/****************************************************************************
* Private Functions
diff --git a/drivers/virtio/virtio-rpmb.c b/drivers/virtio/virtio-rpmb.c
index 81439a4a0fb..473e1bf0a50 100644
--- a/drivers/virtio/virtio-rpmb.c
+++ b/drivers/virtio/virtio-rpmb.c
@@ -31,6 +31,7 @@
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
#include <nuttx/mmcsd.h>
@@ -75,12 +76,13 @@ static int virtio_rpmb_ioctl(FAR struct file *, int,
unsigned long);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_rpmb_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_rpmb_driver) =
{
VIRTIO_ID_RPMB, /* device id */
virtio_rpmb_probe, /* probe */
virtio_rpmb_remove, /* remove */
};
+#define g_virtio_rpmb_driver this_cpu_var_bmp(g_virtio_rpmb_driver)
static const struct file_operations g_virtio_rpmb_ops =
{
diff --git a/drivers/virtio/virtio-rpmsg.c b/drivers/virtio/virtio-rpmsg.c
index fa43b51e3c9..50432b6b32a 100644
--- a/drivers/virtio/virtio-rpmsg.c
+++ b/drivers/virtio/virtio-rpmsg.c
@@ -22,6 +22,7 @@
* Included Files
****************************************************************************/
+#include <nuttx/percpu.h>
#include <nuttx/rpmsg/rpmsg_virtio.h>
#include <nuttx/virtio/virtio.h>
@@ -31,12 +32,13 @@
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_rpmsg_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_rpmsg_driver) =
{
VIRTIO_ID_RPMSG, /* Device id */
rpmsg_virtio_probe, /* Probe */
rpmsg_virtio_remove, /* Remove */
};
+#define g_virtio_rpmsg_driver this_cpu_var_bmp(g_virtio_rpmsg_driver)
/****************************************************************************
* Public Functions
diff --git a/drivers/virtio/virtio-serial.c b/drivers/virtio/virtio-serial.c
index d010297e16a..6654671ecd3 100644
--- a/drivers/virtio/virtio-serial.c
+++ b/drivers/virtio/virtio-serial.c
@@ -30,6 +30,7 @@
#include <errno.h>
#include <stdio.h>
+#include <nuttx/percpu.h>
#include <nuttx/serial/serial.h>
#include <nuttx/spinlock.h>
#include <nuttx/virtio/virtio.h>
@@ -93,21 +94,25 @@ static void virtio_serial_dump(FAR struct virtio_device
*vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_serial_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_serial_driver) =
{
VIRTIO_ID_CONSOLE, /* device id */
virtio_serial_probe, /* probe */
virtio_serial_remove, /* remove */
virtio_serial_dump, /* dump */
};
+#define g_virtio_serial_driver this_cpu_var_bmp(g_virtio_serial_driver)
-static struct virtio_driver g_virtio_rprocserial_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver,
+ g_virtio_rprocserial_driver) =
{
VIRTIO_ID_RPROC_SERIAL, /* device id */
virtio_serial_probe, /* probe */
virtio_serial_remove, /* remove */
virtio_serial_dump, /* dump */
};
+#define g_virtio_rprocserial_driver \
+ this_cpu_var_bmp(g_virtio_rprocserial_driver)
static const struct uart_ops_s g_virtio_serial_ops =
{
@@ -132,10 +137,12 @@ static const struct uart_ops_s g_virtio_serial_ops =
virtio_serial_txempty, /* txempty */
};
-static int g_virtio_serial_idx = 0;
+static DEFINE_PER_CPU_BMP(int, g_virtio_serial_idx);
+#define g_virtio_serial_idx this_cpu_var_bmp(g_virtio_serial_idx)
#ifdef CONFIG_DRIVERS_VIRTIO_SERIAL_CONSOLE
-static struct uart_dev_s *g_virtio_console;
+static DEFINE_PER_CPU_BMP(struct uart_dev_s *, g_virtio_console);
+#define g_virtio_console this_cpu_var_bmp(g_virtio_console)
#endif
/****************************************************************************
diff --git a/drivers/virtio/virtio-snd.c b/drivers/virtio/virtio-snd.c
index e02853a980c..9e12bd7f3bc 100644
--- a/drivers/virtio/virtio-snd.c
+++ b/drivers/virtio/virtio-snd.c
@@ -32,6 +32,7 @@
#include <nuttx/audio/audio.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/percpu.h>
#include <nuttx/virtio/virtio.h>
#include <nuttx/semaphore.h>
@@ -243,12 +244,13 @@ static const struct virtio_snd_format_map_s
g_format_map[] =
}
};
-static struct virtio_driver g_virtio_snd_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_snd_driver) =
{
VIRTIO_ID_SOUND, /* device id */
virtio_snd_probe, /* probe */
virtio_snd_remove, /* remove */
};
+#define g_virtio_snd_driver this_cpu_var_bmp(g_virtio_snd_driver)
static const struct audio_ops_s g_virtio_snd_ops =
{
diff --git a/drivers/virtio/virtio-spi.c b/drivers/virtio/virtio-spi.c
index ff6db6848fd..3ce12389f7b 100644
--- a/drivers/virtio/virtio-spi.c
+++ b/drivers/virtio/virtio-spi.c
@@ -35,6 +35,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/nuttx.h>
+#include <nuttx/percpu.h>
#include <nuttx/queue.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
@@ -118,18 +119,20 @@ static void virtio_spi_dump(FAR struct virtio_device
*vdev);
* Private Data
****************************************************************************/
-static struct virtio_driver g_virtio_spi_driver =
+static DEFINE_PER_CPU_BMP(struct virtio_driver, g_virtio_spi_driver) =
{
VIRTIO_ID_SPI, /* device id */
virtio_spi_probe, /* probe */
virtio_spi_remove, /* remove */
virtio_spi_dump, /* dump */
};
+#define g_virtio_spi_driver this_cpu_var_bmp(g_virtio_spi_driver)
-static struct virtio_spi_bus_s g_virtio_spi_bus =
+static DEFINE_PER_CPU_BMP(struct virtio_spi_bus_s, g_virtio_spi_bus) =
{
SP_UNLOCKED,
};
+#define g_virtio_spi_bus this_cpu_var_bmp(g_virtio_spi_bus)
static const struct spi_ops_s g_virtio_spi_ops =
{