From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 678875A50 for ; Thu, 29 Oct 2015 15:53:45 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 29 Oct 2015 07:53:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,214,1444719600"; d="scan'208";a="822355052" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga001.fm.intel.com with ESMTP; 29 Oct 2015 07:53:43 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id t9TErf1k028940; Thu, 29 Oct 2015 22:53:41 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t9TErc6k014047; Thu, 29 Oct 2015 22:53:40 +0800 Received: (from hxie5@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t9TErcKK013953; Thu, 29 Oct 2015 22:53:38 +0800 From: Huawei Xie To: dev@dpdk.org Date: Thu, 29 Oct 2015 22:53:23 +0800 Message-Id: <1446130409-8217-3-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1446130409-8217-1-git-send-email-huawei.xie@intel.com> References: <1443537953-23917-1-git-send-email-huawei.xie@intel.com> <1446130409-8217-1-git-send-email-huawei.xie@intel.com> Subject: [dpdk-dev] [PATCH v6 2/8] virtio: add software rx ring, fake_buf into virtqueue 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: Thu, 29 Oct 2015 14:53:46 -0000 Changes in v3: - Remove unnecessary NULL test for rte_free - Remove unnecessary assign of local var vq after free Add software RX ring in virtqueue. Add fake_mbuf in virtqueue for wraparound processing. Use global simple_rxtx to indicate whether simple rxtx is enabled Signed-off-by: Huawei Xie --- drivers/net/virtio/virtio_ethdev.c | 11 ++++++++++- drivers/net/virtio/virtio_rxtx.c | 7 +++++++ drivers/net/virtio/virtqueue.h | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 79a3640..82676d3 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -247,8 +247,8 @@ virtio_dev_queue_release(struct virtqueue *vq) { VIRTIO_WRITE_REG_2(hw, VIRTIO_PCI_QUEUE_SEL, vq->queue_id); VIRTIO_WRITE_REG_4(hw, VIRTIO_PCI_QUEUE_PFN, 0); + rte_free(vq->sw_ring); rte_free(vq); - vq = NULL; } } @@ -292,6 +292,9 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, dev->data->port_id, queue_idx); vq = rte_zmalloc(vq_name, sizeof(struct virtqueue) + vq_size * sizeof(struct vq_desc_extra), RTE_CACHE_LINE_SIZE); + vq->sw_ring = rte_zmalloc_socket("rxq->sw_ring", + (RTE_PMD_VIRTIO_RX_MAX_BURST + vq_size) * + sizeof(vq->sw_ring[0]), RTE_CACHE_LINE_SIZE, socket_id); } else if (queue_type == VTNET_TQ) { snprintf(vq_name, sizeof(vq_name), "port%d_tvq%d", dev->data->port_id, queue_idx); @@ -308,6 +311,12 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, PMD_INIT_LOG(ERR, "%s: Can not allocate virtqueue", __func__); return (-ENOMEM); } + if (queue_type == VTNET_RQ && vq->sw_ring == NULL) { + PMD_INIT_LOG(ERR, "%s: Can not allocate RX soft ring", + __func__); + rte_free(vq); + return -ENOMEM; + } vq->hw = hw; vq->port_id = dev->data->port_id; diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index 9324f7f..5c00e9d 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -62,6 +62,8 @@ #define VIRTIO_DUMP_PACKET(m, len) do { } while (0) #endif +static int use_simple_rxtx; + static void vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) { @@ -299,6 +301,11 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type) /* Allocate blank mbufs for the each rx descriptor */ nbufs = 0; error = ENOSPC; + + memset(&vq->fake_mbuf, 0, sizeof(vq->fake_mbuf)); + for (i = 0; i < RTE_PMD_VIRTIO_RX_MAX_BURST; i++) + vq->sw_ring[vq->vq_nentries + i] = &vq->fake_mbuf; + while (!virtqueue_full(vq)) { m = rte_rxmbuf_alloc(vq->mpool); if (m == NULL) diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h index 7789411..6a1ec48 100644 --- a/drivers/net/virtio/virtqueue.h +++ b/drivers/net/virtio/virtqueue.h @@ -190,6 +190,10 @@ struct virtqueue { uint16_t vq_avail_idx; phys_addr_t virtio_net_hdr_mem; /**< hdr for each xmit packet */ + struct rte_mbuf **sw_ring; /**< RX software ring. */ + /* dummy mbuf, for wraparound when processing RX ring. */ + struct rte_mbuf fake_mbuf; + /* Statistics */ uint64_t packets; uint64_t bytes; -- 1.8.1.4