]>
Commit | Line | Data |
---|---|---|
f1a1da6c A |
1 | /* |
2 | * Copyright (c) 2000-2003 Apple Computer, 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 _KERN_TRACE_H_ | |
30 | #define _KERN_TRACE_H_ | |
31 | ||
32 | /* pthread kext, or userspace, kdebug trace points. Defined here and output to | |
33 | * /usr/share/misc/pthread.codes during build. | |
34 | */ | |
35 | ||
76b7b9a2 A |
36 | // userspace trace points force slow-paths, so must be compiled in |
37 | #define ENABLE_USERSPACE_TRACE 0 | |
38 | ||
f1a1da6c A |
39 | // pthread tracing subclasses |
40 | # define _TRACE_SUB_DEFAULT 0 | |
41 | # define _TRACE_SUB_WORKQUEUE 1 | |
214d78a2 A |
42 | // WQ_TRACE_REQUESTS_SUBCLASS is 2, in xnu |
43 | # define _TRACE_SUB_MUTEX 3 | |
44 | # define _TRACE_SUB_CONDVAR 4 | |
c1f56ec9 A |
45 | # define _TRACE_SUB_ULMUTEX 5 |
46 | # define _TRACE_SUB_ULCOND 6 | |
f1a1da6c A |
47 | |
48 | #ifndef _PTHREAD_BUILDING_CODES_ | |
49 | ||
50 | #include <sys/kdebug.h> | |
51 | ||
52 | #ifndef DBG_PTHREAD | |
53 | #define DBG_PTHREAD DBG_WORKQUEUE | |
54 | #endif | |
55 | ||
56 | #if KERNEL | |
2546420a A |
57 | #include <vm/vm_kern.h> |
58 | ||
f1a1da6c A |
59 | extern uint32_t pthread_debug_tracing; |
60 | ||
2546420a A |
61 | static __unused void* |
62 | VM_UNSLIDE(void* ptr) | |
63 | { | |
64 | vm_offset_t unslid_ptr; | |
65 | vm_kernel_unslide_or_perm_external(ptr, &unslid_ptr); | |
66 | return (void*)unslid_ptr; | |
67 | } | |
68 | ||
214d78a2 A |
69 | # define PTHREAD_TRACE(x,a,b,c,d) \ |
70 | { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(TRACE_##x, a, b, c, d, 0); } } | |
f1a1da6c | 71 | |
76b7b9a2 A |
72 | #else // KERNEL |
73 | ||
74 | #if ENABLE_USERSPACE_TRACE | |
75 | # include <sys/kdebug.h> | |
76 | # define PTHREAD_TRACE(x, a, b, c, d) kdebug_trace(TRACE_##x, a, b, c, d) | |
77 | #else // ENABLE_USERSPACE_TRACE | |
78 | # define PTHREAD_TRACE(x, a, b, c, d) do { } while(0) | |
79 | #endif // ENABLE_USERSPACE_TRACE | |
80 | ||
81 | #endif // KERNEL | |
2546420a | 82 | |
f1a1da6c A |
83 | # define TRACE_CODE(name, subclass, code) \ |
84 | static const int TRACE_##name = KDBG_CODE(DBG_PTHREAD, subclass, code) | |
85 | ||
76b7b9a2 | 86 | #else // _PTHREAD_BUILDING_CODES_ |
f1a1da6c A |
87 | /* When not included as a header, this file is pre-processed into perl source to generate |
88 | * the pthread.codes file during build. | |
89 | */ | |
90 | # define DBG_PTHREAD 9 | |
91 | # define STR(x) #x | |
92 | ||
93 | # define TRACE_CODE(name, subclass, code) \ | |
94 | printf("0x%x\t%s\n", ((DBG_PTHREAD << 24) | ((subclass & 0xff) << 16) | ((code & 0x3fff) << 2)), STR(name)) | |
76b7b9a2 | 95 | #endif // _PTHREAD_BUILDING_CODES_ |
f1a1da6c A |
96 | |
97 | /* These defines translate into TRACE_<name> when used in source code, and are | |
98 | * pre-processed out to a codes file by the build system. | |
99 | */ | |
100 | ||
101 | // "default" trace points | |
102 | TRACE_CODE(pthread_thread_create, _TRACE_SUB_DEFAULT, 0x10); | |
103 | TRACE_CODE(pthread_thread_terminate, _TRACE_SUB_DEFAULT, 0x20); | |
104 | TRACE_CODE(pthread_set_qos_self, _TRACE_SUB_DEFAULT, 0x30); | |
105 | ||
f1a1da6c A |
106 | // synch trace points |
107 | TRACE_CODE(psynch_mutex_ulock, _TRACE_SUB_MUTEX, 0x0); | |
108 | TRACE_CODE(psynch_mutex_utrylock_failed, _TRACE_SUB_MUTEX, 0x1); | |
109 | TRACE_CODE(psynch_mutex_uunlock, _TRACE_SUB_MUTEX, 0x2); | |
110 | TRACE_CODE(psynch_ksyn_incorrect_owner, _TRACE_SUB_MUTEX, 0x3); | |
76b7b9a2 A |
111 | TRACE_CODE(psynch_mutex_lock_updatebits, _TRACE_SUB_MUTEX, 0x4); |
112 | TRACE_CODE(psynch_mutex_unlock_updatebits, _TRACE_SUB_MUTEX, 0x5); | |
214d78a2 A |
113 | TRACE_CODE(psynch_mutex_clearprepost, _TRACE_SUB_MUTEX, 0x6); |
114 | TRACE_CODE(psynch_mutex_kwqallocate, _TRACE_SUB_MUTEX, 0x7); | |
115 | TRACE_CODE(psynch_mutex_kwqdeallocate, _TRACE_SUB_MUTEX, 0x8); | |
116 | TRACE_CODE(psynch_mutex_kwqprepost, _TRACE_SUB_MUTEX, 0x9); | |
117 | TRACE_CODE(psynch_mutex_markprepost, _TRACE_SUB_MUTEX, 0x10); | |
118 | TRACE_CODE(psynch_mutex_kwqcollision, _TRACE_SUB_MUTEX, 0x11); | |
119 | TRACE_CODE(psynch_ffmutex_lock_updatebits, _TRACE_SUB_MUTEX, 0x12); | |
120 | TRACE_CODE(psynch_ffmutex_unlock_updatebits, _TRACE_SUB_MUTEX, 0x13); | |
121 | TRACE_CODE(psynch_ffmutex_wake, _TRACE_SUB_MUTEX, 0x14); | |
122 | TRACE_CODE(psynch_mutex_kwqsignal, _TRACE_SUB_MUTEX, 0x15); | |
123 | TRACE_CODE(psynch_ffmutex_wait, _TRACE_SUB_MUTEX, 0x16); | |
124 | TRACE_CODE(psynch_mutex_kwqwait, _TRACE_SUB_MUTEX, 0x17); | |
125 | ||
126 | TRACE_CODE(psynch_cvar_kwait, _TRACE_SUB_CONDVAR, 0x0); | |
127 | TRACE_CODE(psynch_cvar_clrprepost, _TRACE_SUB_CONDVAR, 0x1); | |
128 | TRACE_CODE(psynch_cvar_freeitems, _TRACE_SUB_CONDVAR, 0x2); | |
129 | TRACE_CODE(psynch_cvar_signal, _TRACE_SUB_CONDVAR, 0x3); | |
130 | TRACE_CODE(psynch_cvar_broadcast, _TRACE_SUB_CONDVAR, 0x5); | |
131 | TRACE_CODE(psynch_cvar_zeroed, _TRACE_SUB_CONDVAR, 0x6); | |
132 | TRACE_CODE(psynch_cvar_updateval, _TRACE_SUB_CONDVAR, 0x7); | |
f1a1da6c | 133 | |
c1f56ec9 A |
134 | TRACE_CODE(ulmutex_lock, _TRACE_SUB_ULMUTEX, 0x0); |
135 | TRACE_CODE(ulmutex_trylock, _TRACE_SUB_ULMUTEX, 0x1); | |
136 | TRACE_CODE(ulmutex_lock_wait, _TRACE_SUB_ULMUTEX, 0x2); | |
137 | TRACE_CODE(ulmutex_unlock, _TRACE_SUB_ULMUTEX, 0x3); | |
138 | TRACE_CODE(ulmutex_unlock_wake, _TRACE_SUB_ULMUTEX, 0x4); | |
139 | TRACE_CODE(ulmutex_unlock_steal, _TRACE_SUB_ULMUTEX, 0x5); | |
140 | ||
141 | TRACE_CODE(ulcond_wait, _TRACE_SUB_ULCOND, 0x0); | |
142 | TRACE_CODE(ulcond_signal, _TRACE_SUB_ULCOND, 0x1); | |
143 | ||
f1a1da6c | 144 | #endif // _KERN_TRACE_H_ |