]> git.saurik.com Git - apple/libpthread.git/blob - kern/kern_trace.h
libpthread-330.201.1.tar.gz
[apple/libpthread.git] / kern / kern_trace.h
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
36 // userspace trace points force slow-paths, so must be compiled in
37 #define ENABLE_USERSPACE_TRACE 0
38
39 // pthread tracing subclasses
40 # define _TRACE_SUB_DEFAULT 0
41 # define _TRACE_SUB_WORKQUEUE 1
42 // WQ_TRACE_REQUESTS_SUBCLASS is 2, in xnu
43 # define _TRACE_SUB_MUTEX 3
44 # define _TRACE_SUB_CONDVAR 4
45
46 #ifndef _PTHREAD_BUILDING_CODES_
47
48 #include <sys/kdebug.h>
49
50 #ifndef DBG_PTHREAD
51 #define DBG_PTHREAD DBG_WORKQUEUE
52 #endif
53
54 #if KERNEL
55 #include <vm/vm_kern.h>
56
57 extern uint32_t pthread_debug_tracing;
58
59 static __unused void*
60 VM_UNSLIDE(void* ptr)
61 {
62 vm_offset_t unslid_ptr;
63 vm_kernel_unslide_or_perm_external(ptr, &unslid_ptr);
64 return (void*)unslid_ptr;
65 }
66
67 # define PTHREAD_TRACE(x,a,b,c,d) \
68 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(TRACE_##x, a, b, c, d, 0); } }
69
70 # define PTHREAD_TRACE_WQ(x,a,b,c,d) \
71 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(TRACE_##x, VM_UNSLIDE(a), b, c, d, 0); } }
72
73 # define PTHREAD_TRACE_WQ_REQ(x,a,b,c,d,e) \
74 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(TRACE_##x, VM_UNSLIDE(a), VM_UNSLIDE(b), c, d, e); } }
75
76 #else // KERNEL
77
78 #if ENABLE_USERSPACE_TRACE
79 # include <sys/kdebug.h>
80 # define PTHREAD_TRACE(x, a, b, c, d) kdebug_trace(TRACE_##x, a, b, c, d)
81 #else // ENABLE_USERSPACE_TRACE
82 # define PTHREAD_TRACE(x, a, b, c, d) do { } while(0)
83 #endif // ENABLE_USERSPACE_TRACE
84
85 #endif // KERNEL
86
87 # define TRACE_CODE(name, subclass, code) \
88 static const int TRACE_##name = KDBG_CODE(DBG_PTHREAD, subclass, code)
89
90 #else // _PTHREAD_BUILDING_CODES_
91 /* When not included as a header, this file is pre-processed into perl source to generate
92 * the pthread.codes file during build.
93 */
94 # define DBG_PTHREAD 9
95 # define STR(x) #x
96
97 # define TRACE_CODE(name, subclass, code) \
98 printf("0x%x\t%s\n", ((DBG_PTHREAD << 24) | ((subclass & 0xff) << 16) | ((code & 0x3fff) << 2)), STR(name))
99 #endif // _PTHREAD_BUILDING_CODES_
100
101 /* These defines translate into TRACE_<name> when used in source code, and are
102 * pre-processed out to a codes file by the build system.
103 */
104
105 // "default" trace points
106 TRACE_CODE(pthread_thread_create, _TRACE_SUB_DEFAULT, 0x10);
107 TRACE_CODE(pthread_thread_terminate, _TRACE_SUB_DEFAULT, 0x20);
108 TRACE_CODE(pthread_set_qos_self, _TRACE_SUB_DEFAULT, 0x30);
109
110 // workqueue trace points
111 TRACE_CODE(wq_pthread_exit, _TRACE_SUB_WORKQUEUE, 0x01);
112 TRACE_CODE(wq_workqueue_exit, _TRACE_SUB_WORKQUEUE, 0x02);
113 TRACE_CODE(wq_runthread, _TRACE_SUB_WORKQUEUE, 0x03);
114 TRACE_CODE(wq_runitem, _TRACE_SUB_WORKQUEUE, 0x04);
115 TRACE_CODE(wq_thread_block, _TRACE_SUB_WORKQUEUE, 0x9);
116 TRACE_CODE(wq_thactive_update, _TRACE_SUB_WORKQUEUE, 0xa);
117 TRACE_CODE(wq_add_timer, _TRACE_SUB_WORKQUEUE, 0xb);
118 TRACE_CODE(wq_start_add_timer, _TRACE_SUB_WORKQUEUE, 0x0c);
119 TRACE_CODE(wq_override_start, _TRACE_SUB_WORKQUEUE, 0x12);
120 TRACE_CODE(wq_override_end, _TRACE_SUB_WORKQUEUE, 0x13);
121 TRACE_CODE(wq_override_dispatch, _TRACE_SUB_WORKQUEUE, 0x14);
122 TRACE_CODE(wq_override_reset, _TRACE_SUB_WORKQUEUE, 0x15);
123 TRACE_CODE(wq_thread_create_failed, _TRACE_SUB_WORKQUEUE, 0x1d);
124 TRACE_CODE(wq_thread_create, _TRACE_SUB_WORKQUEUE, 0x1f);
125 TRACE_CODE(wq_run_threadreq, _TRACE_SUB_WORKQUEUE, 0x20);
126 TRACE_CODE(wq_run_threadreq_mgr_merge, _TRACE_SUB_WORKQUEUE, 0x21);
127 TRACE_CODE(wq_run_threadreq_req_select, _TRACE_SUB_WORKQUEUE, 0x22);
128 TRACE_CODE(wq_run_threadreq_thread_select, _TRACE_SUB_WORKQUEUE, 0x23);
129 TRACE_CODE(wq_thread_reset_priority, _TRACE_SUB_WORKQUEUE, 0x24);
130 TRACE_CODE(wq_constrained_admission, _TRACE_SUB_WORKQUEUE, 0x25);
131 TRACE_CODE(wq_wqops_reqthreads, _TRACE_SUB_WORKQUEUE, 0x26);
132 TRACE_CODE(wq_kevent_reqthreads, _TRACE_SUB_WORKQUEUE, 0x27);
133 TRACE_CODE(wq_thread_park, _TRACE_SUB_WORKQUEUE, 0x28);
134 TRACE_CODE(wq_thread_squash, _TRACE_SUB_WORKQUEUE, 0x29);
135
136 // synch trace points
137 TRACE_CODE(psynch_mutex_ulock, _TRACE_SUB_MUTEX, 0x0);
138 TRACE_CODE(psynch_mutex_utrylock_failed, _TRACE_SUB_MUTEX, 0x1);
139 TRACE_CODE(psynch_mutex_uunlock, _TRACE_SUB_MUTEX, 0x2);
140 TRACE_CODE(psynch_ksyn_incorrect_owner, _TRACE_SUB_MUTEX, 0x3);
141 TRACE_CODE(psynch_mutex_lock_updatebits, _TRACE_SUB_MUTEX, 0x4);
142 TRACE_CODE(psynch_mutex_unlock_updatebits, _TRACE_SUB_MUTEX, 0x5);
143 TRACE_CODE(psynch_mutex_clearprepost, _TRACE_SUB_MUTEX, 0x6);
144 TRACE_CODE(psynch_mutex_kwqallocate, _TRACE_SUB_MUTEX, 0x7);
145 TRACE_CODE(psynch_mutex_kwqdeallocate, _TRACE_SUB_MUTEX, 0x8);
146 TRACE_CODE(psynch_mutex_kwqprepost, _TRACE_SUB_MUTEX, 0x9);
147 TRACE_CODE(psynch_mutex_markprepost, _TRACE_SUB_MUTEX, 0x10);
148 TRACE_CODE(psynch_mutex_kwqcollision, _TRACE_SUB_MUTEX, 0x11);
149 TRACE_CODE(psynch_ffmutex_lock_updatebits, _TRACE_SUB_MUTEX, 0x12);
150 TRACE_CODE(psynch_ffmutex_unlock_updatebits, _TRACE_SUB_MUTEX, 0x13);
151 TRACE_CODE(psynch_ffmutex_wake, _TRACE_SUB_MUTEX, 0x14);
152 TRACE_CODE(psynch_mutex_kwqsignal, _TRACE_SUB_MUTEX, 0x15);
153 TRACE_CODE(psynch_ffmutex_wait, _TRACE_SUB_MUTEX, 0x16);
154 TRACE_CODE(psynch_mutex_kwqwait, _TRACE_SUB_MUTEX, 0x17);
155
156 TRACE_CODE(psynch_cvar_kwait, _TRACE_SUB_CONDVAR, 0x0);
157 TRACE_CODE(psynch_cvar_clrprepost, _TRACE_SUB_CONDVAR, 0x1);
158 TRACE_CODE(psynch_cvar_freeitems, _TRACE_SUB_CONDVAR, 0x2);
159 TRACE_CODE(psynch_cvar_signal, _TRACE_SUB_CONDVAR, 0x3);
160 TRACE_CODE(psynch_cvar_broadcast, _TRACE_SUB_CONDVAR, 0x5);
161 TRACE_CODE(psynch_cvar_zeroed, _TRACE_SUB_CONDVAR, 0x6);
162 TRACE_CODE(psynch_cvar_updateval, _TRACE_SUB_CONDVAR, 0x7);
163
164 #endif // _KERN_TRACE_H_