public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Zoltan Menyhart <Zoltan.Menyhart@bull.net>
To: "Chen, Kenneth W" <kenneth.w.chen@intel.com>
Cc: "'Christoph Lameter'" <clameter@sgi.com>,
	"'Nick Piggin'" <nickpiggin@yahoo.com.au>,
	Zoltan Menyhart <Zoltan.Menyhart@free.fr>,
	akpm@osdl.org, linux-kernel@vger.kernel.org,
	linux-ia64@vger.kernel.org
Subject: Re: Fix unlock_buffer() to work the same way as bit_unlock()
Date: Wed, 29 Mar 2006 14:16:38 +0200	[thread overview]
Message-ID: <442A7AA6.7080206@bull.net> (raw)
In-Reply-To: <200603290139.k2T1d1g00702@unix-os.sc.intel.com>

Part 2.
There are a couple of different ways of using / implementing bit-op-s.
I try to summarize them:


1. "Stand alone" bit operations:

By "stand alone" I mean that a modification to a bit field member is
independent of any other operation before / after the bit operation
in question. There is no ordering with respect to the other operations.

They do not provide any SMP synch. semantics, there is no need to
implement them as some atomic operations.


2. Atomic bit operations:

As Linux turned to SMP safe, a couple of bit operations have been
re-implemented by use of some atomic operations.
An early implementation on PCs determined the basic semantics of
these operations, including their fencing behavior.

atomic_ops.txt:

"      obj->dead = 1;
      if (test_and_set_bit(0, &obj->flags))
              /* ... */;
      obj->killed = 1;

   The implementation of test_and_set_bit() must guarentee that
   "obj->dead = 1;" is visible to cpus before the atomic memory operation
   done by test_and_set_bit() becomes visible.  Likewise, the atomic
   memory operation done by test_and_set_bit() must become visible before
   "obj->killed = 1;" is visible."

I am not convenienced that this is a good sync. strategy.
Unfortunately, the acquisition / release semantics were not defined
in Linux via some architecture independent and explicit way.
People simply abused the fact that the bidirectional fencing is
implicitly provided by some architectures for free.

Theoretically, the code fragments like above have to be cleared up
to use explicit ordering primitives. The description in atomic_ops.txt
should state that this is not the way to do... (see the Fencing bit
operations below).
There can be ~20 "test_and_set_bit()" here or there.


The atomic bit operation with requirements to order the preceding /
following operations are mainly used for locking(-like) purposes:


3. Fencing bit operations:

Should someone still insist on using the atomic bit operations as today,
s/he should change to use e.g.:

   obj->dead = 1;
   if (test_and_set_bit_N_fence(0, &obj->flags))
         /* ... */;
   obj->killed = 1;


4. Bit-lock operations:

I summarized the ordering requirements here:
http://marc.theaimsgroup.com/?l=linux-ia64&m=114362989421046&w=2

In order to let the architectures implement these bit-lock
operations efficiently, the usage has to indicate the _minimal_
required ordering semantics, e.g.:

     test_and_set_bit_N_acquire()
or   ordered_test_and_set_bit(acquire, ...)
     release_N_clear_bit()
etc.

The style like:

	do_some_ordering_before()
	bit_op()
	do_some_ordering_after()

is quite correct, however, the compiler is not sufficiently
intelligent to let the architecture dependent part to merge e.g. into
a single machine instruction (if it exists).


Regards,

Zoltan 


  reply	other threads:[~2006-03-29 12:16 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-28  3:59 Fix unlock_buffer() to work the same way as bit_unlock() Christoph Lameter
2006-03-28  8:10 ` Nick Piggin
2006-03-28 18:53   ` Chen, Kenneth W
2006-03-28 21:42     ` Zoltan Menyhart
2006-03-28 23:48       ` Christoph Lameter
2006-03-29  0:07         ` Nick Piggin
2006-03-29  2:23           ` Christoph Lameter
2006-03-29  2:35             ` Nick Piggin
2006-03-29  6:46               ` Chen, Kenneth W
2006-03-29  7:11                 ` Christoph Lameter
2006-03-30  1:34                 ` Nick Piggin
2006-03-29  0:12         ` Chen, Kenneth W
2006-03-29  0:27         ` Chen, Kenneth W
2006-03-29  0:47           ` Christoph Lameter
2006-03-29  1:39             ` Chen, Kenneth W
2006-03-29 12:16               ` Zoltan Menyhart [this message]
2006-03-30  1:56                 ` Nick Piggin
2006-03-29 10:57         ` Zoltan Menyhart
2006-03-29  6:50   ` Chen, Kenneth W
2006-03-30  1:36     ` Nick Piggin
     [not found] ` <442AA13B.3050104@bull.net>
2006-03-30  1:57   ` Nick Piggin
  -- strict thread matches above, loose matches on Subject: below --
2006-03-29 18:33 Boehm, Hans
2006-03-29 19:11 ` Grant Grundler
2006-03-29 19:31 Boehm, Hans
2006-03-29 22:17 ` Christoph Lameter
2006-03-29 22:56 Boehm, Hans
2006-03-29 23:33 ` Christoph Lameter
2006-03-29 23:49   ` Chen, Kenneth W
2006-03-29 23:50     ` Christoph Lameter
2006-03-29 23:50     ` Grant Grundler
2006-03-30  8:43   ` Zoltan Menyhart
2006-03-30  8:55     ` Nick Piggin
2006-03-30 19:11       ` Christoph Lameter
2006-03-30 17:17     ` Christoph Lameter
2006-03-30 17:57 Boehm, Hans
2006-03-30 18:17 ` Christoph Lameter
2006-03-30 22:26 Boehm, Hans

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=442A7AA6.7080206@bull.net \
    --to=zoltan.menyhart@bull.net \
    --cc=Zoltan.Menyhart@free.fr \
    --cc=akpm@osdl.org \
    --cc=clameter@sgi.com \
    --cc=kenneth.w.chen@intel.com \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nickpiggin@yahoo.com.au \
    /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