From: Tim Deegan Subject: Re: [PATCHv2 3/6] xen: generic xadd() for ticket locks Date: Thu, 16 Apr 2015 12:13:25 +0100 Message-ID: <20150416111325.GH13443@deinos.phlegethon.org> References: <1428675597-28465-1-git-send-email-david.vrabel@citrix.com> <1428675597-28465-4-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yihja-0006s7-Up for xen-devel@lists.xenproject.org; Thu, 16 Apr 2015 11:13:27 +0000 Content-Disposition: inline In-Reply-To: <1428675597-28465-4-git-send-email-david.vrabel@citrix.com> 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 Cc: xen-devel@lists.xenproject.org, Keir Fraser , Ian Campbell , Jan Beulich , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org At 15:19 +0100 on 10 Apr (1428679194), David Vrabel wrote: > Provide a generic xadd() implementation for architectures that don't > provide one. > > This is only temporary until arm/arm64 provides an xadd() > implementation. > > Signed-off-by: David Vrabel The logic looks fine, but please: - add a comment explaining what it does; and - convert it to Xen coding style to match the rest of the file. With that, Reviewed-by: Tim Deegan Cheers, Tim. > --- > xen/common/spinlock.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c > index 5fd8b1c..0c4289c 100644 > --- a/xen/common/spinlock.c > +++ b/xen/common/spinlock.c > @@ -10,6 +10,27 @@ > #include > #include > > +#ifndef xadd > + > +static u32 generic_xaddl(volatile u32 *ptr, u32 v) > +{ > + u32 old, new, prev; > + > + old = read_atomic(ptr); > + for(;;) { > + new = old + v; > + prev = cmpxchg(ptr, old, new); > + if (prev == old) > + break; > + old = prev; > + } > + return old; > +} > + > +#define xadd(ptr, v) generic_xaddl((ptr), (v)) > + > +#endif > + > #ifndef NDEBUG > > static atomic_t spin_debug __read_mostly = ATOMIC_INIT(0); > -- > 1.7.10.4 > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel