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 7f8d4248a30 drivers/rptun: add a synchronous start mode without a 
worker thread
7f8d4248a30 is described below

commit 7f8d4248a30bd97f67467a6b5647f0d910ac682d
Author: wangshaoxin <[email protected]>
AuthorDate: Mon Aug 10 15:31:49 2026 +0800

    drivers/rptun: add a synchronous start mode without a worker thread
    
    Every rptun start spawns a short lived "rptun" kernel thread that runs
    rptun_do_start() and then polls rptun_create_devices() until the peer
    has set up every device, so each start/stop cycle allocates and frees a
    TCB and a stack.
    
    Add CONFIG_RPTUN_START_SYNC (default n) to run that sequence in the
    caller instead: no thread and no allocation per cycle, at the cost of
    blocking the caller until the peer is ready. No pid is recorded in this
    mode, because rptun_dev_stop() SIGKILLs the recorded pid, which would be
    the caller.
    
    Signed-off-by: wangshaoxin <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rptun/Kconfig | 25 +++++++++++++++++++++++++
 drivers/rptun/rptun.c | 14 +++++++++++---
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/drivers/rptun/Kconfig b/drivers/rptun/Kconfig
index faf2f814144..0aa8730f6ff 100644
--- a/drivers/rptun/Kconfig
+++ b/drivers/rptun/Kconfig
@@ -110,6 +110,31 @@ config RPTUN_IVSHMEM_RPMB_PATH
 
 endif
 
+config RPTUN_START_SYNC
+       bool "rptun start devices synchronously"
+       default n
+       ---help---
+               By default rptun spawns a short lived "rptun" kernel thread on 
every
+               start to bring the remote proc up and to wait for the peer to 
publish
+               VIRTIO_CONFIG_STATUS_DRIVER_OK.  Each start/stop cycle therefore
+               allocates and releases a TCB and a stack, and the stop path has 
to
+               SIGKILL the thread out of its peer wait.
+
+               Enable this option to run the whole sequence inline in the 
caller's
+               context instead.  No thread is created and a start/stop cycle 
performs
+               no dynamic allocation at all.
+
+               Be aware of the trade-off: the caller blocks until the peer has
+               driven every virtio device in the resource table, forever if the
+               peer has no driver for one of them.
+               With RPTUN_IS_AUTOSTART this stalls board bring-up, and when 
entered
+               through RPTUNIOC_START (rptun_boot()) the global rptun lock is 
held for
+               the whole wait, which blocks rptun_reset()/rptun_poweroff() on 
every
+               rptun instance, including from the panic notifier.
+
+               Only select this when the peer is known to be up before this 
side
+               starts, or when stalling the caller is acceptable.
+
 config RPTUN_PRIORITY
        int "rptun thread priority"
        default 224
diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index fd499443608..ccedaba0211 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -1185,7 +1185,7 @@ static int rptun_do_start(FAR struct remoteproc *rproc)
 static int rptun_start_thread(int argc, FAR char *argv[])
 {
   FAR struct rptun_priv_s *priv =
-  (FAR struct rptun_priv_s *)((uintptr_t)strtoul(argv[2], NULL, 16));
+  (FAR struct rptun_priv_s *)((uintptr_t)strtoul(argv[argc - 1], NULL, 16));
   int ret;
 
   ret = rptun_do_start(&priv->rproc);
@@ -1212,13 +1212,20 @@ static int rptun_dev_start(FAR struct rptun_priv_s 
*priv)
   FAR char *argv[3];
   char arg1[32];
 
-  /* Create a thread to register the virtio and vhost devices */
-
   snprintf(arg1, sizeof(arg1), "%p", priv);
   argv[0] = (FAR char *)RPTUN_GET_CPUNAME(dev);
   argv[1] = arg1;
   argv[2] = NULL;
 
+#ifdef CONFIG_RPTUN_START_SYNC
+  /* Leave priv->pid unset: rptun_dev_stop() kills that pid, and here it
+   * would be the caller.
+   */
+
+  return rptun_start_thread(2, argv);
+#else
+  /* Create a thread to register the virtio and vhost devices */
+
   if (dev->stack != NULL && dev->stack_size != 0u)
     {
       priv->pid = kthread_create_with_stack("rptun",
@@ -1237,6 +1244,7 @@ static int rptun_dev_start(FAR struct rptun_priv_s *priv)
     }
 
   return priv->pid;
+#endif
 }
 
 static int rptun_dev_stop(FAR struct remoteproc *rproc)

Reply via email to