From 1715f07da3f607d7a1426227556178a9d5c7b5f5 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Mon, 25 Jun 2001 23:09:31 +0000 Subject: [PATCH] - Replace the unused KTR_IDLELOOP trace class with a new KTR_WITNESS trace class to trace witness events. - Make the ktr_cpu field of ktr_entry be a standard field rather than one present only in the KTR_EXTEND case. - Move the default definition of KTR_ENTRIES from sys/ktr.h to kern/kern_ktr.c. It has not been needed in the header file since KTR was un-inlined. - Minor include cleanup in kern/kern_ktr.c. - Fiddle with the ktr_cpumask in ktr_tracepoint() to disable KTR events on the current CPU while we are processing an event. - Set the current CPU inside of the critical section to ensure we don't migrate CPU's after the critical section but before we set the CPU. --- sys/kern/kern_ktr.c | 31 +++++++++++++++++-------------- sys/sys/ktr.h | 15 ++++++--------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/sys/kern/kern_ktr.c b/sys/kern/kern_ktr.c index 8902ca57c294..06372b93ee4a 100644 --- a/sys/kern/kern_ktr.c +++ b/sys/kern/kern_ktr.c @@ -38,19 +38,22 @@ #include "opt_ktr.h" #include -#include #include -#include #include #include #include #include #include +#include #include #include #include +#ifndef KTR_ENTRIES +#define KTR_ENTRIES 1024 +#endif + #ifndef KTR_MASK #define KTR_MASK (KTR_GEN) #endif @@ -126,30 +129,30 @@ ktr_tracepoint(u_int mask, const char *format, u_long arg1, u_long arg2, return; if ((ktr_mask & mask) == 0) return; -#ifdef KTR_EXTEND - if (((1 << KTR_CPU) & ktr_cpumask) == 0) - return; -#endif savecrit = critical_enter(); + if (((1 << KTR_CPU) & ktr_cpumask) == 0) { + critical_exit(savecrit); + return; + } + atomic_clear_int(&ktr_cpumask, 1 << KTR_CPU); do { saveindex = ktr_idx; newindex = (saveindex + 1) & (KTR_ENTRIES - 1); } while (atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0); entry = &ktr_buf[saveindex]; - critical_exit(savecrit); - if (ktr_mask & KTR_LOCK) - /* - * We can't use nanotime with KTR_LOCK, it would cause - * endless recursion, at least under the Intel - * architecture. - */ + /* + * 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); #ifdef KTR_EXTEND entry->ktr_filename = filename; entry->ktr_line = line; - entry->ktr_cpu = KTR_CPU; va_start(ap, format); vsnprintf(entry->ktr_desc, KTRDESCSIZE, format, ap); va_end(ap); diff --git a/sys/sys/ktr.h b/sys/sys/ktr.h index 5c39adb8d0f2..fe087c767054 100644 --- a/sys/sys/ktr.h +++ b/sys/sys/ktr.h @@ -65,7 +65,7 @@ #define KTR_NFS 0x00040000 /* The obvious */ #define KTR_VOP 0x00080000 /* The obvious */ #define KTR_VM 0x00100000 /* The virtual memory system */ -#define KTR_IDLELOOP 0x00200000 /* checks done in the idle process */ +#define KTR_WITNESS 0x00200000 #define KTR_RUNQ 0x00400000 /* Run queue */ #define KTR_ALL 0x007fffff @@ -91,16 +91,17 @@ #include -struct ktr_entry { - struct timespec ktr_tv; -#ifdef KTR_EXTEND #ifndef KTRDESCSIZE #define KTRDESCSIZE 80 #endif + +struct ktr_entry { + struct timespec ktr_tv; + int ktr_cpu; +#ifdef KTR_EXTEND char ktr_desc[KTRDESCSIZE]; const char *ktr_filename; int ktr_line; - int ktr_cpu; #else const char *ktr_desc; u_long ktr_parm1; @@ -125,10 +126,6 @@ extern struct ktr_entry ktr_buf[]; #endif /* !LOCORE */ #ifdef KTR -#ifndef KTR_ENTRIES -#define KTR_ENTRIES 1024 -#endif - #ifdef KTR_EXTEND void ktr_tracepoint(u_int mask, const char *filename, u_int line, const char *format, ...) __printflike(4, 5);