Date: Tue, 14 Sep 2004 22:46:45 GMT From: Julian Elischer <julian@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 61511 for review Message-ID: <200409142246.i8EMkjj3033569@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=61511 Change 61511 by julian@julian_ref on 2004/09/14 22:46:41 tweek debugging Affected files ... .. //depot/projects/nsched/sys/kern/kern_switch.c#27 edit .. //depot/projects/nsched/sys/kern/kern_synch.c#14 edit .. //depot/projects/nsched/sys/kern/kern_thread.c#35 edit .. //depot/projects/nsched/sys/kern/sched_4bsd.c#54 edit Differences ... ==== //depot/projects/nsched/sys/kern/kern_switch.c#27 (text+ko) ==== @@ -126,23 +126,43 @@ { struct thread *td2; int count = 0; + int seenlast = 0 + + if (kg->kg_last_assigned == NULL) + seenlast = 1; TAILQ_FOREACH(td2, &kg->kg_runq, td_runq) { /* XXX Debugging hack */ if (!TD_ON_RUNQ(td2)) { - printf("%s: line %d", file, line); + printf("%s: line %d: ", file, line); printf("thread in wrong state, td2= %p\n", td2); panic("corruption in runqueue"); } if (td == td2) { - printf("%s: line %d", file, line); - printf("thread alreadyin runq, td2= %p\n", td); + printf("%s: line %d: ", file, line); + printf("thread alreadyin runq, td2= %p\n", td2); panic("confusion in runqueue"); } if (++count > 10000) { - printf("%s: line %d", file, line); + printf("%s: line %d: ", file, line); printf("corrupt kg_runq, td= %p\n", td); panic("deadlock in runqueue"); } + if (td2->td_sched->ke_state == KES_ONRUNQ) { + if (seenlast) { + printf("%s: line %d: ", file, line); + printf ("Sys td past last, td2= %p\n", td2); + panic("corrupted kg_runq"); + } + } else { + if (!seenlast) { + printf("%s: line %d: ", file, line); + printf ("unsched before last, td2= %p\n", td2); + panic("corrupted kg_runq"); + } + } + if (td2 == kg->kg_last_assigned) { + seenlast = 1; + } } } @@ -185,7 +205,6 @@ td = ke->ke_thread; KASSERT((td->td_kse == ke), ("kse/thread mismatch")); kg = ke->ke_ksegrp; - CHECKRUNQ(kg, NULL) if (td->td_proc->p_flag & P_HADTHREADS) { if (kg->kg_last_assigned == td) { kg->kg_last_assigned = TAILQ_PREV(td, @@ -193,7 +212,6 @@ } TAILQ_REMOVE(&kg->kg_runq, td, td_runq); kg->kg_runnable--; - CHECKRUNQ(kg, td) } CTR2(KTR_RUNQ, "choosethread: td=%p pri=%d", td, td->td_priority); @@ -290,7 +308,6 @@ td3 = TAILQ_PREV(td, threadqueue, td_runq); TAILQ_REMOVE(&kg->kg_runq, td, td_runq); kg->kg_runnable--; - CHECKRUNQ(kg, td) if (ke->ke_state == KES_ONRUNQ) { /* * This thread has been assigned to the system run queue. @@ -307,7 +324,6 @@ kg->kg_last_assigned = td3; /* slot_fill(kg); */ /* will replace it with another */ } - CHECKRUNQ(kg, NULL) } /* @@ -339,7 +355,6 @@ /* It is a threaded process */ kg = td->td_ksegrp; - CHECKRUNQ(kg, NULL) if (ke->ke_state == KES_ONRUNQ) { if (kg->kg_last_assigned == td) { kg->kg_last_assigned = @@ -351,10 +366,8 @@ TAILQ_REMOVE(&kg->kg_runq, td, td_runq); kg->kg_runnable--; TD_SET_CAN_RUN(td); - CHECKRUNQ(kg, td) td->td_priority = newpri; setrunqueue(td, SRQ_BORING); - CHECKRUNQ(kg, NULL) } int limitcount; void @@ -363,7 +376,6 @@ struct ksegrp *kg; struct thread *td2; struct thread *tda; - int count; CTR3(KTR_RUNQ, "setrunqueue: td:%p kg:%p pid:%d", td, td->td_ksegrp, td->td_proc->p_pid); @@ -394,9 +406,20 @@ } CHECKRUNQ(kg, td) + + /* + * If the concurrency has reduced, and we would go in the + * assigned section, then keep removing entries from the + * system run queue, until we are not in that section + * or there is room for us to be put in that section. + * What we MUST avoid is the case where there are threads of less + * priority than the new one scheduled, but it can not + * be scheduled itself. That would lead to a non contiguous set + * of scheduled threads, and everything would break. + */ tda = kg->kg_last_assigned; - if ((kg->kg_avail_opennings <= 0) && - (tda && (tda->td_priority > td->td_priority))) { + while ((kg->kg_avail_opennings <= 0) && + (tda && (tda->td_priority > td->td_priority))) { /* * None free, but there is one we can commandeer. */ @@ -412,7 +435,6 @@ * Add the thread to the ksegrp's run queue at * the appropriate place. */ - count = 0; TAILQ_FOREACH(td2, &kg->kg_runq, td_runq) { if (td2->td_priority > td->td_priority) { kg->kg_runnable++; @@ -425,16 +447,19 @@ kg->kg_runnable++; TAILQ_INSERT_TAIL(&kg->kg_runq, td, td_runq); } - CHECKRUNQ(kg, NULL) + /* * If we have a slot to use, then put the thread on the system * run queue and if needed, readjust the last_assigned pointer. + * it may be that we need to schedule something anyhow + * even if the availabel slots are -ve so that + * all the items < last_assigned are scheduled. */ if (kg->kg_avail_opennings > 0) { if (tda == NULL) { /* * No pre-existing last assigned so whoever is first - * gets the KSE we brought in.. (maybe us) + * gets the slot.. (maybe us) */ td2 = TAILQ_FIRST(&kg->kg_runq); kg->kg_last_assigned = td2; @@ -443,7 +468,7 @@ } else { /* * We are past last_assigned, so - * gave the next slot to whatever is next, + * give the next slot to whatever is next, * which may or may not be us. */ td2 = TAILQ_NEXT(tda, td_runq); @@ -454,6 +479,7 @@ CTR3(KTR_RUNQ, "setrunqueue: held: td%p kg%p pid%d", td, td->td_ksegrp, td->td_proc->p_pid); } + CHECKRUNQ(kg, NULL) } /* @@ -539,7 +565,6 @@ ("thread has no (or wrong) sched-private part.")); KASSERT((td->td_inhibitors == 0), ("setrunqueue: trying to run inhibitted thread")); - CHECKRUNQ(td->td_ksegrp, NULL) pri = td->td_priority; cpri = ctd->td_priority; if (pri >= cpri || cold /* || dumping */ || TD_IS_INHIBITED(ctd) || ==== //depot/projects/nsched/sys/kern/kern_synch.c#14 (text+ko) ==== @@ -335,7 +335,7 @@ PCPU_SET(switchticks, ticks); CTR4(KTR_PROC, "mi_switch: old thread %p (kse %p, pid %ld, %s)", (void *)td, td->td_sched, (long)p->p_pid, p->p_comm); - if (td->td_proc->p_flag & P_SA) + if ((flags & SW_VOL) && (td->td_proc->p_flag & P_SA)) newtd = thread_switchout(td, flags, newtd); sched_switch(td, newtd, flags); ==== //depot/projects/nsched/sys/kern/kern_thread.c#35 (text+ko) ==== ==== //depot/projects/nsched/sys/kern/sched_4bsd.c#54 (text+ko) ====
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200409142246.i8EMkjj3033569>