2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
32 * Contains ETAP buffer and table definitions
39 #include <mach/machine/boolean.h>
40 #include <mach/etap_events.h>
41 #include <mach/clock_types.h>
42 #include <mach/time_value.h>
43 #include <mach/kern_return.h>
46 #define ETAP_CBUFF_ENTRIES 20000
47 #define ETAP_CBUFF_IBUCKETS 10
48 #define ETAP_CBUFF_WIDTH 80
50 #define ETAP_MBUFF_ENTRIES 28000
51 #define ETAP_MBUFF_DATASIZE 4
54 /* ===================================
55 * Event & Subsystem Table Definitions
56 * ===================================
59 #define EVENT_NAME_LENGTH 20 /* max event name size */
61 struct event_table_entry
{
62 unsigned short event
; /* etap event type */
63 unsigned short status
; /* event trace status */
64 char name
[EVENT_NAME_LENGTH
]; /* event text name */
65 unsigned short dynamic
; /* dynamic ID (0=none) */
68 struct subs_table_entry
{
69 unsigned short subs
; /* etap subsystem type */
70 char name
[EVENT_NAME_LENGTH
]; /* subsystem text name */
73 typedef struct event_table_entry
* event_table_t
;
74 typedef struct subs_table_entry
* subs_table_t
;
75 typedef unsigned short etap_event_t
;
77 #define EVENT_TABLE_NULL ((event_table_t) 0)
84 typedef mach_timespec_t etap_time_t
;
86 /* =============================
87 * Cumulative buffer definitions
88 * =============================
92 * The cbuff_data structure contains cumulative lock
93 * statistical information for EITHER hold operations
98 unsigned long triggered
; /* number of event occurances */
99 etap_time_t time
; /* sum of event durations */
100 etap_time_t time_sq
; /* sum of squared durations */
101 etap_time_t min_time
; /* min duration of event */
102 etap_time_t max_time
; /* max duration of event */
106 * The cbuff_entry contains all trace data for an event.
107 * The cumulative buffer consists of these entries.
111 etap_event_t event
; /* event type */
112 unsigned short kind
; /* read,write,or simple */
113 unsigned int instance
; /* & of event struct */
114 struct cbuff_data hold
; /* hold trace data */
115 struct cbuff_data wait
; /* wait trace data */
116 unsigned long hold_interval
[ETAP_CBUFF_IBUCKETS
]; /* hold interval array */
117 unsigned long wait_interval
[ETAP_CBUFF_IBUCKETS
]; /* wait interval array */
120 typedef struct cbuff_entry
* cbuff_entry_t
;
122 #define CBUFF_ENTRY_NULL ((cbuff_entry_t)0)
125 * The cumulative buffer maintains a header which is used by
126 * both the kernel instrumentation and the ETAP user-utilities.
129 struct cumulative_buffer
{
130 unsigned long next
; /* next available entry in buffer */
131 unsigned short static_start
; /* first static entry in buffer */
132 struct cbuff_entry entry
[ETAP_CBUFF_ENTRIES
]; /* buffer entries */
135 typedef struct cumulative_buffer
* cumulative_buffer_t
;
138 /* ===========================
139 * ETAP probe data definitions
140 * ===========================
143 typedef unsigned int etap_data_t
[ETAP_MBUFF_DATASIZE
];
145 #define ETAP_DATA_ENTRY sizeof(unsigned int)
146 #define ETAP_DATA_SIZE ETAP_DATA_ENTRY * ETAP_MBUFF_DATASIZE
147 #define ETAP_DATA_NULL (etap_data_t*) 0
149 /* ==========================
150 * Monitor buffer definitions
151 * ==========================
155 * The mbuff_entry structure contains trace event instance data.
159 unsigned short event
; /* event type */
160 unsigned short flags
; /* event strain flags */
161 unsigned int instance
; /* address of event (lock, thread, etc.) */
162 unsigned int pc
; /* program counter */
163 etap_time_t time
; /* operation time */
164 etap_data_t data
; /* event specific data */
167 typedef struct mbuff_entry
* mbuff_entry_t
;
170 * Each circular monitor buffer will contain maintanence
171 * information and mon_entry records.
174 struct monitor_buffer
{
175 unsigned long free
; /* index of next available record */
176 unsigned long timestamp
; /* timestamp of last wrap around */
177 struct mbuff_entry entry
[1]; /* buffer entries (holder) */
180 typedef struct monitor_buffer
* monitor_buffer_t
;
183 /* ===================
184 * Event strains/flags
185 * ===================
186 */ /* | |t|b|e|k|u|m|s|r|w| | | | | */
187 /* ----------------------------- */
188 #define WRITE_LOCK 0x10 /* | | | | | | | | | |1| | | | | */
189 #define READ_LOCK 0x20 /* | | | | | | | | |1| | | | | | */
190 #define COMPLEX_LOCK 0x30 /* | | | | | | | | |1|1| | | | | */
191 #define SPIN_LOCK 0x40 /* | | | | | | | |1| | | | | | | */
192 #define MUTEX_LOCK 0x80 /* | | | | | | |1| | | | | | | | */
193 #define USER_EVENT 0x100 /* | | | | | |1| | | | | | | | | */
194 #define KERNEL_EVENT 0x200 /* | | | | |1| | | | | | | | | | */
195 #define EVENT_END 0x400 /* | | | |1| | | | | | | | | | | */
196 #define EVENT_BEGIN 0x800 /* | | |1| | | | | | | | | | | | */
197 #define SYSCALL_TRAP 0x1000 /* | |1| | | | | | | | | | | | | */
200 /* =========================
201 * Event trace status values
202 * =========================
203 */ /* | | | | | | | | | | |M|M|C|C| */
204 /* | | | | | | | | | | |d|c|d|c| */
205 /* ----------------------------- */
206 #define CUM_CONTENTION 0x1 /* | | | | | | | | | | | | | |1| */
207 #define CUM_DURATION 0x2 /* | | | | | | | | | | | | |1| | */
208 #define MON_CONTENTION 0x4 /* | | | | | | | | | | | |1| | | */
209 #define MON_DURATION 0x8 /* | | | | | | | | | | |1| | | | */
211 #define ETAP_TRACE_ON 0xf /* | | | | | | | | | | |1|1|1|1| */
212 #define ETAP_TRACE_OFF 0x0 /* | | | | | | | | | | | | | | | */
215 /* ==================
222 #define ETAP_CUMULATIVE 0x3 /* | | | | | | | | | | | | |1|1| */
223 #define ETAP_MONITORED 0xc /* | | | | | | | | | | |1|1| | | */
224 #define ETAP_RESET 0xf0f0
228 #define ETAP_CONTENTION 0x5 /* | | | | | | | | | | | |1| |1| */
229 #define ETAP_DURATION 0xa /* | | | | | | | | | | |1| |1| | */
232 /* ===============================
233 * Buffer/Table flavor definitions
234 * ===============================
237 #define ETAP_TABLE_EVENT 0
238 #define ETAP_TABLE_SUBSYSTEM 1
239 #define ETAP_BUFFER_CUMULATIVE 2
240 #define ETAP_BUFFER_MONITORED 3
242 /* ==========================
243 * ETAP function declarations
244 * ==========================
248 kern_return_t
etap_trace_event(
253 unsigned short args
[]);
256 kern_return_t
etap_probe(
257 unsigned short eventno
,
258 unsigned short event_id
,
259 unsigned int data_size
,
262 /* =================================================================
263 * convienience user probe macro - only used if DO_PROBE is #defined
264 * =================================================================
267 #define PROBE_DATA(subsys, tag, data0, data1, data2, data3) \
270 _mmmm[0] = (u_int)data0; \
271 _mmmm[1] = (u_int)data1; \
272 _mmmm[2] = (u_int)data2; \
273 _mmmm[3] = (u_int)data3; \
274 etap_probe(subsys, tag, sizeof (etap_data_t), &_mmmm); \
277 #define PROBE_DATA(type, tag, data0, data1, data2, data3)
278 #endif /* DO_PROBE */
279 #endif /* _MACH_ETAP_H_ */