From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <huawei.xie@intel.com>
Received: from mga01.intel.com (mga01.intel.com [192.55.52.88])
 by dpdk.org (Postfix) with ESMTP id DE1372931
 for <dev@dpdk.org>; Thu,  2 Jun 2016 10:40:01 +0200 (CEST)
Received: from fmsmga004.fm.intel.com ([10.253.24.48])
 by fmsmga101.fm.intel.com with ESMTP; 02 Jun 2016 01:39:51 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.26,405,1459839600"; d="scan'208";a="114679605"
Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202])
 by fmsmga004.fm.intel.com with ESMTP; 02 Jun 2016 01:39:38 -0700
Received: from fmsmsx121.amr.corp.intel.com (10.18.125.36) by
 fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Thu, 2 Jun 2016 01:39:38 -0700
Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by
 fmsmsx121.amr.corp.intel.com (10.18.125.36) with Microsoft SMTP Server (TLS)
 id 14.3.248.2; Thu, 2 Jun 2016 01:39:38 -0700
Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.150]) by
 SHSMSX151.ccr.corp.intel.com ([169.254.3.193]) with mapi id 14.03.0248.002;
 Thu, 2 Jun 2016 16:39:37 +0800
From: "Xie, Huawei" <huawei.xie@intel.com>
To: Yuanhan Liu <yuanhan.liu@linux.intel.com>
CC: "dev@dpdk.org" <dev@dpdk.org>, "stephen@networkplumber.org"
 <stephen@networkplumber.org>, "Ananyev, Konstantin"
 <konstantin.ananyev@intel.com>, "thomas.monjalon@6wind.com"
 <thomas.monjalon@6wind.com>
Thread-Topic: [dpdk-dev] [PATCH] virtio: use volatile to get used->idx in
 the loop
Thread-Index: AdG7yA4yoCOUROu/Rf+v+VEjIsQC1w==
Date: Thu, 2 Jun 2016 08:39:36 +0000
Message-ID: <C37D651A908B024F974696C65296B57B4C7C22F6@SHSMSX101.ccr.corp.intel.com>
References: <1464106601-981-1-git-send-email-huawei.xie@intel.com>
 <20160530082258.GF5641@yliu-dev.sh.intel.com>
 <C37D651A908B024F974696C65296B57B4C7C00DB@SHSMSX101.ccr.corp.intel.com>
 <20160601060532.GK5641@yliu-dev.sh.intel.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [10.239.127.40]
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
Subject: Re: [dpdk-dev] [PATCH] virtio: use volatile to get used->idx in the
 loop
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 02 Jun 2016 08:40:02 -0000

On 6/1/2016 2:03 PM, Yuanhan Liu wrote:=0A=
> On Wed, Jun 01, 2016 at 05:40:08AM +0000, Xie, Huawei wrote:=0A=
>> On 5/30/2016 4:20 PM, Yuanhan Liu wrote:=0A=
>>> On Wed, May 25, 2016 at 12:16:41AM +0800, Huawei Xie wrote:=0A=
>>>> There is no external function call or any barrier in the loop,=0A=
>>>> the used->idx would only be retrieved once.=0A=
>>>>=0A=
>>>> Signed-off-by: Huawei Xie <huawei.xie@intel.com>=0A=
>>>> ---=0A=
>>>>  drivers/net/virtio/virtio_ethdev.c | 3 ++-=0A=
>>>>  1 file changed, 2 insertions(+), 1 deletion(-)=0A=
>>>>=0A=
>>>> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/v=
irtio_ethdev.c=0A=
>>>> index c3fb628..f6d6305 100644=0A=
>>>> --- a/drivers/net/virtio/virtio_ethdev.c=0A=
>>>> +++ b/drivers/net/virtio/virtio_ethdev.c=0A=
>>>> @@ -204,7 +204,8 @@ virtio_send_command(struct virtqueue *vq, struct v=
irtio_pmd_ctrl *ctrl,=0A=
>>>>  		usleep(100);=0A=
>>>>  	}=0A=
>>>>  =0A=
>>>> -	while (vq->vq_used_cons_idx !=3D vq->vq_ring.used->idx) {=0A=
>>>> +	while (vq->vq_used_cons_idx !=3D=0A=
>>>> +	       *((volatile uint16_t *)(&vq->vq_ring.used->idx))) {=0A=
>>> I'm wondering maybe we could fix VIRTQUEUE_NUSED (which has no such=0A=
>>> qualifier) and use this macro here?=0A=
>>>=0A=
>>> If you check the reference of that macro, you might find similar=0A=
>>> issues, say, it is also used inside the while-loop of=0A=
>>> virtio_recv_mergeable_pkts().=0A=
>>>=0A=
>>> 	--yliu=0A=
>>>  =0A=
>>>=0A=
>> Yes, seems it has same issue though haven't confirmed with asm code.=0A=
> So, move the "volatile" qualifier to VIRTQUEUE_NUSED?=0A=
>=0A=
> 	--yliu=0A=
>=0A=
=0A=
Yes, anyway this is just intermediate fix. In next patch, will declare=0A=
the idx as volatile, and remove the qualifier in the macro.=0A=