This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a32ff0ec0bddc0c425292bd750f20f15b5781acf Author: Bowen Wang <[email protected]> AuthorDate: Wed Nov 18 23:07:22 2026 +0800 drivers/rpmsg: add a small memory pool for rpmsg services rpmsg services allocate small, short-lived buffers (name service records, message headers) on hot paths. Add rpmsg_pool_alloc() and rpmsg_pool_free() on top of a mempool sized by RPMSG_POOL_COUNT and RPMSG_POOL_SIZE; with RPMSG_POOL_COUNT = 0 they fall back to alloca() and a no-op free. Signed-off-by: Bowen Wang <[email protected]> --- drivers/rpmsg/Kconfig | 16 ++++++++++++++++ drivers/rpmsg/rpmsg.c | 19 +++++++++++++++++++ include/nuttx/rpmsg/rpmsg.h | 12 ++++++++++++ 3 files changed, 47 insertions(+) diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index 24785887980..437945325eb 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -116,6 +116,22 @@ config RPMSG_PANIC_DUMP_LEVEL 2 - Verbose: full dump on panic Manual rpmsg dump command is not affected. +config RPMSG_POOL_COUNT + int "rpmsg pool buffer count" + default 0 + ---help--- + This macro sets the count of rpmsg pool buffers, each pool + can be used to allocate rpmsg buffers. 0 means disable + rpmsg pool. + +config RPMSG_POOL_SIZE + int "rpmsg pool size" + depends on RPMSG_POOL_COUNT != 0 + default 64 + ---help--- + This macro sets the size of each rpmsg pool, which is used + to allocate rpmsg buffers. The default value is 64 bytes. + endif # RPMSG config RPMSG_ROUTER diff --git a/drivers/rpmsg/rpmsg.c b/drivers/rpmsg/rpmsg.c index 4befc3be89b..4e36324bc8c 100644 --- a/drivers/rpmsg/rpmsg.c +++ b/drivers/rpmsg/rpmsg.c @@ -36,6 +36,7 @@ #include <nuttx/clock.h> #include <nuttx/kmalloc.h> #include <nuttx/list.h> +#include <nuttx/mm/mempool.h> #include <nuttx/mutex.h> #include <nuttx/nuttx.h> #include <nuttx/rwsem.h> @@ -124,6 +125,11 @@ static const struct file_operations g_rpmsg_dev_ops = rpmsg_dev_ioctl, /* ioctl */ }; +#if CONFIG_RPMSG_POOL_COUNT > 0 +MEMPOOL_DEFINE(g_rpmsg_pool, CONFIG_RPMSG_POOL_SIZE, + CONFIG_RPMSG_POOL_COUNT, CONFIG_RPMSG_POOL_COUNT, 0); +#endif + #ifdef CONFIG_RPMSG_WQUEUE_GLOBAL static struct rpmsg_wqueue_s g_rpmsg_wqueues[CONFIG_RPMSG_WQUEUE_NUMBER]; #endif @@ -468,6 +474,19 @@ int rpmsg_get_timestamp(FAR struct rpmsg_device *rdev, FAR const void *data, return rpmsg->ops->get_timestamp(rpmsg, data, ts); } +#if CONFIG_RPMSG_POOL_COUNT > 0 +FAR void *rpmsg_pool_alloc(size_t size) +{ + DEBUGASSERT(size <= CONFIG_RPMSG_POOL_SIZE); + return mempool_allocate(&g_rpmsg_pool, UINT_MAX); +} + +void rpmsg_pool_free(FAR void *addr) +{ + mempool_release(&g_rpmsg_pool, addr); +} +#endif + int rpmsg_register_callback(FAR void *priv, rpmsg_dev_cb_t device_created, rpmsg_dev_cb_t device_destroy, diff --git a/include/nuttx/rpmsg/rpmsg.h b/include/nuttx/rpmsg/rpmsg.h index 3944aa3674a..eae7cc2a9b0 100644 --- a/include/nuttx/rpmsg/rpmsg.h +++ b/include/nuttx/rpmsg/rpmsg.h @@ -32,6 +32,8 @@ #include <nuttx/atomic.h> #include <nuttx/compiler.h> +#include <alloca.h> + #ifdef CONFIG_RPMSG #include <nuttx/fs/ioctl.h> @@ -53,6 +55,11 @@ #define RPMSG_SIGNAL_RUNNING TIOCM_CD +#if CONFIG_RPMSG_POOL_COUNT <= 0 +# define rpmsg_pool_alloc(size) alloca(size) +# define rpmsg_pool_free(addr) +#endif + #define rpmsg_wait(e, s) rpmsg_tickwait(e, s, CLOCK_MAX) /**************************************************************************** @@ -110,6 +117,11 @@ static inline_function bool rpmsg_is_running(FAR struct rpmsg_device *rdev) return rpmsg_get_signals(rdev) & RPMSG_SIGNAL_RUNNING; } +#if CONFIG_RPMSG_POOL_COUNT > 0 +FAR void *rpmsg_pool_alloc(size_t size); +void rpmsg_pool_free(FAR void *addr); +#endif + int rpmsg_register_callback(FAR void *priv, rpmsg_dev_cb_t device_created, rpmsg_dev_cb_t device_destroy,
