diff options
author | julian <julian@FreeBSD.org> | 2002-10-14 20:34:31 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 2002-10-14 20:34:31 +0000 |
commit | 9ce470a533cf51e65a0e46f0d3f76a7467037479 (patch) | |
tree | ec5f595c6f180bad73ef2a0656ff0fb1edeac3a7 /sys/kern/kern_switch.c | |
parent | e53d0f994c6510cd95298e77954eea9fa4efa067 (diff) | |
download | FreeBSD-src-9ce470a533cf51e65a0e46f0d3f76a7467037479.zip FreeBSD-src-9ce470a533cf51e65a0e46f0d3f76a7467037479.tar.gz |
Tidy up the scheduler's code for changing the priority of a thread.
Logically pretty much a NOP.
Diffstat (limited to 'sys/kern/kern_switch.c')
-rw-r--r-- | sys/kern/kern_switch.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/sys/kern/kern_switch.c b/sys/kern/kern_switch.c index 14d6b2f..d171cb3 100644 --- a/sys/kern/kern_switch.c +++ b/sys/kern/kern_switch.c @@ -277,13 +277,14 @@ kse_reassign(struct kse *ke) CTR1(KTR_RUNQ, "kse_reassign: ke%p idled", ke); } +#if 0 /* * Remove a thread from its KSEGRP's run queue. * This in turn may remove it from a KSE if it was already assigned * to one, possibly causing a new thread to be assigned to the KSE * and the KSE getting a new priority (unless it's a BOUND thread/KSE pair). */ -void +static void remrunqueue(struct thread *td) { struct thread *td2, *td3; @@ -325,6 +326,51 @@ remrunqueue(struct thread *td) kse_reassign(ke); } } +#endif + +/* + * Change the priority of a thread that is on the run queue. + */ +void +adjustrunqueue( struct thread *td, int newpri) +{ + struct ksegrp *kg; + struct kse *ke; + + mtx_assert(&sched_lock, MA_OWNED); + KASSERT ((TD_ON_RUNQ(td)), ("adjustrunqueue: Bad state on run queue")); + /* + * If it's a bound thread/KSE pair, take the shortcut. All non-KSE + * threads are BOUND. + */ + ke = td->td_kse; + CTR1(KTR_RUNQ, "adjustrunqueue: td%p", td); + if ((td->td_flags & TDF_UNBOUND) == 0) { + /* We only care about the kse in the run queue. */ + if (ke->ke_rqindex != (newpri / RQ_PPQ)) { + sched_rem(ke); + td->td_priority = newpri; + sched_add(ke); + } + return; + } + /* + * An unbound thread. This is not optimised yet. + */ + kg = td->td_ksegrp; + kg->kg_runnable--; + TD_SET_CAN_RUN(td); + if (ke) { + if (kg->kg_last_assigned == td) { + kg->kg_last_assigned = + TAILQ_PREV(td, threadqueue, td_runq); + } + sched_rem(ke); + } + TAILQ_REMOVE(&kg->kg_runq, td, td_runq); + td->td_priority = newpri; + setrunqueue(td); +} void setrunqueue(struct thread *td) @@ -663,18 +709,6 @@ runq_remove(struct runq *rq, struct kse *ke) } #if 0 -static void -runq_readjust(struct runq *rq, struct kse *ke) -{ - - if (ke->ke_rqindex != (ke->ke_thread->td_priority / RQ_PPQ)) { - runq_remove(rq, ke); - runq_add(rq, ke); - } -} -#endif - -#if 0 void panc(char *string1, char *string2) { |