From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Emilio G. Cota" Subject: Re: [PATCH 1/4] ptr_ring: port ptr_ring from linux kernel to QEMU Date: Tue, 16 Oct 2018 12:40:19 -0400 Message-ID: <20181016164019.GA5666@flamenco> References: <20181016111006.629-1-xiaoguangrong@tencent.com> <20181016111006.629-2-xiaoguangrong@tencent.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, quintela@redhat.com, mtosatti@redhat.com, Xiao Guangrong , qemu-devel@nongnu.org, peterx@redhat.com, dgilbert@redhat.com, wei.w.wang@intel.com, mst@redhat.com, jiang.biao2@zte.com.cn, pbonzini@redhat.com To: guangrong.xiao@gmail.com Return-path: Content-Disposition: inline In-Reply-To: <20181016111006.629-2-xiaoguangrong@tencent.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel2=m.gmane.org@nongnu.org Sender: "Qemu-devel" List-Id: kvm.vger.kernel.org On Tue, Oct 16, 2018 at 19:10:03 +0800, guangrong.xiao@gmail.com wrote: (snip) > diff --git a/include/qemu/ptr_ring.h b/include/qemu/ptr_ring.h > new file mode 100644 > index 0000000000..d8266d45f6 > --- /dev/null > +++ b/include/qemu/ptr_ring.h > @@ -0,0 +1,235 @@ (snip) > +#define SMP_CACHE_BYTES 64 > +#define ____cacheline_aligned_in_smp \ > + __attribute__((__aligned__(SMP_CACHE_BYTES))) You could use QEMU_ALIGNED() here. > + > +#define WRITE_ONCE(ptr, val) \ > + (*((volatile typeof(ptr) *)(&(ptr))) = (val)) > +#define READ_ONCE(ptr) (*((volatile typeof(ptr) *)(&(ptr)))) Why not atomic_read/set, like in the rest of the QEMU code base? Furthermore, READ_ONCE in the kernel implies smp_read_barrier_depends, whereas here you're not bringing that in. That means that your barrier pairing, e.g. > + /* Pairs with READ_ONCE in ptr_ring_consume. */ > + smp_wmb(); is incorrect for Alpha. Thanks, E.