On Tue, 28 May 2002 14:56:04 -0400 (EDT),
  John Baldwin <[EMAIL PROTECTED]> said:

>> The prototype patch is at:
>> http://people.FreeBSD.org/~tanimura/patches/ippreempt.diff.gz
>> And the p4 depot
>> //depot/user/tanimura/ippreempt/...
>> The patch is for only i386 at the moment.
>> The following is the brief description of the patch:

jhb> I would prefer that this was hung off the preemption stuff I've already done
jhb> rather than reinventing it.  I would also prefer that we get a preemptive
jhb> kernel w/o this done stable before adding extra complication.

Or I can integrate your work in //depot/user/jhb/preemption/... into
//depot/user/tanimura/ippreempt/... .

>> Miscellaneous stuff:
>> If a thread spins for an adaptive mutex, propagate its priority to the
>> owner thread of the mutex.  This prevents preemption of the owner
>> thread by a thread with the priority in between the owner thread and
>> the spinning thread.

jhb> Ewww, I'd rather avoid this if possible.  This is just an optimization,
jhb> but it would depend on how complicated this makes the mutex code to see
jhb> if it's worth it or not.

The owner thread of an adaptive mutex never lowers its priority until
it releases the mutex.  We should thus bump the priority of the owner
thread not during but just before spinning.  However, it is difficult
to know if the current thread can spin prior to calling

In addition, I would say that spinning can be done even more
efficiently.  At the moment, we try an atomic test-and-set
instruction in each spin.  As another thread holds the mutex, we are
likely to execute an expensive test-and-set instruction quite a lot of

Maybe we can solve both of the issues above by roughly checking if a
thread can keep spinning without acquiring any locks, in the similar
way as we do for a spin mutex.  First, test the following conditions:

- The owner of the mutex has not changed.
- The owner is on a processor.

If both of the conditions satisfy, keep spinning.  Otherwise, try
test-and-set.  The pseudo-code would look like this:

while (!_obtain_lock(m, td)) {

        if (unowned(m)) {

        owner = mtx_owner(m);
        if (oncpu(owner)) {
                bump_priority(owner, td);

                /* Spin without holding sched_lock. */

                while (owner == mtx_owner(m) && oncpu(owner)) {
                        /* Handle interrupts. */
                        /* Spin. */



The code above does not use any test-and-set instructions, nor does it
keep bumping the priority of the owner during spinning.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to