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
Thu Dec 30 12:52:45 PST 2004

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 
  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
  Revision  Changes    Path
  1.71      +102 -14   src/sys/kern/sched_4bsd.c
  1.144     +77 -20    src/sys/kern/sched_ule.c
  1.151     +120 -71   src/sys/kern/subr_turnstile.c
  1.415     +1 -0      src/sys/sys/proc.h
  1.23      +2 -0      src/sys/sys/sched.h
  1.6       +1 -0      src/sys/sys/turnstile.h

More information about the cvs-src mailing list