From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Xie, Huawei" Subject: Re: [PATCH] virtio: use volatile to get used->idx in the loop Date: Wed, 25 May 2016 08:25:20 +0000 Message-ID: References: <1464106601-981-1-git-send-email-huawei.xie@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "stephen@networkplumber.org" , "Ananyev, Konstantin" , "thomas.monjalon@6wind.com" , "ms >> Michael S. Tsirkin" , Yuanhan Liu , "Tan, Jianfeng" To: "dev@dpdk.org" Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 02DEE2BC6 for ; Wed, 25 May 2016 10:25:23 +0200 (CEST) Content-Language: en-US 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" On 5/25/2016 4:12 PM, Xie, Huawei 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 =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/virt= io_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 virt= io_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= > uint32_t idx, desc_idx, used_idx;=0A= > struct vring_used_elem *uep;=0A= > =0A= =0A= Find this issue when do the code rework of RX/TX queue.=0A= As in other places, we also have loop retrieving the value of avial->idx=0A= or used->idx, i prefer to declare the index in vq structure as volatile=0A= to avoid potential issue.=0A= =0A= Stephen:=0A= Another question is why we need a loop here?=0A= =0A= /huawei=0A=