]> git.saurik.com Git - apple/libpthread.git/blob - kern/kern_trace.h
libpthread-218.51.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 // pthread tracing subclasses
37 # define _TRACE_SUB_DEFAULT 0
38 # define _TRACE_SUB_WORKQUEUE 1
39 # define _TRACE_SUB_MUTEX 2
40
41 #ifndef _PTHREAD_BUILDING_CODES_
42
43 #include <sys/kdebug.h>
44
45 #ifndef DBG_PTHREAD
46 #define DBG_PTHREAD DBG_WORKQUEUE
47 #endif
48
49 #if KERNEL
50 #include <vm/vm_kern.h>
51
52 extern uint32_t pthread_debug_tracing;
53
54 static __unused void*
55 VM_UNSLIDE(void* ptr)
56 {
57 vm_offset_t unslid_ptr;
58 vm_kernel_unslide_or_perm_external(ptr, &unslid_ptr);
59 return (void*)unslid_ptr;
60 }
61
62 # define PTHREAD_TRACE(x,a,b,c,d,e) \
63 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e); } }
64
65 # define PTHREAD_TRACE1(x,a,b,c,d,e) \
66 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e); } }
67 #endif
68
69 # define PTHREAD_TRACE_WQ(x,a,b,c,d,e) \
70 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(x, VM_UNSLIDE(a), b, c, d, e); } }
71
72 # define PTHREAD_TRACE1_WQ(x,a,b,c,d,e) \
73 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT1(x, VM_UNSLIDE(a), b, c, d, e); } }
74
75 # define TRACE_CODE(name, subclass, code) \
76 static const int TRACE_##name = KDBG_CODE(DBG_PTHREAD, subclass, code)
77
78 #else
79 /* When not included as a header, this file is pre-processed into perl source to generate
80 * the pthread.codes file during build.
81 */
82 # define DBG_PTHREAD 9
83 # define STR(x) #x
84
85 # define TRACE_CODE(name, subclass, code) \
86 printf("0x%x\t%s\n", ((DBG_PTHREAD << 24) | ((subclass & 0xff) << 16) | ((code & 0x3fff) << 2)), STR(name))
87 #endif
88
89 /* These defines translate into TRACE_<name> when used in source code, and are
90 * pre-processed out to a codes file by the build system.
91 */
92
93 // "default" trace points
94 TRACE_CODE(pthread_thread_create, _TRACE_SUB_DEFAULT, 0x10);
95 TRACE_CODE(pthread_thread_terminate, _TRACE_SUB_DEFAULT, 0x20);
96 TRACE_CODE(pthread_set_qos_self, _TRACE_SUB_DEFAULT, 0x30);
97
98 // workqueue trace points
99 TRACE_CODE(wq_pthread_exit, _TRACE_SUB_WORKQUEUE, 0x01);
100 TRACE_CODE(wq_workqueue_exit, _TRACE_SUB_WORKQUEUE, 0x02);
101 TRACE_CODE(wq_run_nextitem, _TRACE_SUB_WORKQUEUE, 0x03);
102 TRACE_CODE(wq_runitem, _TRACE_SUB_WORKQUEUE, 0x04);
103 TRACE_CODE(wq_req_threads, _TRACE_SUB_WORKQUEUE, 0x05);
104 TRACE_CODE(wq_req_octhreads, _TRACE_SUB_WORKQUEUE, 0x06);
105 TRACE_CODE(wq_thread_suspend, _TRACE_SUB_WORKQUEUE, 0x07);
106 TRACE_CODE(wq_thread_park, _TRACE_SUB_WORKQUEUE, 0x08);
107 TRACE_CODE(wq_thread_block, _TRACE_SUB_WORKQUEUE, 0x9);
108 TRACE_CODE(wq_new_max_scheduled, _TRACE_SUB_WORKQUEUE, 0xa);
109 TRACE_CODE(wq_add_timer, _TRACE_SUB_WORKQUEUE, 0xb);
110 TRACE_CODE(wq_start_add_timer, _TRACE_SUB_WORKQUEUE, 0x0c);
111 TRACE_CODE(wq_stalled, _TRACE_SUB_WORKQUEUE, 0x0d);
112 TRACE_CODE(wq_reset_priority, _TRACE_SUB_WORKQUEUE, 0x0e);
113 TRACE_CODE(wq_thread_yielded, _TRACE_SUB_WORKQUEUE, 0x0f);
114 TRACE_CODE(wq_delay_octhreads, _TRACE_SUB_WORKQUEUE, 0x10);
115 TRACE_CODE(wq_overcommitted, _TRACE_SUB_WORKQUEUE, 0x11);
116 TRACE_CODE(wq_override_start, _TRACE_SUB_WORKQUEUE, 0x12);
117 TRACE_CODE(wq_override_end, _TRACE_SUB_WORKQUEUE, 0x13);
118 TRACE_CODE(wq_override_dispatch, _TRACE_SUB_WORKQUEUE, 0x14);
119 TRACE_CODE(wq_override_reset, _TRACE_SUB_WORKQUEUE, 0x15);
120 TRACE_CODE(wq_req_event_manager, _TRACE_SUB_WORKQUEUE, 0x16);
121 TRACE_CODE(wq_kevent_req_threads, _TRACE_SUB_WORKQUEUE, 0x17);
122 TRACE_CODE(wq_req_kevent_threads, _TRACE_SUB_WORKQUEUE, 0x18);
123 TRACE_CODE(wq_req_kevent_octhreads, _TRACE_SUB_WORKQUEUE, 0x19);
124 TRACE_CODE(wq_thread_limit_exceeded, _TRACE_SUB_WORKQUEUE, 0x1a);
125 TRACE_CODE(wq_thread_constrained_maxed, _TRACE_SUB_WORKQUEUE, 0x1b);
126 TRACE_CODE(wq_thread_add_during_exit, _TRACE_SUB_WORKQUEUE, 0x1c);
127 TRACE_CODE(wq_thread_create_failed, _TRACE_SUB_WORKQUEUE, 0x1d);
128 TRACE_CODE(wq_manager_request, _TRACE_SUB_WORKQUEUE, 0x1e);
129 TRACE_CODE(wq_thread_create, _TRACE_SUB_WORKQUEUE, 0x1f);
130
131 // synch trace points
132 TRACE_CODE(psynch_mutex_ulock, _TRACE_SUB_MUTEX, 0x0);
133 TRACE_CODE(psynch_mutex_utrylock_failed, _TRACE_SUB_MUTEX, 0x1);
134 TRACE_CODE(psynch_mutex_uunlock, _TRACE_SUB_MUTEX, 0x2);
135 TRACE_CODE(psynch_ksyn_incorrect_owner, _TRACE_SUB_MUTEX, 0x3);
136
137 #endif // _KERN_TRACE_H_