All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: Tim Deegan <tim@xen.org>, David Vrabel <david.vrabel@citrix.com>
Cc: xen-devel@lists.xenproject.org, Keir Fraser <keir@xen.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: Re: [PATCHv2 4/6] x86: provide xadd()
Date: Thu, 16 Apr 2015 12:38:40 +0100	[thread overview]
Message-ID: <552F9F40.7030403@citrix.com> (raw)
In-Reply-To: <20150416112556.GI13443@deinos.phlegethon.org>

On 16/04/15 12:25, Tim Deegan wrote:
> At 15:19 +0100 on 10 Apr (1428679195), David Vrabel wrote:
>> xadd() atomically adds a value and returns the previous value.  This
>> is needed to implement ticket locks.
>>
>> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
>> ---
>>  xen/include/asm-x86/system.h |   29 +++++++++++++++++++++++++++++
>>  1 file changed, 29 insertions(+)
>>
>> diff --git a/xen/include/asm-x86/system.h b/xen/include/asm-x86/system.h
>> index 7111329..1e6c6a8 100644
>> --- a/xen/include/asm-x86/system.h
>> +++ b/xen/include/asm-x86/system.h
>> @@ -117,6 +117,35 @@ static always_inline unsigned long __cmpxchg(
>>                                     (unsigned long)__n,sizeof(*(ptr)))); \
>>  })
>>  
>> +static always_inline unsigned long __xadd(
>> +    volatile void *ptr, unsigned long v, int size)
>> +{
>> +    switch ( size )
>> +    {
>> +    case 1:
>> +        asm volatile ( "lock; xaddb %b0,%1"
>> +                       : "+r" (v), "+m" (*__xg((volatile void *)ptr)));
>> +        return v;
>> +    case 2:
>> +        asm volatile ( "lock; xaddw %w0,%1"
>> +                       : "+r" (v), "+m" (*__xg((volatile void *)ptr)));
>> +        return v;
>> +    case 4:
>> +        asm volatile ( "lock; xaddl %k0,%1"
>> +                       : "+r" (v), "+m" (*__xg((volatile void *)ptr)));
>> +        return v;
>> +    case 8:
>> +        asm volatile ( "lock; xaddq %q0,%1"
>> +                       : "+r" (v), "+m" (*__xg((volatile void *)ptr)));
>> +        return v;
>> +    }
>> +    return 0;
> 
> ASSERT_UNREACHABLE(), rather?  And some appropriate BUILD_BUG_ON?
> 
> But also: AFAICS the GCC builtin __sync_fetch_and_add() does almost
> exactly this (the difference being that those are also compiler
> barriers where this is only a CPU barrier).  Should we be using it
> instead?

I wasn't aware of the GCC built-ins -- I'll try them out. I think asm
volatile is a compiler barrier though.

David

  reply	other threads:[~2015-04-16 11:38 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-10 14:19 [PATCHv2 0/6] Use ticket locks for spinlocks David Vrabel
2015-04-10 14:19 ` [PATCHv2 1/6] x86/hvm: don't include asm/spinlock.h David Vrabel
2015-04-10 15:24   ` Andrew Cooper
2015-04-13 13:13     ` David Vrabel
2015-04-13 13:15       ` Andrew Cooper
2015-04-16 11:09   ` Tim Deegan
2015-04-10 14:19 ` [PATCHv2 2/6] x86/mtrr: include asm/atomic.h David Vrabel
2015-04-10 15:25   ` Andrew Cooper
2015-04-16 11:10   ` Tim Deegan
2015-04-10 14:19 ` [PATCHv2 3/6] xen: generic xadd() for ticket locks David Vrabel
2015-04-14 13:17   ` Ian Campbell
2015-04-14 16:37     ` David Vrabel
2015-04-15  8:34       ` Ian Campbell
2015-04-16 11:13   ` Tim Deegan
2015-04-16 15:28   ` Jan Beulich
2015-04-17 12:32     ` Ian Campbell
2015-04-17 12:33       ` Ian Campbell
2015-04-17 12:34       ` David Vrabel
2015-04-17 13:09         ` Ian Campbell
2015-04-17 13:13           ` David Vrabel
2015-04-10 14:19 ` [PATCHv2 4/6] x86: provide xadd() David Vrabel
2015-04-16 11:25   ` Tim Deegan
2015-04-16 11:38     ` David Vrabel [this message]
2015-04-16 11:41       ` Tim Deegan
2015-04-16 11:49     ` Jan Beulich
2015-04-16 12:49       ` Tim Deegan
2015-04-16 12:55         ` Ian Campbell
2015-04-16 13:19           ` Jan Beulich
2015-04-16 14:07             ` Ian Campbell
2015-04-16 14:09               ` Ian Campbell
2015-04-16 12:00     ` Ian Campbell
2015-04-10 14:19 ` [PATCHv2 5/6] xen: use ticket locks for spin locks David Vrabel
2015-04-10 15:29   ` Andrew Cooper
2015-04-10 16:44   ` Boris Ostrovsky
2015-04-10 17:29     ` David Vrabel
2015-04-10 17:58       ` Boris Ostrovsky
2015-04-16 12:03   ` Tim Deegan
2015-04-16 12:46     ` David Vrabel
2015-04-16 12:50       ` Tim Deegan
2015-04-16 13:32     ` Jan Beulich
2015-04-21  9:59     ` David Vrabel
2015-04-10 14:19 ` [PATCHv2 6/6] x86, arm: remove asm/spinlock.h from all architectures David Vrabel
2015-04-16 12:51   ` Tim Deegan
2015-04-16 15:29   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=552F9F40.7030403@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.