Skip to content

Commit

Permalink
rpmsg_virtio.c: make virtqueue_kick optional in one time or each time
Browse files Browse the repository at this point in the history
add VQ_RX_EMPTY_NOTIFY config to define the behavior. If
disable VQ_RX_EMPTY_NOTIFY, notify the other side each
time a buffer is released. If enable VQ_RX_EMPTY_NOTIFY,
only one notification when the RX queue is empty to
improve performance

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
  • Loading branch information
wyr-7 committed Oct 8, 2024
1 parent c468328 commit 739d623
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
8 changes: 8 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ if (WITH_VIRTIO_MMIO_DRV)
add_definitions(-DWITH_VIRTIO_MMIO_DRV)
endif (WITH_VIRTIO_MMIO_DRV)

option (WITH_VQ_RX_EMPTY_NOTIFY "Build with virtqueue rx empty notify enabled" OFF)

if (NOT WITH_VQ_RX_EMPTY_NOTIFY)
add_definitions(-DVQ_RX_EMPTY_NOTIFY=0)
else (NOT WITH_VQ_RX_EMPTY_NOTIFY)
add_definitions(-DVQ_RX_EMPTY_NOTIFY=1)
endif (NOT WITH_VQ_RX_EMPTY_NOTIFY)

option (WITH_DCACHE "Build with all cache operations enabled" OFF)

if (WITH_DCACHE)
Expand Down
31 changes: 24 additions & 7 deletions lib/rpmsg/rpmsg_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ static bool rpmsg_virtio_release_rx_buffer_nolock(struct rpmsg_virtio_device *rv
/* Return buffer on virtqueue. */
len = virtqueue_get_buffer_length(rvdev->rvq, idx);
rpmsg_virtio_return_buffer(rvdev, rp_hdr, len, idx);
/* Tell peer we returned an rx buffer */
virtqueue_kick(rvdev->rvq);

return true;
}
Expand All @@ -337,8 +335,11 @@ static void rpmsg_virtio_release_rx_buffer(struct rpmsg_device *rdev,
rp_hdr = RPMSG_LOCATE_HDR(rxbuf);

metal_mutex_acquire(&rdev->lock);
if (rpmsg_virtio_buf_held_dec_test(rp_hdr))
if (rpmsg_virtio_buf_held_dec_test(rp_hdr)) {
rpmsg_virtio_release_rx_buffer_nolock(rvdev, rp_hdr);
/* Tell peer we returned an rx buffer */
virtqueue_kick(rvdev->rvq);
}
metal_mutex_release(&rdev->lock);
}

Expand Down Expand Up @@ -560,6 +561,9 @@ static void rpmsg_virtio_rx_callback(struct virtqueue *vq)
struct rpmsg_device *rdev = &rvdev->rdev;
struct rpmsg_endpoint *ept;
struct rpmsg_hdr *rp_hdr;
#if VIRTIO_ENABLED(VQ_RX_EMPTY_NOTIFY)
bool release = false;
#endif
uint32_t len;
uint16_t idx;
int status;
Expand All @@ -568,16 +572,22 @@ static void rpmsg_virtio_rx_callback(struct virtqueue *vq)
/* Process the received data from remote node */
metal_mutex_acquire(&rdev->lock);
rp_hdr = rpmsg_virtio_get_rx_buffer(rvdev, &len, &idx);
metal_mutex_release(&rdev->lock);

/* No more filled rx buffers */
if (!rp_hdr)
if (!rp_hdr) {
#if VIRTIO_ENABLED(VQ_RX_EMPTY_NOTIFY)
/* Tell peer we returned some rx buffer */
if (release) {
virtqueue_kick(rvdev->rvq);
}
#endif
metal_mutex_release(&rdev->lock);
break;
}

rp_hdr->reserved = idx;

/* Get the channel node from the remote device channels list. */
metal_mutex_acquire(&rdev->lock);
ept = rpmsg_get_ept_from_addr(rdev, rp_hdr->dst);
rpmsg_ept_incref(ept);
RPMSG_BUF_HELD_INC(rp_hdr);
Expand All @@ -600,8 +610,15 @@ static void rpmsg_virtio_rx_callback(struct virtqueue *vq)

metal_mutex_acquire(&rdev->lock);
rpmsg_ept_decref(ept);
if (rpmsg_virtio_buf_held_dec_test(rp_hdr))
if (rpmsg_virtio_buf_held_dec_test(rp_hdr)) {
rpmsg_virtio_release_rx_buffer_nolock(rvdev, rp_hdr);
#if VIRTIO_ENABLED(VQ_RX_EMPTY_NOTIFY)
release = true;
#else
/* Tell peer we returned an rx buffer */
virtqueue_kick(rvdev->rvq);
#endif
}
metal_mutex_release(&rdev->lock);
}
}
Expand Down

0 comments on commit 739d623

Please sign in to comment.