X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/blobdiff_plain/f8abf63c2915f73cda605e7f5a04a6d2605f0733..3b998fa96afe52828957ea4f65d15320eb0fe240:/sys/kern/lwkt_thread.c diff --git a/sys/kern/lwkt_thread.c b/sys/kern/lwkt_thread.c index 97d8d74a28..9f6ba58ec9 100644 --- a/sys/kern/lwkt_thread.c +++ b/sys/kern/lwkt_thread.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved. + * Copyright (c) 2003-2010 The DragonFly Project. All rights reserved. * * This code is derived from software contributed to The DragonFly Project * by Matthew Dillon @@ -75,11 +75,13 @@ #define KTR_CTXSW KTR_ALL #endif KTR_INFO_MASTER(ctxsw); -KTR_INFO(KTR_CTXSW, ctxsw, sw, 0, "sw %p > %p", 2 * sizeof(struct thread *)); -KTR_INFO(KTR_CTXSW, ctxsw, pre, 1, "pre %p > %p", 2 * sizeof(struct thread *)); -KTR_INFO(KTR_CTXSW, ctxsw, newtd, 2, "new_td %p %s", sizeof (struct thread *) + - sizeof(char *)); -KTR_INFO(KTR_CTXSW, ctxsw, deadtd, 3, "dead_td %p", sizeof (struct thread *)); +KTR_INFO(KTR_CTXSW, ctxsw, sw, 0, "#cpu[%d].td = %p", + sizeof(int) + sizeof(struct thread *)); +KTR_INFO(KTR_CTXSW, ctxsw, pre, 1, "#cpu[%d].td = %p", + sizeof(int) + sizeof(struct thread *)); +KTR_INFO(KTR_CTXSW, ctxsw, newtd, 2, "#threads[%p].name = %s", + sizeof (struct thread *) + sizeof(char *)); +KTR_INFO(KTR_CTXSW, ctxsw, deadtd, 3, "#threads[%p].name = ", sizeof (struct thread *)); static MALLOC_DEFINE(M_THREAD, "thread", "lwkt threads"); @@ -354,6 +356,7 @@ lwkt_init_thread(thread_t td, void *stack, int stksize, int flags, td->td_flags = flags; td->td_gd = gd; td->td_pri = TDPRI_KERN_DAEMON + TDPRI_CRIT; + td->td_toks_stop = &td->td_toks_base; #ifdef SMP if ((flags & TDF_MPSAFE) == 0) td->td_mpcount = 1; @@ -518,7 +521,7 @@ lwkt_switch(void) td->td_release(td); crit_enter_gd(gd); - if (td->td_toks) + if (TD_TOKS_HELD(td)) lwkt_relalltokens(td); /* @@ -633,7 +636,7 @@ again: * cause the core MP lock to be released. */ if ((ntd->td_mpcount && mpheld == 0 && !cpu_try_mplock()) || - (ntd->td_toks && lwkt_getalltokens(ntd) == 0) + (TD_TOKS_HELD(ntd) && lwkt_getalltokens(ntd) == 0) ) { u_int32_t rqmask = gd->gd_runqmask; @@ -651,7 +654,7 @@ again: * failure, but the variable is only needed for * the loop. */ - if (ntd->td_toks && !lwkt_getalltokens(ntd)) { + if (TD_TOKS_HELD(ntd) && !lwkt_getalltokens(ntd)) { /* spinning due to token contention */ #ifdef INVARIANTS ++token_contention_count; @@ -770,7 +773,7 @@ using_idle_thread: KKASSERT(tos_ok); } #endif - KTR_LOG(ctxsw_sw, td, ntd); + KTR_LOG(ctxsw_sw, gd->gd_cpuid, ntd); td->td_switch(ntd); } /* NOTE: current cpu may have changed after switch */ @@ -870,7 +873,7 @@ lwkt_preempt(thread_t ntd, int critpri) need_lwkt_resched(); return; } - if (ntd->td_toks) { + if (TD_TOKS_HELD(ntd)) { ++preempt_miss; need_lwkt_resched(); return; @@ -912,7 +915,7 @@ lwkt_preempt(thread_t ntd, int critpri) ++preempt_hit; ntd->td_preempted = td; td->td_flags |= TDF_PREEMPT_LOCK; - KTR_LOG(ctxsw_pre, td, ntd); + KTR_LOG(ctxsw_pre, gd->gd_cpuid, ntd); td->td_switch(ntd); KKASSERT(ntd->td_preempted && (td->td_flags & TDF_PREEMPT_DONE));