From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: dev@dpdk.org
Cc: huawei.xie@intel.com, Thomas Monjalon <thomas.monjalon@6wind.com>,
Panu Matilainen <pmatilai@redhat.com>,
Traynor Kevin <kevin.traynor@intel.com>,
Rich Lane <rich.lane@bigswitch.com>,
Tetsuya Mukawa <mukawa@igel.co.jp>,
Ilya Maximets <i.maximets@samsung.com>,
Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [dpdk-dev] [PATCH v3 20/20] vhost: make buf vector for scatter Rx local
Date: Tue, 7 Jun 2016 11:52:10 +0800 [thread overview]
Message-ID: <1465271530-27878-21-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1465271530-27878-1-git-send-email-yuanhan.liu@linux.intel.com>
From: Ilya Maximets <i.maximets@samsung.com>
Array of buf_vector's is just an array for temporary storing information
about available descriptors. It used only locally in virtio_dev_merge_rx()
and there is no reason for that array to be shared.
Fix that by allocating local buf_vec inside virtio_dev_merge_rx().
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Tested-by: Rich Lane <rich.lane@bigswitch.com>
Acked-by: Rich Lane <rich.lane@bigswitch.com>
---
lib/librte_vhost/vhost-net.h | 1 -
lib/librte_vhost/vhost_rxtx.c | 41 ++++++++++++++++++++++-------------------
2 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index 590a039..162ad04 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -87,7 +87,6 @@ struct vhost_virtqueue {
/* Physical address of used ring, for logging */
uint64_t log_guest_addr;
- struct buf_vector buf_vec[BUF_VECTOR_MAX];
} __rte_cache_aligned;
/* Old kernels have no such macro defined */
diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index c9cd1c5..96720db 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -335,7 +335,8 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
static inline int
fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
- uint32_t *allocated, uint32_t *vec_idx)
+ uint32_t *allocated, uint32_t *vec_idx,
+ struct buf_vector *buf_vec)
{
uint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];
uint32_t vec_id = *vec_idx;
@@ -346,9 +347,9 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
return -1;
len += vq->desc[idx].len;
- vq->buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
- vq->buf_vec[vec_id].buf_len = vq->desc[idx].len;
- vq->buf_vec[vec_id].desc_idx = idx;
+ buf_vec[vec_id].buf_addr = vq->desc[idx].addr;
+ buf_vec[vec_id].buf_len = vq->desc[idx].len;
+ buf_vec[vec_id].desc_idx = idx;
vec_id++;
if ((vq->desc[idx].flags & VRING_DESC_F_NEXT) == 0)
@@ -371,7 +372,8 @@ fill_vec_buf(struct vhost_virtqueue *vq, uint32_t avail_idx,
*/
static inline int
reserve_avail_buf_mergeable(struct vhost_virtqueue *vq, uint32_t size,
- uint16_t *start, uint16_t *end)
+ uint16_t *start, uint16_t *end,
+ struct buf_vector *buf_vec)
{
uint16_t res_start_idx;
uint16_t res_cur_idx;
@@ -393,7 +395,7 @@ again:
return -1;
if (unlikely(fill_vec_buf(vq, res_cur_idx, &allocated,
- &vec_idx) < 0))
+ &vec_idx, buf_vec) < 0))
return -1;
res_cur_idx++;
@@ -427,7 +429,7 @@ again:
static inline uint32_t __attribute__((always_inline))
copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
uint16_t res_start_idx, uint16_t res_end_idx,
- struct rte_mbuf *m)
+ struct rte_mbuf *m, struct buf_vector *buf_vec)
{
struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
uint32_t vec_idx = 0;
@@ -444,10 +446,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
LOG_DEBUG(VHOST_DATA, "(%d) current index %d | end index %d\n",
dev->vid, cur_idx, res_end_idx);
- if (vq->buf_vec[vec_idx].buf_len < dev->vhost_hlen)
+ if (buf_vec[vec_idx].buf_len < dev->vhost_hlen)
return -1;
- desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+ desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
rte_prefetch0((void *)(uintptr_t)desc_addr);
virtio_hdr.num_buffers = res_end_idx - res_start_idx;
@@ -456,10 +458,10 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
virtio_enqueue_offload(m, &virtio_hdr.hdr);
copy_virtio_net_hdr(dev, desc_addr, virtio_hdr);
- vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
+ vhost_log_write(dev, buf_vec[vec_idx].buf_addr, dev->vhost_hlen);
PRINT_PACKET(dev, (uintptr_t)desc_addr, dev->vhost_hlen, 0);
- desc_avail = vq->buf_vec[vec_idx].buf_len - dev->vhost_hlen;
+ desc_avail = buf_vec[vec_idx].buf_len - dev->vhost_hlen;
desc_offset = dev->vhost_hlen;
mbuf_avail = rte_pktmbuf_data_len(m);
@@ -467,7 +469,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
while (mbuf_avail != 0 || m->next != NULL) {
/* done with current desc buf, get the next one */
if (desc_avail == 0) {
- desc_idx = vq->buf_vec[vec_idx].desc_idx;
+ desc_idx = buf_vec[vec_idx].desc_idx;
if (!(vq->desc[desc_idx].flags & VRING_DESC_F_NEXT)) {
/* Update used ring with desc information */
@@ -481,12 +483,12 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
}
vec_idx++;
- desc_addr = gpa_to_vva(dev, vq->buf_vec[vec_idx].buf_addr);
+ desc_addr = gpa_to_vva(dev, buf_vec[vec_idx].buf_addr);
/* Prefetch buffer address. */
rte_prefetch0((void *)(uintptr_t)desc_addr);
desc_offset = 0;
- desc_avail = vq->buf_vec[vec_idx].buf_len;
+ desc_avail = buf_vec[vec_idx].buf_len;
}
/* done with current mbuf, get the next one */
@@ -501,7 +503,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
rte_memcpy((void *)((uintptr_t)(desc_addr + desc_offset)),
rte_pktmbuf_mtod_offset(m, void *, mbuf_offset),
cpy_len);
- vhost_log_write(dev, vq->buf_vec[vec_idx].buf_addr + desc_offset,
+ vhost_log_write(dev, buf_vec[vec_idx].buf_addr + desc_offset,
cpy_len);
PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset),
cpy_len, 0);
@@ -513,7 +515,7 @@ copy_mbuf_to_desc_mergeable(struct virtio_net *dev, struct vhost_virtqueue *vq,
}
used_idx = cur_idx & (vq->size - 1);
- vq->used->ring[used_idx].id = vq->buf_vec[vec_idx].desc_idx;
+ vq->used->ring[used_idx].id = buf_vec[vec_idx].desc_idx;
vq->used->ring[used_idx].len = desc_offset;
vhost_log_used_vring(dev, vq,
offsetof(struct vring_used, ring[used_idx]),
@@ -529,6 +531,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
struct vhost_virtqueue *vq;
uint32_t pkt_idx = 0, nr_used = 0;
uint16_t start, end;
+ struct buf_vector buf_vec[BUF_VECTOR_MAX];
LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__);
if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) {
@@ -548,8 +551,8 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
for (pkt_idx = 0; pkt_idx < count; pkt_idx++) {
uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen;
- if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len,
- &start, &end) < 0)) {
+ if (unlikely(reserve_avail_buf_mergeable(vq, pkt_len, &start,
+ &end, buf_vec) < 0)) {
LOG_DEBUG(VHOST_DATA,
"(%d) failed to get enough desc from vring\n",
dev->vid);
@@ -557,7 +560,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id,
}
nr_used = copy_mbuf_to_desc_mergeable(dev, vq, start, end,
- pkts[pkt_idx]);
+ pkts[pkt_idx], buf_vec);
rte_smp_wmb();
/*
--
1.9.0
next prev parent reply other threads:[~2016-06-07 3:51 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-02 22:25 [dpdk-dev] [PATCH 00/16] vhost ABI/API refactoring Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 01/16] vhost: declare backend with int type Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 02/16] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 03/16] vhost: declare device_fh as int Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 04/16] example/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 05/16] vhost: rename device_fh to vid Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 06/16] vhost: get device by vid only Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 07/16] vhost: move vhost_device_ctx to cuse Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 08/16] vhost: query pmd internal by vid Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 09/16] vhost: add few more functions Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 10/16] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-10 16:17 ` Rich Lane
2016-05-10 16:39 ` Yuanhan Liu
2016-05-10 17:13 ` Rich Lane
2016-05-10 17:29 ` Yuanhan Liu
2016-05-10 19:22 ` Thomas Monjalon
2016-05-02 22:25 ` [dpdk-dev] [PATCH 11/16] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 12/16] vhost: remove unnecessary fields Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 13/16] vhost: remove virtio-net.h Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 14/16] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 15/16] vhost: per device vhost_hlen Yuanhan Liu
2016-05-02 22:25 ` [dpdk-dev] [PATCH 16/16] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 01/19] vhost: declare backend with int type Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 02/19] vhost: set/reset dev flags internally Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 03/19] vhost: declare device fh as int Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 04/19] examples/vhost: make a copy of virtio device id Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 05/19] vhost: rename device fh to vid Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 06/19] vhost: get device by vid only Yuanhan Liu
2016-05-13 5:24 ` [dpdk-dev] [PATCH v2 07/19] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 08/19] vhost: introduce new API to export numa node Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 09/19] vhost: introduce new API to export number of queues Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 10/19] vhost: introduce new API to export ifname Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 11/19] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 12/19] vhost: remove dependency on priv field Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 13/19] vhost: export vid as the only interface to applications Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 14/19] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 15/19] vhost: remove unnecessary fields Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 16/19] vhost: remove virtio-net.h Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 17/19] vhost: reserve few more space for future extension Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 18/19] vhost: per device virtio net header len Yuanhan Liu
2016-05-13 5:25 ` [dpdk-dev] [PATCH v2 19/19] vhost: make buf vector for scatter Rx local Yuanhan Liu
2016-05-26 17:04 ` [dpdk-dev] [PATCH v2 00/19] vhost ABI/API refactoring Rich Lane
2016-05-27 1:36 ` Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 00/20] " Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 01/20] vhost: declare backend with int type Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 02/20] vhost: set/reset dev flags internally Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 03/20] vhost: declare device fh as int Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 04/20] examples/vhost: make a copy of virtio device id Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 05/20] vhost: rename device fh to vid Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 06/20] vhost: get device by vid only Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 07/20] vhost: move vhost device ctx to cuse Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 08/20] vhost: introduce new API to export numa node Yuanhan Liu
2016-06-07 11:42 ` Panu Matilainen
2016-06-07 12:45 ` Yuanhan Liu
2016-06-08 21:51 ` Rich Lane
2016-06-09 4:45 ` Yuanhan Liu
2016-06-13 10:05 ` Yuanhan Liu
2016-06-07 3:51 ` [dpdk-dev] [PATCH v3 09/20] vhost: introduce new API to export number of queues Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 10/20] vhost: introduce new API to export ifname Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 11/20] vhost: introduce new API to export queue free entries Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 12/20] vhost: remove dependency on priv field Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 13/20] vhost: export vid as the only interface to applications Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 14/20] vhost: hide internal structs/macros/functions Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 15/20] vhost: remove unnecessary fields Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 16/20] vhost: remove virtio-net.h Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 17/20] vhost: reserve few more space for future extension Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 18/20] examples/tep_term: adapt to new vhost ABI/API changes Yuanhan Liu
2016-06-07 3:52 ` [dpdk-dev] [PATCH v3 19/20] vhost: per device virtio net header len Yuanhan Liu
2016-06-07 3:52 ` Yuanhan Liu [this message]
2016-06-14 12:00 ` [dpdk-dev] [PATCH v3 00/20] vhost ABI/API refactoring Yuanhan Liu
2016-06-30 7:39 ` Panu Matilainen
2016-06-30 7:57 ` Yuanhan Liu
2016-06-30 9:05 ` Panu Matilainen
2016-06-30 11:15 ` Mcnamara, John
2016-06-30 11:40 ` 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=1465271530-27878-21-git-send-email-yuanhan.liu@linux.intel.com \
--to=yuanhan.liu@linux.intel.com \
--cc=dev@dpdk.org \
--cc=huawei.xie@intel.com \
--cc=i.maximets@samsung.com \
--cc=kevin.traynor@intel.com \
--cc=mukawa@igel.co.jp \
--cc=pmatilai@redhat.com \
--cc=rich.lane@bigswitch.com \
--cc=thomas.monjalon@6wind.com \
/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).