PowerPC reservations
Michael R. Zucca
mrz5149 at acm.org
Fri Nov 11 02:20:55 EST 2005
Kalle Pokki wrote:
> Am I just not getting how this is really supposed to work? Are there
> still some other constructs in use to prevent this, e.g. extra stwcx.
> instructions when changing the thread of execution?
Yes. When a context switch occurs, there's a stcwx. to clear any
reservations from the previous thread. When you enter another thread
from a context switch, you enter it with no reservations pending.
So you might have something that looks like this:
thread 1 -> lwarx w/ successful reservation
context switch -> stwcx.. to garbage location to clear any reservations
thread 2 -> stwcx. fails since there's no reservation pending
context switch -> stwcx. to garbage location to clear any reservations
thread 1 -> stwcx. fails since there's no reservation pending
thread 1 -> loops to try lwarx again
So the context switcher protects a reservation from "leaking" into
another thread. In that sense, you can act as though lwarx/stwcx. pairs
belong to a single thread.
The other important thing to remember is that there can only be one
outstanding reservation. Thus, lwarx and stcwx. instructions have to be
"paired" or you're going to get unexpected results.
More information about the Linuxppc-embedded
mailing list