Skip to contentSkip to conversation

Synchronizing Bit operations V2

DISCUSSION Chen, Kenneth W 2 participants 5 messages Mar 31, 2006

lore
Share & tools
lore
#0 lore raw

Chen, Kenneth W wrote on Thursday, March 30, 2006 6:45 PM

Quoted 12 lines

Christoph Lameter wrote on Thursday, March 30, 2006 6:38 PM

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

Neither one is correct because there will always be one combination of clear_bit with these macros that does not generate the required memory barrier.

Can you give an example? Which combination?

For Option(1)

smp_mb__before_clear_bit()
clear_bit(...)(

Quoted 6 lines

Sorry, you totally lost me. It could me I'm extremely slow today. For option (1), on ia64, clear_bit has release semantic already. The comb of __before_clear_bit + clear_bit provides the required ordering. Did I miss something? By the way, we are talking about detail implementation on one specific architecture. Not some generic concept that clear_bit has no ordering stuff in there.

By the way, this is the same thing on x86: look at include/asm-i386/bitops.h:

#define smp_mb__before_clear_bit() barrier()
#define smp_mb__after_clear_bit() barrier()

A simple compiler barrier, nothing but
#define barrier() __asm__ __volatile__("": : :"memory")

See, no memory ordering there, because clear_bit already has a LOCK prefix.

- Ken

#1 lore raw
Quoted 9 lines · Kenneth W

By the way, this is the same thing on x86: look at include/asm-i386/bitops.h:

#define smp_mb__before_clear_bit() barrier()
#define smp_mb__after_clear_bit() barrier()

A simple compiler barrier, nothing but
#define barrier() __asm__ __volatile__("": : :"memory")

See, no memory ordering there, because clear_bit already has a LOCK prefix.

And that implies barrier behavior right?

#2 lore raw

Christoph Lameter wrote on Thursday, March 30, 2006 6:56 PM

Quoted 11 lines
Quoted 9 lines

By the way, this is the same thing on x86: look at include/asm-i386/bitops.h:

#define smp_mb__before_clear_bit() barrier()
#define smp_mb__after_clear_bit() barrier()

A simple compiler barrier, nothing but
#define barrier() __asm__ __volatile__("": : :"memory")

See, no memory ordering there, because clear_bit already has a LOCK prefix.

And that implies barrier behavior right?

No, not the memory ordering semantics you are thinking about. It just tell compiler not to be over smart and schedule a load operation above that point Intel compiler is good at schedule memory load way ahead of its use to hide memory latency. gcc probably does that too, I'm not 100% sure. This prevents the compiler to schedule load before that line.

- Ken

#3 lore raw
Quoted 6 lines · Kenneth W
Quoted 1 line
Quoted 1 line

See, no memory ordering there, because clear_bit already has a LOCK prefix.

No, not the memory ordering semantics you are thinking about. It just tell compiler not to be over smart and schedule a load operation above that point Intel compiler is good at schedule memory load way ahead of its use to hide memory latency. gcc probably does that too, I'm not 100% sure. This prevents the compiler to schedule load before that line.

The compiler? I thought we were talking about the processor.

I was referring to the LOCK prefix. Doesnt that insure the processor to go into a special state and make the bus go into a special state that implies a barrier?

#4 lore raw

Christoph Lameter wrote on Thursday, March 30, 2006 7:09 PM

Quoted 3 lines

I was referring to the LOCK prefix. Doesnt that insure the processor to go into a special state and make the bus go into a special state that implies a barrier?

Yes, that's why on i386 both smp_mb__before_clear_bit() and smp_mb__after_clear_bit() are noop.