]> git.saurik.com Git - apple/libpthread.git/blame - kern/kern_trace.h
libpthread-416.11.1.tar.gz
[apple/libpthread.git] / kern / kern_trace.h
CommitLineData
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
f1a1da6c
A
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
2546420a
A
55#include <vm/vm_kern.h>
56
f1a1da6c
A
57extern uint32_t pthread_debug_tracing;
58
2546420a
A
59static __unused void*
60VM_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
214d78a2
A
67# define PTHREAD_TRACE(x,a,b,c,d) \
68 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(TRACE_##x, a, b, c, d, 0); } }
f1a1da6c 69
214d78a2
A
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); } }
2546420a 72
a0619f9c 73# define PTHREAD_TRACE_WQ_REQ(x,a,b,c,d,e) \
214d78a2 74 { if (pthread_debug_tracing) { KERNEL_DEBUG_CONSTANT(TRACE_##x, VM_UNSLIDE(a), VM_UNSLIDE(b), c, d, e); } }
a0619f9c 75
76b7b9a2
A
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
2546420a 86
f1a1da6c
A
87# define TRACE_CODE(name, subclass, code) \
88 static const int TRACE_##name = KDBG_CODE(DBG_PTHREAD, subclass, code)
89
76b7b9a2 90#else // _PTHREAD_BUILDING_CODES_
f1a1da6c
A
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))
76b7b9a2 99#endif // _PTHREAD_BUILDING_CODES_
f1a1da6c
A
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
106TRACE_CODE(pthread_thread_create, _TRACE_SUB_DEFAULT, 0x10);
107TRACE_CODE(pthread_thread_terminate, _TRACE_SUB_DEFAULT, 0x20);
108TRACE_CODE(pthread_set_qos_self, _TRACE_SUB_DEFAULT, 0x30);
109
110// workqueue trace points
111TRACE_CODE(wq_pthread_exit, _TRACE_SUB_WORKQUEUE, 0x01);
112TRACE_CODE(wq_workqueue_exit, _TRACE_SUB_WORKQUEUE, 0x02);
a0619f9c 113TRACE_CODE(wq_runthread, _TRACE_SUB_WORKQUEUE, 0x03);
f1a1da6c 114TRACE_CODE(wq_runitem, _TRACE_SUB_WORKQUEUE, 0x04);
f1a1da6c 115TRACE_CODE(wq_thread_block, _TRACE_SUB_WORKQUEUE, 0x9);
a0619f9c 116TRACE_CODE(wq_thactive_update, _TRACE_SUB_WORKQUEUE, 0xa);
f1a1da6c
A
117TRACE_CODE(wq_add_timer, _TRACE_SUB_WORKQUEUE, 0xb);
118TRACE_CODE(wq_start_add_timer, _TRACE_SUB_WORKQUEUE, 0x0c);
f1a1da6c
A
119TRACE_CODE(wq_override_start, _TRACE_SUB_WORKQUEUE, 0x12);
120TRACE_CODE(wq_override_end, _TRACE_SUB_WORKQUEUE, 0x13);
121TRACE_CODE(wq_override_dispatch, _TRACE_SUB_WORKQUEUE, 0x14);
122TRACE_CODE(wq_override_reset, _TRACE_SUB_WORKQUEUE, 0x15);
964d3577 123TRACE_CODE(wq_thread_create_failed, _TRACE_SUB_WORKQUEUE, 0x1d);
2546420a 124TRACE_CODE(wq_thread_create, _TRACE_SUB_WORKQUEUE, 0x1f);
a0619f9c
A
125TRACE_CODE(wq_run_threadreq, _TRACE_SUB_WORKQUEUE, 0x20);
126TRACE_CODE(wq_run_threadreq_mgr_merge, _TRACE_SUB_WORKQUEUE, 0x21);
127TRACE_CODE(wq_run_threadreq_req_select, _TRACE_SUB_WORKQUEUE, 0x22);
128TRACE_CODE(wq_run_threadreq_thread_select, _TRACE_SUB_WORKQUEUE, 0x23);
129TRACE_CODE(wq_thread_reset_priority, _TRACE_SUB_WORKQUEUE, 0x24);
130TRACE_CODE(wq_constrained_admission, _TRACE_SUB_WORKQUEUE, 0x25);
131TRACE_CODE(wq_wqops_reqthreads, _TRACE_SUB_WORKQUEUE, 0x26);
132TRACE_CODE(wq_kevent_reqthreads, _TRACE_SUB_WORKQUEUE, 0x27);
133TRACE_CODE(wq_thread_park, _TRACE_SUB_WORKQUEUE, 0x28);
134TRACE_CODE(wq_thread_squash, _TRACE_SUB_WORKQUEUE, 0x29);
f1a1da6c
A
135
136// synch trace points
137TRACE_CODE(psynch_mutex_ulock, _TRACE_SUB_MUTEX, 0x0);
138TRACE_CODE(psynch_mutex_utrylock_failed, _TRACE_SUB_MUTEX, 0x1);
139TRACE_CODE(psynch_mutex_uunlock, _TRACE_SUB_MUTEX, 0x2);
140TRACE_CODE(psynch_ksyn_incorrect_owner, _TRACE_SUB_MUTEX, 0x3);
76b7b9a2
A
141TRACE_CODE(psynch_mutex_lock_updatebits, _TRACE_SUB_MUTEX, 0x4);
142TRACE_CODE(psynch_mutex_unlock_updatebits, _TRACE_SUB_MUTEX, 0x5);
214d78a2
A
143TRACE_CODE(psynch_mutex_clearprepost, _TRACE_SUB_MUTEX, 0x6);
144TRACE_CODE(psynch_mutex_kwqallocate, _TRACE_SUB_MUTEX, 0x7);
145TRACE_CODE(psynch_mutex_kwqdeallocate, _TRACE_SUB_MUTEX, 0x8);
146TRACE_CODE(psynch_mutex_kwqprepost, _TRACE_SUB_MUTEX, 0x9);
147TRACE_CODE(psynch_mutex_markprepost, _TRACE_SUB_MUTEX, 0x10);
148TRACE_CODE(psynch_mutex_kwqcollision, _TRACE_SUB_MUTEX, 0x11);
149TRACE_CODE(psynch_ffmutex_lock_updatebits, _TRACE_SUB_MUTEX, 0x12);
150TRACE_CODE(psynch_ffmutex_unlock_updatebits, _TRACE_SUB_MUTEX, 0x13);
151TRACE_CODE(psynch_ffmutex_wake, _TRACE_SUB_MUTEX, 0x14);
152TRACE_CODE(psynch_mutex_kwqsignal, _TRACE_SUB_MUTEX, 0x15);
153TRACE_CODE(psynch_ffmutex_wait, _TRACE_SUB_MUTEX, 0x16);
154TRACE_CODE(psynch_mutex_kwqwait, _TRACE_SUB_MUTEX, 0x17);
155
156TRACE_CODE(psynch_cvar_kwait, _TRACE_SUB_CONDVAR, 0x0);
157TRACE_CODE(psynch_cvar_clrprepost, _TRACE_SUB_CONDVAR, 0x1);
158TRACE_CODE(psynch_cvar_freeitems, _TRACE_SUB_CONDVAR, 0x2);
159TRACE_CODE(psynch_cvar_signal, _TRACE_SUB_CONDVAR, 0x3);
160TRACE_CODE(psynch_cvar_broadcast, _TRACE_SUB_CONDVAR, 0x5);
161TRACE_CODE(psynch_cvar_zeroed, _TRACE_SUB_CONDVAR, 0x6);
162TRACE_CODE(psynch_cvar_updateval, _TRACE_SUB_CONDVAR, 0x7);
f1a1da6c
A
163
164#endif // _KERN_TRACE_H_