Re: [PATCH 8/8] i386: bitops: smp_mb__{before, after}_clear_bit() definitions



On Tue, 24 Jul 2007, Nick Piggin wrote:

Satyam Sharma wrote:

Consider this (the above two functions exist
only for clear_bit(),
the atomic variant, as you already know), the
_only_ memory reference
we care about is that of the address of the
passed bit-string:

No. Memory barriers explicitly extend to all
memory references.

[ Compiler barrier, you mean, that's not true of CPU
barriers. ]

For the purpose of this discussion (Linux memory
barrier semantics, on WB memory), it is true of CPU
and compiler barriers.

On later Intel processors, if the memory address range being referenced
(and say written to) by the (locked) instruction is in the cache of a
CPU, then it will not assert the LOCK signal on the system bus --
thus not assume exclusive use of shared memory. So other CPUs are free
to modify (other) memory at that point. Cache coherency will still
ensure _that_ (locked) memory area is still updated atomically, though.

Obviously because we want some kind of ordering
guarantee at a given point. All the CPU barriers
in the world are useless if the compiler can reorder
access over them.

Yes ...

As for a compiler barrier, the asm there already
guarantees the compiler
will not optimize references to _that_ address

One or both of us still fails to understand the other.

... I think the culprit is me ...

bit_spin_lock(LOCK_NR, &word);
var++;
/* this is bit_spin_unlock(LOCK_NR, &word); */
smp_mb__before_clear_bit();
clear_bit(LOCK_NR, &word);

Yup, David has laid this out clearly, as well.

Are you saying that it is OK for the store to var to
be reordered below the clear_bit? If not, what are you
saying?

I might be making a radical turn-around here, but all of a
sudden I think it's actually a good idea to put a complete
memory clobber in set_bit/clear_bit and friends themselves,
and leave the "__" variants as they are.


Satyam
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • [PATCH] Document Linuxs memory barriers [try #2]
    ... The attached patch documents the Linux kernel's memory barriers. ... I've tried to get rid of the concept of memory accesses appearing on the bus; ... barring implicit enforcement by the CPU. ...
    (Linux-Kernel)
  • Re: Uses for memory barriers
    ... The memory controller handled the hardware to make sure that reads ... CPU, but you could have some real bad problems if you didn't ... My questions concern memory barriers only, ... need to protect such variables with spin-locks anyway. ...
    (Linux-Kernel)
  • Re: [RFC patch 08/18] cnt32_to_63 should use smp_rmb()
    ... does not stop the CPU from doing the reads in any order it wants. ... restrictions imposed by barriers, cacheability attributes, MMIO attributes and ... going and servicing the interrupt handler. ... not some memory mapped device register, ...
    (Linux-Kernel)
  • Re: Uses for memory barriers
    ... trying to present a high-level description of the requirements memory ... barriers must fulfill in order to support usable synchronization. ... Whichever CPU acquires the lock last had better be the one whose value ... So even though the load of A happened -after- the store A=2, ...
    (Linux-Kernel)
  • Re: Are memory barriers needed on uniprocessor systems?
    ... problem that memory barriers solve ever happen to multithreaded ...   necessary book-keeping to ensure that programs execute as if all ... The code might run on a machine with one CPU or a dozen. ...
    (comp.programming.threads)