From: "Jan Beulich" Subject: Re: [PATCHv3 3/4] xen: use ticket locks for spin locks Date: Thu, 30 Apr 2015 00:48:21 +0100 Message-ID: <55417BD502000078000CE124@mail.emea.novell.com> References: <1429611088-23950-1-git-send-email-david.vrabel@citrix.com> <1429611088-23950-4-git-send-email-david.vrabel@citrix.com> <20150423120302.GG10810@deinos.phlegethon.org> <553915BA0200007800075314@mail.emea.novell.com> <20150423144342.GC10824@deinos.phlegethon.org> <553924C20200007800075518@mail.emea.novell.com> <5540FA62.4090900@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YnbiK-0002qT-Hr for xen-devel@lists.xenproject.org; Wed, 29 Apr 2015 23:48:24 +0000 In-Reply-To: <5540FA62.4090900@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: david.vrabel@citrix.com, tim@xen.org Cc: keir@xen.org, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, jennifer.herbert@citrix.com, xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> David Vrabel 04/29/15 5:39 PM >>> >On 23/04/15 15:58, Jan Beulich wrote: >>>>> On 23.04.15 at 16:43, wrote: >>> At 14:54 +0100 on 23 Apr (1429800874), Jan Beulich wrote: >>> AIUI, the '++' could end up as a word-size read, modify, and word-size >>> write. If another CPU updates .tail parallel, that update could get >>> lost. >> >> Ah, right, compilers are allowed to do that, albeit normally wouldn't >> unless the architecture has no suitable loads/stores. > >lock->tickets.head++; > >7b: 66 83 07 01 addw $0x1,(%rdi) > >write_atomic(&lock->tickets.head, lock->tickets.head + 1); > >7b: 0f b7 07 movzwl (%rdi),%eax >7e: 83 c0 01 add $0x1,%eax >81: 66 89 07 mov %ax,(%rdi) > >Do you want a new add_atomic() operation? e.g., > >#define add_atomic(ptr, inc) \ >asm volatile ("addw %1,%w" \ >: "+m" (*(ptr)) : "ri" (inc) : "memory") < >(but obviously handling all the different sizes.) I think that would be desirable. Jan