From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1CF2546091; Wed, 15 Jan 2025 13:59:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7D1E140430; Wed, 15 Jan 2025 13:59:55 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id A99AA402F2 for ; Wed, 15 Jan 2025 13:59:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736945993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QbqED/zM0nF+WwsgW5GZjazH1rg2TIVO9SYIBanVp4E=; b=asQG/ncq1Lpc79f7hO6Ouj+yi8XlQTRckSCOAVBJcvbbRnx0FfW9mLOm8pPISPcLcI3yFA E6tZKq8Vbtoz3chGzCufTNahnTLEe/lRHH3y3X9K4aWhoC4sXkhOoeD63Ik7bA3iCX5TGP bYB5YjYokLzpLAQNTb9VHB/4cLf+Wy0= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-iW5iVUUrMbKJ6oYoyXyoWg-1; Wed, 15 Jan 2025 07:59:50 -0500 X-MC-Unique: iW5iVUUrMbKJ6oYoyXyoWg-1 X-Mimecast-MFC-AGG-ID: iW5iVUUrMbKJ6oYoyXyoWg Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 774FC196E042; Wed, 15 Jan 2025 12:59:49 +0000 (UTC) Received: from max-p1.redhat.com (unknown [10.39.208.25]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0FE4019560AA; Wed, 15 Jan 2025 12:59:47 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, david.marchand@redhat.com, chenbox@nvidia.com Cc: Maxime Coquelin Subject: [PATCH v2 2/4] vhost: rework dequeue path error handling Date: Wed, 15 Jan 2025 13:59:36 +0100 Message-ID: <20250115125938.2699577-3-maxime.coquelin@redhat.com> In-Reply-To: <20250115125938.2699577-1-maxime.coquelin@redhat.com> References: <20250115125938.2699577-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: RtMYvpajYQEVh13Y6lH-nyxNmcQJGHg3TQi6EpladMQ_1736945989 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch refactors the error handling in the Vhost dequeue path to ease its maintenance and readability. Suggested-by: David Marchand Signed-off-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index a340e5a772..3a4955fd30 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -3593,6 +3593,7 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, struct rte_mbuf *rarp_mbuf = NULL; struct vhost_virtqueue *vq; int16_t success = 1; + uint16_t nb_rx = 0; dev = get_device(vid); if (!dev) @@ -3602,25 +3603,23 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, VHOST_DATA_LOG(dev->ifname, ERR, "%s: built-in vhost net backend is disabled.", __func__); - return 0; + goto out_no_unlock; } if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->nr_vring))) { VHOST_DATA_LOG(dev->ifname, ERR, "%s: invalid virtqueue idx %d.", __func__, queue_id); - return 0; + goto out_no_unlock; } vq = dev->virtqueue[queue_id]; if (unlikely(rte_rwlock_read_trylock(&vq->access_lock) != 0)) - return 0; + goto out_no_unlock; - if (unlikely(!vq->enabled)) { - count = 0; + if (unlikely(!vq->enabled)) goto out_access_unlock; - } vhost_user_iotlb_rd_lock(vq); @@ -3630,7 +3629,6 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, virtio_dev_vring_translate(dev, vq); - count = 0; goto out_no_unlock; } @@ -3657,7 +3655,6 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, rarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac); if (rarp_mbuf == NULL) { VHOST_DATA_LOG(dev->ifname, ERR, "failed to make RARP packet."); - count = 0; goto out; } /* @@ -3672,17 +3669,17 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, if (vq_is_packed(dev)) { if (dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS) - count = virtio_dev_tx_packed_legacy(dev, vq, mbuf_pool, pkts, count); + nb_rx = virtio_dev_tx_packed_legacy(dev, vq, mbuf_pool, pkts, count); else - count = virtio_dev_tx_packed_compliant(dev, vq, mbuf_pool, pkts, count); + nb_rx = virtio_dev_tx_packed_compliant(dev, vq, mbuf_pool, pkts, count); } else { if (dev->flags & VIRTIO_DEV_LEGACY_OL_FLAGS) - count = virtio_dev_tx_split_legacy(dev, vq, mbuf_pool, pkts, count); + nb_rx = virtio_dev_tx_split_legacy(dev, vq, mbuf_pool, pkts, count); else - count = virtio_dev_tx_split_compliant(dev, vq, mbuf_pool, pkts, count); + nb_rx = virtio_dev_tx_split_compliant(dev, vq, mbuf_pool, pkts, count); } - vhost_queue_stats_update(dev, vq, pkts, count); + vhost_queue_stats_update(dev, vq, pkts, nb_rx); out: vhost_user_iotlb_rd_unlock(vq); @@ -3691,10 +3688,10 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, rte_rwlock_read_unlock(&vq->access_lock); if (unlikely(rarp_mbuf != NULL)) - count += 1; + nb_rx += 1; out_no_unlock: - return count; + return nb_rx; } static __rte_always_inline uint16_t -- 2.47.1