From: Aggelos Economopoulos Date: Sat, 5 Sep 2009 00:46:14 +0000 (+0300) Subject: add KTR_CTXSW option to log context switches X-Git-Url: https://gitweb.dragonflybsd.org/~polachok/dragonfly.git/commitdiff_plain/d850923cde9a684d3509eec67512169ed91f0aad add KTR_CTXSW option to log context switches This logs the current thread and the thread we switch to on every context switch or thread preemption event when enabled. --- diff --git a/share/man/man4/ktr.4 b/share/man/man4/ktr.4 index 8bf0f6cce1..eba9f009e9 100644 --- a/share/man/man4/ktr.4 +++ b/share/man/man4/ktr.4 @@ -53,6 +53,7 @@ .Cd options KTR_TOKENS .\".Cd options KTR_TSLEEP .Cd options KTR_USB_MEMORY +.Cd options KTR_CTXSW .Sh DESCRIPTION The .Nm @@ -119,6 +120,8 @@ IPI performance testing LWKT token related events .It Dv KTR_USB_MEMORY USB memory allocation +.It Dv KTR_CTXSW +context switches .El .Ss Verbose Mode By default, events are only logged to the internal buffer for examination diff --git a/sys/conf/options b/sys/conf/options index 1b1faf49f3..34b92c8dad 100644 --- a/sys/conf/options +++ b/sys/conf/options @@ -606,6 +606,7 @@ KTR_IFQ opt_ktr.h KTR_IF_START opt_ktr.h KTR_HAMMER opt_ktr.h KTR_ETHERNET opt_ktr.h +KTR_CTXSW opt_ktr.h # options for the Atheros driver ATH_DEBUG opt_ath.h diff --git a/sys/kern/lwkt_thread.c b/sys/kern/lwkt_thread.c index d3359049a7..9c3be36464 100644 --- a/sys/kern/lwkt_thread.c +++ b/sys/kern/lwkt_thread.c @@ -68,6 +68,12 @@ #include #include +#if !defined(KTR_CTXSW) +#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 *)); static MALLOC_DEFINE(M_THREAD, "thread", "lwkt threads"); @@ -775,6 +781,7 @@ using_idle_thread: #ifdef __amd64__ KKASSERT(jg_tos_ok(ntd)); #endif + KTR_LOG(ctxsw_sw, td, ntd); td->td_switch(ntd); } /* NOTE: current cpu may have changed after switch */ @@ -916,6 +923,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); td->td_switch(ntd); KKASSERT(ntd->td_preempted && (td->td_flags & TDF_PREEMPT_DONE));