2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _KERN_TRACE_H_
30 #define _KERN_TRACE_H_
32 /* pthread kext, or userspace, kdebug trace points. Defined here and output to
33 * /usr/share/misc/pthread.codes during build.
36 // userspace trace points force slow-paths, so must be compiled in
37 #define ENABLE_USERSPACE_TRACE 0
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 # define _TRACE_SUB_ULMUTEX 5
46 # define _TRACE_SUB_ULCOND 6
48 #ifndef _PTHREAD_BUILDING_CODES_
50 #include <sys/kdebug.h>
53 #define DBG_PTHREAD DBG_WORKQUEUE
57 #include <vm/vm_kern.h>
59 extern uint32_t pthread_debug_tracing
;
64 vm_offset_t unslid_ptr
;
65 vm_kernel_unslide_or_perm_external(ptr
, &unslid_ptr
);
66 return (void*)unslid_ptr
;
69 # define PTHREAD_TRACE(x,a,b,c,d) \
70 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(TRACE_##x, a, b, c, d, 0); } }
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
83 # define TRACE_CODE(name, subclass, code) \
84 static const int TRACE_##name = KDBG_CODE(DBG_PTHREAD, subclass, code)
86 #else // _PTHREAD_BUILDING_CODES_
87 /* When not included as a header, this file is pre-processed into perl source to generate
88 * the pthread.codes file during build.
90 # define DBG_PTHREAD 9
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))
95 #endif // _PTHREAD_BUILDING_CODES_
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.
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);
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);
111 TRACE_CODE(psynch_mutex_lock_updatebits
, _TRACE_SUB_MUTEX
, 0x4);
112 TRACE_CODE(psynch_mutex_unlock_updatebits
, _TRACE_SUB_MUTEX
, 0x5);
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);
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);
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);
141 TRACE_CODE(ulcond_wait
, _TRACE_SUB_ULCOND
, 0x0);
142 TRACE_CODE(ulcond_signal
, _TRACE_SUB_ULCOND
, 0x1);
144 #endif // _KERN_TRACE_H_