1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1996 Berkeley Software Design, Inc. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Berkeley Software Design Inc's name may not be used to endorse or 15 * promote products derived from this software without specific prior 16 * written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * from BSDI $Id: ktr.h,v 1.10.2.7 2000/03/16 21:44:42 cp Exp $ 31 */ 32 33 /* 34 * Wraparound kernel trace buffer support. 35 */ 36 37 #ifndef _SYS_KTR_H_ 38 #define _SYS_KTR_H_ 39 40 #include <sys/ktr_class.h> 41 42 /* 43 * Version number for ktr_entry struct. Increment this when you break binary 44 * compatibility. 45 */ 46 #define KTR_VERSION 2 47 48 #define KTR_PARMS 6 49 50 #ifndef LOCORE 51 52 #include <sys/param.h> 53 #include <sys/_cpuset.h> 54 55 struct ktr_entry { 56 u_int64_t ktr_timestamp; 57 int ktr_cpu; 58 int ktr_line; 59 const char *ktr_file; 60 const char *ktr_desc; 61 struct thread *ktr_thread; 62 u_long ktr_parms[KTR_PARMS]; 63 }; 64 65 extern cpuset_t ktr_cpumask; 66 extern uint64_t ktr_mask; 67 extern int ktr_entries; 68 extern int ktr_verbose; 69 70 extern volatile int ktr_idx; 71 extern struct ktr_entry *ktr_buf; 72 73 #ifdef KTR 74 75 void ktr_tracepoint(uint64_t mask, const char *file, int line, 76 const char *format, u_long arg1, u_long arg2, u_long arg3, 77 u_long arg4, u_long arg5, u_long arg6); 78 79 #define CTR6(m, format, p1, p2, p3, p4, p5, p6) do { \ 80 if (KTR_COMPILE & (m)) \ 81 ktr_tracepoint((m), __FILE__, __LINE__, format, \ 82 (u_long)(p1), (u_long)(p2), (u_long)(p3), \ 83 (u_long)(p4), (u_long)(p5), (u_long)(p6)); \ 84 } while (0) 85 #define CTR0(m, format) CTR6(m, format, 0, 0, 0, 0, 0, 0) 86 #define CTR1(m, format, p1) CTR6(m, format, p1, 0, 0, 0, 0, 0) 87 #define CTR2(m, format, p1, p2) CTR6(m, format, p1, p2, 0, 0, 0, 0) 88 #define CTR3(m, format, p1, p2, p3) CTR6(m, format, p1, p2, p3, 0, 0, 0) 89 #define CTR4(m, format, p1, p2, p3, p4) CTR6(m, format, p1, p2, p3, p4, 0, 0) 90 #define CTR5(m, format, p1, p2, p3, p4, p5) CTR6(m, format, p1, p2, p3, p4, p5, 0) 91 #else /* KTR */ 92 #define CTR0(m, d) (void)0 93 #define CTR1(m, d, p1) (void)0 94 #define CTR2(m, d, p1, p2) (void)0 95 #define CTR3(m, d, p1, p2, p3) (void)0 96 #define CTR4(m, d, p1, p2, p3, p4) (void)0 97 #define CTR5(m, d, p1, p2, p3, p4, p5) (void)0 98 #define CTR6(m, d, p1, p2, p3, p4, p5, p6) (void)0 99 #endif /* KTR */ 100 101 #define TR0(d) CTR0(KTR_GEN, d) 102 #define TR1(d, p1) CTR1(KTR_GEN, d, p1) 103 #define TR2(d, p1, p2) CTR2(KTR_GEN, d, p1, p2) 104 #define TR3(d, p1, p2, p3) CTR3(KTR_GEN, d, p1, p2, p3) 105 #define TR4(d, p1, p2, p3, p4) CTR4(KTR_GEN, d, p1, p2, p3, p4) 106 #define TR5(d, p1, p2, p3, p4, p5) CTR5(KTR_GEN, d, p1, p2, p3, p4, p5) 107 #define TR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_GEN, d, p1, p2, p3, p4, p5, p6) 108 109 #define _KTR_MACRO(m, format, _1, _2, _3, _4, _5, _6, NAME, ...) \ 110 NAME 111 #define CTR(...) \ 112 _KTR_MACRO(__VA_ARGS__, CTR6, CTR5, CTR4, CTR3, CTR2, CTR1, \ 113 CTR0)(__VA_ARGS__) 114 #define TR(...) CTR(KTR_GEN, __VA_ARGS__) 115 116 /* 117 * The event macros implement KTR graphic plotting facilities provided 118 * by src/tools/sched/schedgraph.py. Three generic types of events are 119 * supported: states, counters, and points. 120 * 121 * m is the ktr class for ktr_mask. 122 * ident is the string identifier that owns the event (ie: "thread 10001") 123 * etype is the type of event to plot (state, counter, point) 124 * edat is the event specific data (state name, counter value, point name) 125 * up to four attributes may be supplied as a name, value pair of arguments. 126 * 127 * etype and attribute names must be string constants. This minimizes the 128 * number of ktr slots required by construction the final format strings 129 * at compile time. Both must also include a colon and format specifier 130 * (ie. "prio:%d", prio). It is recommended that string arguments be 131 * contained within escaped quotes if they may contain ',' or ':' characters. 132 * 133 * The special attribute (KTR_ATTR_LINKED, ident) creates a reference to another 134 * id on the graph for easy traversal of related graph elements. 135 */ 136 137 #define KTR_ATTR_LINKED "linkedto:\"%s\"" 138 #define KTR_EFMT(egroup, ident, etype) \ 139 "KTRGRAPH group:\"" egroup "\", id:\"%s\", " etype ", attributes: " 140 141 #define KTR_EVENT0(m, egroup, ident, etype, edat) \ 142 CTR2(m, KTR_EFMT(egroup, ident, etype) "none", ident, edat) 143 #define KTR_EVENT1(m, egroup, ident, etype, edat, a0, v0) \ 144 CTR3(m, KTR_EFMT(egroup, ident, etype) a0, ident, edat, (v0)) 145 #define KTR_EVENT2(m, egroup, ident, etype, edat, a0, v0, a1, v1) \ 146 CTR4(m, KTR_EFMT(egroup, ident, etype) a0 ", " a1, \ 147 ident, edat, (v0), (v1)) 148 #define KTR_EVENT3(m, egroup, ident, etype, edat, a0, v0, a1, v1, a2, v2)\ 149 CTR5(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2, \ 150 ident, edat, (v0), (v1), (v2)) 151 #define KTR_EVENT4(m, egroup, ident, etype, edat, \ 152 a0, v0, a1, v1, a2, v2, a3, v3) \ 153 CTR6(m,KTR_EFMT(egroup, ident, etype) a0 ", " a1 ", " a2 ", " a3,\ 154 ident, edat, (v0), (v1), (v2), (v3)) 155 156 /* 157 * State functions graph state changes on an ident. 158 */ 159 #define KTR_STATE0(m, egroup, ident, state) \ 160 KTR_EVENT0(m, egroup, ident, "state:\"%s\"", state) 161 #define KTR_STATE1(m, egroup, ident, state, a0, v0) \ 162 KTR_EVENT1(m, egroup, ident, "state:\"%s\"", state, a0, (v0)) 163 #define KTR_STATE2(m, egroup, ident, state, a0, v0, a1, v1) \ 164 KTR_EVENT2(m, egroup, ident, "state:\"%s\"", state, a0, (v0), a1, (v1)) 165 #define KTR_STATE3(m, egroup, ident, state, a0, v0, a1, v1, a2, v2) \ 166 KTR_EVENT3(m, egroup, ident, "state:\"%s\"", \ 167 state, a0, (v0), a1, (v1), a2, (v2)) 168 #define KTR_STATE4(m, egroup, ident, state, a0, v0, a1, v1, a2, v2, a3, v3)\ 169 KTR_EVENT4(m, egroup, ident, "state:\"%s\"", \ 170 state, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 171 172 /* 173 * Counter functions graph counter values. The counter id 174 * must not be intermixed with a state id. 175 */ 176 #define KTR_COUNTER0(m, egroup, ident, counter) \ 177 KTR_EVENT0(m, egroup, ident, "counter:%d", counter) 178 #define KTR_COUNTER1(m, egroup, ident, edat, a0, v0) \ 179 KTR_EVENT1(m, egroup, ident, "counter:%d", counter, a0, (v0)) 180 #define KTR_COUNTER2(m, egroup, ident, counter, a0, v0, a1, v1) \ 181 KTR_EVENT2(m, egroup, ident, "counter:%d", counter, a0, (v0), a1, (v1)) 182 #define KTR_COUNTER3(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2) \ 183 KTR_EVENT3(m, egroup, ident, "counter:%d", \ 184 counter, a0, (v0), a1, (v1), a2, (v2)) 185 #define KTR_COUNTER4(m, egroup, ident, counter, a0, v0, a1, v1, a2, v2, a3, v3)\ 186 KTR_EVENT4(m, egroup, ident, "counter:%d", \ 187 counter, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 188 189 /* 190 * Point functions plot points of interest on counter or state graphs. 191 */ 192 #define KTR_POINT0(m, egroup, ident, point) \ 193 KTR_EVENT0(m, egroup, ident, "point:\"%s\"", point) 194 #define KTR_POINT1(m, egroup, ident, point, a0, v0) \ 195 KTR_EVENT1(m, egroup, ident, "point:\"%s\"", point, a0, (v0)) 196 #define KTR_POINT2(m, egroup, ident, point, a0, v0, a1, v1) \ 197 KTR_EVENT2(m, egroup, ident, "point:\"%s\"", point, a0, (v0), a1, (v1)) 198 #define KTR_POINT3(m, egroup, ident, point, a0, v0, a1, v1, a2, v2) \ 199 KTR_EVENT3(m, egroup, ident, "point:\"%s\"", point, \ 200 a0, (v0), a1, (v1), a2, (v2)) 201 #define KTR_POINT4(m, egroup, ident, point, a0, v0, a1, v1, a2, v2, a3, v3)\ 202 KTR_EVENT4(m, egroup, ident, "point:\"%s\"", \ 203 point, a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 204 205 /* 206 * Start functions denote the start of a region of code or operation 207 * and should be paired with stop functions for timing of nested 208 * sequences. 209 * 210 * Specifying extra attributes with the name "key" will result in 211 * multi-part keys. For example a block device and offset pair 212 * might be used to describe a buf undergoing I/O. 213 */ 214 #define KTR_START0(m, egroup, ident, key) \ 215 KTR_EVENT0(m, egroup, ident, "start:0x%jX", (uintmax_t)key) 216 #define KTR_START1(m, egroup, ident, key, a0, v0) \ 217 KTR_EVENT1(m, egroup, ident, "start:0x%jX", (uintmax_t)key, a0, (v0)) 218 #define KTR_START2(m, egroup, ident, key, a0, v0, a1, v1) \ 219 KTR_EVENT2(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 220 a0, (v0), a1, (v1)) 221 #define KTR_START3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ 222 KTR_EVENT3(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 223 a0, (v0), a1, (v1), a2, (v2)) 224 #define KTR_START4(m, egroup, ident, key, \ 225 a0, v0, a1, v1, a2, v2, a3, v3) \ 226 KTR_EVENT4(m, egroup, ident, "start:0x%jX", (uintmax_t)key, \ 227 a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 228 229 /* 230 * Stop functions denote the end of a region of code or operation 231 * and should be paired with start functions for timing of nested 232 * sequences. 233 */ 234 #define KTR_STOP0(m, egroup, ident, key) \ 235 KTR_EVENT0(m, egroup, ident, "stop:0x%jX", (uintmax_t)key) 236 #define KTR_STOP1(m, egroup, ident, key, a0, v0) \ 237 KTR_EVENT1(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, a0, (v0)) 238 #define KTR_STOP2(m, egroup, ident, key, a0, v0, a1, v1) \ 239 KTR_EVENT2(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 240 a0, (v0), a1, (v1)) 241 #define KTR_STOP3(m, egroup, ident, key, a0, v0, a1, v1, a2, v2)\ 242 KTR_EVENT3(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 243 a0, (v0), a1, (v1), a2, (v2)) 244 #define KTR_STOP4(m, egroup, ident, \ 245 key, a0, v0, a1, v1, a2, v2, a3, v3) \ 246 KTR_EVENT4(m, egroup, ident, "stop:0x%jX", (uintmax_t)key, \ 247 a0, (v0), a1, (v1), a2, (v2), a3, (v3)) 248 249 /* 250 * Trace initialization events, similar to CTR with KTR_INIT, but 251 * completely ifdef'ed out if KTR_INIT isn't in KTR_COMPILE (to 252 * save string space, the compiler doesn't optimize out strings 253 * for the conditional ones above). 254 */ 255 #if (KTR_COMPILE & KTR_INIT) != 0 256 #define ITR0(d) CTR0(KTR_INIT, d) 257 #define ITR1(d, p1) CTR1(KTR_INIT, d, p1) 258 #define ITR2(d, p1, p2) CTR2(KTR_INIT, d, p1, p2) 259 #define ITR3(d, p1, p2, p3) CTR3(KTR_INIT, d, p1, p2, p3) 260 #define ITR4(d, p1, p2, p3, p4) CTR4(KTR_INIT, d, p1, p2, p3, p4) 261 #define ITR5(d, p1, p2, p3, p4, p5) CTR5(KTR_INIT, d, p1, p2, p3, p4, p5) 262 #define ITR6(d, p1, p2, p3, p4, p5, p6) CTR6(KTR_INIT, d, p1, p2, p3, p4, p5, p6) 263 #else 264 #define ITR0(d) 265 #define ITR1(d, p1) 266 #define ITR2(d, p1, p2) 267 #define ITR3(d, p1, p2, p3) 268 #define ITR4(d, p1, p2, p3, p4) 269 #define ITR5(d, p1, p2, p3, p4, p5) 270 #define ITR6(d, p1, p2, p3, p4, p5, p6) 271 #endif 272 273 #endif /* !LOCORE */ 274 275 #endif /* !_SYS_KTR_H_ */ 276