public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vladislav Bolkhovitin <vst@vlnb.net>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Marcelo Tosatti <marcelo.tosatti@cyclades.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86 bitops.h commentary on instruction reordering
Date: Tue, 10 Aug 2004 16:28:01 +0400	[thread overview]
Message-ID: <4118BF51.8030303@vlnb.net> (raw)
In-Reply-To: <1092086514.14770.7.camel@localhost.localdomain>

Alan Cox wrote:

> On Llu, 2004-08-09 at 21:12, Vladislav Bolkhovitin wrote:
> 
>>Well, Marcelo, sorry if I'm getting too annoying, but we had a race with 
>>cache coherency during SCST (SCSI target mid-level) development. We 
>>discovered that on P4 Xeon after atomic_set() there is very small 
>>window, when atomic_read() on another CPUs returns the old value. We had 
>>to rewrite the code without using atomic_set(). Isn't it cache coherency 
>>issue?
> 
> atomic_set/atomic_read are _atomic_ operations. Nothing is said about
> ordering. You get old or new but not half and half. Two atomic_inc's
> will both occur and so on.
> 
> If you want ordering you need locks otherwise there is nothing defining
> the time order of both processors.
> 
> How can you even measure such a window without locking to know what the
> state of the processors is ?

We didn't measure it, we just had lockup. In our code in the commands 
serialization we have two paths: the regular (fast) one, where the 
atomic value is equal to current value and there are no locks used, 
because only one command can be on the fast path, and the slow one, 
where the atomic and the current values are different, so lock used to 
perform all necessary job. After the fast path the atomic value gets 
incremented together with some checks on it. We used to use atomic_set() 
here and sometimes had lockup.

>>And, BTW, returning to the original topic, would it be better to make 
>>set_bit() and friends guarantee not to be reordered on all 
>>architectures, instead of just add the comment. Otherwise, what is the 
> 
> 
> x86 and some other platforms have certain ordering guarantees. set_bit
> doesn't guarantee them but it happens to unavoidably work for most
> (ab)uses.

So, seems there is no difference between operations with and without 
"__" prefix (like set_bit() and __set_bit()) now? Maybe, it's worth to 
leave only one version of them?

>>right thing? In some places in SCST we heavy rely on non-ordering 
>>guarantees.
> 
> 
> Then you will get burned on most hardware.

Designing that we also be guided by the comments, which turned out to be 
misleading :).

Actually, I feel it would be perfect if someone wrote a document, where 
he described various issues with using atomic variables and bit 
operations on various architectures, like some FAQ. For example, this 
thread has at least several good questions and answers. Also, I can add 
one more question: for an user it could be non-obvious why 
smp_mb__after_atomic_*() and friends needed. This document wouldn't be 
big, so it didn't take too much time to write it, but it would help a 
*lot* for people who wish to write portable code.

Thanks,
Vlad


  reply	other threads:[~2004-08-10 12:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-05 20:06 [PATCH] x86 bitops.h commentary on instruction reordering Marcelo Tosatti
2004-08-06 14:17 ` Vladislav Bolkhovitin
2004-08-06 14:33   ` Marcelo Tosatti
2004-08-06 15:36     ` Vladislav Bolkhovitin
2004-08-06 15:53       ` Marcelo Tosatti
2004-08-06 16:52         ` Vladislav Bolkhovitin
2004-08-06 17:09           ` Marcelo Tosatti
2004-08-06 22:33             ` H. Peter Anvin
2004-08-07  1:01               ` Zwane Mwaikambo
2004-08-07 22:16               ` Alan Cox
2004-08-09 15:14             ` Vladislav Bolkhovitin
2004-08-09 15:50               ` Marcelo Tosatti
2004-08-09 17:35                 ` Vladislav Bolkhovitin
     [not found]                   ` <20040809183437.GD6361@logos.cnet>
2004-08-09 20:12                     ` Vladislav Bolkhovitin
2004-08-09 21:21                       ` Alan Cox
2004-08-10 12:28                         ` Vladislav Bolkhovitin [this message]
2004-08-09 11:58         ` Maciej W. Rozycki
     [not found] <2pY7Y-W1-7@gated-at.bofh.it>
     [not found] ` <2qdJL-3sh-27@gated-at.bofh.it>
     [not found]   ` <2qePx-4eM-21@gated-at.bofh.it>
     [not found]     ` <2qf8S-4pI-31@gated-at.bofh.it>
     [not found]       ` <2qg4V-54c-17@gated-at.bofh.it>
     [not found]         ` <2qgoh-5og-29@gated-at.bofh.it>
     [not found]           ` <2qhkn-649-41@gated-at.bofh.it>
     [not found]             ` <2rkgh-zP-45@gated-at.bofh.it>
     [not found]               ` <2rlFk-1wC-27@gated-at.bofh.it>
     [not found]                 ` <2rmhX-20I-17@gated-at.bofh.it>
     [not found]                   ` <2roWw-40d-19@gated-at.bofh.it>
     [not found]                     ` <2roWw-40d-17@gated-at.bofh.it>
2004-08-09 21:23                       ` Andi Kleen
2004-08-10 12:26                         ` Vladislav Bolkhovitin

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=4118BF51.8030303@vlnb.net \
    --to=vst@vlnb.net \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.tosatti@cyclades.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox