From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 0B191C4E2 for ; Fri, 19 Feb 2016 11:56:55 +0100 (CET) Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O2S00AR0JQT9S20@mailout1.w1.samsung.com> for dev@dpdk.org; Fri, 19 Feb 2016 10:56:53 +0000 (GMT) X-AuditID: cbfec7f4-f79026d00000418a-f5-56c6f4f5dec6 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 33.CC.16778.5F4F6C65; Fri, 19 Feb 2016 10:56:53 +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 <0O2S001Z8JQJEA80@eusync4.samsung.com>; Fri, 19 Feb 2016 10:56:53 +0000 (GMT) From: Ilya Maximets To: dev@dpdk.org, Huawei Xie , Yuanhan Liu Date: Fri, 19 Feb 2016 13:56:40 +0300 Message-id: <1455879400-17827-4-git-send-email-i.maximets@samsung.com> X-Mailer: git-send-email 2.5.0 In-reply-to: <1455879400-17827-1-git-send-email-i.maximets@samsung.com> References: <1455879400-17827-1-git-send-email-i.maximets@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprKLMWRmVeSWpSXmKPExsVy+t/xa7pfvxwLM/h3U9Xi3aftTBbtM88y WVxp/8luMXGSicX0pxEWk2dLWVyfcIHVgd1jw4l+Vo9fC5ayeize85LJ4861PWwe804GevRt WcUYwBbFZZOSmpNZllqkb5fAlfF93RvWgud8FVMXLmdqYPzJ3cXIySEhYCLx92kTG4QtJnHh 3nowW0hgKaNE66PULkYuILuVSWLW7HZWkASbgI7EqdVHGEFsEYEEiSP7f7OCFDELLGOUuHhi MhNIQlggTmJnQyvYJBYBVYmeuTvBGngF3CSmPVkDZHMAbZOTWHAhHSTMKeAu8f/HF3aIxW4S M96fY5zAyLuAkWEVo2hqaXJBcVJ6rqFecWJucWleul5yfu4mRkhgfdnBuPiY1SFGAQ5GJR7e CwbHwoRYE8uKK3MPMUpwMCuJ8Na+AgrxpiRWVqUW5ccXleakFh9ilOZgURLnnbvrfYiQQHpi SWp2ampBahFMlomDU6qBUXq1sbphVOIGi7bIrr8WGV9evrvr91Jgj6iBw8H29/+z7un8iQxw nz7P5XuTZvtat0lh73xzN82+FeNUd/ZcNcfy5SKeJg+vXDvIwhXMNuVUTM4uYQZ/nW8fDxQU FKyZfnfBFZVTbD1Nt9c787y64M11MGhP1cyi6MJwhrXHdbisPj57le0Ro8RSnJFoqMVcVJwI AFhZ/sMoAgAA Cc: Ilya Maximets , Dyasly Sergey Subject: [dpdk-dev] [PATCH RFC v2 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: Fri, 19 Feb 2016 10:56:55 -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 9095fb1..a03f687 100644 --- a/lib/librte_vhost/vhost_rxtx.c +++ b/lib/librte_vhost/vhost_rxtx.c @@ -281,10 +281,13 @@ 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; - /* 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)) @@ -586,19 +589,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