From: David Vrabel <david.vrabel@citrix.com>
To: Tim Deegan <tim@xen.org>
Cc: Keir Fraser <keir@xen.org>,
Ian Campbell <ian.campbell@citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Jennifer Herbert <jennifer.herbert@citrix.com>,
Jan Beulich <JBeulich@suse.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCHv3 3/4] xen: use ticket locks for spin locks
Date: Wed, 29 Apr 2015 18:00:00 +0100 [thread overview]
Message-ID: <55410E10.3060200@citrix.com> (raw)
In-Reply-To: <20150429165643.GB6279@deinos.phlegethon.org>
On 29/04/15 17:56, Tim Deegan wrote:
> At 16:36 +0100 on 29 Apr (1430325362), David Vrabel wrote:
>> On 23/04/15 15:58, Jan Beulich wrote:
>>>>>> On 23.04.15 at 16:43, <tim@xen.org> wrote:
>>>> At 14:54 +0100 on 23 Apr (1429800874), Jan Beulich wrote:
>>>>>>>> On 23.04.15 at 14:03, <tim@xen.org> wrote:
>>>>>> At 11:11 +0100 on 21 Apr (1429614687), David Vrabel wrote:
>>>>>>> void _spin_unlock(spinlock_t *lock)
>>>>>>> {
>>>>>>> + smp_mb();
>>>>>>> preempt_enable();
>>>>>>> LOCK_PROFILE_REL;
>>>>>>> - _raw_spin_unlock(&lock->raw);
>>>>>>> + lock->tickets.head++;
>>>>>>
>>>>>> This needs to be done with an explicit atomic (though not locked)
>>>>>> write; otherwise the compiler might use some unsuitable operation that
>>>>>> clobbers .tail as well.
>>>>>
>>>>> How do you imagine that to happen? An increment of one
>>>>> structure member surely won't modify any others.
>>>>
>>>> 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 guess so. An equivalent 'inc' operation would be even shorter,
> but maybe GCC has its reasons for using addw + immediate?
> (Ah, it's in the optimization manual: addw $1 is preferred because it
> sets all the flags, whereas inc sets only some, so the inc has a
> dependence on the previous instruction to set flags.)
>
> It needs some careful naming -- this series will add two
> new add operations, currently xadd() and add_atomic(), where xadd() is
> the more atomic of the two, IYSWIM.
Should I rename xadd() to arch_fetch_and_add() to match the GCC builtin
name?
David
next prev parent reply other threads:[~2015-04-29 17:00 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-21 10:11 [PATCHv3 0/4] Use ticket locks for spinlocks David Vrabel
2015-04-21 10:11 ` [PATCHv3 1/4] x86: provide xadd() David Vrabel
2015-04-21 10:36 ` Jan Beulich
2015-04-21 12:36 ` David Vrabel
2015-04-21 13:12 ` Jan Beulich
2015-04-21 13:15 ` David Vrabel
2015-04-21 13:20 ` Jan Beulich
2015-04-21 10:11 ` [PATCHv3 2/4] arm: " David Vrabel
2015-04-21 10:11 ` [PATCHv3 3/4] xen: use ticket locks for spin locks David Vrabel
2015-04-23 11:58 ` Jan Beulich
2015-04-28 15:56 ` David Vrabel
2015-04-28 23:15 ` Jan Beulich
2015-04-29 15:21 ` David Vrabel
2015-04-29 23:56 ` Jan Beulich
2015-04-30 10:09 ` Tim Deegan
2015-04-30 11:55 ` David Vrabel
2015-04-23 12:03 ` Tim Deegan
2015-04-23 13:43 ` David Vrabel
2015-04-23 13:45 ` Andrew Cooper
2015-04-23 14:58 ` Tim Deegan
2015-04-23 14:24 ` Tim Deegan
2015-04-23 14:51 ` Tim Deegan
2015-04-23 13:54 ` Jan Beulich
2015-04-23 14:43 ` Tim Deegan
2015-04-23 14:58 ` Jan Beulich
2015-04-29 15:36 ` David Vrabel
2015-04-29 16:56 ` Tim Deegan
2015-04-29 17:00 ` David Vrabel [this message]
2015-04-30 9:00 ` Tim Deegan
2015-04-29 23:48 ` Jan Beulich
2015-04-21 10:11 ` [PATCHv3 4/4] x86, arm: remove asm/spinlock.h from all architectures David Vrabel
2015-04-21 10:22 ` [PATCHv3 0/4] Use ticket locks for spinlocks Jan Beulich
2015-04-21 11:24 ` Jennifer Herbert
2015-04-23 12:42 ` David Vrabel
2015-04-30 15:44 ` David Vrabel
2015-05-04 7:18 ` 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=55410E10.3060200@citrix.com \
--to=david.vrabel@citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=jennifer.herbert@citrix.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.