Date: Tue, 25 Jun 2002 15:23:29 -0700 (PDT) From: Julian Elischer <julian@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 13429 for review Message-ID: <200206252223.g5PMNTN12416@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=13429 Change 13429 by julian@julian_ref on 2002/06/25 15:23:13 Fix STUPID bug in run queue addition code. Affected files ... ... //depot/projects/kse/sys/kern/kern_switch.c#61 edit Differences ... ==== //depot/projects/kse/sys/kern/kern_switch.c#61 (text+ko) ==== @@ -305,6 +305,7 @@ struct kse *ke; struct ksegrp *kg; struct thread *td2; + struct thread *tda; CTR1(KTR_RUNQ, "setrunqueue: td%p", td); mtx_assert(&sched_lock, MA_OWNED); @@ -328,6 +329,7 @@ * Ok, so we are threading with this thread. * We don't have a KSE, see if we can get one.. */ + tda = kg->kg_last_assigned; if ((ke = td->td_kse) == NULL) { /* * We will need a KSE, see if there is one.. @@ -344,27 +346,24 @@ TAILQ_REMOVE(&kg->kg_iq, ke, ke_kgrlist); ke->ke_state = KES_UNQUEUED; kg->kg_idle_kses--; - ke->ke_thread = td; - td->td_kse = ke; KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self4!")); - } else if ((kg->kg_last_assigned) && - (kg->kg_last_assigned->td_priority > td->td_priority)) { + } else if (tda && (tda->td_priority > td->td_priority)) { /* * None free, but there is one we can commandeer. */ - td2 = kg->kg_last_assigned; - kg->kg_last_assigned = - TAILQ_PREV(td2, threadqueue, td_runq); - ke = td2->td_kse; + ke = tda->td_kse; + tda->td_kse = NULL; + ke->ke_thread = NULL; + tda = kg->kg_last_assigned = + TAILQ_PREV(tda, threadqueue, td_runq); runq_remove(&runq, ke); - ke->ke_thread = td; - td2->td_kse = NULL; - td->td_kse = ke; KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self5!")); } } else { KASSERT(ke->ke_thread == td, ("KSE/thread mismatch")); KASSERT(ke->ke_state != KES_IDLE, ("KSE unexpectedly idle")); + ke->ke_thread = NULL; + td->td_kse = NULL; } /* @@ -387,9 +386,34 @@ * If needed, readjust the last_assigned pointer. */ if (ke) { - if (kg->kg_last_assigned == - TAILQ_PREV(td, threadqueue, td_runq)) { - kg->kg_last_assigned = td; + if (tda == NULL) { + /* + * No pre-existing last assigned so whoever is first + * gets the KSE we borught in.. (may be us) + */ + td2 = TAILQ_FIRST(&kg->kg_runq); + KASSERT((td2->td_kse == NULL), + ("unexpected ke present")); + td2->td_kse = ke; + ke->ke_thread = td2; + kg->kg_last_assigned = td2; + } else if (tda->td_priority > td->td_priority) { + /* + * It's ours, grab it, but last_assigned is past us + * so don't change it. + */ + td->td_kse = ke; + ke->ke_thread = td; + } else { + /* + * We are past last_assigned, so + * put the new kse on whatever is next, + * which may or may not be us. + */ + td2 = TAILQ_NEXT(tda, td_runq); + kg->kg_last_assigned = td2; + td2->td_kse = ke; + ke->ke_thread = td2; } runq_add(&runq, ke); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206252223.g5PMNTN12416>