xref: /xnu-8019.80.24/bsd/sys/kdebug_private.h (revision a325d9c4a84054e40bbe985afedcb50ab80993ea)
1 /*
2  * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 
29 #ifndef BSD_KDEBUG_PRIVATE_H
30 #define BSD_KDEBUG_PRIVATE_H
31 
32 #include <stdint.h>
33 #include <stdbool.h>
34 #include <sys/cdefs.h>
35 #include <sys/kdebug.h>
36 
37 __BEGIN_DECLS
38 
39 #if !KERNEL
40 
41 #include <Availability.h>
42 
43 #pragma mark - user space SPI
44 
45 /*
46  * OS components can use the full precision of the "code" field
47  * (Class, SubClass, Code) to inject events using kdebug_trace() by
48  * using:
49  *
50  * kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, 1, 2, 3, 4);
51  *
52  * These trace points can be included in production code, since they
53  * use reserved, non-overlapping ranges.  The performance impact when
54  * kernel tracing is not enabled is minimal.  However, when tracing is enabled,
55  * each tracepoint becomes a syscall.  For this reason, os_signpost(3) is
56  * recommended instead of kdebug_trace(2).
57  *
58  * Classes can be reserved by filing a Radar in xnu | ktrace.
59  *
60  * 64-bit arguments may be truncated if the system is using a 32-bit
61  * kernel.
62  *
63  * On error, -1 will be returned and errno will indicate the error.
64  */
65 int kdebug_trace(uint32_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3,
66     uint64_t arg4)
67 __OSX_AVAILABLE(10.10) __IOS_AVAILABLE(8.2);
68 
69 /*!
70  * @function kdebug_trace_string
71  *
72  * @discussion
73  * This function emits strings to kdebug trace along with an ID and allows
74  * for previously-traced strings to be overwritten and invalidated.
75  *
76  * To start tracing a string and generate an ID to use to refer to it:
77  *
78  *      string_id = kdebug_trace_string(debugid, 0, "string");
79  *
80  * To replace a string previously traced:
81  *
82  *      string_id = kdebug_trace_string(debugid, string_id, "new string");
83  *
84  * To invalidate a string ID:
85  *
86  *      string_id = kdebug_trace_string(debugid, string_id, NULL);
87  *
88  * To check for errors:
89  *
90  *      if ((int64_t)string_id == -1) { perror("string error") }
91  *
92  * @param debugid
93  * The `debugid` to check if its enabled before tracing and include as
94  * an argument in the event containing the string.
95  *
96  * Some classes or subclasses are reserved for specific uses and are not
97  * allowed to be used with this function.  No function qualifiers are
98  * allowed on `debugid`.
99  *
100  * @param str_id
101  * When 0, a new ID will be generated and returned if tracing is
102  * enabled.
103  *
104  * Otherwise `str_id` must contain an ID that was previously generated
105  * with this function.  Clents should pass NULL in `str` if `str_id`
106  * is no longer in use.  Otherwise, the string previously mapped to
107  * `str_id` will be overwritten with the contents of `str`.
108  *
109  * @param str
110  * A NUL-terminated 'C' string containing the characters that should be
111  * traced alongside `str_id`.
112  *
113  * If necessary, the string will be truncated at an
114  * implementation-defined length.  The string must not be the empty
115  * string, but can be NULL if a valid `str_id` is provided.
116  *
117  * @return
118  * 0 if tracing is disabled or `debugid` is being filtered out of trace.
119  * It can also return (int64_t)-1 if an error occured. Otherwise,
120  * it returns the ID to use to refer to the string in future
121  * kdebug_trace(2) calls.
122  *
123  * The errors that can occur are:
124  *
125  * EINVAL
126  *      There are function qualifiers on `debugid`, `str` is empty, or
127  *      `str_id` was not generated by this function.
128  * EPERM
129  *      The `debugid`'s class or subclass is reserved for internal use.
130  * EFAULT
131  *      `str` is an invalid address or NULL when `str_id` is 0.
132  */
133 extern uint64_t kdebug_trace_string(uint32_t debugid, uint64_t str_id,
134     const char *str)
135 __OSX_AVAILABLE(10.11) __IOS_AVAILABLE(9.0);
136 
137 /*
138  * Although the performance impact of kdebug_trace() when kernel
139  * tracing is not enabled is minimal, it may require the caller to
140  * perform an expensive calculation/summarization. This cost can be
141  * skipped by checking the kdebug_is_enabled() predicate:
142  *
143  * if (kdebug_is_enabled(KDBG_CODE(DBG_XPC, 15, 1))) {
144  *     uint64_t arg1 = ...;
145  *     uint64_t arg2 = ...;
146  *     kdebug_trace(KDBG_CODE(DBG_XPC, 15, 1) | DBG_FUNC_NONE, arg1, arg2, 0, 0);
147  * }
148  *
149  * If tracing is enabled for the code at the time of the check, 1
150  * will be returned. Otherwise, 0 will be returned.
151  */
152 extern bool kdebug_is_enabled(uint32_t code)
153 __API_AVAILABLE(macos(10.12), ios(10), watchos(3), tvos(10));
154 
155 /*
156  * Returns a pointer to the userspace typefilter, if one is available.
157  * May return NULL.
158  */
159 extern void *kdebug_typefilter(void)
160 __API_AVAILABLE(macos(10.12), ios(10), watchos(3), tvos(10));
161 
162 /*
163  * Returns true if kdebug is using continuous time for its events, and false
164  * otherwise.
165  */
166 extern bool kdebug_using_continuous_time(void)
167 __API_AVAILABLE(macos(10.15), ios(13), tvos(13), watchos(6));
168 
169 /*
170  * Convert an absolute time to a kdebug timestamp.
171  */
172 extern uint64_t kdebug_timestamp_from_absolute(uint64_t abstime)
173 __API_AVAILABLE(macos(12), ios(15), tvos(15), watchos(8));
174 
175 /*
176  * Convert a continuous time to a kdebug timestamp.
177  */
178 extern uint64_t kdebug_timestamp_from_continuous(uint64_t conttime)
179 __API_AVAILABLE(macos(12), ios(15), tvos(15), watchos(8));
180 
181 /*
182  * Capture a kdebug timestamp for the current time.
183  */
184 extern uint64_t kdebug_timestamp(void)
185 __API_AVAILABLE(macos(12), ios(15), tvos(15), watchos(8));
186 
187 #endif /* !KERNEL */
188 
189 #pragma mark - private debugids
190 
191 #define DBG_PPT         36
192 #define DBG_PERFCTRL    39
193 #define DBG_CLPC        50
194 #define DBG_MUSE        52
195 
196 /* **** 128 to 139 are reserved for IOP tracing **** */
197 #define DBG_ANS         128
198 #define DBG_SIO         129
199 #define DBG_SEP         130
200 #define DBG_ISP         131
201 #define DBG_OSCAR       132
202 #define DBG_EMBEDDEDGFX 133
203 #define DBG_PMP         134
204 #define DBG_RTKIT       135
205 
206 #define MACH_BRIDGE_RCV_TS      0x1     /* receive timestamp pair from interrupt handler */
207 #define MACH_BRIDGE_REMOTE_TIME 0x2     /* calculate remote timestamp */
208 #define MACH_BRIDGE_RESET_TS    0x3     /* reset timestamp conversion parameters */
209 #define MACH_BRIDGE_TS_PARAMS   0x4     /* recompute timestamp conversion parameters */
210 #define MACH_BRIDGE_SKIP_TS     0x5     /* skip timestamp */
211 #define MACH_BRIDGE_TS_MISMATCH 0x6     /* mismatch between predicted and received remote timestamp */
212 #define MACH_BRIDGE_OBSV_RATE   0x7     /* out of range observed rates */
213 
214 /* DBG_SKYWALK has same toplevel code as DBG_DLIL, so don't reuse subcodes */
215 #define DBG_SKYWALK_ALWAYSON    0x10
216 #define DBG_SKYWALK_FLOWSWITCH  0x11
217 #define DBG_SKYWALK_NETIF       0x12
218 #define DBG_SKYWALK_CHANNEL     0x13
219 #define DBG_SKYWALK_PACKET      0x14
220 
221 #define PPT_TEST            0x01
222 #define PPT_JETSAM_HIWAT    0x02
223 #define PPT_JETSAM_TOPPROC  0x03
224 
225 #define SKYWALKDBG_CODE(SubClass, code) KDBG_CODE(DBG_DLIL, SubClass, code)
226 #define PPTDBG_CODE(SubClass, code) KDBG_CODE(DBG_PPT, SubClass, code)
227 #define PERFCTRL_CODE(SubClass, code) KDBG_CODE(DBG_PERFCTRL, SubClass, code)
228 
229 #if !defined(DRIVERKIT)
230 
231 extern unsigned int kdebug_enable;
232 
233 /*
234  * Bits used by kdebug_enable.  These used to control which events are traced at
235  * runtime.
236  */
237 #define KDEBUG_ENABLE_TRACE     0x001U
238 /*
239  * If set, the timestamps in events are expected to be continuous times.
240  * Otherwise, the timestamps are absolute times.  IOPs should observe this bit
241  * in order to log events that can be merged cleanly with other event streams.
242  */
243 #define KDEBUG_ENABLE_CONT_TIME 0x020U
244 
245 #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE)
246 
247 /* obsolete kdebug_enable bits */
248 #define KDEBUG_ENABLE_ENTROPY   0x002U
249 #define KDEBUG_ENABLE_CHUD      0x004U
250 #define KDEBUG_ENABLE_PPT       0x008U
251 #define KDEBUG_ENABLE_SERIAL    0x010U
252 #define KDEBUG_PPT    (KDEBUG_ENABLE_PPT)
253 #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE | KDEBUG_ENABLE_PPT)
254 
255 /*
256  * The kernel debug configuration level.  These values control which events are
257  * compiled in under different build configurations.
258  *
259  * Infer the supported kernel debug event level from config option.  Use
260  * (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect unaudited debug
261  * code.
262  */
263 #define KDEBUG_LEVEL_NONE     0
264 #define KDEBUG_LEVEL_IST      1
265 #define KDEBUG_LEVEL_STANDARD 2
266 #define KDEBUG_LEVEL_FULL     3
267 
268 #if NO_KDEBUG
269 #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE
270 #elif IST_KDEBUG
271 #define KDEBUG_LEVEL KDEBUG_LEVEL_IST
272 #elif KDEBUG
273 #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL
274 #else
275 #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD
276 /*
277  * Currently, all other kernel configurations (development, etc) build with
278  * KDEBUG_LEVEL_STANDARD.
279  */
280 #endif
281 
282 /*
283  * Some Apple internal clients try to use the kernel macros in user space.
284  */
285 #ifndef KERNEL_DEBUG
286 #define KERNEL_DEBUG(...) do { } while (0)
287 #endif /* !defined(KERNEL_DEBUG) */
288 
289 #pragma mark - private definitions
290 
291 /*
292  * Ensure that both LP32 and LP64 variants of arm64 use the same kd_buf
293  * structure.
294  */
295 #if defined(__arm64__)
296 typedef uint64_t kd_buf_argtype;
297 #else
298 typedef uintptr_t kd_buf_argtype;
299 #endif
300 
301 typedef struct {
302 	uint64_t timestamp;
303 	kd_buf_argtype arg1;
304 	kd_buf_argtype arg2;
305 	kd_buf_argtype arg3;
306 	kd_buf_argtype arg4;
307 	kd_buf_argtype arg5; /* the thread ID */
308 	uint32_t debugid;
309 /*
310  * Ensure that both LP32 and LP64 variants of arm64 use the same kd_buf
311  * structure.
312  */
313 #if defined(__LP64__) || defined(__arm64__)
314 	uint32_t cpuid;
315 	kd_buf_argtype unused;
316 #endif
317 } kd_buf;
318 
319 #if defined(__LP64__) || defined(__arm64__)
320 #define KDBG_TIMESTAMP_MASK             0xffffffffffffffffULL
321 static inline void
kdbg_set_cpu(kd_buf * kp,int cpu)322 kdbg_set_cpu(kd_buf *kp, int cpu)
323 {
324 	kp->cpuid = (unsigned int)cpu;
325 }
326 static inline int
kdbg_get_cpu(kd_buf * kp)327 kdbg_get_cpu(kd_buf *kp)
328 {
329 	return (int)kp->cpuid;
330 }
331 static inline void
kdbg_set_timestamp(kd_buf * kp,uint64_t thetime)332 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
333 {
334 	kp->timestamp = thetime;
335 }
336 static inline uint64_t
kdbg_get_timestamp(kd_buf * kp)337 kdbg_get_timestamp(kd_buf *kp)
338 {
339 	return kp->timestamp;
340 }
341 static inline void
kdbg_set_timestamp_and_cpu(kd_buf * kp,uint64_t thetime,int cpu)342 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
343 {
344 	kdbg_set_timestamp(kp, thetime);
345 	kdbg_set_cpu(kp, cpu);
346 }
347 #else
348 #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL
349 #define KDBG_CPU_MASK       0xff00000000000000ULL
350 #define KDBG_CPU_SHIFT      56
351 static inline void
kdbg_set_cpu(kd_buf * kp,int cpu)352 kdbg_set_cpu(kd_buf *kp, int cpu)
353 {
354 	kp->timestamp = (kp->timestamp & KDBG_TIMESTAMP_MASK) |
355 	    (((uint64_t) cpu) << KDBG_CPU_SHIFT);
356 }
357 static inline int
kdbg_get_cpu(kd_buf * kp)358 kdbg_get_cpu(kd_buf *kp)
359 {
360 	return (int) (((kp)->timestamp & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT);
361 }
362 static inline void
kdbg_set_timestamp(kd_buf * kp,uint64_t thetime)363 kdbg_set_timestamp(kd_buf *kp, uint64_t thetime)
364 {
365 	kp->timestamp = thetime & KDBG_TIMESTAMP_MASK;
366 }
367 static inline uint64_t
kdbg_get_timestamp(kd_buf * kp)368 kdbg_get_timestamp(kd_buf *kp)
369 {
370 	return kp->timestamp & KDBG_TIMESTAMP_MASK;
371 }
372 static inline void
kdbg_set_timestamp_and_cpu(kd_buf * kp,uint64_t thetime,int cpu)373 kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu)
374 {
375 	kp->timestamp = (thetime & KDBG_TIMESTAMP_MASK) |
376 	    (((uint64_t) cpu) << KDBG_CPU_SHIFT);
377 }
378 #endif
379 
380 /*
381  * 2^16 bits (8 kilobytes), one for each possible class/subclass combination
382  */
383 #define KDBG_TYPEFILTER_BITMAP_SIZE ((256 * 256) / 8)
384 
385 /*
386  * Bits for kd_ctrl_page.flags, KERN_KD{D,E}FLAGS.
387  */
388 /* disable tracing when buffers are full */
389 #define KDBG_NOWRAP          0x0002
390 /* buffer has wrapped */
391 #define KDBG_WRAPPED         0x0008
392 /* only include processes with kdebug bit set in proc */
393 #define KDBG_PIDCHECK        0x0010
394 /* thread map is initialized */
395 #define KDBG_MAPINIT         0x0020
396 /* exclude processes based on kdebug bit in proc */
397 #define KDBG_PIDEXCLUDE      0x0040
398 /* whether the kdebug locks are intialized */
399 #define KDBG_LOCKINIT        0x0080
400 /* word size of the kernel */
401 #define KDBG_LP64            0x0100
402 /* whether timestamps are in continuous time */
403 #define KDBG_CONTINUOUS_TIME 0x0200
404 /* coprocessor tracing is disabled */
405 #define KDBG_DISABLE_COPROCS 0x0400
406 
407 /* flags that are allowed to be set by user space */
408 #define KDBG_USERFLAGS  (KDBG_NOWRAP | KDBG_CONTINUOUS_TIME | KDBG_DISABLE_COPROCS)
409 
410 /* obsolete flags */
411 #define KDBG_INIT              0x01
412 #define KDBG_FREERUN           0x04
413 
414 /* bits for kd_ctrl_page.flags and kbufinfo_t.flags */
415 
416 /* only trace events within a range */
417 #define KDBG_RANGECHECK       0x00100000U
418 /* only trace at most 4 types of events, at the code granularity */
419 #define KDBG_VALCHECK         0x00200000U
420 /* check class and subclass against the typefilter */
421 #define KDBG_TYPEFILTER_CHECK 0x00400000U
422 /* we are going to use 64-bit debugid in arg4 */
423 #define KDBG_DEBUGID_64       0x00800000U
424 /* kdebug trace buffers are initialized */
425 #define KDBG_BUFINIT          0x80000000U
426 
427 /* bits for the type field of kd_regtype */
428 #define KDBG_CLASSTYPE  0x10000
429 #define KDBG_SUBCLSTYPE 0x20000
430 #define KDBG_RANGETYPE  0x40000
431 #define KDBG_TYPENONE   0x80000
432 #define KDBG_CKTYPES    0xF0000
433 
434 typedef struct {
435 	unsigned int type;
436 	unsigned int value1;
437 	unsigned int value2;
438 	unsigned int value3;
439 	unsigned int value4;
440 } kd_regtype;
441 
442 typedef struct {
443 	/* number of events that can fit in the buffers */
444 	int nkdbufs;
445 	/* set if trace is disabled */
446 	int nolog;
447 	/* kd_ctrl_page.flags */
448 	unsigned int flags;
449 	/* number of threads in thread map */
450 	int nkdthreads;
451 	/* the owning pid */
452 	int bufid;
453 } kbufinfo_t;
454 
455 typedef struct {
456 	/* the thread ID */
457 #if defined(__arm64__)
458 	uint64_t thread;
459 #else
460 	uintptr_t thread __kernel_data_semantics;
461 #endif
462 	/* 0 for invalid, otherwise the PID (or 1 for kernel_task) */
463 	int valid;
464 	/* the name of the process owning the thread */
465 	char command[20];
466 } kd_threadmap;
467 
468 typedef struct {
469 	uint32_t version_no;
470 	uint32_t cpu_count;
471 } kd_cpumap_header;
472 
473 /* cpumap flags */
474 #define KDBG_CPUMAP_IS_IOP      0x1
475 
476 typedef struct {
477 	uint32_t cpu_id;
478 	uint32_t flags;
479 	char name[8];
480 } kd_cpumap;
481 
482 typedef struct {
483 	uint32_t cpu_id;
484 	uint32_t flags;
485 	char name[32];
486 } kd_cpumap_ext;
487 
488 typedef struct {
489 	int             version_no;
490 	int             thread_count;
491 	uint64_t        TOD_secs;
492 	uint32_t        TOD_usecs;
493 } RAW_header;
494 
495 #define RAW_VERSION0    0x55aa0000
496 #define RAW_VERSION1    0x55aa0101
497 #define RAW_VERSION2    0x55aa0200 /* Only used by kperf and Instruments */
498 
499 /*
500  * Bits set in the comm page for kdebug.
501  */
502 #define KDEBUG_COMMPAGE_ENABLE_TRACE      0x1
503 #define KDEBUG_COMMPAGE_ENABLE_TYPEFILTER 0x2 /* Forced to false if ENABLE_TRACE is 0 */
504 #define KDEBUG_COMMPAGE_CONTINUOUS        0x4 /* Forced to false if ENABLE_TRACE is 0 */
505 
506 #pragma mark - Tests
507 
508 enum kdebug_test {
509 	KDTEST_KERNEL_MACROS = 1,
510 	KDTEST_OLD_TIMESTAMP = 2,
511 	KDTEST_FUTURE_TIMESTAMP = 3,
512 	KDTEST_SETUP_IOP = 4,
513 	KDTEST_SETUP_COPROCESSOR = 5,
514 	KDTEST_CONTINUOUS_TIMESTAMP = 6,
515 	KDTEST_ABSOLUTE_TIMESTAMP = 7,
516 };
517 
518 #pragma mark - EnergyTracing
519 
520 /* for EnergyTracing user space & clients */
521 #define kEnTrCompKernel     2
522 
523 /*
524  *   EnergyTracing opcodes
525  *
526  *   Activations use DBG_FUNC_START/END.
527  *   Events are DBG_FUNC_NONE.
528  */
529 
530 /* Socket reads and writes are uniquely identified by the (sanitized)
531  *  pointer to the socket struct in question.  To associate this address
532  *  with the user space file descriptor, we have a socket activation with
533  *  the FD as its identifier and the socket struct pointer as its value.
534  */
535 #define kEnTrActKernSocket      1
536 #define kEnTrActKernSockRead    2
537 #define kEnTrActKernSockWrite   3
538 
539 #define kEnTrActKernPoll        10
540 #define kEnTrActKernSelect      11
541 #define kEnTrActKernKQWait      12
542 
543 // events
544 #define kEnTrEvUnblocked        256
545 
546 // EnergyTracing flags (the low-order 16 bits of 'quality')
547 #define kEnTrFlagNonBlocking    1 << 0
548 #define kEnTrFlagNoWork         1 << 1
549 
550 /*
551  * EnergyTracing macros.
552  */
553 
554 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST)
555 // whether to bother calculating EnergyTracing inputs
556 // could change in future to see if DBG_ENERGYTRACE is active
557 #define ENTR_SHOULDTRACE kdebug_enable
558 // encode logical EnergyTracing into 32/64 KDebug trace
559 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value)   \
560 do {                                                                    \
561     uint32_t kdcode__;                                                  \
562     uintptr_t highval__, lowval__, mask__ = 0xffffffff;                 \
563     kdcode__ = KDBG_CODE(DBG_ENERGYTRACE,component,opcode)|(lifespan);  \
564     highval__ = ((value) >> 32) & mask__;                               \
565     lowval__ = (value) & mask__;                                        \
566     ENTR_KDTRACEFUNC(kdcode__, id, quality, highval__, lowval__);       \
567 } while(0)
568 
569 /*
570  *   Trace the association of two existing activations.
571  *
572  *   An association is traced as a modification to the parent activation.
573  *   In order to fit the sub-activation's component, activation code, and
574  *   activation ID into a kdebug tracepoint, the arguments that would hold
575  *   the value are left separate, and one stores the component and opcode
576  *   of the sub-activation, while the other stores the pointer-sized
577  *   activation ID.
578  *
579  *           arg2                   arg3               arg4
580  +-----------------+  +~+----+----+--------+   +----------+
581  |kEnTrModAssociate|  | |    |    |        |   |          |
582  +-----------------+  +~+----+----+--------+   +----------+
583  *                           8-bits unused       sub-activation ID
584  *                                8-bit sub-component
585  *                                     16-bit sub-opcode
586  *
587  */
588 #define kEnTrModAssociate (1 << 28)
589 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id,              \
590 	    sub_comp, sub_opcode, sub_act_id)              \
591 do {                                                                    \
592     unsigned sub_compcode = ((unsigned)sub_comp << 16) | sub_opcode;    \
593     ENTR_KDTRACEFUNC(KDBG_CODE(DBG_ENERGYTRACE,par_comp,par_opcode),    \
594 	             par_act_id, kEnTrModAssociate, sub_compcode,       \
595 	             sub_act_id);                                       \
596 } while(0)
597 
598 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
599 
600 #define ENTR_SHOULDTRACE FALSE
601 #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value)   \
602 	                            do {} while (0)
603 #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id,              \
604 	    sub_comp, sub_opcode, sub_act_id)              \
605 	                            do {} while (0)
606 
607 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */
608 
609 #endif /* !defined(DRIVERKIT) */
610 
611 __END_DECLS
612 
613 #endif /* !defined(BSD_KDEBUG_PRIVATE_H) */
614