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 9E13AA0547; Fri, 10 Sep 2021 11:05:50 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B61240DDE; Fri, 10 Sep 2021 11:05:50 +0200 (CEST) Received: from m12-17.163.com (m12-17.163.com [220.181.12.17]) by mails.dpdk.org (Postfix) with ESMTP id 3077E406B4; Fri, 10 Sep 2021 11:05:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=12I58 XPGiZF5qND4B2HK+o8US7RJPNJW1RTInHM3gBI=; b=dcIDcstCXYcAbSvpo9kWd KA6twUEzBFtx6KBXRWTDJdbVBwl8Fgrmv96Xqp5nGHC+o+YioxYp+gxYuKO3ZbGQ OUESSOhYw5GMsduV/UlUHOUnH2KDOqchCEoIvNNc0aqFtQ/WsjnjlPDOH/Rg9D/J /6Jxp2xkb7rQF62lGxJAcw= Received: from DESKTOP-ONA2IA7.localdomain (unknown [112.17.247.202]) by smtp13 (Coremail) with SMTP id EcCowACn1jrcHzthRl0nLg--.10406S4; Fri, 10 Sep 2021 17:05:43 +0800 (CST) From: Gaoxiang Liu To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, liugaoxiang@huawei.com, Gaoxiang Liu , stable@dpdk.org Date: Fri, 10 Sep 2021 17:05:30 +0800 Message-Id: <20210910090530.893-1-gaoxiangliu0@163.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210910021117.130-1-gaoxiangliu0@163.com> References: <20210910021117.130-1-gaoxiangliu0@163.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: EcCowACn1jrcHzthRl0nLg--.10406S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuryUtrWrXw18GrW3CF1ftFb_yoW5urWxpF 43KF9xAr45tF47Gw4xAF43uw15AFZ2kw17GrsrGw1fKrW2yF1xXas2kF1SvryxKr9xCrZ0 vF1Fv3WDGa4Y9aDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Ub18PUUUUU= X-Originating-IP: [112.17.247.202] X-CM-SenderInfo: xjdr5xxdqjzxjxq6il2tof0z/1tbiWwcKOlSIrdBqkwAAs0 Subject: [dpdk-dev] [PATCH] vhost: merge repeated loop in vhost Tx 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 Sender: "dev" To improve performance of vhost Tx, merge repeated loop in eth_vhost_tx. Move "vlan insert" from eth_vhost_tx to virtio_dev_rx_packed and virtio_dev_rx_split to reduce a loop iteration. Fixes: f63d356ee993 ("net/vhost: insert/strip VLAN header in software") Cc: stable@dpdk.org Signed-off-by: Gaoxiang Liu --- drivers/net/vhost/rte_eth_vhost.c | 25 ++++--------------------- lib/vhost/virtio_net.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c index a202931e9a..ae20550976 100644 --- a/drivers/net/vhost/rte_eth_vhost.c +++ b/drivers/net/vhost/rte_eth_vhost.c @@ -428,7 +428,6 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { struct vhost_queue *r = q; uint16_t i, nb_tx = 0; - uint16_t nb_send = 0; uint64_t nb_bytes = 0; uint64_t nb_missed = 0; @@ -440,33 +439,17 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) if (unlikely(rte_atomic32_read(&r->allow_queuing) == 0)) goto out; - for (i = 0; i < nb_bufs; i++) { - struct rte_mbuf *m = bufs[i]; - - /* Do VLAN tag insertion */ - if (m->ol_flags & PKT_TX_VLAN_PKT) { - int error = rte_vlan_insert(&m); - if (unlikely(error)) { - rte_pktmbuf_free(m); - continue; - } - } - - bufs[nb_send] = m; - ++nb_send; - } - /* Enqueue packets to guest RX queue */ - while (nb_send) { + while (nb_bufs) { uint16_t nb_pkts; - uint16_t num = (uint16_t)RTE_MIN(nb_send, + uint16_t num = (uint16_t)RTE_MIN(nb_bufs, VHOST_MAX_PKT_BURST); nb_pkts = rte_vhost_enqueue_burst(r->vid, r->virtqueue_id, &bufs[nb_tx], num); nb_tx += nb_pkts; - nb_send -= nb_pkts; + nb_bufs -= nb_pkts; if (nb_pkts < num) break; } @@ -474,7 +457,7 @@ eth_vhost_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) for (i = 0; likely(i < nb_tx); i++) nb_bytes += bufs[i]->pkt_len; - nb_missed = nb_bufs - nb_tx; + nb_missed = nb_bufs; r->stats.pkts += nb_tx; r->stats.bytes += nb_bytes; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 8549afbbe1..2057f4e7fe 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1218,6 +1218,16 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen; uint16_t nr_vec = 0; + /* Do VLAN tag insertion */ + if (pkts[pkt_idx]->ol_flags & PKT_TX_VLAN_PKT) { + int error = rte_vlan_insert(&pkts[pkt_idx]); + if (unlikely(error)) { + rte_pktmbuf_free(pkts[pkt_idx]); + pkts[pkt_idx] = NULL; + continue; + } + } + if (unlikely(reserve_avail_buf_split(dev, vq, pkt_len, buf_vec, &num_buffers, avail_head, &nr_vec) < 0)) { @@ -1490,6 +1500,17 @@ virtio_dev_rx_packed(struct virtio_net *dev, do { rte_prefetch0(&vq->desc_packed[vq->last_avail_idx]); + /* Do VLAN tag insertion */ + if (pkts[pkt_idx]->ol_flags & PKT_TX_VLAN_PKT) { + int error = rte_vlan_insert(&pkts[pkt_idx]); + if (unlikely(error)) { + rte_pktmbuf_free(pkts[pkt_idx]); + pkts[pkt_idx] = NULL; + pkt_idx++; + continue; + } + } + if (count - pkt_idx >= PACKED_BATCH_SIZE) { if (!virtio_dev_rx_sync_batch_packed(dev, vq, &pkts[pkt_idx])) { -- 2.32.0