From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 9CEBF2BD3 for ; Wed, 24 Feb 2016 12:47:37 +0100 (CET) Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O3100GR8VFD2GA0@mailout2.w1.samsung.com> for dev@dpdk.org; Wed, 24 Feb 2016 11:47:37 +0000 (GMT) X-AuditID: cbfec7f4-f79026d00000418a-3d-56cd9859b0d8 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 12.06.16778.9589DC65; Wed, 24 Feb 2016 11:47:37 +0000 (GMT) Received: from imaximets.rnd.samsung.ru ([106.109.129.180]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O3100380VF3RS40@eusync4.samsung.com>; Wed, 24 Feb 2016 11:47:37 +0000 (GMT) From: Ilya Maximets To: dev@dpdk.org, Huawei Xie , Yuanhan Liu Date: Wed, 24 Feb 2016 14:47:18 +0300 Message-id: <1456314438-4021-4-git-send-email-i.maximets@samsung.com> X-Mailer: git-send-email 2.5.0 In-reply-to: <1456314438-4021-1-git-send-email-i.maximets@samsung.com> References: <1456314438-4021-1-git-send-email-i.maximets@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBLMWRmVeSWpSXmKPExsVy+t/xa7qRM86GGWw4JWzx7tN2Jov2mWeZ LK60/2S3mDjJxGL60wiLYz2fWC0mz5ay+LJpOpvF9QkXWB04PS7232H02HCin9Xj14KlrB6N zyU8Fu95yeRx59oeNo95JwM9+rasYgzgiOKySUnNySxLLdK3S+DKOHYxq+AUf8WTSStZGhhP 83QxcnJICJhI3L5xgh3CFpO4cG89WxcjF4eQwFJGif49m9khnFYmiU8HvzGDVLEJ6EicWn2E EcQWEUiQOLL/NytIEbPAb0aJHXuawIqEBeIkTszoALNZBFQlHh5sYAGxeQVcJW6sOgo0lQNo nZzEggvpIGFOATeJxbMWg5ULAZW8fXGcaQIj7wJGhlWMoqmlyQXFSem5hnrFibnFpXnpesn5 uZsYIeH3ZQfj4mNWhxgFOBiVeHgfbDgTJsSaWFZcmXuIUYKDWUmEN27a2TAh3pTEyqrUovz4 otKc1OJDjNIcLErivHN3vQ8REkhPLEnNTk0tSC2CyTJxcEo1MMoU7nutvXvXmh7hjdWm38K+ Gq8rOH2B91r9uafndn/xE58TqnFGw78qUTrx2JqOD0eZHp44/Pv7yuiQU9dWpivvZfxe22N8 5Pa/o/t+CQRX9weazoxLXZ/heGzRZJ8vu64pm8lIM+ll9Lkx5U05xzGnI10779Xktm/O7zlu v+WJPJ301OPalWdKLMUZiYZazEXFiQAOfDkXOwIAAA== Cc: Dyasly Sergey , Ilya Maximets Subject: [dpdk-dev] [PATCH RFC v3 3/3] vhost: avoid reordering of used->idx and last_used_idx updating. 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: Wed, 24 Feb 2016 11:47:37 -0000 Calling rte_vhost_enqueue_burst() simultaneously from different threads for the same queue_id requires additional SMP memory barrier to avoid reordering of used->idx and last_used_idx updates. In case of virtio_dev_rx() memory barrier rte_mb() simply moved one instruction higher. Signed-off-by: Ilya Maximets --- lib/librte_vhost/vhost_rxtx.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c index a8e2582..4d37aa3 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -323,13 +323,16 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, rte_pause(); *(volatile uint16_t *)&vq->used->idx += count; - vq->last_used_idx = res_end_idx; vhost_log_used_vring(dev, vq, offsetof(struct vring_used, idx), sizeof(vq->used->idx)); - /* flush used->idx update before we read avail->flags. */ + /* + * Flush used->idx update to make it visible to virtio and all other + * threads before allowing to modify it. + */ rte_mb(); + vq->last_used_idx = res_end_idx; /* Kick the guest if necessary. */ if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) @@ -645,19 +648,24 @@ virtio_dev_merge_rx(struct virtio_net *dev, uint16_t queue_id, rte_pause(); *(volatile uint16_t *)&vq->used->idx += entry_success; + /* + * Flush used->idx update to make it visible to all + * other threads before allowing to modify it. + */ + rte_smp_wmb(); + vq->last_used_idx = res_cur_idx; } merge_rx_exit: if (likely(pkt_idx)) { - /* flush used->idx update before we read avail->flags. */ + /* Flush used->idx update to make it visible to virtio. */ rte_mb(); /* Kick the guest if necessary. */ if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) eventfd_write(vq->callfd, (eventfd_t)1); } - return pkt_idx; } -- 2.5.0