From 66ac46bd154cfa3d8ca207bfc01035f794a2cad0 Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 13 Dec 2001 10:33:20 +0000 Subject: [PATCH] Use a per-thread variable for keeping state when a thread is processing a KTR log entry. Any KTR requests made while working on an entry are ignored/discarded to prevent recursion. This is a better fix for the hack to futz with the CPU mask and call getnanotime() if KTR_LOCK or KTR_WITNESS was on. It also covers the actual formatting of the log entry including dumping it to the display which the earlier hacks did not. --- sys/kern/kern_ktr.c | 18 ++++++++---------- sys/sys/proc.h | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_ktr.c b/sys/kern/kern_ktr.c index 6badb3df9ae5..309d6e31bb1b 100644 --- a/sys/kern/kern_ktr.c +++ b/sys/kern/kern_ktr.c @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -121,6 +121,7 @@ ktr_tracepoint(u_int mask, const char *format, u_long arg1, u_long arg2, struct ktr_entry *entry; int newindex, saveindex; critical_t savecrit; + struct thread *td; #ifdef KTR_EXTEND va_list ap; #endif @@ -129,27 +130,23 @@ ktr_tracepoint(u_int mask, const char *format, u_long arg1, u_long arg2, return; if ((ktr_mask & mask) == 0) return; + td = curthread; + if (td->td_inktr) + return; savecrit = critical_enter(); if (((1 << KTR_CPU) & ktr_cpumask) == 0) { critical_exit(savecrit); return; } - atomic_clear_int(&ktr_cpumask, 1 << KTR_CPU); + td->td_inktr++; do { saveindex = ktr_idx; newindex = (saveindex + 1) & (KTR_ENTRIES - 1); } while (atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0); entry = &ktr_buf[saveindex]; - /* - * XXX: The ktr_cpumask atomic ops should make this unnecessary. - */ - if ((ktr_mask & (KTR_LOCK | KTR_WITNESS)) != 0) - getnanotime(&entry->ktr_tv); - else - nanotime(&entry->ktr_tv); - atomic_set_int(&ktr_cpumask, 1 << KTR_CPU); entry->ktr_cpu = KTR_CPU; critical_exit(savecrit); + nanotime(&entry->ktr_tv); #ifdef KTR_EXTEND entry->ktr_filename = filename; entry->ktr_line = line; @@ -176,6 +173,7 @@ ktr_tracepoint(u_int mask, const char *format, u_long arg1, u_long arg2, entry->ktr_parm5 = arg5; entry->ktr_parm6 = arg6; #endif + td->td_inktr--; } #ifdef DDB diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 48ba36994960..beab3160feb9 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -253,6 +253,7 @@ struct thread { void *td_wchan; /* (j) Sleep address. */ const char *td_wmesg; /* (j) Reason for sleep. */ u_char td_lastcpu; /* (j) Last cpu we were on. */ + u_char td_inktr; /* (k) Currently handling a KTR. */ short td_locks; /* (k) DEBUG: lockmgr count of locks */ struct mtx *td_blocked; /* (j) Mutex process is blocked on. */ struct ithd *td_ithd; /* (b) For interrupt threads only. */