]> git.saurik.com Git - apple/libpthread.git/blob - kern/kern_trace.h
libpthread-301.50.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 # define _TRACE_SUB_MUTEX 2
43
44 #ifndef _PTHREAD_BUILDING_CODES_
45
46 #include <sys/kdebug.h>
47
48 #ifndef DBG_PTHREAD
49 #define DBG_PTHREAD DBG_WORKQUEUE
50 #endif
51
52 #if KERNEL
53 #include <vm/vm_kern.h>
54
55 extern uint32_t pthread_debug_tracing;
56
57 static __unused void*
58 VM_UNSLIDE(void* ptr)
59 {
60 vm_offset_t unslid_ptr;
61 vm_kernel_unslide_or_perm_external(ptr, &unslid_ptr);
62 return (void*)unslid_ptr;
63 }
64
65 # define PTHREAD_TRACE(x,a,b,c,d,e) \
66 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e); } }
67
68 # define PTHREAD_TRACE_WQ(x,a,b,c,d,e) \
69 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(x, VM_UNSLIDE(a), b, c, d, e); } }
70
71 # define PTHREAD_TRACE_WQ_REQ(x,a,b,c,d,e) \
72 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(x, VM_UNSLIDE(a), VM_UNSLIDE(b), c, d, e); } }
73
74 #else // KERNEL
75
76 #if ENABLE_USERSPACE_TRACE
77 # include <sys/kdebug.h>
78 # define PTHREAD_TRACE(x, a, b, c, d) kdebug_trace(TRACE_##x, a, b, c, d)
79 #else // ENABLE_USERSPACE_TRACE
80 # define PTHREAD_TRACE(x, a, b, c, d) do { } while(0)
81 #endif // ENABLE_USERSPACE_TRACE
82
83 #endif // KERNEL
84
85 # define TRACE_CODE(name, subclass, code) \
86 static const int TRACE_##name = KDBG_CODE(DBG_PTHREAD, subclass, code)
87
88 #else // _PTHREAD_BUILDING_CODES_
89 /* When not included as a header, this file is pre-processed into perl source to generate
90 * the pthread.codes file during build.
91 */
92 # define DBG_PTHREAD 9
93 # define STR(x) #x
94
95 # define TRACE_CODE(name, subclass, code) \
96 printf("0x%x\t%s\n", ((DBG_PTHREAD << 24) | ((subclass & 0xff) << 16) | ((code & 0x3fff) << 2)), STR(name))
97 #endif // _PTHREAD_BUILDING_CODES_
98
99 /* These defines translate into TRACE_<name> when used in source code, and are
100 * pre-processed out to a codes file by the build system.
101 */
102
103 // "default" trace points
104 TRACE_CODE(pthread_thread_create, _TRACE_SUB_DEFAULT, 0x10);
105 TRACE_CODE(pthread_thread_terminate, _TRACE_SUB_DEFAULT, 0x20);
106 TRACE_CODE(pthread_set_qos_self, _TRACE_SUB_DEFAULT, 0x30);
107
108 // workqueue trace points
109 TRACE_CODE(wq_pthread_exit, _TRACE_SUB_WORKQUEUE, 0x01);
110 TRACE_CODE(wq_workqueue_exit, _TRACE_SUB_WORKQUEUE, 0x02);
111 TRACE_CODE(wq_runthread, _TRACE_SUB_WORKQUEUE, 0x03);
112 TRACE_CODE(wq_runitem, _TRACE_SUB_WORKQUEUE, 0x04);
113 TRACE_CODE(wq_thread_block, _TRACE_SUB_WORKQUEUE, 0x9);
114 TRACE_CODE(wq_thactive_update, _TRACE_SUB_WORKQUEUE, 0xa);
115 TRACE_CODE(wq_add_timer, _TRACE_SUB_WORKQUEUE, 0xb);
116 TRACE_CODE(wq_start_add_timer, _TRACE_SUB_WORKQUEUE, 0x0c);
117 TRACE_CODE(wq_override_start, _TRACE_SUB_WORKQUEUE, 0x12);
118 TRACE_CODE(wq_override_end, _TRACE_SUB_WORKQUEUE, 0x13);
119 TRACE_CODE(wq_override_dispatch, _TRACE_SUB_WORKQUEUE, 0x14);
120 TRACE_CODE(wq_override_reset, _TRACE_SUB_WORKQUEUE, 0x15);
121 TRACE_CODE(wq_thread_create_failed, _TRACE_SUB_WORKQUEUE, 0x1d);
122 TRACE_CODE(wq_thread_create, _TRACE_SUB_WORKQUEUE, 0x1f);
123 TRACE_CODE(wq_run_threadreq, _TRACE_SUB_WORKQUEUE, 0x20);
124 TRACE_CODE(wq_run_threadreq_mgr_merge, _TRACE_SUB_WORKQUEUE, 0x21);
125 TRACE_CODE(wq_run_threadreq_req_select, _TRACE_SUB_WORKQUEUE, 0x22);
126 TRACE_CODE(wq_run_threadreq_thread_select, _TRACE_SUB_WORKQUEUE, 0x23);
127 TRACE_CODE(wq_thread_reset_priority, _TRACE_SUB_WORKQUEUE, 0x24);
128 TRACE_CODE(wq_constrained_admission, _TRACE_SUB_WORKQUEUE, 0x25);
129 TRACE_CODE(wq_wqops_reqthreads, _TRACE_SUB_WORKQUEUE, 0x26);
130 TRACE_CODE(wq_kevent_reqthreads, _TRACE_SUB_WORKQUEUE, 0x27);
131 TRACE_CODE(wq_thread_park, _TRACE_SUB_WORKQUEUE, 0x28);
132 TRACE_CODE(wq_thread_squash, _TRACE_SUB_WORKQUEUE, 0x29);
133
134 // synch trace points
135 TRACE_CODE(psynch_mutex_ulock, _TRACE_SUB_MUTEX, 0x0);
136 TRACE_CODE(psynch_mutex_utrylock_failed, _TRACE_SUB_MUTEX, 0x1);
137 TRACE_CODE(psynch_mutex_uunlock, _TRACE_SUB_MUTEX, 0x2);
138 TRACE_CODE(psynch_ksyn_incorrect_owner, _TRACE_SUB_MUTEX, 0x3);
139 TRACE_CODE(psynch_mutex_lock_updatebits, _TRACE_SUB_MUTEX, 0x4);
140 TRACE_CODE(psynch_mutex_unlock_updatebits, _TRACE_SUB_MUTEX, 0x5);
141
142 #endif // _KERN_TRACE_H_