Re: [PATCH 4/6] futex: Add FUTEX_LOCK with optional adaptive spinning

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Darren Hart
Date: Wednesday, April 7, 2010 - 8:25 pm

Thomas Gleixner wrote:

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
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 2/6] futex: add futex_q static initializer, Darren Hart, (Mon Apr 5, 1:23 pm)
[PATCH 3/6] futex: refactor futex_lock_pi_atomic, Darren Hart, (Mon Apr 5, 1:23 pm)
[No subject], Ulrich Drepper, (Tue Apr 6, 7:47 am)
[No subject], Peter Zijlstra, (Tue Apr 6, 7:51 am)
[No subject], Darren Hart, (Tue Apr 6, 8:28 am)
[No subject], Peter Zijlstra, (Tue Apr 6, 8:29 am)
[No subject], Darren Hart, (Tue Apr 6, 8:33 am)
[No subject], Peter Zijlstra, (Tue Apr 6, 8:37 am)
[No subject], Avi Kivity, (Tue Apr 6, 9:06 am)
[No subject], Avi Kivity, (Tue Apr 6, 9:10 am)
[No subject], Thomas Gleixner, (Tue Apr 6, 9:14 am)
[No subject], Avi Kivity, (Tue Apr 6, 9:20 am)
[No subject], Alan Cox, (Tue Apr 6, 9:44 am)
[No subject], Alan Cox, (Tue Apr 6, 9:53 am)
[No subject], Alan Cox, (Tue Apr 6, 9:54 am)
[No subject], Thomas Gleixner, (Tue Apr 6, 9:55 am)
[No subject], Ulrich Drepper, (Tue Apr 6, 10:34 am)
Re: [PATCH 4/6] futex: Add FUTEX_LOCK with optional adapti ..., Darren Hart, (Wed Apr 7, 8:25 pm)