165556Sjasone/*- 265556Sjasone * Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved. 365556Sjasone * 465556Sjasone * Redistribution and use in source and binary forms, with or without 565556Sjasone * modification, are permitted provided that the following conditions 665556Sjasone * are met: 765556Sjasone * 1. Redistributions of source code must retain the above copyright 865556Sjasone * notice, this list of conditions and the following disclaimer. 965556Sjasone * 2. Redistributions in binary form must reproduce the above copyright 1065556Sjasone * notice, this list of conditions and the following disclaimer in the 1165556Sjasone * documentation and/or other materials provided with the distribution. 1265556Sjasone * 3. Berkeley Software Design Inc's name may not be used to endorse or 1365556Sjasone * promote products derived from this software without specific prior 1465556Sjasone * written permission. 1565556Sjasone * 1665556Sjasone * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND 1765556Sjasone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1865556Sjasone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1965556Sjasone * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE 2065556Sjasone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2165556Sjasone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2265556Sjasone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2365556Sjasone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2465556Sjasone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2565556Sjasone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2665556Sjasone * SUCH DAMAGE. 2765556Sjasone * 2865556Sjasone * from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $ 2965556Sjasone * $FreeBSD$ 3065556Sjasone */ 3165556Sjasone 3265556Sjasone/* 3365556Sjasone * Wraparound kernel trace buffer support. 3465556Sjasone */ 3565556Sjasone 3665556Sjasone#ifndef _SYS_KTR_H_ 3765556Sjasone#define _SYS_KTR_H_ 3865556Sjasone 3965556Sjasone/* 4065556Sjasone * Trace classes 41154790Sjhb * 42154790Sjhb * Two of the trace classes (KTR_DEV and KTR_SUBSYS) are special in that 43154790Sjhb * they are really placeholders so that indvidual drivers and subsystems 44154790Sjhb * can map their internal tracing to the general class when they wish to 45154790Sjhb * have tracing enabled and map it to 0 when they don't. 4665556Sjasone */ 4765556Sjasone#define KTR_GEN 0x00000001 /* General (TR) */ 4865556Sjasone#define KTR_NET 0x00000002 /* Network */ 4965556Sjasone#define KTR_DEV 0x00000004 /* Device driver */ 5065556Sjasone#define KTR_LOCK 0x00000008 /* MP locking */ 5165556Sjasone#define KTR_SMP 0x00000010 /* MP general */ 52154790Sjhb#define KTR_SUBSYS 0x00000020 /* Subsystem. */ 53153493Snjl#define KTR_PMAP 0x00000040 /* Pmap tracing */ 54153493Snjl#define KTR_MALLOC 0x00000080 /* Malloc tracing */ 5565556Sjasone#define KTR_TRAP 0x00000100 /* Trap processing */ 5665556Sjasone#define KTR_INTR 0x00000200 /* Interrupt tracing */ 57153493Snjl#define KTR_SIG 0x00000400 /* Signal processing */ 58191653Sbms#define KTR_SPARE2 0x00000800 /* XXX Used by cxgb */ 5965556Sjasone#define KTR_PROC 0x00001000 /* Process scheduling */ 6065556Sjasone#define KTR_SYSC 0x00002000 /* System call */ 6165556Sjasone#define KTR_INIT 0x00004000 /* System initialization */ 62191653Sbms#define KTR_SPARE3 0x00008000 /* XXX Used by cxgb */ 63191653Sbms#define KTR_SPARE4 0x00010000 /* XXX Used by cxgb */ 64112109Sjhb#define KTR_EVH 0x00020000 /* Eventhandler */ 65153493Snjl#define KTR_VFS 0x00040000 /* VFS events */ 66153493Snjl#define KTR_VOP 0x00080000 /* Auto-generated vop events */ 67153493Snjl#define KTR_VM 0x00100000 /* The virtual memory system */ 68191653Sbms#define KTR_INET 0x00200000 /* IPv4 stack */ 6972376Sjake#define KTR_RUNQ 0x00400000 /* Run queue */ 70102450Siedowse#define KTR_CONTENTION 0x00800000 /* Lock contention */ 71133228Srwatson#define KTR_UMA 0x01000000 /* UMA slab allocator */ 72133228Srwatson#define KTR_CALLOUT 0x02000000 /* Callouts and timeouts */ 73136755Srwatson#define KTR_GEOM 0x04000000 /* GEOM I/O events */ 74136805Srwatson#define KTR_BUSDMA 0x08000000 /* busdma(9) events */ 75191653Sbms#define KTR_INET6 0x10000000 /* IPv6 stack */ 76139314Sjeff#define KTR_SCHED 0x20000000 /* Machine parsed sched info. */ 77140696Sjeff#define KTR_BUF 0x40000000 /* Buffer cache */ 78140696Sjeff#define KTR_ALL 0x7fffffff 7965556Sjasone 8065556Sjasone/* Trace classes to compile in */ 81153174Smarius#ifdef KTR 8265556Sjasone#ifndef KTR_COMPILE 83149734Sglebius#define KTR_COMPILE (KTR_ALL) 8465556Sjasone#endif 85153174Smarius#else /* !KTR */ 86153174Smarius#undef KTR_COMPILE 87153174Smarius#define KTR_COMPILE 0 88153174Smarius#endif /* KTR */ 8965556Sjasone 9093503Sjake/* 9193503Sjake * Version number for ktr_entry struct. Increment this when you break binary 9293503Sjake * compatibility. 9393503Sjake */ 94147279Sjeff#define KTR_VERSION 2 9565556Sjasone 9693503Sjake#define KTR_PARMS 6 9765556Sjasone 9893503Sjake#ifndef LOCORE 9978784Sjhb 100222813Sattilio#include <sys/param.h> 101222813Sattilio#include <sys/_cpuset.h> 102222813Sattilio 10365556Sjasonestruct ktr_entry { 10493503Sjake u_int64_t ktr_timestamp; 10578784Sjhb int ktr_cpu; 10665556Sjasone int ktr_line; 10793503Sjake const char *ktr_file; 10872761Sjhb const char *ktr_desc; 109147278Sjeff struct thread *ktr_thread; 11093503Sjake u_long ktr_parms[KTR_PARMS]; 11165556Sjasone}; 11265556Sjasone 113222813Sattilioextern cpuset_t ktr_cpumask; 11465556Sjasoneextern int ktr_mask; 11565556Sjasoneextern int ktr_entries; 11668420Sjhbextern int ktr_verbose; 11765556Sjasone 11865556Sjasoneextern volatile int ktr_idx; 119243046Sjeffextern struct ktr_entry *ktr_buf; 12065556Sjasone 12165556Sjasone#ifdef KTR 12265556Sjasone 12393503Sjakevoid ktr_tracepoint(u_int mask, const char *file, int line, 12493503Sjake const char *format, u_long arg1, u_long arg2, u_long arg3, 12593503Sjake u_long arg4, u_long arg5, u_long arg6); 12665556Sjasone 12787592Sobrien#define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \ 12887592Sobrien if (KTR_COMPILE & (m)) \ 12993503Sjake ktr_tracepoint((m), __FILE__, __LINE__, format, \ 13093573Sjhb (u_long)(p1), (u_long)(p2), (u_long)(p3), \ 13193573Sjhb (u_long)(p4), (u_long)(p5), (u_long)(p6)); \ 13287592Sobrien } while(0) 13387621Sobrien#define CTR0(m, format) CTR6(m, format, 0, 0, 0, 0, 0, 0) 13487621Sobrien#define CTR1(m, format, p1) CTR6(m, format, p1, 0, 0, 0, 0, 0) 13587621Sobrien#define CTR2(m, format, p1, p2) CTR6(m, format, p1, p2, 0, 0, 0, 0) 13687621Sobrien#define CTR3(m, format, p1, p2, p3) CTR6(m, format, p1, p2, p3, 0, 0, 0) 13787621Sobrien#define CTR4(m, format, p1, p2, p3, p4) CTR6(m, format, p1, p2, p3, p4, 0, 0) 13887621Sobrien#define CTR5(m, format, p1, p2, p3, p4, p5) CTR6(m, format, p1, p2, p3, p4, p5, 0) 13965556Sjasone#else /* KTR */ 140194578Srdivacky#define CTR0(m, d) (void)0 141194578Srdivacky#define CTR1(m, d, p1) (void)0 142194578Srdivacky#define CTR2(m, d, p1, p2) (void)0 143194578Srdivacky#define CTR3(m, d, p1, p2, p3) (void)0 144194578Srdivacky#define CTR4(m, d, p1, p2, p3, p4) (void)0 145194578Srdivacky#define CTR5(m, d, p1, p2, p3, p4, p5) (void)0 146194578Srdivacky#define CTR6(m, d, p1, p2, p3, p4, p5, p6) (void)0 14765556Sjasone#endif /* KTR */ 14865556Sjasone 14965556Sjasone#define TR0(d) CTR0(KTR_GEN, d) 15065556Sjasone#define TR1(d, p1) CTR1(KTR_GEN, d, p1) 15165556Sjasone#define TR2(d, p1, p2) CTR2(KTR_GEN, d, p1, p2) 15265556Sjasone#define TR3(d, p1, p2, p3) CTR3(KTR_GEN, d, p1, p2, p3) 15365556Sjasone#define TR4(d, p1, p2, p3, p4) CTR4(KTR_GEN, d, p1, p2, p3, p4) 15465556Sjasone#define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5) 15587957Sjhb#define TR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_GEN, d, p1, p2, p3, p4, p5, p6) 15665556Sjasone 15765556Sjasone/* 158187357Sjeff * The event macros implement KTR graphic plotting facilities provided 159187357Sjeff * by src/tools/sched/schedgraph.py. Three generic types of events are 160187357Sjeff * supported: states, counters, and points. 161187357Sjeff * 162187357Sjeff * m is the ktr class for ktr_mask. 163187357Sjeff * ident is the string identifier that owns the event (ie: "thread 10001") 164187357Sjeff * etype is the type of event to plot (state, counter, point) 165187357Sjeff * edat is the event specific data (state name, counter value, point name) 166187357Sjeff * up to four attributes may be supplied as a name, value pair of arguments. 167187357Sjeff * 168187357Sjeff * etype and attribute names must be string constants. This minimizes the 169187357Sjeff * number of ktr slots required by construction the final format strings 170187357Sjeff * at compile time. Both must also include a colon and format specifier 171187357Sjeff * (ie. "prio:%d", prio). It is recommended that string arguments be 172187357Sjeff * contained within escaped quotes if they may contain ',' or ':' characters. 173187357Sjeff * 174187357Sjeff * The special attribute (KTR_ATTR_LINKED, ident) creates a reference to another 175187357Sjeff * id on the graph for easy traversal of related graph elements. 176187357Sjeff */ 177187357Sjeff 178187357Sjeff#define KTR_ATTR_LINKED "linkedto:\"%s\"" 179187357Sjeff#define KTR_EFMT(egroup, ident, etype) \ 180187357Sjeff "KTRGRAPH group:\"" egroup "\", id:\"%s\", " etype ", attributes: " 181187357Sjeff 182187357Sjeff#define KTR_EVENT0(m, egroup, ident, etype, edat) \ 183187357Sjeff CTR2(m, KTR_EFMT(egroup, ident, etype) "none", ident, edat) 184187357Sjeff#define KTR_EVENT1(m, egroup, ident, etype, edat, a0, v0) \ 185187357Sjeff CTR3(m, KTR_EFMT(egroup, ident, etype) a0, ident, edat, (v0)) 186187357Sjeff#define KTR_EVENT2(m, egroup, ident, etype, edat, a0, v0, a1, v1) \ 187187357Sjeff CTR4(m, KTR_EFMT(egroup, ident, etype) a0 ", " a1, \ 188187357Sjeff ident, edat, (v0), (v1)) 189187357Sjeff#define KTR_EVENT3(m, egroup, ident, etype, edat, a0, v0, a1, v1, a2, v2)\ 190187357Sjeff CTR5(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2, \ 191187357Sjeff ident, edat, (v0), (v1), (v2)) 192187357Sjeff#define KTR_EVENT4(m, egroup, ident, etype, edat, \ 193187357Sjeff a0, v0, a1, v1, a2, v2, a3, v3) \ 194210443Smav CTR6(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2 ", " a3,\ 195187357Sjeff ident, edat, (v0), (v1), (v2), (v3)) 196187357Sjeff 197187357Sjeff/* 198187357Sjeff * State functions graph state changes on an ident. 199187357Sjeff */ 200187357Sjeff#define KTR_STATE0(m, egroup, ident, state) \ 201187357Sjeff KTR_EVENT0(m, egroup, ident, "state:\"%s\"", state) 202187357Sjeff#define KTR_STATE1(m, egroup, ident, state, a0, v0) \ 203187357Sjeff KTR_EVENT1(m, egroup, ident, "state:\"%s\"", state, a0, (v0)) 204187357Sjeff#define KTR_STATE2(m, egroup, ident, state, a0, v0, a1, v1) \ 205187357Sjeff KTR_EVENT2(m, egroup, ident, "state:\"%s\"", state, a0, (v0), a1, (v1)) 206187357Sjeff#define KTR_STATE3(m, egroup, ident, state, a0, v0, a1, v1, a2, v2) \ 207187357Sjeff KTR_EVENT3(m, egroup, ident, "state:\"%s\"", \ 208187357Sjeff state, a0, (v0), a1, (v1), a2, (v2)) 209187357Sjeff#define KTR_STATE4(m, egroup, ident, state, a0, v0, a1, v1, a2, v2, a3, v3)\ 210187357Sjeff KTR_EVENT4(m, egroup, ident, "state:\"%s\"", \ 211187357Sjeff state, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 212187357Sjeff 213187357Sjeff/* 214187357Sjeff * Counter functions graph counter values. The counter id 215187357Sjeff * must not be intermixed with a state id. 216187357Sjeff */ 217187357Sjeff#define KTR_COUNTER0(m, egroup, ident, counter) \ 218187357Sjeff KTR_EVENT0(m, egroup, ident, "counter:%d", counter) 219187357Sjeff#define KTR_COUNTER1(m, egroup, ident, edat, a0, v0) \ 220187357Sjeff KTR_EVENT1(m, egroup, ident, "counter:%d", counter, a0, (v0)) 221187357Sjeff#define KTR_COUNTER2(m, egroup, ident, counter, a0, v0, a1, v1) \ 222187357Sjeff KTR_EVENT2(m, egroup, ident, "counter:%d", counter, a0, (v0), a1, (v1)) 223187357Sjeff#define KTR_COUNTER3(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2) \ 224187357Sjeff KTR_EVENT3(m, egroup, ident, "counter:%d", \ 225187357Sjeff counter, a0, (v0), a1, (v1), a2, (v2)) 226187357Sjeff#define KTR_COUNTER4(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2, a3, v3)\ 227187357Sjeff KTR_EVENT4(m, egroup, ident, "counter:%d", \ 228187357Sjeff counter, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 229187357Sjeff 230187357Sjeff/* 231187357Sjeff * Point functions plot points of interest on counter or state graphs. 232187357Sjeff */ 233187357Sjeff#define KTR_POINT0(m, egroup, ident, point) \ 234187357Sjeff KTR_EVENT0(m, egroup, ident, "point:\"%s\"", point) 235187357Sjeff#define KTR_POINT1(m, egroup, ident, point, a0, v0) \ 236187357Sjeff KTR_EVENT1(m, egroup, ident, "point:\"%s\"", point, a0, (v0)) 237187357Sjeff#define KTR_POINT2(m, egroup, ident, point, a0, v0, a1, v1) \ 238187357Sjeff KTR_EVENT2(m, egroup, ident, "point:\"%s\"", point, a0, (v0), a1, (v1)) 239187357Sjeff#define KTR_POINT3(m, egroup, ident, point, a0, v0, a1, v1, a2, v2) \ 240187357Sjeff KTR_EVENT3(m, egroup, ident, "point:\"%s\"", point, \ 241187357Sjeff a0, (v0), a1, (v1), a2, (v2)) 242187357Sjeff#define KTR_POINT4(m, egroup, ident, point, a0, v0, a1, v1, a2, v2, a3, v3)\ 243187357Sjeff KTR_EVENT4(m, egroup, ident, "point:\"%s\"", \ 244187357Sjeff point, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 245187357Sjeff 246187357Sjeff/* 247244445Sjeff * Start functions denote the start of a region of code or operation 248244445Sjeff * and should be paired with stop functions for timing of nested 249244445Sjeff * sequences. 250244445Sjeff * 251244445Sjeff * Specifying extra attributes with the name "key" will result in 252244445Sjeff * multi-part keys. For example a block device and offset pair 253244445Sjeff * might be used to describe a buf undergoing I/O. 254244445Sjeff */ 255244445Sjeff#define KTR_START0(m, egroup, ident, key) \ 256244445Sjeff KTR_EVENT0(m, egroup, ident, "start:0x%jX", (uintmax_t)key) 257244445Sjeff#define KTR_START1(m, egroup, ident, key, a0, v0) \ 258244445Sjeff KTR_EVENT1(m, egroup, ident, "start:0x%jX", (uintmax_t)key, a0, (v0)) 259244445Sjeff#define KTR_START2(m, egroup, ident, key, a0, v0, a1, v1) \ 260244445Sjeff KTR_EVENT2(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 261244445Sjeff a0, (v0), a1, (v1)) 262244445Sjeff#define KTR_START3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ 263244445Sjeff KTR_EVENT3(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 264244445Sjeff a0, (v0), a1, (v1), a2, (v2)) 265244445Sjeff#define KTR_START4(m, egroup, ident, key, \ 266244445Sjeff a0, v0, a1, v1, a2, v2, a3, v3) \ 267244445Sjeff KTR_EVENT4(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 268244445Sjeff a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 269244445Sjeff 270244445Sjeff/* 271244445Sjeff * Stop functions denote the end of a region of code or operation 272244445Sjeff * and should be paired with start functions for timing of nested 273244445Sjeff * sequences. 274244445Sjeff */ 275244445Sjeff#define KTR_STOP0(m, egroup, ident, key) \ 276244445Sjeff KTR_EVENT0(m, egroup, ident, "stop:0x%jX", (uintmax_t)key) 277244445Sjeff#define KTR_STOP1(m, egroup, ident, key, a0, v0) \ 278244445Sjeff KTR_EVENT1(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, a0, (v0)) 279244445Sjeff#define KTR_STOP2(m, egroup, ident, key, a0, v0, a1, v1) \ 280244445Sjeff KTR_EVENT2(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 281244445Sjeff a0, (v0), a1, (v1)) 282244445Sjeff#define KTR_STOP3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ 283244445Sjeff KTR_EVENT3(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 284244445Sjeff a0, (v0), a1, (v1), a2, (v2)) 285244445Sjeff#define KTR_STOP4(m, egroup, ident, \ 286244445Sjeff key, a0, v0, a1, v1, a2, v2, a3, v3) \ 287244445Sjeff KTR_EVENT4(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 288244445Sjeff a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 289244445Sjeff 290244445Sjeff/* 29165556Sjasone * Trace initialization events, similar to CTR with KTR_INIT, but 29265556Sjasone * completely ifdef'ed out if KTR_INIT isn't in KTR_COMPILE (to 29365556Sjasone * save string space, the compiler doesn't optimize out strings 29465556Sjasone * for the conditional ones above). 29565556Sjasone */ 29665556Sjasone#if (KTR_COMPILE & KTR_INIT) != 0 29765556Sjasone#define ITR0(d) CTR0(KTR_INIT, d) 29865556Sjasone#define ITR1(d, p1) CTR1(KTR_INIT, d, p1) 29965556Sjasone#define ITR2(d, p1, p2) CTR2(KTR_INIT, d, p1, p2) 30065556Sjasone#define ITR3(d, p1, p2, p3) CTR3(KTR_INIT, d, p1, p2, p3) 30165556Sjasone#define ITR4(d, p1, p2, p3, p4) CTR4(KTR_INIT, d, p1, p2, p3, p4) 30265556Sjasone#define ITR5(d, p1, p2, p3, p4, p5) CTR5(KTR_INIT, d, p1, p2, p3, p4, p5) 30387957Sjhb#define ITR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_INIT, d, p1, p2, p3, p4, p5, p6) 30465556Sjasone#else 30565556Sjasone#define ITR0(d) 30665556Sjasone#define ITR1(d, p1) 30765556Sjasone#define ITR2(d, p1, p2) 30865556Sjasone#define ITR3(d, p1, p2, p3) 30965556Sjasone#define ITR4(d, p1, p2, p3, p4) 31065556Sjasone#define ITR5(d, p1, p2, p3, p4, p5) 31187621Sobrien#define ITR6(d, p1, p2, p3, p4, p5, p6) 31265556Sjasone#endif 31365556Sjasone 314153174Smarius#endif /* !LOCORE */ 315153174Smarius 31665556Sjasone#endif /* !_SYS_KTR_H_ */ 317