]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kperf/buffer.h
2 * Copyright (c) 2011-2016 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 /* wrapper around kdebug */
31 #include <sys/kdebug.h>
34 #define PERF_CODE(SubClass, code) KDBG_CODE(DBG_PERF, SubClass, code)
36 /* broad sub-classes */
37 #define PERF_GENERIC (0)
38 #define PERF_THREADINFO (1)
39 #define PERF_CALLSTACK (2)
40 #define PERF_TIMER (3)
47 #define PERF_MEMINFO (10)
49 /* helpers for 32-bit */
50 #define UPPER_32(U64) ((U64) >> 32)
51 #define LOWER_32(U64) ((U64) & (UINT32_MAX))
52 #define ENCODE_UPPER_64(U32) (((uint64_t)(U32)) << 32)
53 #define ENCODE_LOWER_64(U32) (((uint64_t)(U32)) & (UINT32_MAX))
56 #define PERF_GEN_CODE(code) PERF_CODE(PERF_GENERIC, code)
57 #define PERF_GEN_EVENT PERF_GEN_CODE(0)
59 #define PERF_TI_CODE(code) PERF_CODE(PERF_THREADINFO, code)
60 #define PERF_TI_SAMPLE PERF_TI_CODE(0)
61 #define PERF_TI_DATA PERF_TI_CODE(1)
62 #define PERF_TI_XSAMPLE PERF_TI_CODE(2)
63 #define PERF_TI_XPEND PERF_TI_CODE(3)
64 #define PERF_TI_XDATA PERF_TI_CODE(4)
65 #define PERF_TI_CSWITCH PERF_TI_CODE(5)
66 #define PERF_TI_SCHEDSAMPLE PERF_TI_CODE(6)
67 #define PERF_TI_SCHEDDATA PERF_TI_CODE(7)
68 #define PERF_TI_SNAPSAMPLE PERF_TI_CODE(8)
69 #define PERF_TI_SNAPDATA PERF_TI_CODE(9)
70 #define PERF_TI_DISPSAMPLE PERF_TI_CODE(10)
71 #define PERF_TI_DISPDATA PERF_TI_CODE(11)
72 #define PERF_TI_DISPPEND PERF_TI_CODE(12)
73 #define PERF_TI_SNAPDATA_32 PERF_TI_CODE(13)
74 #define PERF_TI_DISPDATA_32 PERF_TI_CODE(14)
75 #define PERF_TI_SCHEDDATA1_32 PERF_TI_CODE(15)
76 #define PERF_TI_SCHEDDATA2_32 PERF_TI_CODE(16)
78 #define PERF_CS_CODE(code) PERF_CODE(PERF_CALLSTACK, code)
79 #define PERF_CS_KSAMPLE PERF_CS_CODE(0)
80 #define PERF_CS_UPEND PERF_CS_CODE(1)
81 #define PERF_CS_USAMPLE PERF_CS_CODE(2)
82 #define PERF_CS_KDATA PERF_CS_CODE(3)
83 #define PERF_CS_UDATA PERF_CS_CODE(4)
84 #define PERF_CS_KHDR PERF_CS_CODE(5)
85 #define PERF_CS_UHDR PERF_CS_CODE(6)
86 #define PERF_CS_ERROR PERF_CS_CODE(7)
87 #define PERF_CS_BACKTRACE PERF_CS_CODE(8)
88 #define PERF_CS_LOG PERF_CS_CODE(9)
90 #define PERF_TM_CODE(code) PERF_CODE(PERF_TIMER, code)
91 #define PERF_TM_FIRE PERF_TM_CODE(0)
92 #define PERF_TM_SCHED PERF_TM_CODE(1)
93 #define PERF_TM_HNDLR PERF_TM_CODE(2)
95 #define PERF_PET_CODE(code) PERF_CODE(PERF_PET, code)
96 #define PERF_PET_THREAD PERF_PET_CODE(0)
97 #define PERF_PET_ERROR PERF_PET_CODE(1)
98 #define PERF_PET_RUN PERF_PET_CODE(2)
99 #define PERF_PET_PAUSE PERF_PET_CODE(3)
100 #define PERF_PET_IDLE PERF_PET_CODE(4)
101 #define PERF_PET_SAMPLE PERF_PET_CODE(5)
102 #define PERF_PET_SCHED PERF_PET_CODE(6)
103 #define PERF_PET_END PERF_PET_CODE(7)
104 #define PERF_PET_SAMPLE_TASK PERF_PET_CODE(8)
105 #define PERF_PET_SAMPLE_THREAD PERF_PET_CODE(9)
107 #define PERF_AST_CODE(code) PERF_CODE(PERF_AST, code)
108 #define PERF_AST_HNDLR PERF_AST_CODE(0)
109 #define PERF_AST_ERROR PERF_AST_CODE(1)
111 #define PERF_KPC_CODE(code) PERF_CODE(PERF_KPC, code)
112 #define PERF_KPC_HNDLR PERF_KPC_CODE(0)
113 #define PERF_KPC_FCOUNTER PERF_KPC_CODE(1)
114 #define PERF_KPC_COUNTER PERF_KPC_CODE(2)
115 #define PERF_KPC_DATA PERF_KPC_CODE(3)
116 #define PERF_KPC_CONFIG PERF_KPC_CODE(4)
117 #define PERF_KPC_CFG_REG PERF_KPC_CODE(5)
118 #define PERF_KPC_DATA32 PERF_KPC_CODE(6)
119 #define PERF_KPC_CFG_REG32 PERF_KPC_CODE(7)
120 #define PERF_KPC_DATA_THREAD PERF_KPC_CODE(8)
121 #define PERF_KPC_DATA_THREAD32 PERF_KPC_CODE(9)
122 #define PERF_KPC_CPU_SAMPLE PERF_KPC_CODE(10)
123 #define PERF_KPC_THREAD_SAMPLE PERF_KPC_CODE(11)
125 #define PERF_KDBG_CODE(code) PERF_CODE(PERF_KDBG, code)
126 #define PERF_KDBG_HNDLR PERF_KDBG_CODE(0)
128 #define PERF_TK_CODE(code) PERF_CODE(PERF_TASK, code)
129 #define PERF_TK_SNAP_SAMPLE PERF_TK_CODE(0)
130 #define PERF_TK_SNAP_DATA PERF_TK_CODE(1)
131 #define PERF_TK_SNAP_DATA1_32 PERF_TK_CODE(2)
132 #define PERF_TK_SNAP_DATA2_32 PERF_TK_CODE(3)
134 #define PERF_MI_CODE(code) PERF_CODE(PERF_MEMINFO, code)
135 #define PERF_MI_SAMPLE PERF_MI_CODE(0)
136 #define PERF_MI_DATA PERF_MI_CODE(1)
138 /* error sub-codes for trace data */
149 /* level of kperf's logging to kdebug */
150 #define KPERF_DEBUG_DATA 0
151 #define KPERF_DEBUG_INFO 1
152 #define KPERF_DEBUG_VERBOSE 2
153 extern int kperf_debug_level
;
155 /* BUF_DATA tracepoints are for logging actual kperf results. */
157 #define BUF_DATA_INT(EVENTID, A0, A1, A2, A3) KERNEL_DEBUG_CONSTANT_IST(~KDEBUG_ENABLE_PPT, EVENTID, A0, A1, A2, A3, 0)
159 #define BUF_DATA(EVENTID, ...) BUF_DATA_(EVENTID, ## __VA_ARGS__, 4, 3, 2, 1, 0)
160 #define BUF_DATA_(EVENTID, A1, A2, A3, A4, N_ARGS, ...) BUF_DATA##N_ARGS(EVENTID, A1, A2, A3, A4)
161 #define BUF_DATA0(EVENTID, A1, A2, A3, A4) BUF_DATA_INT(EVENTID, 0, 0, 0, 0)
162 #define BUF_DATA1(EVENTID, A1, A2, A3, A4) BUF_DATA_INT(EVENTID, A1, 0, 0, 0)
163 #define BUF_DATA2(EVENTID, A1, A2, A3, A4) BUF_DATA_INT(EVENTID, A1, A2, 0, 0)
164 #define BUF_DATA3(EVENTID, A1, A2, A3, A4) BUF_DATA_INT(EVENTID, A1, A2, A3, 0)
165 #define BUF_DATA4(EVENTID, A1, A2, A3, A4) BUF_DATA_INT(EVENTID, A1, A2, A3, A4)
168 * BUF_INFO tracepoints are for logging debugging information relevant to
169 * testing kperf's internal functions.
172 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
173 #define BUF_INFO_INT(EVENTID, A1, A2, A3, A4) if (__improbable(kperf_debug_level >= KPERF_DEBUG_INFO)) KERNEL_DEBUG_CONSTANT(EVENTID, A1, A2, A3, A4, 0)
175 #define BUF_INFO_INT(EVENTID, A1, A2, A3, A4) do { (void)(EVENTID); (void)(A1); (void)(A2); (void)(A3); (void)(A4); } while ((0))
178 #define BUF_INFO(EVENTID, ...) BUF_INFO_(EVENTID, ## __VA_ARGS__, 4, 3, 2, 1, 0)
179 #define BUF_INFO_(EVENTID, A1, A2, A3, A4, N_ARGS, ...) BUF_INFO##N_ARGS(EVENTID, A1, A2, A3, A4)
180 #define BUF_INFO0(EVENTID, A1, A2, A3, A4) BUF_INFO_INT(EVENTID, 0, 0, 0, 0)
181 #define BUF_INFO1(EVENTID, A1, A2, A3, A4) BUF_INFO_INT(EVENTID, A1, 0, 0, 0)
182 #define BUF_INFO2(EVENTID, A1, A2, A3, A4) BUF_INFO_INT(EVENTID, A1, A2, 0, 0)
183 #define BUF_INFO3(EVENTID, A1, A2, A3, A4) BUF_INFO_INT(EVENTID, A1, A2, A3, 0)
184 #define BUF_INFO4(EVENTID, A1, A2, A3, A4) BUF_INFO_INT(EVENTID, A1, A2, A3, A4)
187 * BUF_VERB tracepoints are for logging precise details of kperf's
188 * internal functions, like timing information for samplers.
191 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
192 #define BUF_VERB_INT(EVENTID, A1, A2, A3, A4) if (__improbable(kperf_debug_level >= KPERF_DEBUG_VERBOSE)) KERNEL_DEBUG_CONSTANT(EVENTID, A1, A2, A3, A4, 0)
194 #define BUF_VERB_INT(EVENTID, A1, A2, A3, A4) do { (void)(EVENTID); (void)(A1); (void)(A2); (void)(A3); (void)(A4); } while ((0))
197 #define BUF_VERB(EVENTID, ...) BUF_VERB_(EVENTID, ## __VA_ARGS__, 4, 3, 2, 1, 0)
198 #define BUF_VERB_(EVENTID, A1, A2, A3, A4, N_ARGS, ...) BUF_VERB##N_ARGS(EVENTID, A1, A2, A3, A4)
199 #define BUF_VERB0(EVENTID, A1, A2, A3, A4) BUF_VERB_INT(EVENTID, 0, 0, 0, 0)
200 #define BUF_VERB1(EVENTID, A1, A2, A3, A4) BUF_VERB_INT(EVENTID, A1, 0, 0, 0)
201 #define BUF_VERB2(EVENTID, A1, A2, A3, A4) BUF_VERB_INT(EVENTID, A1, A2, 0, 0)
202 #define BUF_VERB3(EVENTID, A1, A2, A3, A4) BUF_VERB_INT(EVENTID, A1, A2, A3, 0)
203 #define BUF_VERB4(EVENTID, A1, A2, A3, A4) BUF_VERB_INT(EVENTID, A1, A2, A3, A4)