Skip to content

drivers/rpmsg: dispatch rx in per-device work queues - #21971

Open
CV-Bowen wants to merge 3 commits into
apache:masterfrom
CV-Bowen:up/P102-rpmsg-wqueue
Open

CV-Bowen wants to merge 3 commits into
apache:masterfrom
CV-Bowen:up/P102-rpmsg-wqueue

Conversation

@CV-Bowen

Copy link
Copy Markdown
Contributor

Summary

rpmsg_virtio receives with its own kthread per device: the rx interrupt
moves every non-RT buffer to a readyrx list and wakes the thread, which
then runs the endpoint callbacks one by one. A callback that blocks (for
example in rpmsg_wait() for a tx buffer) stalls the whole device, and
other transports cannot reuse the scheme.

This PR moves rx scheduling into the rpmsg framework:

  • drivers/rpmsg: dispatch rx in per-device work queues: each device
    creates CONFIG_RPMSG_WQUEUE_NUMBER work queues; the rx interrupt
    queues a buffer with rpmsg_queue_rx_work() on the queue picked by the
    endpoint priority (bound RT endpoints are still handled in the
    interrupt). rpmsg_wait() called from one of these queues runs the
    queue's pending works while it waits, bounded by a recursion limit, so
    a blocking callback no longer stalls rx. The kthread and the
    readyrx/freerx lists in rpmsg_virtio are removed.
  • drivers/rpmsg: add an option to share the work queues between devices: CONFIG_RPMSG_WQUEUE_GLOBAL creates one set of queues in
    rpmsg_initialize() for all devices.
  • drivers/rpmsg: fix rpmsg_wait() not returning in the recursive path:
    at the recursion limit rpmsg_wait() returned an error although the
    semaphore could still be posted; keep waiting instead. Adds
    rpmsg_tickwait() with a timeout (rpmsg_wait() becomes a wrapper)
    and passes the remaining time to the transport wait op.

Impact

  • Kconfig: RPMSG_VIRTIO_PRIORITY / RPMSG_VIRTIO_STACKSIZE are replaced
    by RPMSG_WQUEUE_PRIORITY / RPMSG_WQUEUE_STACKSIZE (same defaults),
    plus RPMSG_WQUEUE_NUMBER (default 1) and RPMSG_WQUEUE_GLOBAL
    (default n). No in-tree defconfig sets the old options. RPMSG now
    selects SCHED_WORKQUEUE.
  • The rx thread is named rpmsg-<cpu>-<n> instead of rpmsg-virtio.
  • Public API: new rpmsg_tickwait(); rpmsg_wait() keeps its signature
    (now a macro), so the existing callers are unchanged.
  • Private API in drivers/rpmsg/rpmsg.h: the transport wait/post ops
    lose the semaphore argument, and rpmsg_register() takes the number of
    rx works to preallocate; rpmsg_port and rpmsg_router_edge pass 0.

Testing

Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205

qemu-armv8a:rpserver + qemu-armv8a:rpproxy (rptun ivshmem; the pair also
talks over rpmsg_port_uart). A test-only patch (not in this PR) logs, once
per endpoint, whether the ping callback runs in the interrupt and in
which task. rpmsg ping all 20 1024 3 0 pings with the normal endpoint,
... 11 0 with the RT one:

master this PR, RPMSG_WQUEUE_NUMBER=1 =3
normal endpoint, virtio task rpmsg-virtio task rpmsg-<cpu>-0 task rpmsg-<cpu>-1 (default priority maps to the middle queue)
RT endpoint, virtio in irq in irq in irq
RT endpoint, port_uart task rpmsg-uart-rx same same
20 x 1024 pings, both sides, both endpoints pass pass pass

With =3 each device has three queues at priority 224..226 (ps), and
with RPMSG_WQUEUE_GLOBAL=y, RPMSG_WQUEUE_NUMBER=2 there is one shared
pair rpmsg-glb-0/1; pings and rpmsgfs (cat /sp/version from the
proxy) pass there too.

ping path, this PR, RPMSG_WQUEUE_NUMBER=3
[proxy] PINGPATH rpmsg-ping in irq=0 task=rpmsg-server-1
[proxy] PINGPATH rpmsg-ping-rt in irq=0 task=rpmsg-uart-rx
[proxy] PINGPATH rpmsg-ping-rt in irq=1 task=-
[server] PINGPATH rpmsg-ping in irq=0 task=rpmsg-proxy-1
[server] PINGPATH rpmsg-ping-rt in irq=0 task=rpmsg-uart-rx
[server] PINGPATH rpmsg-ping-rt in irq=1 task=-
ping path, master
[proxy] PINGPATH rpmsg-ping in irq=0 task=rpmsg-virtio
[proxy] PINGPATH rpmsg-ping-rt in irq=0 task=rpmsg-uart-rx
[proxy] PINGPATH rpmsg-ping-rt in irq=1 task=-
[server] PINGPATH rpmsg-ping in irq=0 task=rpmsg-virtio
[server] PINGPATH rpmsg-ping-rt in irq=0 task=rpmsg-uart-rx
[server] PINGPATH rpmsg-ping-rt in irq=1 task=-
ps, RPMSG_WQUEUE_NUMBER=3 / RPMSG_WQUEUE_GLOBAL=y
  TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK            STACK    USED FILLED COMMAND
    9     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0008064 0001280  15.8%  rpmsg-proxy-0
   10     0     0 225 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0008064 0002224  27.5%  rpmsg-proxy-1
   11     0     0 226 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0008064 0002128  26.3%  rpmsg-proxy-2
    1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0008064 0001280  15.8%  rpmsg-glb-0
    2     0     0 225 FIFO     Kthread   - Waiting  Semaphore 0000000000000000 0008064 0002224  27.5%  rpmsg-glb-1

Every commit builds with no warning on sim:rpserver,
qemu-armv8a:rpproxy, and sim:rpserver with RPMSG_WQUEUE_GLOBAL=y.

No regression in rpmsg: sim:rpserver/rpproxy and qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current master needs for nxinit to start nsh there; unrelated to this change.

rpmsg_virtio ran its own kthread per device, waking it through readyrx/
freerx node lists for every received buffer. Move the rx scheduling into
the rpmsg framework: each device gets CONFIG_RPMSG_WQUEUE_NUMBER work
queues, and rpmsg_queue_rx_work() hands a received buffer to the queue
picked by the endpoint priority. A bound RT endpoint is still processed
in the interrupt; an unbound one and every other endpoint go to a work
queue, and a name service message takes the priority of the endpoint it
binds.

rpmsg_wait() now runs the pending works of the calling queue while it
waits, so a service that blocks inside a callback no longer stalls rx,
with the depth bounded by RPMSG_RECURSIVE_LIMIT. The transport wait/post
ops lose their semaphore argument, and rpmsg_register() takes the number
of rx works to preallocate (0 for rpmsg_port and rpmsg_router_edge).

CONFIG_RPMSG_VIRTIO_PRIORITY/STACKSIZE become CONFIG_RPMSG_WQUEUE_*.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: guanyi3 <guanyi3@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
With CONFIG_RPMSG_WQUEUE_GLOBAL, rpmsg_initialize() creates one set of
CONFIG_RPMSG_WQUEUE_NUMBER work queues and every rpmsg device queues its
works there, instead of each device creating its own set. This saves the
thread stacks on a system with several remote cores.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
rpmsg_wait() run on an rpmsg work queue returned RPMSG_EOPNOTSUPP once
the recursion reached RPMSG_RECURSIVE_LIMIT, even though the semaphore it
waited for could still be posted. rpmsg_virtio_notify_wait() then could
not finish waiting for a tx buffer.

Keep looping until the semaphore is taken: at the limit, only wait
instead of dispatching more works. Add rpmsg_tickwait() with a timeout,
make rpmsg_wait() a wrapper with no timeout, and pass the remaining time
to the transport wait op so that rpmsg_virtio_notify_wait() can give up
after RPMSG_VIRTIO_TIMEOUT_MS.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: L The size of the change in this PR is large labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants