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 E4601A0555; Thu, 9 Jun 2022 11:46:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D77DB41614; Thu, 9 Jun 2022 11:46:08 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 12D2D40220 for ; Thu, 9 Jun 2022 11:46:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654767967; x=1686303967; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GBFXgkDx+k1FJ2Zm56S4xC17obDyQUznf/yL7BsSDzg=; b=nuitFTubGLvwZw1ryo3WiUx+PnUHvNWJ1YDXcxmWFbbQ5gy0FVPD6PWb dGPcI/BjKjIdoYjvVJ3fCZB9jJZalKPLtBog7uqAVns2NMOWzO0SuOUI3 zVvWW2O6zeoHspKOt9deOg+4D1lbehGEgrwEN1aRA5UP83W4w+FaNCETq RvhJsFvEnaLpcTuj+nDosuID8lEatDsdCdKt7eqjA0bLKB5oSokoJtKkb vXC0NGeu91Dk/Z7CgNZG/NyU81dim4m3erwrNhQk1/ZQACTrUNZrOIJiI BUTkrfQfYnVC7ycMrfqyMgIZnTYhi7WtK7xNnUQYIWeQkArNvgEqucCnG w==; X-IronPort-AV: E=McAfee;i="6400,9594,10372"; a="338987035" X-IronPort-AV: E=Sophos;i="5.91,287,1647327600"; d="scan'208";a="338987035" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2022 02:46:06 -0700 X-IronPort-AV: E=Sophos;i="5.91,287,1647327600"; d="scan'208";a="637387612" Received: from unknown (HELO localhost.localdomain) ([10.239.251.55]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jun 2022 02:46:03 -0700 From: Yuan Wang To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, dev@dpdk.org Cc: jiayu.hu@intel.com, xuan.ding@intel.com, sunil.pai.g@intel.com, Yuan Wang Subject: [PATCH v5 2/2] example/vhost: support to clear in-flight packets for async dequeue Date: Fri, 10 Jun 2022 01:34:04 +0800 Message-Id: <20220609173404.1769210-3-yuanx.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220609173404.1769210-1-yuanx.wang@intel.com> References: <20220413182742.860659-1-yuanx.wang@intel.com> <20220609173404.1769210-1-yuanx.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 allows vring_state_changed() to clear in-flight dequeue packets. It also clears the in-flight packets in a thread-safe way in destroy_device(). Signed-off-by: Yuan Wang --- examples/vhost/main.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index e7fee5aa1b..a679ef738c 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -1543,6 +1543,25 @@ vhost_clear_queue_thread_unsafe(struct vhost_dev *vdev, uint16_t queue_id) } } +static void +vhost_clear_queue(struct vhost_dev *vdev, uint16_t queue_id) +{ + uint16_t n_pkt = 0; + int pkts_inflight; + + int16_t dma_id = dma_bind[vid2socketid[vdev->vid]].dmas[queue_id].dev_id; + pkts_inflight = rte_vhost_async_get_inflight(vdev->vid, queue_id); + + struct rte_mbuf *m_cpl[pkts_inflight]; + + while (pkts_inflight) { + n_pkt = rte_vhost_clear_queue(vdev->vid, queue_id, m_cpl, + pkts_inflight, dma_id, 0); + free_pkts(m_cpl, n_pkt); + pkts_inflight = rte_vhost_async_get_inflight(vdev->vid, queue_id); + } +} + /* * Remove a device from the specific data core linked list and from the * main linked list. Synchronization occurs through the use of the @@ -1600,13 +1619,13 @@ destroy_device(int vid) vdev->vid); if (dma_bind[vid].dmas[VIRTIO_RXQ].async_enabled) { - vhost_clear_queue_thread_unsafe(vdev, VIRTIO_RXQ); + vhost_clear_queue(vdev, VIRTIO_RXQ); rte_vhost_async_channel_unregister(vid, VIRTIO_RXQ); dma_bind[vid].dmas[VIRTIO_RXQ].async_enabled = false; } if (dma_bind[vid].dmas[VIRTIO_TXQ].async_enabled) { - vhost_clear_queue_thread_unsafe(vdev, VIRTIO_TXQ); + vhost_clear_queue(vdev, VIRTIO_TXQ); rte_vhost_async_channel_unregister(vid, VIRTIO_TXQ); dma_bind[vid].dmas[VIRTIO_TXQ].async_enabled = false; } @@ -1765,9 +1784,6 @@ vring_state_changed(int vid, uint16_t queue_id, int enable) if (!vdev) return -1; - if (queue_id != VIRTIO_RXQ) - return 0; - if (dma_bind[vid2socketid[vid]].dmas[queue_id].async_enabled) { if (!enable) vhost_clear_queue_thread_unsafe(vdev, queue_id); -- 2.25.1