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 3EAF3A0547; Thu, 9 Sep 2021 16:01:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 72F094115A; Thu, 9 Sep 2021 16:01:11 +0200 (CEST) Received: from m12-14.163.com (m12-14.163.com [220.181.12.14]) by mails.dpdk.org (Postfix) with ESMTP id EA42940041; Thu, 9 Sep 2021 16:01:08 +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=aCzzd ZAAfl9VlyLkUmV2S0VgaBzr3oeFzJpWjrZ0koM=; b=Yxf+EqVfASFUzxkBHVqLt fCDQ3a0JUcwzIxOZLOzO6/1Jn30IyW65bx4qmUiwruSpWqdW0fvW7w7U/OvFJwUb rmapRCvV2k3Z8yv5f2tBjc31z6ZgjrA37dMqyU2RFWeSvEP2+OvT+h2q0I4dvdnQ brHxdWlXPzcNPj2cEFQGH8= Received: from DESKTOP-ONA2IA7.localdomain (unknown [223.104.244.244]) by smtp10 (Coremail) with SMTP id DsCowACXyfCOEzphW3pHGw--.14358S4; Thu, 09 Sep 2021 22:00:59 +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: Thu, 9 Sep 2021 22:00:43 +0800 Message-Id: <20210909140043.1226-1-gaoxiangliu0@163.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: DsCowACXyfCOEzphW3pHGw--.14358S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxuryUtrWUCF4kWw1xCr1xXwb_yoW5ury3pF 43KF9xAr45tF47W3WxAF13uw15AFZ2kw17GrsxGw1fKrW2yr17Xa92kF1Svr1xKr9xCrZ8 ZF1Fv3WDGa4Y9aDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UEhFsUUUUU= X-Originating-IP: [223.104.244.244] X-CM-SenderInfo: xjdr5xxdqjzxjxq6il2tof0z/1tbiMhsJOlWBvSVQbAAAsq 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 a202931e9..ae2055097 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 b93482587..35309cba7 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1223,6 +1223,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)) { @@ -1374,6 +1384,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_batch_packed(dev, vq, &pkts[pkt_idx])) { -- 2.32.0