From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by dpdk.org (Postfix) with ESMTP id 8E3098E59 for ; Fri, 4 Dec 2015 02:12:47 +0100 (CET) Received: by pacdm15 with SMTP id dm15so77811137pac.3 for ; Thu, 03 Dec 2015 17:12:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JvVHidrV4bMksZtuWNw6Dzycjws/2UM1JOqgv0cO63Q=; b=Q1eH1A3d/O5jMvVmaKVuDpgWrihlY7FC0uJAiBMld/bXL6pt7sDmspIU+NKz3UecpO evF3tamxF46ZVNBsyX/5gMXWrTsteFFuc4pH6oE6cInBmqV/aT8TqFxxZO9JQTtxKtrI n5w9f8PwKIxUsn0np+tfshsrDebLrRkcIR64YvNEAUhbL4R2UqbC0p7J7Z6recDgwnvx mifSbpJolh6xT6PqLJw0OoQOe2WPdjw55DUThKV1mWd0cPNcd1bDBiJBUX3TXW/fQ5l3 VaqpNEss6RcVpChsqgK0cqcg4UEm6HBFs6eSQ+gk7rSGJQWEUX8U+zQ9Bee2NkLP6eSY eKQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JvVHidrV4bMksZtuWNw6Dzycjws/2UM1JOqgv0cO63Q=; b=JaSkyM9BvO/pOCukifAO/Di/LYdSYhK9ME01fnUzUOcRC/TeouC06Faq16sqVLwHGs BFAdLRx2bfg6hZKjwdenay07j8zN4zSgBaj+S1iZeHVPF1w/32zItjw8mEYmWQ7keQkc A+1e1t2DhGiafm+bp0Jj5VbpnAL4t35teriUtvxTyStKiVmJIFs0tDKJwuVA1c9W+0/6 /vWroWkQ9j7kdrDEvDhJDoSgSq6KOs2fkDYECaEHtKsOADMy8ZDDcy7f+47M9/yrKWNA eh0wHiEYdCZNiciQRmF2ZP+6+wk7ElRnmVQBYXrohV/WOQ3h2lzF2E7UcJHh7lpH/nqL Z6Kg== X-Gm-Message-State: ALoCoQlCd4vxfDW6XEMOcx3XCeCbybbnfqV2pXJrVDAQY+Yp/kK2NPPPMIRp7SgQGhtOJTiMy43b X-Received: by 10.66.138.101 with SMTP id qp5mr17619084pab.113.1449191566977; Thu, 03 Dec 2015 17:12:46 -0800 (PST) Received: from xeon-e3.home.lan (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by smtp.gmail.com with ESMTPSA id b15sm13110257pfj.7.2015.12.03.17.12.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Dec 2015 17:12:46 -0800 (PST) From: Stephen Hemminger To: huawei.xie@intel.com, yuanhan.liu@linux.intel.com Date: Thu, 3 Dec 2015 17:12:54 -0800 Message-Id: <1449191574-14629-3-git-send-email-stephen@networkplumber.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1449191574-14629-1-git-send-email-stephen@networkplumber.org> References: <1449191574-14629-1-git-send-email-stephen@networkplumber.org> Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH 2/2] virtio: clean up space checks on xmit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Dec 2015 01:12:48 -0000 The space check for transmit ring only needs a single conditional. I.e only need to recheck for space if there was no space in first check. This can help performance and simplifies loop. Signed-off-by: Stephen Hemminger --- drivers/net/virtio/virtio_rxtx.c | 68 +++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 466fee6..7cb932a 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -832,7 +832,6 @@ uint16_t virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { struct virtqueue *txvq = tx_queue; - struct rte_mbuf *txm; uint16_t nb_used, nb_tx; int error; @@ -846,58 +845,49 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) if (likely(nb_used > txvq->vq_nentries - txvq->vq_free_thresh)) virtio_xmit_cleanup(txvq, nb_used); - nb_tx = 0; - - while (nb_tx < nb_pkts) { + for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) { + struct rte_mbuf *txm = tx_pkts[nb_tx]; /* Need one more descriptor for virtio header. */ - int need = tx_pkts[nb_tx]->nb_segs - txvq->vq_free_cnt + 1; + int need = txm->nb_segs - txvq->vq_free_cnt + 1; - /*Positive value indicates it need free vring descriptors */ + /* Positive value indicates it need free vring descriptors */ if (unlikely(need > 0)) { nb_used = VIRTQUEUE_NUSED(txvq); virtio_rmb(); need = RTE_MIN(need, (int)nb_used); virtio_xmit_cleanup(txvq, need); - need = (int)tx_pkts[nb_tx]->nb_segs - - txvq->vq_free_cnt + 1; + need = txm->nb_segs - txvq->vq_free_cnt + 1; + if (unlikely(need > 0)) { + PMD_TX_LOG(ERR, + "No free tx descriptors to transmit"); + break; + } } - /* - * Zero or negative value indicates it has enough free - * descriptors to use for transmitting. - */ - if (likely(need <= 0)) { - txm = tx_pkts[nb_tx]; - - /* Do VLAN tag insertion */ - if (unlikely(txm->ol_flags & PKT_TX_VLAN_PKT)) { - error = rte_vlan_insert(&txm); - if (unlikely(error)) { - rte_pktmbuf_free(txm); - ++nb_tx; - continue; - } - } - - /* Enqueue Packet buffers */ - error = virtqueue_enqueue_xmit(txvq, txm); + /* Do VLAN tag insertion */ + if (unlikely(txm->ol_flags & PKT_TX_VLAN_PKT)) { + error = rte_vlan_insert(&txm); if (unlikely(error)) { - if (error == ENOSPC) - PMD_TX_LOG(ERR, "virtqueue_enqueue Free count = 0"); - else if (error == EMSGSIZE) - PMD_TX_LOG(ERR, "virtqueue_enqueue Free count < 1"); - else - PMD_TX_LOG(ERR, "virtqueue_enqueue error: %d", error); - break; + rte_pktmbuf_free(txm); + continue; } - nb_tx++; - txvq->bytes += txm->pkt_len; - virtio_update_packet_stats(txvq, txm); - } else { - PMD_TX_LOG(ERR, "No free tx descriptors to transmit"); + } + + /* Enqueue Packet buffers */ + error = virtqueue_enqueue_xmit(txvq, txm); + if (unlikely(error)) { + if (error == ENOSPC) + PMD_TX_LOG(ERR, "virtqueue_enqueue Free count = 0"); + else if (error == EMSGSIZE) + PMD_TX_LOG(ERR, "virtqueue_enqueue Free count < 1"); + else + PMD_TX_LOG(ERR, "virtqueue_enqueue error: %d", error); break; } + + txvq->bytes += txm->pkt_len; + virtio_update_packet_stats(txvq, txm); } txvq->packets += nb_tx; -- 2.1.4