- Remove much of the inlining of the KTR tracepoints into a ktr_tracepoint()
function declared in kern_ktr.c. The only inline checks left are the checks that compare KTR_COMPILE with the supplied mask and thus should be optimized away into either nothing or a direct call to ktr_tracepoint(). - Move several KTR-related options to opt_ktr.h now that they are only needed by kern_ktr.c and not by ktr.h. - Add in the ktr_verbose functionality if KTR_EXTEND is turned on. If the global variable 'ktr_verbose' is non-zero, then KTR messages will be dumped to the console. This variable can be set by either kernel code or via the 'debug.ktr_verbose' sysctl. It defaults to off unless the KTR_VERBOSE kernel option is specified in which case it defaults to on. This can be useful when the machine locks up spinning in a loop with interrupts disabled as you might be able to see what it is doing when it locks up. Requested by: phk
This commit is contained in:
parent
7d1fae05bb
commit
d8f03321bd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=68420
@ -461,11 +461,12 @@ PCFCLOCK_MAX_RETRIES opt_pcfclock.h
|
||||
TDFX_LINUX opt_tdfx.h
|
||||
|
||||
KTR opt_global.h
|
||||
KTR_MASK opt_global.h
|
||||
KTR_CPUMASK opt_global.h
|
||||
KTR_MASK opt_ktr.h
|
||||
KTR_CPUMASK opt_ktr.h
|
||||
KTR_COMPILE opt_global.h
|
||||
KTR_ENTRIES opt_global.h
|
||||
KTR_EXTEND opt_global.h
|
||||
KTR_VERBOSE opt_ktr.h
|
||||
MUTEX_DEBUG opt_global.h
|
||||
WITNESS opt_global.h
|
||||
WITNESS_DDB opt_witness.h
|
||||
|
@ -30,14 +30,34 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* This module holds the global variables used by KTR.
|
||||
* This module holds the global variables used by KTR and the ktr_tracepoint()
|
||||
* function that does the actual tracing.
|
||||
*/
|
||||
|
||||
#include "opt_ktr.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ktr.h>
|
||||
#include <sys/libkern.h>
|
||||
#include <sys/linker_set.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/systm.h>
|
||||
#include <machine/stdarg.h>
|
||||
|
||||
#ifndef KTR_MASK
|
||||
#define KTR_MASK (KTR_GEN)
|
||||
#endif
|
||||
|
||||
#ifndef KTR_CPUMASK
|
||||
#define KTR_CPUMASK (~0)
|
||||
#endif
|
||||
|
||||
#ifdef SMP
|
||||
#define KTR_CPU cpuid
|
||||
#else
|
||||
#define KTR_CPU 0
|
||||
#endif
|
||||
|
||||
#ifdef KTR_EXTEND
|
||||
/*
|
||||
@ -49,7 +69,7 @@ SYSCTL_INT(_debug, OID_AUTO, ktr_extend, CTLFLAG_RD, &ktr_extend, 1, "");
|
||||
#else
|
||||
int ktr_extend = 0;
|
||||
SYSCTL_INT(_debug, OID_AUTO, ktr_extend, CTLFLAG_RD, &ktr_extend, 0, "");
|
||||
#endif
|
||||
#endif /* KTR_EXTEND */
|
||||
|
||||
int ktr_cpumask = KTR_CPUMASK;
|
||||
SYSCTL_INT(_debug, OID_AUTO, ktr_cpumask, CTLFLAG_RW, &ktr_cpumask, KTR_CPUMASK, "");
|
||||
@ -62,3 +82,67 @@ SYSCTL_INT(_debug, OID_AUTO, ktr_entries, CTLFLAG_RD, &ktr_entries, KTR_ENTRIES,
|
||||
|
||||
volatile int ktr_idx = 0;
|
||||
struct ktr_entry ktr_buf[KTR_ENTRIES];
|
||||
|
||||
#ifdef KTR_VERBOSE
|
||||
int ktr_verbose = 1;
|
||||
#else
|
||||
int ktr_verbose = 0;
|
||||
#endif
|
||||
SYSCTL_INT(_debug, OID_AUTO, ktr_verbose, CTLFLAG_RW, &ktr_verbose, 0, "");
|
||||
|
||||
#ifdef KTR
|
||||
#ifdef KTR_EXTEND
|
||||
void
|
||||
ktr_tracepoint(u_int mask, char *filename, u_int line, char *format, ...)
|
||||
#else
|
||||
void
|
||||
ktr_tracepoint(u_int mask, char *format, u_long arg1, u_long arg2, u_long arg3,
|
||||
u_long arg4, u_long arg5)
|
||||
#endif
|
||||
{
|
||||
struct ktr_entry *entry;
|
||||
int newindex, saveindex, saveintr;
|
||||
#ifdef KTR_EXTEND
|
||||
va_list ap;
|
||||
#endif
|
||||
|
||||
if ((ktr_mask & mask) == 0)
|
||||
return;
|
||||
#ifdef KTR_EXTEND
|
||||
if (((1 << KTR_CPU) & ktr_cpumask) == 0)
|
||||
return;
|
||||
#endif
|
||||
saveintr = save_intr();
|
||||
disable_intr();
|
||||
do {
|
||||
saveindex = ktr_idx;
|
||||
newindex = (saveindex + 1) & (KTR_ENTRIES - 1);
|
||||
} while (atomic_cmpset_rel_int(&ktr_idx, saveindex, newindex) == 0);
|
||||
entry = &ktr_buf[saveindex];
|
||||
restore_intr(saveintr);
|
||||
nanotime(&entry->ktr_tv);
|
||||
#ifdef KTR_EXTEND
|
||||
strncpy(entry->ktr_filename, filename, KTRFILENAMESIZE - 1);
|
||||
entry->ktr_filename[KTRFILENAMESIZE - 1] = '\0';
|
||||
snprintf(entry->ktr_filename, KTRFILENAMESIZE, "%s", __FILE__);
|
||||
entry->ktr_line = line;
|
||||
entry->ktr_cpu = KTR_CPU;
|
||||
va_start(ap, format);
|
||||
vsnprintf(entry->ktr_desc, KTRDESCSIZE, format, ap);
|
||||
va_end(ap);
|
||||
if (ktr_verbose) {
|
||||
va_start(ap, format);
|
||||
vprintf(format, ap);
|
||||
printf("\n");
|
||||
va_end(ap);
|
||||
}
|
||||
#else
|
||||
entry->ktr_desc = format;
|
||||
entry->ktr_parm1 = arg1;
|
||||
entry->ktr_parm2 = arg2;
|
||||
entry->ktr_parm3 = arg3;
|
||||
entry->ktr_parm4 = arg4;
|
||||
entry->ktr_parm5 = arg5;
|
||||
#endif
|
||||
}
|
||||
#endif /* KTR */
|
||||
|
165
sys/sys/ktr.h
165
sys/sys/ktr.h
@ -85,14 +85,6 @@
|
||||
#define KTR_COMPILE (KTR_GEN)
|
||||
#endif
|
||||
|
||||
#ifndef KTR_MASK
|
||||
#define KTR_MASK (KTR_GEN)
|
||||
#endif
|
||||
|
||||
#ifndef KTR_CPUMASK
|
||||
#define KTR_CPUMASK (~0)
|
||||
#endif
|
||||
|
||||
#ifndef LOCORE
|
||||
|
||||
#include <sys/time.h>
|
||||
@ -126,6 +118,7 @@ extern int ktr_extend;
|
||||
extern int ktr_cpumask;
|
||||
extern int ktr_mask;
|
||||
extern int ktr_entries;
|
||||
extern int ktr_verbose;
|
||||
|
||||
extern volatile int ktr_idx;
|
||||
extern struct ktr_entry ktr_buf[];
|
||||
@ -138,138 +131,38 @@ extern struct ktr_entry ktr_buf[];
|
||||
#endif
|
||||
|
||||
#ifdef KTR_EXTEND
|
||||
#ifndef _TR_CPU
|
||||
#ifdef SMP
|
||||
#define _TR_CPU cpuid
|
||||
void ktr_tracepoint(u_int mask, char *filename, u_int line,
|
||||
char *format, ...);
|
||||
#else
|
||||
#define _TR_CPU 0
|
||||
void ktr_tracepoint(u_int mask, char *format, u_long arg1, u_long arg2,
|
||||
u_long arg3, u_long arg4, u_long arg5);
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _TR
|
||||
#define _TR() \
|
||||
struct ktr_entry *_ktrptr; \
|
||||
int _ktr_newidx, _ktr_saveidx; \
|
||||
int _tr_intrsave = save_intr(); \
|
||||
disable_intr(); \
|
||||
do { \
|
||||
_ktr_saveidx = ktr_idx; \
|
||||
_ktr_newidx = (ktr_idx + 1) & (KTR_ENTRIES - 1); \
|
||||
} while (atomic_cmpset_int(&ktr_idx, _ktr_saveidx, _ktr_newidx) == 0); \
|
||||
_ktrptr = &ktr_buf[_ktr_saveidx]; \
|
||||
restore_intr(_tr_intrsave); \
|
||||
nanotime(&_ktrptr->ktr_tv); \
|
||||
snprintf (_ktrptr->ktr_filename, KTRFILENAMESIZE, "%s", __FILE__); \
|
||||
_ktrptr->ktr_line = __LINE__; \
|
||||
_ktrptr->ktr_cpu = _TR_CPU;
|
||||
#endif
|
||||
#define CTR0(m, _desc) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if ((ktr_mask & (m)) && ((1 << _TR_CPU) & ktr_cpumask)) { \
|
||||
_TR() \
|
||||
memcpy (_ktrptr->ktr_desc, _desc, KTRDESCSIZE); \
|
||||
} \
|
||||
}
|
||||
#define CTR1(m, _desc, _p1) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if ((ktr_mask & (m)) && ((1 << _TR_CPU) & ktr_cpumask)) { \
|
||||
_TR() \
|
||||
snprintf (_ktrptr->ktr_desc, KTRDESCSIZE, _desc, _p1); \
|
||||
} \
|
||||
}
|
||||
#define CTR2(m, _desc, _p1, _p2) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if ((ktr_mask & (m)) && ((1 << _TR_CPU) & ktr_cpumask)) { \
|
||||
_TR() \
|
||||
snprintf (_ktrptr->ktr_desc, KTRDESCSIZE, _desc, _p1, _p2); \
|
||||
} \
|
||||
}
|
||||
#define CTR3(m, _desc, _p1, _p2, _p3) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if ((ktr_mask & (m)) && ((1 << _TR_CPU) & ktr_cpumask)) { \
|
||||
_TR() \
|
||||
snprintf (_ktrptr->ktr_desc, KTRDESCSIZE, _desc, _p1, _p2, _p3); \
|
||||
} \
|
||||
}
|
||||
#define CTR4(m, _desc, _p1, _p2, _p3, _p4) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if ((ktr_mask & (m)) && ((1 << _TR_CPU) & ktr_cpumask)) { \
|
||||
_TR() \
|
||||
snprintf (_ktrptr->ktr_desc, KTRDESCSIZE, _desc, _p1, _p2, _p3, _p4); \
|
||||
} \
|
||||
}
|
||||
#define CTR5(m, _desc, _p1, _p2, _p3, _p4, _p5) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if ((ktr_mask & (m)) && ((1 << _TR_CPU) & ktr_cpumask)) { \
|
||||
_TR() \
|
||||
snprintf (_ktrptr->ktr_desc, KTRDESCSIZE, _desc, _p1, _p2, _p3, _p4, _p5); \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef KTR_EXTEND
|
||||
#define CTR(m, format, args...) do { \
|
||||
if (KTR_COMPILE & (m)) \
|
||||
ktr_tracepoint((m), __FILE__, __LINE__, format , ##args); \
|
||||
} while(0)
|
||||
|
||||
#define CTR0(m, format) CTR(m, format)
|
||||
#define CTR1(m, format, p1) CTR(m, format, p1)
|
||||
#define CTR2(m, format, p1, p2) CTR(m, format, p1, p2)
|
||||
#define CTR3(m, format, p1, p2, p3) CTR(m, format, p1, p2, p3)
|
||||
#define CTR4(m, format, p1, p2, p3, p4) CTR(m, format, p1, p2, p3, p4)
|
||||
#define CTR5(m, format, p1, p2, p3, p4, p5) \
|
||||
CTR(m, format, p1, p2, p3, p4, p5)
|
||||
#else /* not extended */
|
||||
#ifndef _TR
|
||||
#define _TR(_desc) \
|
||||
struct ktr_entry *_ktrptr; \
|
||||
int _ktr_newidx, _ktr_saveidx; \
|
||||
do { \
|
||||
_ktr_saveidx = ktr_idx; \
|
||||
_ktr_newidx = (ktr_idx + 1) & (KTR_ENTRIES - 1); \
|
||||
} while (atomic_cmpset_int(&ktr_idx, _ktr_saveidx, _ktr_newidx) == 0); \
|
||||
_ktrptr = &ktr_buf[_ktr_saveidx]; \
|
||||
nanotime(&_ktrptr->ktr_tv); \
|
||||
_ktrptr->ktr_desc = (_desc);
|
||||
#endif
|
||||
#define CTR0(m, _desc) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if (ktr_mask & (m)) { \
|
||||
_TR(_desc) \
|
||||
} \
|
||||
}
|
||||
#define CTR1(m, _desc, _p1) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if (ktr_mask & (m)) { \
|
||||
_TR(_desc) \
|
||||
_ktrptr->ktr_parm1 = (u_long)(_p1); \
|
||||
} \
|
||||
}
|
||||
#define CTR2(m, _desc, _p1, _p2) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if (ktr_mask & (m)) { \
|
||||
_TR(_desc) \
|
||||
_ktrptr->ktr_parm1 = (u_long)(_p1); \
|
||||
_ktrptr->ktr_parm2 = (u_long)(_p2); \
|
||||
} \
|
||||
}
|
||||
#define CTR3(m, _desc, _p1, _p2, _p3) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if (ktr_mask & (m)) { \
|
||||
_TR(_desc) \
|
||||
_ktrptr->ktr_parm1 = (u_long)(_p1); \
|
||||
_ktrptr->ktr_parm2 = (u_long)(_p2); \
|
||||
_ktrptr->ktr_parm3 = (u_long)(_p3); \
|
||||
} \
|
||||
}
|
||||
#define CTR4(m, _desc, _p1, _p2, _p3, _p4) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if (ktr_mask & (m)) { \
|
||||
_TR(_desc) \
|
||||
_ktrptr->ktr_parm1 = (u_long)(_p1); \
|
||||
_ktrptr->ktr_parm2 = (u_long)(_p2); \
|
||||
_ktrptr->ktr_parm3 = (u_long)(_p3); \
|
||||
_ktrptr->ktr_parm4 = (u_long)(_p4); \
|
||||
} \
|
||||
}
|
||||
#define CTR5(m, _desc, _p1, _p2, _p3, _p4, _p5) \
|
||||
if (KTR_COMPILE & (m)) { \
|
||||
if (ktr_mask & (m)) { \
|
||||
_TR(_desc) \
|
||||
_ktrptr->ktr_parm1 = (u_long)(_p1); \
|
||||
_ktrptr->ktr_parm2 = (u_long)(_p2); \
|
||||
_ktrptr->ktr_parm3 = (u_long)(_p3); \
|
||||
_ktrptr->ktr_parm4 = (u_long)(_p4); \
|
||||
_ktrptr->ktr_parm5 = (u_long)(_p5); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
#define CTR5(m, format, p1, p2, p3, p4, p5) do { \
|
||||
if (KTR_COMPILE & (m)) \
|
||||
ktr_tracepoint((m), format, (u_long)p1, (u_long)p2, \
|
||||
(u_long)p3, (u_long)p4, (u_long)p5); \
|
||||
} while(0)
|
||||
#define CTR0(m, format) CTR5(m, format, 0, 0, 0, 0, 0)
|
||||
#define CTR1(m, format, p1) CTR5(m, format, p1, 0, 0, 0, 0)
|
||||
#define CTR2(m, format, p1, p2) CTR5(m, format, p1, p2, 0, 0, 0)
|
||||
#define CTR3(m, format, p1, p2, p3) CTR5(m, format, p1, p2, p3, 0, 0)
|
||||
#define CTR4(m, format, p1, p2, p3, p4) CTR5(m, format, p1, p2, p3, p4, 0)
|
||||
#endif /* KTR_EXTEND */
|
||||
#else /* KTR */
|
||||
#undef KTR_COMPILE
|
||||
#define KTR_COMPILE 0
|
||||
|
Loading…
Reference in New Issue
Block a user