ktr.h revision 78784
1/*- 2 * Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Berkeley Software Design Inc's name may not be used to endorse or 13 * promote products derived from this software without specific prior 14 * written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $ 29 * $FreeBSD: head/sys/sys/ktr.h 78784 2001-06-25 23:09:31Z jhb $ 30 */ 31 32/* 33 * Wraparound kernel trace buffer support. 34 */ 35 36#ifndef _SYS_KTR_H_ 37#define _SYS_KTR_H_ 38 39/* Requires sys/types.h, sys/time.h, machine/atomic.h, and machine/cpufunc.h */ 40 41#include <machine/atomic.h> 42#include <machine/cpufunc.h> 43 44/* 45 * Trace classes 46 */ 47#define KTR_GEN 0x00000001 /* General (TR) */ 48#define KTR_NET 0x00000002 /* Network */ 49#define KTR_DEV 0x00000004 /* Device driver */ 50#define KTR_LOCK 0x00000008 /* MP locking */ 51#define KTR_SMP 0x00000010 /* MP general */ 52#define KTR_FS 0x00000020 /* Filesystem */ 53#define KTR_PMAP 0x00000040 /* Pmap tracing */ 54#define KTR_MALLOC 0x00000080 /* Malloc tracing */ 55#define KTR_TRAP 0x00000100 /* Trap processing */ 56#define KTR_INTR 0x00000200 /* Interrupt tracing */ 57#define KTR_SIG 0x00000400 /* Signal processing */ 58#define KTR_CLK 0x00000800 /* hardclock verbose */ 59#define KTR_PROC 0x00001000 /* Process scheduling */ 60#define KTR_SYSC 0x00002000 /* System call */ 61#define KTR_INIT 0x00004000 /* System initialization */ 62#define KTR_KGDB 0x00008000 /* Trace kgdb internals */ 63#define KTR_IO 0x00010000 /* Upper I/O */ 64#define KTR_LOCKMGR 0x00020000 65#define KTR_NFS 0x00040000 /* The obvious */ 66#define KTR_VOP 0x00080000 /* The obvious */ 67#define KTR_VM 0x00100000 /* The virtual memory system */ 68#define KTR_WITNESS 0x00200000 69#define KTR_RUNQ 0x00400000 /* Run queue */ 70#define KTR_ALL 0x007fffff 71 72/* 73 * Trace classes which can be assigned to particular use at compile time 74 * These must remain in high 22 as some assembly code counts on it 75 */ 76#define KTR_CT1 0x010000000 77#define KTR_CT2 0x020000000 78#define KTR_CT3 0x040000000 79#define KTR_CT4 0x080000000 80#define KTR_CT5 0x100000000 81#define KTR_CT6 0x200000000 82#define KTR_CT7 0x400000000 83#define KTR_CT8 0x800000000 84 85/* Trace classes to compile in */ 86#ifndef KTR_COMPILE 87#define KTR_COMPILE (KTR_GEN) 88#endif 89 90#ifndef LOCORE 91 92#include <sys/time.h> 93 94#ifndef KTRDESCSIZE 95#define KTRDESCSIZE 80 96#endif 97 98struct ktr_entry { 99 struct timespec ktr_tv; 100 int ktr_cpu; 101#ifdef KTR_EXTEND 102 char ktr_desc[KTRDESCSIZE]; 103 const char *ktr_filename; 104 int ktr_line; 105#else 106 const char *ktr_desc; 107 u_long ktr_parm1; 108 u_long ktr_parm2; 109 u_long ktr_parm3; 110 u_long ktr_parm4; 111 u_long ktr_parm5; 112#endif 113}; 114 115/* These variables are used by gdb to analyse the output */ 116extern int ktr_extend; 117 118extern int ktr_cpumask; 119extern int ktr_mask; 120extern int ktr_entries; 121extern int ktr_verbose; 122 123extern volatile int ktr_idx; 124extern struct ktr_entry ktr_buf[]; 125 126#endif /* !LOCORE */ 127#ifdef KTR 128 129#ifdef KTR_EXTEND 130void ktr_tracepoint(u_int mask, const char *filename, u_int line, 131 const char *format, ...) __printflike(4, 5); 132#else 133void ktr_tracepoint(u_int mask, const char *format, u_long arg1, u_long arg2, 134 u_long arg3, u_long arg4, u_long arg5); 135#endif 136 137#ifdef KTR_EXTEND 138#define CTR(m, format, args...) do { \ 139 if (KTR_COMPILE & (m)) \ 140 ktr_tracepoint((m), __FILE__, __LINE__, format , ##args); \ 141 } while(0) 142 143#define CTR0(m, format) CTR(m, format) 144#define CTR1(m, format, p1) CTR(m, format, p1) 145#define CTR2(m, format, p1, p2) CTR(m, format, p1, p2) 146#define CTR3(m, format, p1, p2, p3) CTR(m, format, p1, p2, p3) 147#define CTR4(m, format, p1, p2, p3, p4) CTR(m, format, p1, p2, p3, p4) 148#define CTR5(m, format, p1, p2, p3, p4, p5) \ 149 CTR(m, format, p1, p2, p3, p4, p5) 150#else /* not extended */ 151#define CTR5(m, format, p1, p2, p3, p4, p5) do { \ 152 if (KTR_COMPILE & (m)) \ 153 ktr_tracepoint((m), format, (u_long)p1, (u_long)p2, \ 154 (u_long)p3, (u_long)p4, (u_long)p5); \ 155 } while(0) 156#define CTR0(m, format) CTR5(m, format, 0, 0, 0, 0, 0) 157#define CTR1(m, format, p1) CTR5(m, format, p1, 0, 0, 0, 0) 158#define CTR2(m, format, p1, p2) CTR5(m, format, p1, p2, 0, 0, 0) 159#define CTR3(m, format, p1, p2, p3) CTR5(m, format, p1, p2, p3, 0, 0) 160#define CTR4(m, format, p1, p2, p3, p4) CTR5(m, format, p1, p2, p3, p4, 0) 161#endif /* KTR_EXTEND */ 162#else /* KTR */ 163#undef KTR_COMPILE 164#define KTR_COMPILE 0 165#define CTR0(m, d) 166#define CTR1(m, d, p1) 167#define CTR2(m, d, p1, p2) 168#define CTR3(m, d, p1, p2, p3) 169#define CTR4(m, d, p1, p2, p3, p4) 170#define CTR5(m, d, p1, p2, p3, p4, p5) 171#endif /* KTR */ 172 173#define TR0(d) CTR0(KTR_GEN, d) 174#define TR1(d, p1) CTR1(KTR_GEN, d, p1) 175#define TR2(d, p1, p2) CTR2(KTR_GEN, d, p1, p2) 176#define TR3(d, p1, p2, p3) CTR3(KTR_GEN, d, p1, p2, p3) 177#define TR4(d, p1, p2, p3, p4) CTR4(KTR_GEN, d, p1, p2, p3, p4) 178#define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5) 179 180/* 181 * Trace initialization events, similar to CTR with KTR_INIT, but 182 * completely ifdef'ed out if KTR_INIT isn't in KTR_COMPILE (to 183 * save string space, the compiler doesn't optimize out strings 184 * for the conditional ones above). 185 */ 186#if (KTR_COMPILE & KTR_INIT) != 0 187#define ITR0(d) CTR0(KTR_INIT, d) 188#define ITR1(d, p1) CTR1(KTR_INIT, d, p1) 189#define ITR2(d, p1, p2) CTR2(KTR_INIT, d, p1, p2) 190#define ITR3(d, p1, p2, p3) CTR3(KTR_INIT, d, p1, p2, p3) 191#define ITR4(d, p1, p2, p3, p4) CTR4(KTR_INIT, d, p1, p2, p3, p4) 192#define ITR5(d, p1, p2, p3, p4, p5) CTR5(KTR_INIT, d, p1, p2, p3, p4, p5) 193#else 194#define ITR0(d) 195#define ITR1(d, p1) 196#define ITR2(d, p1, p2) 197#define ITR3(d, p1, p2, p3) 198#define ITR4(d, p1, p2, p3, p4) 199#define ITR5(d, p1, p2, p3, p4, p5) 200#endif 201 202#endif /* !_SYS_KTR_H_ */ 203