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 39258858Sattilio#include <sys/ktr_class.h> 4065556Sjasone 4193503Sjake/* 4293503Sjake * Version number for ktr_entry struct. Increment this when you break binary 4393503Sjake * compatibility. 4493503Sjake */ 45147279Sjeff#define KTR_VERSION 2 4665556Sjasone 4793503Sjake#define KTR_PARMS 6 4865556Sjasone 4993503Sjake#ifndef LOCORE 5078784Sjhb 51222813Sattilio#include <sys/param.h> 52222813Sattilio#include <sys/_cpuset.h> 53222813Sattilio 5465556Sjasonestruct ktr_entry { 5593503Sjake u_int64_t ktr_timestamp; 5678784Sjhb int ktr_cpu; 5765556Sjasone int ktr_line; 5893503Sjake const char *ktr_file; 5972761Sjhb const char *ktr_desc; 60147278Sjeff struct thread *ktr_thread; 6193503Sjake u_long ktr_parms[KTR_PARMS]; 6265556Sjasone}; 6365556Sjasone 64222813Sattilioextern cpuset_t ktr_cpumask; 65283283Sjhbextern uint64_t ktr_mask; 6665556Sjasoneextern int ktr_entries; 6768420Sjhbextern int ktr_verbose; 6865556Sjasone 6965556Sjasoneextern volatile int ktr_idx; 70243046Sjeffextern struct ktr_entry *ktr_buf; 7165556Sjasone 7265556Sjasone#ifdef KTR 7365556Sjasone 74283283Sjhbvoid ktr_tracepoint(uint64_t mask, const char *file, int line, 7593503Sjake const char *format, u_long arg1, u_long arg2, u_long arg3, 7693503Sjake u_long arg4, u_long arg5, u_long arg6); 7765556Sjasone 7887592Sobrien#define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \ 7987592Sobrien if (KTR_COMPILE & (m)) \ 8093503Sjake ktr_tracepoint((m), __FILE__, __LINE__, format, \ 8193573Sjhb (u_long)(p1), (u_long)(p2), (u_long)(p3), \ 8293573Sjhb (u_long)(p4), (u_long)(p5), (u_long)(p6)); \ 8387592Sobrien } while(0) 8487621Sobrien#define CTR0(m, format) CTR6(m, format, 0, 0, 0, 0, 0, 0) 8587621Sobrien#define CTR1(m, format, p1) CTR6(m, format, p1, 0, 0, 0, 0, 0) 8687621Sobrien#define CTR2(m, format, p1, p2) CTR6(m, format, p1, p2, 0, 0, 0, 0) 8787621Sobrien#define CTR3(m, format, p1, p2, p3) CTR6(m, format, p1, p2, p3, 0, 0, 0) 8887621Sobrien#define CTR4(m, format, p1, p2, p3, p4) CTR6(m, format, p1, p2, p3, p4, 0, 0) 8987621Sobrien#define CTR5(m, format, p1, p2, p3, p4, p5) CTR6(m, format, p1, p2, p3, p4, p5, 0) 9065556Sjasone#else /* KTR */ 91194578Srdivacky#define CTR0(m, d) (void)0 92194578Srdivacky#define CTR1(m, d, p1) (void)0 93194578Srdivacky#define CTR2(m, d, p1, p2) (void)0 94194578Srdivacky#define CTR3(m, d, p1, p2, p3) (void)0 95194578Srdivacky#define CTR4(m, d, p1, p2, p3, p4) (void)0 96194578Srdivacky#define CTR5(m, d, p1, p2, p3, p4, p5) (void)0 97194578Srdivacky#define CTR6(m, d, p1, p2, p3, p4, p5, p6) (void)0 9865556Sjasone#endif /* KTR */ 9965556Sjasone 10065556Sjasone#define TR0(d) CTR0(KTR_GEN, d) 10165556Sjasone#define TR1(d, p1) CTR1(KTR_GEN, d, p1) 10265556Sjasone#define TR2(d, p1, p2) CTR2(KTR_GEN, d, p1, p2) 10365556Sjasone#define TR3(d, p1, p2, p3) CTR3(KTR_GEN, d, p1, p2, p3) 10465556Sjasone#define TR4(d, p1, p2, p3, p4) CTR4(KTR_GEN, d, p1, p2, p3, p4) 10565556Sjasone#define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5) 10687957Sjhb#define TR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_GEN, d, p1, p2, p3, p4, p5, p6) 10765556Sjasone 10865556Sjasone/* 109187357Sjeff * The event macros implement KTR graphic plotting facilities provided 110187357Sjeff * by src/tools/sched/schedgraph.py. Three generic types of events are 111187357Sjeff * supported: states, counters, and points. 112187357Sjeff * 113187357Sjeff * m is the ktr class for ktr_mask. 114187357Sjeff * ident is the string identifier that owns the event (ie: "thread 10001") 115187357Sjeff * etype is the type of event to plot (state, counter, point) 116187357Sjeff * edat is the event specific data (state name, counter value, point name) 117187357Sjeff * up to four attributes may be supplied as a name, value pair of arguments. 118187357Sjeff * 119187357Sjeff * etype and attribute names must be string constants. This minimizes the 120187357Sjeff * number of ktr slots required by construction the final format strings 121187357Sjeff * at compile time. Both must also include a colon and format specifier 122187357Sjeff * (ie. "prio:%d", prio). It is recommended that string arguments be 123187357Sjeff * contained within escaped quotes if they may contain ',' or ':' characters. 124187357Sjeff * 125187357Sjeff * The special attribute (KTR_ATTR_LINKED, ident) creates a reference to another 126187357Sjeff * id on the graph for easy traversal of related graph elements. 127187357Sjeff */ 128187357Sjeff 129187357Sjeff#define KTR_ATTR_LINKED "linkedto:\"%s\"" 130187357Sjeff#define KTR_EFMT(egroup, ident, etype) \ 131187357Sjeff "KTRGRAPH group:\"" egroup "\", id:\"%s\", " etype ", attributes: " 132187357Sjeff 133187357Sjeff#define KTR_EVENT0(m, egroup, ident, etype, edat) \ 134187357Sjeff CTR2(m, KTR_EFMT(egroup, ident, etype) "none", ident, edat) 135187357Sjeff#define KTR_EVENT1(m, egroup, ident, etype, edat, a0, v0) \ 136187357Sjeff CTR3(m, KTR_EFMT(egroup, ident, etype) a0, ident, edat, (v0)) 137187357Sjeff#define KTR_EVENT2(m, egroup, ident, etype, edat, a0, v0, a1, v1) \ 138187357Sjeff CTR4(m, KTR_EFMT(egroup, ident, etype) a0 ", " a1, \ 139187357Sjeff ident, edat, (v0), (v1)) 140187357Sjeff#define KTR_EVENT3(m, egroup, ident, etype, edat, a0, v0, a1, v1, a2, v2)\ 141187357Sjeff CTR5(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2, \ 142187357Sjeff ident, edat, (v0), (v1), (v2)) 143187357Sjeff#define KTR_EVENT4(m, egroup, ident, etype, edat, \ 144187357Sjeff a0, v0, a1, v1, a2, v2, a3, v3) \ 145210443Smav CTR6(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2 ", " a3,\ 146187357Sjeff ident, edat, (v0), (v1), (v2), (v3)) 147187357Sjeff 148187357Sjeff/* 149187357Sjeff * State functions graph state changes on an ident. 150187357Sjeff */ 151187357Sjeff#define KTR_STATE0(m, egroup, ident, state) \ 152187357Sjeff KTR_EVENT0(m, egroup, ident, "state:\"%s\"", state) 153187357Sjeff#define KTR_STATE1(m, egroup, ident, state, a0, v0) \ 154187357Sjeff KTR_EVENT1(m, egroup, ident, "state:\"%s\"", state, a0, (v0)) 155187357Sjeff#define KTR_STATE2(m, egroup, ident, state, a0, v0, a1, v1) \ 156187357Sjeff KTR_EVENT2(m, egroup, ident, "state:\"%s\"", state, a0, (v0), a1, (v1)) 157187357Sjeff#define KTR_STATE3(m, egroup, ident, state, a0, v0, a1, v1, a2, v2) \ 158187357Sjeff KTR_EVENT3(m, egroup, ident, "state:\"%s\"", \ 159187357Sjeff state, a0, (v0), a1, (v1), a2, (v2)) 160187357Sjeff#define KTR_STATE4(m, egroup, ident, state, a0, v0, a1, v1, a2, v2, a3, v3)\ 161187357Sjeff KTR_EVENT4(m, egroup, ident, "state:\"%s\"", \ 162187357Sjeff state, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 163187357Sjeff 164187357Sjeff/* 165187357Sjeff * Counter functions graph counter values. The counter id 166187357Sjeff * must not be intermixed with a state id. 167187357Sjeff */ 168187357Sjeff#define KTR_COUNTER0(m, egroup, ident, counter) \ 169187357Sjeff KTR_EVENT0(m, egroup, ident, "counter:%d", counter) 170187357Sjeff#define KTR_COUNTER1(m, egroup, ident, edat, a0, v0) \ 171187357Sjeff KTR_EVENT1(m, egroup, ident, "counter:%d", counter, a0, (v0)) 172187357Sjeff#define KTR_COUNTER2(m, egroup, ident, counter, a0, v0, a1, v1) \ 173187357Sjeff KTR_EVENT2(m, egroup, ident, "counter:%d", counter, a0, (v0), a1, (v1)) 174187357Sjeff#define KTR_COUNTER3(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2) \ 175187357Sjeff KTR_EVENT3(m, egroup, ident, "counter:%d", \ 176187357Sjeff counter, a0, (v0), a1, (v1), a2, (v2)) 177187357Sjeff#define KTR_COUNTER4(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2, a3, v3)\ 178187357Sjeff KTR_EVENT4(m, egroup, ident, "counter:%d", \ 179187357Sjeff counter, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 180187357Sjeff 181187357Sjeff/* 182187357Sjeff * Point functions plot points of interest on counter or state graphs. 183187357Sjeff */ 184187357Sjeff#define KTR_POINT0(m, egroup, ident, point) \ 185187357Sjeff KTR_EVENT0(m, egroup, ident, "point:\"%s\"", point) 186187357Sjeff#define KTR_POINT1(m, egroup, ident, point, a0, v0) \ 187187357Sjeff KTR_EVENT1(m, egroup, ident, "point:\"%s\"", point, a0, (v0)) 188187357Sjeff#define KTR_POINT2(m, egroup, ident, point, a0, v0, a1, v1) \ 189187357Sjeff KTR_EVENT2(m, egroup, ident, "point:\"%s\"", point, a0, (v0), a1, (v1)) 190187357Sjeff#define KTR_POINT3(m, egroup, ident, point, a0, v0, a1, v1, a2, v2) \ 191187357Sjeff KTR_EVENT3(m, egroup, ident, "point:\"%s\"", point, \ 192187357Sjeff a0, (v0), a1, (v1), a2, (v2)) 193187357Sjeff#define KTR_POINT4(m, egroup, ident, point, a0, v0, a1, v1, a2, v2, a3, v3)\ 194187357Sjeff KTR_EVENT4(m, egroup, ident, "point:\"%s\"", \ 195187357Sjeff point, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 196187357Sjeff 197187357Sjeff/* 198244445Sjeff * Start functions denote the start of a region of code or operation 199244445Sjeff * and should be paired with stop functions for timing of nested 200244445Sjeff * sequences. 201244445Sjeff * 202244445Sjeff * Specifying extra attributes with the name "key" will result in 203244445Sjeff * multi-part keys. For example a block device and offset pair 204244445Sjeff * might be used to describe a buf undergoing I/O. 205244445Sjeff */ 206244445Sjeff#define KTR_START0(m, egroup, ident, key) \ 207244445Sjeff KTR_EVENT0(m, egroup, ident, "start:0x%jX", (uintmax_t)key) 208244445Sjeff#define KTR_START1(m, egroup, ident, key, a0, v0) \ 209244445Sjeff KTR_EVENT1(m, egroup, ident, "start:0x%jX", (uintmax_t)key, a0, (v0)) 210244445Sjeff#define KTR_START2(m, egroup, ident, key, a0, v0, a1, v1) \ 211244445Sjeff KTR_EVENT2(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 212244445Sjeff a0, (v0), a1, (v1)) 213244445Sjeff#define KTR_START3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ 214244445Sjeff KTR_EVENT3(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 215244445Sjeff a0, (v0), a1, (v1), a2, (v2)) 216244445Sjeff#define KTR_START4(m, egroup, ident, key, \ 217244445Sjeff a0, v0, a1, v1, a2, v2, a3, v3) \ 218244445Sjeff KTR_EVENT4(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 219244445Sjeff a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 220244445Sjeff 221244445Sjeff/* 222244445Sjeff * Stop functions denote the end of a region of code or operation 223244445Sjeff * and should be paired with start functions for timing of nested 224244445Sjeff * sequences. 225244445Sjeff */ 226244445Sjeff#define KTR_STOP0(m, egroup, ident, key) \ 227244445Sjeff KTR_EVENT0(m, egroup, ident, "stop:0x%jX", (uintmax_t)key) 228244445Sjeff#define KTR_STOP1(m, egroup, ident, key, a0, v0) \ 229244445Sjeff KTR_EVENT1(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, a0, (v0)) 230244445Sjeff#define KTR_STOP2(m, egroup, ident, key, a0, v0, a1, v1) \ 231244445Sjeff KTR_EVENT2(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 232244445Sjeff a0, (v0), a1, (v1)) 233244445Sjeff#define KTR_STOP3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ 234244445Sjeff KTR_EVENT3(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 235244445Sjeff a0, (v0), a1, (v1), a2, (v2)) 236244445Sjeff#define KTR_STOP4(m, egroup, ident, \ 237244445Sjeff key, a0, v0, a1, v1, a2, v2, a3, v3) \ 238244445Sjeff KTR_EVENT4(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 239244445Sjeff a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 240244445Sjeff 241244445Sjeff/* 24265556Sjasone * Trace initialization events, similar to CTR with KTR_INIT, but 24365556Sjasone * completely ifdef'ed out if KTR_INIT isn't in KTR_COMPILE (to 24465556Sjasone * save string space, the compiler doesn't optimize out strings 24565556Sjasone * for the conditional ones above). 24665556Sjasone */ 24765556Sjasone#if (KTR_COMPILE & KTR_INIT) != 0 24865556Sjasone#define ITR0(d) CTR0(KTR_INIT, d) 24965556Sjasone#define ITR1(d, p1) CTR1(KTR_INIT, d, p1) 25065556Sjasone#define ITR2(d, p1, p2) CTR2(KTR_INIT, d, p1, p2) 25165556Sjasone#define ITR3(d, p1, p2, p3) CTR3(KTR_INIT, d, p1, p2, p3) 25265556Sjasone#define ITR4(d, p1, p2, p3, p4) CTR4(KTR_INIT, d, p1, p2, p3, p4) 25365556Sjasone#define ITR5(d, p1, p2, p3, p4, p5) CTR5(KTR_INIT, d, p1, p2, p3, p4, p5) 25487957Sjhb#define ITR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_INIT, d, p1, p2, p3, p4, p5, p6) 25565556Sjasone#else 25665556Sjasone#define ITR0(d) 25765556Sjasone#define ITR1(d, p1) 25865556Sjasone#define ITR2(d, p1, p2) 25965556Sjasone#define ITR3(d, p1, p2, p3) 26065556Sjasone#define ITR4(d, p1, p2, p3, p4) 26165556Sjasone#define ITR5(d, p1, p2, p3, p4, p5) 26287621Sobrien#define ITR6(d, p1, p2, p3, p4, p5, p6) 26365556Sjasone#endif 26465556Sjasone 265153174Smarius#endif /* !LOCORE */ 266153174Smarius 26765556Sjasone#endif /* !_SYS_KTR_H_ */ 268