cvs commit: src/sys/kern sched_4bsd.c sched_ule.c subr_turnstile.c src/sys/sys proc.h sched.h turnstile.h

John Baldwin jhb at FreeBSD.org
Thu Dec 30 12:59:23 PST 2004


On Thursday 30 December 2004 03:52 pm, John Baldwin wrote:
> jhb         2004-12-30 20:52:44 UTC
>
>   FreeBSD src repository
>
>   Modified files:
>     sys/kern             sched_4bsd.c sched_ule.c subr_turnstile.c
>     sys/sys              proc.h sched.h turnstile.h
>   Log:
>   Rework the interface between priority propagation (lending) and the
>   schedulers a bit to ensure more correct handling of priorities and fewer
>   priority inversions:
>   - Add two functions to the sched(9) API to handle priority lending:
>     sched_lend_prio() and sched_unlend_prio().  The turnstile code uses
> these functions to ask the scheduler to lend a thread a set priority and to
> tell the scheduler when it thinks it is ok for a thread to stop borrowing
> priority.  The unlend case is slightly complex in that the turnstile code
> tells the scheduler what the minimum priority of the thread needs to be to
> satisfy the requirements of any other threads blocked on locks owned by the
> thread in question.  The scheduler then decides where the thread can go
> back to normal mode (if it's normal priority is high enough to satisfy the
> pending lock requests) or it it should continue to use the priority
> specified to the sched_unlend_prio() call.  This involves adding a new
> per-thread flag TDF_BORROWING that replaces the ULE-only kse flag for
> priority elevation.
>   - Schedulers now refuse to lower the priority of a thread that is
> currently borrowing another therad's priority.
>   - If a scheduler changes the priority of a thread that is currently
> sitting on a turnstile, it will call a new function turnstile_adjust() to
> inform the turnstile code of the change.  This function resorts the thread
> on the priority list of the turnstile if needed, and if the thread ends up
> at the head of the list (due to having the highest priority) and its
> priority was raised, then it will propagate that new priority to the owner
> of the lock it is blocked on.
>
>   Some additional fixes specific to the 4BSD scheduler include:
>   - Common code for updating the priority of a thread when the user
> priority of its associated kse group has been consolidated in a new static
> function resetpriority_thread().  One change to this function is that it
> will now only adjust the priority of a thread if it already has a time
> sharing priority, thus preserving any boosts from a tsleep() until the
> thread returns to userland.  Also, resetpriority() no longer calls
> maybe_resched() on each thread in the group. Instead, the code calling
> resetpriority() is responsible for calling resetpriority_thread() on any
> threads that need to be updated.
>   - schedcpu() now uses resetpriority_thread() instead of just calling
>     sched_prio() directly after it updates a kse group's user priority.
>   - sched_clock() now uses resetpriority_thread() rather than writing
>     directly to td_priority.
>   - sched_nice() now updates all the priorities of the threads after the
>     group priority has been adjusted.
>
>   Discussed with: bde
>   Reviewed by:    ups, jeffr
>   Tested on:      4bsd, ule
>   Tested on:      i386, alpha, sparc64

I just noticed while committing this that I lost part of the recent change to 
ULE to handle priority elevation in that it doesn't reevaluate a kse's slice 
after ending priority lending.  I will work up a patch for this and test it 
shortly followed by a commit once all is well.

-- 
John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the cvs-src mailing list