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
commit 7dab87892e2d230df4b06965e7dda942d8cf7c73 Author: Yongrong Wang <[email protected]> AuthorDate: Wed Dec 17 20:41:55 2025 +0800 drivers/rpmsg/rpmsg_virtio: enable the tx done interrupt only while waiting The tx virtqueue callback was enabled once at start-up, so the peer raised an interrupt for every tx buffer it returned, although the sender only needs it when it is blocked waiting for a free buffer. Count the senders waiting in rpmsg_virtio_notify_wait(): the first one enables the callback and the last one disables it again, as Linux virtio_rpmsg_bus does with rpmsg_upref_sleepers() and rpmsg_downref_sleepers(). After enabling the callback, check the virtqueue again under the device lock and only sleep if no buffer has come back in between, so a buffer returned just before the callback was enabled does not leave the sender waiting for the timeout. Drop the enable at start-up. Signed-off-by: Yongrong Wang <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- drivers/rpmsg/rpmsg_virtio.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/rpmsg/rpmsg_virtio.c b/drivers/rpmsg/rpmsg_virtio.c index ee323c97257..fff69da6166 100644 --- a/drivers/rpmsg/rpmsg_virtio.c +++ b/drivers/rpmsg/rpmsg_virtio.c @@ -75,6 +75,7 @@ struct rpmsg_virtio_priv_s vq_notify notifytx; uint16_t headrx; uint16_t headtx; + int sleepertx; struct work_s startwork; #ifdef CONFIG_RPMSG_VIRTIO_PM spinlock_t lock; @@ -688,10 +689,39 @@ static int rpmsg_virtio_notify_wait(FAR struct rpmsg_device *rdev, { FAR struct rpmsg_virtio_priv_s *priv = container_of(rdev, struct rpmsg_virtio_priv_s, rvdev); - int ret; + FAR struct virtqueue *vq = priv->rvdev.svq; + int ret = 0; + + metal_mutex_acquire(&rdev->lock); + if (priv->sleepertx++ == 0) + { + /* We are the first sleeping context, enable tx-complete interrupts */ + + virtqueue_enable_cb(vq); + } + + if ((priv->vdev->role == VIRTIO_DEV_DRIVER && virtqueue_nused(vq) == 0) || + (priv->vdev->role == VIRTIO_DEV_DEVICE && virtqueue_navail(vq) == 0)) + { + metal_mutex_release(&rdev->lock); + ret = rpmsg_tickwait(&priv->rvdev.rdev.ns_ept, &priv->semtx, + MSEC2TICK(RPMSG_VIRTIO_TIMEOUT_MS)); + metal_mutex_acquire(&rdev->lock); + } - ret = rpmsg_tickwait(&priv->rvdev.rdev.ns_ept, &priv->semtx, - MSEC2TICK(RPMSG_VIRTIO_TIMEOUT_MS)); + /* Disable "tx-complete" interrupts after waking up if we're the last + * sleeper. This avoids redundant interrupt overhead when buffers are + * available. + */ + + if (--priv->sleepertx == 0) + { + /* We are the last sleeping context, disable tx-complete interrupts */ + + virtqueue_disable_cb(vq); + } + + metal_mutex_release(&rdev->lock); return ret == -ETIMEDOUT ? 0 : ret; } @@ -799,12 +829,6 @@ static void rpmsg_virtio_start_worker(FAR void *arg) rpmsg_virtio_rx_dispatch(priv); priv->init = true; - /* Open tx buffer return callback before the services created - * below can wait for a tx buffer. - */ - - virtqueue_enable_cb(priv->rvdev.svq); - /* Broadcast device_created to all registers */ rpmsg_device_created(&priv->rpmsg);
