From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 971782C72 for ; Wed, 25 May 2016 10:34:28 +0200 (CEST) Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDAC6A78A; Wed, 25 May 2016 08:34:27 +0000 (UTC) Received: from redhat.com (vpn1-7-163.ams2.redhat.com [10.36.7.163]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u4P8YPxY011253; Wed, 25 May 2016 04:34:25 -0400 Date: Wed, 25 May 2016 11:34:24 +0300 From: "Michael S. Tsirkin" To: "Xie, Huawei" Cc: "dev@dpdk.org" , "stephen@networkplumber.org" , "Ananyev, Konstantin" , "thomas.monjalon@6wind.com" , Yuanhan Liu , "Tan, Jianfeng" Message-ID: <20160525113224-mutt-send-email-mst@redhat.com> References: <1464106601-981-1-git-send-email-huawei.xie@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 25 May 2016 08:34:28 +0000 (UTC) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 May 2016 08:34:28 -0000 On Wed, May 25, 2016 at 08:25:20AM +0000, Xie, Huawei wrote: > On 5/25/2016 4:12 PM, Xie, Huawei wrote: > > There is no external function call or any barrier in the loop, > > the used->idx would only be retrieved once. > > > > Signed-off-by: Huawei Xie > > --- > > drivers/net/virtio/virtio_ethdev.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c > > index c3fb628..f6d6305 100644 > > --- a/drivers/net/virtio/virtio_ethdev.c > > +++ b/drivers/net/virtio/virtio_ethdev.c > > @@ -204,7 +204,8 @@ virtio_send_command(struct virtqueue *vq, struct virtio_pmd_ctrl *ctrl, > > usleep(100); > > } > > > > - while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) { > > + while (vq->vq_used_cons_idx != > > + *((volatile uint16_t *)(&vq->vq_ring.used->idx))) { > > uint32_t idx, desc_idx, used_idx; > > struct vring_used_elem *uep; > > > > Find this issue when do the code rework of RX/TX queue. > As in other places, we also have loop retrieving the value of avial->idx > or used->idx, i prefer to declare the index in vq structure as volatile > to avoid potential issue. It might be a good idea to wrap this in a macro similar to ACCESS_ONCE in Linux. > > Stephen: > Another question is why we need a loop here? > > /huawei -- MST