Skip to contentSkip to conversation

Make x86_32 uni-processor Atomic ops, Atomic

BUG FIX Michael S. Zick 2 participants 3 messages May 22, 2009

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines · you
Quoted 1 line · Michael S. Zick

Found in the bit-rot for 32-bit, x86, Uni-processor builds:

Actually uni processor should not use the lock prefix because it doesn't need it; the only exception are some special ops used in para-virtualization which are special cased.

Unless you have interrupts enabled, then you have two contexts. Only xchg is "naturally" atomic.

Mike

Quoted 2 lines

-Andi

#1 lore raw
Quoted 3 lines

Unless you have interrupts enabled, then you have two contexts. Only xchg is "naturally" atomic.

Isn't the lock prefix about consistency between multiple processors? The x86 architecture always handles interrupts on instruction boundaries. I'm guessing you're worried about definitions like

static inline void atomic_inc(atomic_t *v)

{
	asm volatile(LOCK_PREFIX "incl %0"
		     : "+m" (v->counter));
}

which compiles to just "incl" (with no lock prefix) on uniprocessor kernels; but the IA-32 architecture guarantees that the incl instruction cannot be interrupted between reading the old value and writing the new value.

- R.

#2 lore raw
Quoted 14 lines · Roland Dreier
Quoted 3 lines

Unless you have interrupts enabled, then you have two contexts. Only xchg is "naturally" atomic.

Isn't the lock prefix about consistency between multiple processors? The x86 architecture always handles interrupts on instruction boundaries. I'm guessing you're worried about definitions like

static inline void atomic_inc(atomic_t *v)

{
	asm volatile(LOCK_PREFIX "incl %0"
		     : "+m" (v->counter));
}
Quoted 5 lines

which compiles to just "incl" (with no lock prefix) on uniprocessor kernels; but the IA-32 architecture guarantees that the incl instruction cannot be interrupted between reading the old value and writing the new value.

Not prior to P-4, and since then only "may" be done atomically, see reference post in my earlier reply.

PS: And yes, that was where I spotted the usage first. ;)

Mike

Quoted 3 lines

- R.