kern_switch.c (133219) | kern_switch.c (133396) |
---|---|
1/* 2 * Copyright (c) 2001 Jake Burkholder <jake@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 72 unchanged lines hidden (view full) --- 81 82The result of this scheme is that the M available KSEs are always 83queued at the priorities they have inherrited from the M highest priority 84threads for that KSEGROUP. If this situation changes, the KSEs are 85reassigned to keep this true. 86***/ 87 88#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 2001 Jake Burkholder <jake@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 72 unchanged lines hidden (view full) --- 81 82The result of this scheme is that the M available KSEs are always 83queued at the priorities they have inherrited from the M highest priority 84threads for that KSEGROUP. If this situation changes, the KSEs are 85reassigned to keep this true. 86***/ 87 88#include <sys/cdefs.h> |
89__FBSDID("$FreeBSD: head/sys/kern/kern_switch.c 133219 2004-08-06 15:49:44Z jhb $"); | 89__FBSDID("$FreeBSD: head/sys/kern/kern_switch.c 133396 2004-08-09 18:21:12Z julian $"); |
90 91#include "opt_full_preemption.h" 92 93#include <sys/param.h> 94#include <sys/systm.h> 95#include <sys/kdb.h> 96#include <sys/kernel.h> 97#include <sys/ktr.h> --- 110 unchanged lines hidden (view full) --- 208 209 /* 210 * If we found one, assign it the kse, otherwise idle the kse. 211 */ 212 if (td) { 213 kg->kg_last_assigned = td; 214 td->td_kse = ke; 215 ke->ke_thread = td; | 90 91#include "opt_full_preemption.h" 92 93#include <sys/param.h> 94#include <sys/systm.h> 95#include <sys/kdb.h> 96#include <sys/kernel.h> 97#include <sys/ktr.h> --- 110 unchanged lines hidden (view full) --- 208 209 /* 210 * If we found one, assign it the kse, otherwise idle the kse. 211 */ 212 if (td) { 213 kg->kg_last_assigned = td; 214 td->td_kse = ke; 215 ke->ke_thread = td; |
216 sched_add(td); | |
217 CTR2(KTR_RUNQ, "kse_reassign: ke%p -> td%p", ke, td); | 216 CTR2(KTR_RUNQ, "kse_reassign: ke%p -> td%p", ke, td); |
217 sched_add(td); |
|
218 return; 219 } 220 221 ke->ke_state = KES_IDLE; 222 ke->ke_thread = NULL; 223 TAILQ_INSERT_TAIL(&kg->kg_iq, ke, ke_kgrlist); 224 kg->kg_idle_kses++; 225 CTR1(KTR_RUNQ, "kse_reassign: ke%p on idle queue", ke); --- 96 unchanged lines hidden (view full) --- 322void 323setrunqueue(struct thread *td) 324{ 325 struct kse *ke; 326 struct ksegrp *kg; 327 struct thread *td2; 328 struct thread *tda; 329 | 218 return; 219 } 220 221 ke->ke_state = KES_IDLE; 222 ke->ke_thread = NULL; 223 TAILQ_INSERT_TAIL(&kg->kg_iq, ke, ke_kgrlist); 224 kg->kg_idle_kses++; 225 CTR1(KTR_RUNQ, "kse_reassign: ke%p on idle queue", ke); --- 96 unchanged lines hidden (view full) --- 322void 323setrunqueue(struct thread *td) 324{ 325 struct kse *ke; 326 struct ksegrp *kg; 327 struct thread *td2; 328 struct thread *tda; 329 |
330 CTR1(KTR_RUNQ, "setrunqueue: td%p", td); | 330 CTR4(KTR_RUNQ, "setrunqueue: td:%p ke:%p kg:%p pid:%d", 331 td, td->td_kse, td->td_ksegrp, td->td_proc->p_pid); |
331 mtx_assert(&sched_lock, MA_OWNED); 332 KASSERT((TD_CAN_RUN(td) || TD_IS_RUNNING(td)), 333 ("setrunqueue: bad thread state")); 334 TD_SET_RUNQ(td); 335 kg = td->td_ksegrp; 336 kg->kg_runnable++; 337 if ((td->td_proc->p_flag & P_SA) == 0) { 338 /* --- 7 unchanged lines hidden (view full) --- 346 347 tda = kg->kg_last_assigned; 348 if ((ke = td->td_kse) == NULL) { 349 if (kg->kg_idle_kses) { 350 /* 351 * There is a free one so it's ours for the asking.. 352 */ 353 ke = TAILQ_FIRST(&kg->kg_iq); | 332 mtx_assert(&sched_lock, MA_OWNED); 333 KASSERT((TD_CAN_RUN(td) || TD_IS_RUNNING(td)), 334 ("setrunqueue: bad thread state")); 335 TD_SET_RUNQ(td); 336 kg = td->td_ksegrp; 337 kg->kg_runnable++; 338 if ((td->td_proc->p_flag & P_SA) == 0) { 339 /* --- 7 unchanged lines hidden (view full) --- 347 348 tda = kg->kg_last_assigned; 349 if ((ke = td->td_kse) == NULL) { 350 if (kg->kg_idle_kses) { 351 /* 352 * There is a free one so it's ours for the asking.. 353 */ 354 ke = TAILQ_FIRST(&kg->kg_iq); |
355 CTR2(KTR_RUNQ, "setrunqueue: kg:%p: Use free ke:%p", 356 kg, ke); |
|
354 TAILQ_REMOVE(&kg->kg_iq, ke, ke_kgrlist); 355 ke->ke_state = KES_THREAD; 356 kg->kg_idle_kses--; 357 } else if (tda && (tda->td_priority > td->td_priority)) { 358 /* 359 * None free, but there is one we can commandeer. 360 */ 361 ke = tda->td_kse; | 357 TAILQ_REMOVE(&kg->kg_iq, ke, ke_kgrlist); 358 ke->ke_state = KES_THREAD; 359 kg->kg_idle_kses--; 360 } else if (tda && (tda->td_priority > td->td_priority)) { 361 /* 362 * None free, but there is one we can commandeer. 363 */ 364 ke = tda->td_kse; |
365 CTR3(KTR_RUNQ, 366 "setrunqueue: kg:%p: take ke:%p from td: %p", 367 kg, ke, tda); |
|
362 sched_rem(tda); 363 tda->td_kse = NULL; 364 ke->ke_thread = NULL; 365 tda = kg->kg_last_assigned = 366 TAILQ_PREV(tda, threadqueue, td_runq); 367 } 368 } else { 369 /* --- 48 unchanged lines hidden (view full) --- 418 * which may or may not be us. 419 */ 420 td2 = TAILQ_NEXT(tda, td_runq); 421 kg->kg_last_assigned = td2; 422 td2->td_kse = ke; 423 ke->ke_thread = td2; 424 } 425 sched_add(ke->ke_thread); | 368 sched_rem(tda); 369 tda->td_kse = NULL; 370 ke->ke_thread = NULL; 371 tda = kg->kg_last_assigned = 372 TAILQ_PREV(tda, threadqueue, td_runq); 373 } 374 } else { 375 /* --- 48 unchanged lines hidden (view full) --- 424 * which may or may not be us. 425 */ 426 td2 = TAILQ_NEXT(tda, td_runq); 427 kg->kg_last_assigned = td2; 428 td2->td_kse = ke; 429 ke->ke_thread = td2; 430 } 431 sched_add(ke->ke_thread); |
432 } else { 433 CTR3(KTR_RUNQ, "setrunqueue: held: td%p kg%p pid%d", 434 td, td->td_ksegrp, td->td_proc->p_pid); |
|
426 } 427} 428 429/* 430 * Kernel thread preemption implementation. Critical sections mark 431 * regions of code in which preemptions are not allowed. 432 */ 433void --- 200 unchanged lines hidden (view full) --- 634{ 635 struct rqhead *rqh; 636 int pri; 637 638 pri = ke->ke_thread->td_priority / RQ_PPQ; 639 ke->ke_rqindex = pri; 640 runq_setbit(rq, pri); 641 rqh = &rq->rq_queues[pri]; | 435 } 436} 437 438/* 439 * Kernel thread preemption implementation. Critical sections mark 440 * regions of code in which preemptions are not allowed. 441 */ 442void --- 200 unchanged lines hidden (view full) --- 643{ 644 struct rqhead *rqh; 645 int pri; 646 647 pri = ke->ke_thread->td_priority / RQ_PPQ; 648 ke->ke_rqindex = pri; 649 runq_setbit(rq, pri); 650 rqh = &rq->rq_queues[pri]; |
642 CTR4(KTR_RUNQ, "runq_add: p=%p pri=%d %d rqh=%p", 643 ke->ke_proc, ke->ke_thread->td_priority, pri, rqh); | 651 CTR5(KTR_RUNQ, "runq_add: td=%p ke=%p pri=%d %d rqh=%p", 652 ke->ke_thread, ke, ke->ke_thread->td_priority, pri, rqh); |
644 TAILQ_INSERT_TAIL(rqh, ke, ke_procq); 645} 646 647/* 648 * Return true if there are runnable processes of any priority on the run 649 * queue, false otherwise. Has no side effects, does not modify the run 650 * queue structure. 651 */ --- 49 unchanged lines hidden (view full) --- 701{ 702 struct rqhead *rqh; 703 int pri; 704 705 KASSERT(ke->ke_proc->p_sflag & PS_INMEM, 706 ("runq_remove: process swapped out")); 707 pri = ke->ke_rqindex; 708 rqh = &rq->rq_queues[pri]; | 653 TAILQ_INSERT_TAIL(rqh, ke, ke_procq); 654} 655 656/* 657 * Return true if there are runnable processes of any priority on the run 658 * queue, false otherwise. Has no side effects, does not modify the run 659 * queue structure. 660 */ --- 49 unchanged lines hidden (view full) --- 710{ 711 struct rqhead *rqh; 712 int pri; 713 714 KASSERT(ke->ke_proc->p_sflag & PS_INMEM, 715 ("runq_remove: process swapped out")); 716 pri = ke->ke_rqindex; 717 rqh = &rq->rq_queues[pri]; |
709 CTR4(KTR_RUNQ, "runq_remove: p=%p pri=%d %d rqh=%p", 710 ke, ke->ke_thread->td_priority, pri, rqh); | 718 CTR5(KTR_RUNQ, "runq_remove: td=%p, ke=%p pri=%d %d rqh=%p", 719 ke->ke_thread, ke, ke->ke_thread->td_priority, pri, rqh); |
711 KASSERT(ke != NULL, ("runq_remove: no proc on busy queue")); 712 TAILQ_REMOVE(rqh, ke, ke_procq); 713 if (TAILQ_EMPTY(rqh)) { 714 CTR0(KTR_RUNQ, "runq_remove: empty"); 715 runq_clrbit(rq, pri); 716 } 717} 718 --- 104 unchanged lines hidden --- | 720 KASSERT(ke != NULL, ("runq_remove: no proc on busy queue")); 721 TAILQ_REMOVE(rqh, ke, ke_procq); 722 if (TAILQ_EMPTY(rqh)) { 723 CTR0(KTR_RUNQ, "runq_remove: empty"); 724 runq_clrbit(rq, pri); 725 } 726} 727 --- 104 unchanged lines hidden --- |