No need for ownertid at all really. The cmpxchg always tries to go from
0 to curtid. I've pushed the futex_owner() call outside the loop for a
one time lookup.
That's an interesting question, and I'm not sure what the right answer
is. The current approach of the adaptive spinning in the kernel is to
spin until the owner changes or deschedules, then stop and block. The
idea is that if you didn't get the lock before the owner changed, you
aren't going to get it in a very short period of time (you have at least
an entire critical section to wait through plus whatever time you've
already spent spinning). However, blocking just so another task can spin
doesn't really make sense either, and makes the lock less fair than it
could otherwise be.
My goal in starting this is to provide a more intelligent mechanism than
sched_yield() for userspace to use to determine when to spin and when to
sleep. The current implementation allows for spinning up until the owner
changes, deschedules, or the timeslice expires. I believe these are much
better than spinning for some fixed number of cycles and then yield for
some unpredictable amount of time until CFS decides to schedule you back in.
Still, the criteria for breaking the spin are something that needs more
eyes, and more numbers before I can be confident in any approach.
Noted.
Thanks,
--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
--