DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huawei Xie <huawei.xie@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v4 3/7] virtio: rx/tx ring layout optimization
Date: Thu, 22 Oct 2015 20:09:47 +0800	[thread overview]
Message-ID: <1445515791-25909-4-git-send-email-huawei.xie@intel.com> (raw)
In-Reply-To: <1445515791-25909-1-git-send-email-huawei.xie@intel.com>

Changes in V4:
- fix the error in tx ring layout chart in this commit message.

In DPDK based switching envrioment, mostly vhost runs on a dedicated core
while virtio processing in guest VMs runs on different cores.
Take RX for example, with generic implementation, for each guest buffer,
a) virtio driver allocates a descriptor from free descriptor list
b) modify the entry of avail ring to point to allocated descriptor
c) after packet is received, free the descriptor

When vhost fetches the avail ring, it need to fetch the modified L1 cache from
virtio core, which is a heavy cost in current CPU implementation.

This idea of this optimization is:
    allocate the fixed descriptor for each entry of avail ring, so avail ring will
always be the same during the run.
This removes L1M cache transfer from virtio core to vhost core for avail ring.
(Note we couldn't avoid the cache transfer for descriptors).
Besides, descriptor allocation and free operation is eliminated.
This also makes vector procesing possible to further accelerate the processing.

This is the layout for the avail ring(take 256 ring entries for example), with
each entry pointing to the descriptor with the same index.
                    avail
                    idx
                    +
                    |
+----+----+---+-------------+------+
| 0  | 1  | 2 | ... |  254  | 255  |  avail ring
+-+--+-+--+-+-+---------+---+--+---+
  |    |    |       |   |      |
  |    |    |       |   |      |
  v    v    v       |   v      v
+-+--+-+--+-+-+---------+---+--+---+
| 0  | 1  | 2 | ... |  254  | 255  |  desc ring
+----+----+---+-------------+------+
                    |
                    |
+----+----+---+-------------+------+
| 0  | 1  | 2 |     |  254  | 255  |  used ring
+----+----+---+-------------+------+
                    |
                    +

This is the ring layout for TX.
As we need one virtio header for each xmit packet, we have 128 slots available.

                         ++
                         ||
                         ||
+-----+-----+-----+--------------+------+------+------+
|  0  |  1  | ... |  127 || 128  | 129  | ...  | 255  |   avail ring
+--+--+--+--+-----+---+------+---+--+---+------+--+---+
   |     |            |  ||  |      |             |
   v     v            v  ||  v      v             v
+--+--+--+--+-----+---+------+---+--+---+------+--+---+
| 128 | 129 | ... |  255 || 128  | 129  | ...  | 255  |   desc ring for virtio_net_hdr
+--+--+--+--+-----+---+------+---+--+---+------+--+---+
   |     |            |  ||  |      |             |
   v     v            v  ||  v      v             v
+--+--+--+--+-----+---+------+---+--+---+------+--+---+
|  0  |  1  | ... |  127 ||  0   |  1   | ...  | 127  |   desc ring for tx dat
+-----+-----+-----+--------------+------+------+------+
                         ||
                         ||
                         ++

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
 drivers/net/virtio/virtio_rxtx.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index 5c00e9d..7c82a6a 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -302,6 +302,12 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)
 		nbufs = 0;
 		error = ENOSPC;
 
+		if (use_simple_rxtx)
+			for (i = 0; i < vq->vq_nentries; i++) {
+				vq->vq_ring.avail->ring[i] = i;
+				vq->vq_ring.desc[i].flags = VRING_DESC_F_WRITE;
+			}
+
 		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;
@@ -332,6 +338,24 @@ virtio_dev_vring_start(struct virtqueue *vq, int queue_type)
 		VIRTIO_WRITE_REG_4(vq->hw, VIRTIO_PCI_QUEUE_PFN,
 			vq->mz->phys_addr >> VIRTIO_PCI_QUEUE_ADDR_SHIFT);
 	} else if (queue_type == VTNET_TQ) {
+		if (use_simple_rxtx) {
+			int mid_idx  = vq->vq_nentries >> 1;
+			for (i = 0; i < mid_idx; i++) {
+				vq->vq_ring.avail->ring[i] = i + mid_idx;
+				vq->vq_ring.desc[i + mid_idx].next = i;
+				vq->vq_ring.desc[i + mid_idx].addr =
+					vq->virtio_net_hdr_mem +
+						mid_idx * vq->hw->vtnet_hdr_size;
+				vq->vq_ring.desc[i + mid_idx].len =
+					vq->hw->vtnet_hdr_size;
+				vq->vq_ring.desc[i + mid_idx].flags =
+					VRING_DESC_F_NEXT;
+				vq->vq_ring.desc[i].flags = 0;
+			}
+			for (i = mid_idx; i < vq->vq_nentries; i++)
+				vq->vq_ring.avail->ring[i] = i;
+		}
+
 		VIRTIO_WRITE_REG_2(vq->hw, VIRTIO_PCI_QUEUE_SEL,
 			vq->vq_queue_index);
 		VIRTIO_WRITE_REG_4(vq->hw, VIRTIO_PCI_QUEUE_PFN,
-- 
1.8.1.4

  parent reply	other threads:[~2015-10-22 12:10 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29 14:45 [dpdk-dev] [PATCH 0/8] virtio: virtio ring layout optimization and RX vector processing Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 1/8] virtio: add configure for simple virtio rx/tx Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 2/8] virtio: add virtio_rxtx.h header file Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 3/8] virtio: add software rx ring, fake_buf, simple_rxtx into virtqueue Huawei Xie
2015-09-29 16:15   ` Stephen Hemminger
2015-09-29 14:45 ` [dpdk-dev] [PATCH 4/8] virtio: rx/tx ring layout optimization Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 5/8] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 6/8] virtio: virtio vec rx Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 7/8] virtio: simple tx routine Huawei Xie
2015-09-29 14:45 ` [dpdk-dev] [PATCH 8/8] virtio: rxtx_func_get Huawei Xie
2015-09-29 15:41 ` [dpdk-dev] [PATCH 0/8] virtio: virtio ring layout optimization and RX vector processing Xie, Huawei
2015-10-18  6:28 ` [dpdk-dev] [PATCH v2 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-18  6:28 ` Huawei Xie
2015-10-18  6:28   ` [dpdk-dev] [PATCH v2 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-18  6:28   ` [dpdk-dev] [PATCH v2 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-19  4:20     ` Stephen Hemminger
2015-10-19  5:06       ` Xie, Huawei
2015-10-20 15:32         ` Xie, Huawei
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 3/7] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 5/7] virtio: virtio vec rx Huawei Xie
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 6/7] virtio: simple tx routine Huawei Xie
2015-10-19  4:16     ` Stephen Hemminger
2015-10-19  5:22       ` Xie, Huawei
2015-10-19  4:18     ` Stephen Hemminger
2015-10-19  5:15       ` Xie, Huawei
2015-10-19  4:19     ` Stephen Hemminger
2015-10-19  5:12       ` Xie, Huawei
2015-10-18  6:29   ` [dpdk-dev] [PATCH v2 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-20 15:30 ` [dpdk-dev] [PATCH v3 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 3/7] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 5/7] virtio: virtio vec rx Huawei Xie
2015-10-22  4:04     ` Wang, Zhihong
2015-10-22  5:48       ` Xie, Huawei
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 6/7] virtio: simple tx routine Huawei Xie
2015-10-20 18:58     ` Stephen Hemminger
2015-10-22  5:43       ` Xie, Huawei
2015-10-20 15:30   ` [dpdk-dev] [PATCH v3 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-22  2:50     ` Tan, Jianfeng
2015-10-22 11:40       ` Xie, Huawei
2015-10-22 12:09 ` [dpdk-dev] [PATCH v4 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-22 12:09   ` Huawei Xie [this message]
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-23  5:56     ` Tan, Jianfeng
2015-10-25 15:40       ` Xie, Huawei
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 5/7] virtio: virtio vec rx Huawei Xie
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 6/7] virtio: simple tx routine Huawei Xie
2015-10-22 16:57     ` Stephen Hemminger
2015-10-23  2:17       ` Xie, Huawei
2015-10-23  2:20         ` Xie, Huawei
2015-10-22 12:09   ` [dpdk-dev] [PATCH v4 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-22 16:58     ` Stephen Hemminger
2015-10-23  1:38       ` Xie, Huawei
2015-10-25 15:34 ` [dpdk-dev] [PATCH v5 0/7] virtio ring layout optimization and simple rx/tx processing Huawei Xie
2015-10-25 15:34   ` [dpdk-dev] [PATCH v5 1/7] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-25 15:34   ` [dpdk-dev] [PATCH v5 2/7] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 3/7] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 4/7] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 5/7] virtio: virtio vec rx Huawei Xie
2015-10-26  8:34     ` Wang, Zhihong
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 6/7] virtio: simple tx routine Huawei Xie
2015-10-25 15:35   ` [dpdk-dev] [PATCH v5 7/7] virtio: pick simple rx/tx func Huawei Xie
2015-10-27  1:44   ` [dpdk-dev] [PATCH v5 0/7] virtio ring layout optimization and simple rx/tx processing Tan, Jianfeng
2015-10-27  2:15     ` Yuanhan Liu
2015-10-27 10:17       ` Bruce Richardson
2015-10-29 14:53 ` [dpdk-dev] [PATCH v6 0/8] " Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 1/8] virtio: add virtio_rxtx.h header file Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 2/8] virtio: add software rx ring, fake_buf into virtqueue Huawei Xie
2015-10-30 18:13     ` Thomas Monjalon
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 3/8] virtio: rx/tx ring layout optimization Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 4/8] virtio: fill RX avail ring with blank mbufs Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 5/8] virtio: virtio vec rx Huawei Xie
2015-10-30 18:19     ` Thomas Monjalon
2015-11-02  2:18       ` Xie, Huawei
2015-11-02  7:28         ` Thomas Monjalon
2015-11-02  8:49           ` Xie, Huawei
2015-11-02  9:03             ` Thomas Monjalon
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 6/8] virtio: simple tx routine Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 7/8] virtio: pick simple rx/tx func Huawei Xie
2015-10-29 14:53   ` [dpdk-dev] [PATCH v6 8/8] doc: update release notes 2.2 about virtio performance optimization Huawei Xie
2015-10-30  2:05   ` [dpdk-dev] [PATCH v6 0/8] virtio ring layout optimization and simple rx/tx processing Tan, Jianfeng
2015-11-02 22:09     ` Thomas Monjalon
2015-11-02 22:10       ` Thomas Monjalon
2015-11-03 10:30         ` Xie, Huawei
2015-11-27  6:03   ` Xu, Qian Q
2015-12-17  5:22     ` Xie, Huawei
2015-12-17  9:08       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445515791-25909-4-git-send-email-huawei.xie@intel.com \
    --to=huawei.xie@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).