From fce2956c2476c0bb256a1c51a17a02a99723170d Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Thu, 31 Dec 2020 09:33:24 -0500 Subject: [PATCH] vhost: always acknowledge kickfd in intr kickfd of virtvq should be akcnowledged firstly in vhost_vq_avail_ring_get function, in case there is no available requests then kickfd won't get acked. Change-Id: I9c2f0cc19be9da54649991ddab5a5b5640ed941a Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5780 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- lib/vhost/vhost.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index d5f97cccb..e948a8706 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -183,9 +183,26 @@ vhost_vq_avail_ring_get(struct spdk_vhost_virtqueue *virtqueue, uint16_t *reqs, uint16_t size_mask = vring->size - 1; uint16_t last_idx = virtqueue->last_avail_idx, avail_idx = avail->idx; uint16_t count, i; + int rc; + uint64_t num_events; spdk_smp_rmb(); + if (virtqueue->vsession && spdk_unlikely(virtqueue->vsession->interrupt_mode)) { + /* Acknowledge vring's kickfd */ + rc = read(vring->kickfd, &num_events, sizeof(num_events)); + if (rc < 0) { + SPDK_ERRLOG("failed to acknowledge kickfd: %s.\n", spdk_strerror(errno)); + return -errno; + } + + if ((uint16_t)(avail_idx - last_idx) != num_events) { + SPDK_DEBUGLOG(vhost_ring, + "virtqueue gets %d reqs, but kickfd shows %lu reqs\n", + avail_idx - last_idx, num_events); + } + } + count = avail_idx - last_idx; if (spdk_likely(count == 0)) { return 0; @@ -199,25 +216,7 @@ vhost_vq_avail_ring_get(struct spdk_vhost_virtqueue *virtqueue, uint16_t *reqs, } count = spdk_min(count, reqs_len); - if (virtqueue->vsession && virtqueue->vsession->interrupt_mode) { - /* if completed IO number is larger than SPDK_AIO_QUEUE_DEPTH, - * io_getevent should be called again to ensure all completed IO are processed. - */ - int rc; - uint64_t num_events; - - rc = read(vring->kickfd, &num_events, sizeof(num_events)); - if (rc < 0) { - SPDK_ERRLOG("failed to acknowledge kickfd: %s.\n", spdk_strerror(errno)); - return -errno; - } - - if ((uint16_t)(avail_idx - last_idx) != num_events) { - SPDK_DEBUGLOG(vhost_ring, - "virtqueue gets %d reqs, but kickfd shows %lu reqs\n", - avail_idx - last_idx, num_events); - } - + if (virtqueue->vsession && spdk_unlikely(virtqueue->vsession->interrupt_mode)) { if (num_events > count) { SPDK_DEBUGLOG(vhost_ring, "virtqueue kickfd shows %lu reqs, take %d, send notice for other reqs\n",