summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2001-12-13 10:33:20 +0000
committerjhb <jhb@FreeBSD.org>2001-12-13 10:33:20 +0000
commit66ac46bd154cfa3d8ca207bfc01035f794a2cad0 (patch)
tree46d810ffb3e04f55297cead7d82b3beb7e7721c4
parent02911c1b4a09f6798f8a4a40e1fde436c27dd792 (diff)
downloadFreeBSD-src-66ac46bd154cfa3d8ca207bfc01035f794a2cad0.zip
FreeBSD-src-66ac46bd154cfa3d8ca207bfc01035f794a2cad0.tar.gz
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.
-rw-r--r--sys/kern/kern_ktr.c18
-rw-r--r--sys/sys/proc.h1
2 files changed, 9 insertions, 10 deletions
diff --git a/sys/kern/kern_ktr.c b/sys/kern/kern_ktr.c
index 6badb3d..309d6e3 100644
--- a/sys/kern/kern_ktr.c
+++ b/sys/kern/kern_ktr.c
@@ -42,7 +42,7 @@
#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/libkern.h>
-#include <sys/pcpu.h>
+#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
#include <sys/time.h>
@@ -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 48ba369..beab316 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. */
OpenPOWER on IntegriCloud