From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yuanhan Liu Subject: [PATCH v7 7/7] vhost: retrieve avail head once Date: Fri, 14 Oct 2016 17:34:38 +0800 Message-ID: <1476437678-7102-8-git-send-email-yuanhan.liu@linux.intel.com> References: <1474336817-22683-1-git-send-email-zhihong.wang@intel.com> <1476437678-7102-1-git-send-email-yuanhan.liu@linux.intel.com> Cc: Maxime Coquelin , Yuanhan Liu , Zhihong Wang To: dev@dpdk.org Return-path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 334B66CD2 for ; Fri, 14 Oct 2016 11:33:54 +0200 (CEST) In-Reply-To: <1476437678-7102-1-git-send-email-yuanhan.liu@linux.intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" There is no need to retrieve the latest avail head every time we enqueue a packet in the mereable Rx path by avail_idx = *((volatile uint16_t *)&vq->avail->idx); Instead, we could just retrieve it once at the beginning of the enqueue path. This could diminish the cache penalty slightly, because the virtio driver could be updating it while vhost is reading it (for each packet). Signed-off-by: Yuanhan Liu Signed-off-by: Zhihong Wang --- lib/librte_vhost/virtio_net.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 12a037b..b784dba 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -387,10 +387,10 @@ 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, - struct buf_vector *buf_vec, uint16_t *num_buffers) + struct buf_vector *buf_vec, uint16_t *num_buffers, + uint16_t avail_head) { uint16_t cur_idx; - uint16_t avail_idx; uint32_t vec_idx = 0; uint16_t tries = 0; @@ -401,8 +401,7 @@ reserve_avail_buf_mergeable(struct vhost_virtqueue *vq, uint32_t size, cur_idx = vq->last_avail_idx; while (size > 0) { - avail_idx = *((volatile uint16_t *)&vq->avail->idx); - if (unlikely(cur_idx == avail_idx)) + if (unlikely(cur_idx == avail_head)) return -1; if (unlikely(fill_vec_buf(vq, cur_idx, &vec_idx, buf_vec, @@ -523,6 +522,7 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, uint32_t pkt_idx = 0; uint16_t num_buffers; struct buf_vector buf_vec[BUF_VECTOR_MAX]; + uint16_t avail_head; LOG_DEBUG(VHOST_DATA, "(%d) %s\n", dev->vid, __func__); if (unlikely(!is_valid_virt_queue_idx(queue_id, 0, dev->virt_qp_nb))) { @@ -542,11 +542,12 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]); vq->shadow_used_idx = 0; + avail_head = *((volatile uint16_t *)&vq->avail->idx); 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, buf_vec, - &num_buffers) < 0)) { + &num_buffers, avail_head) < 0)) { LOG_DEBUG(VHOST_DATA, "(%d) failed to get enough desc from vring\n", dev->vid); -- 1.9.0