2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
29 * Contains ETAP buffer and table definitions
36 #include <mach/machine/boolean.h>
37 #include <mach/etap_events.h>
38 #include <mach/clock_types.h>
39 #include <mach/time_value.h>
40 #include <mach/kern_return.h>
43 #define ETAP_CBUFF_ENTRIES 20000
44 #define ETAP_CBUFF_IBUCKETS 10
45 #define ETAP_CBUFF_WIDTH 80
47 #define ETAP_MBUFF_ENTRIES 28000
48 #define ETAP_MBUFF_DATASIZE 4
51 /* ===================================
52 * Event & Subsystem Table Definitions
53 * ===================================
56 #define EVENT_NAME_LENGTH 20 /* max event name size */
58 struct event_table_entry
{
59 unsigned short event
; /* etap event type */
60 unsigned short status
; /* event trace status */
61 char name
[EVENT_NAME_LENGTH
]; /* event text name */
62 unsigned short dynamic
; /* dynamic ID (0=none) */
65 struct subs_table_entry
{
66 unsigned short subs
; /* etap subsystem type */
67 char name
[EVENT_NAME_LENGTH
]; /* subsystem text name */
70 typedef struct event_table_entry
* event_table_t
;
71 typedef struct subs_table_entry
* subs_table_t
;
72 typedef unsigned short etap_event_t
;
74 #define EVENT_TABLE_NULL ((event_table_t) 0)
81 typedef mach_timespec_t etap_time_t
;
83 /* =============================
84 * Cumulative buffer definitions
85 * =============================
89 * The cbuff_data structure contains cumulative lock
90 * statistical information for EITHER hold operations
95 unsigned long triggered
; /* number of event occurances */
96 etap_time_t time
; /* sum of event durations */
97 etap_time_t time_sq
; /* sum of squared durations */
98 etap_time_t min_time
; /* min duration of event */
99 etap_time_t max_time
; /* max duration of event */
103 * The cbuff_entry contains all trace data for an event.
104 * The cumulative buffer consists of these entries.
108 etap_event_t event
; /* event type */
109 unsigned short kind
; /* read,write,or simple */
110 unsigned int instance
; /* & of event struct */
111 struct cbuff_data hold
; /* hold trace data */
112 struct cbuff_data wait
; /* wait trace data */
113 unsigned long hold_interval
[ETAP_CBUFF_IBUCKETS
]; /* hold interval array */
114 unsigned long wait_interval
[ETAP_CBUFF_IBUCKETS
]; /* wait interval array */
117 typedef struct cbuff_entry
* cbuff_entry_t
;
119 #define CBUFF_ENTRY_NULL ((cbuff_entry_t)0)
122 * The cumulative buffer maintains a header which is used by
123 * both the kernel instrumentation and the ETAP user-utilities.
126 struct cumulative_buffer
{
127 unsigned long next
; /* next available entry in buffer */
128 unsigned short static_start
; /* first static entry in buffer */
129 struct cbuff_entry entry
[ETAP_CBUFF_ENTRIES
]; /* buffer entries */
132 typedef struct cumulative_buffer
* cumulative_buffer_t
;
135 /* ===========================
136 * ETAP probe data definitions
137 * ===========================
140 typedef unsigned int etap_data_t
[ETAP_MBUFF_DATASIZE
];
142 #define ETAP_DATA_ENTRY sizeof(unsigned int)
143 #define ETAP_DATA_SIZE ETAP_DATA_ENTRY * ETAP_MBUFF_DATASIZE
144 #define ETAP_DATA_NULL (etap_data_t*) 0
146 /* ==========================
147 * Monitor buffer definitions
148 * ==========================
152 * The mbuff_entry structure contains trace event instance data.
156 unsigned short event
; /* event type */
157 unsigned short flags
; /* event strain flags */
158 unsigned int instance
; /* address of event (lock, thread, etc.) */
159 unsigned int pc
; /* program counter */
160 etap_time_t time
; /* operation time */
161 etap_data_t data
; /* event specific data */
164 typedef struct mbuff_entry
* mbuff_entry_t
;
167 * Each circular monitor buffer will contain maintanence
168 * information and mon_entry records.
171 struct monitor_buffer
{
172 unsigned long free
; /* index of next available record */
173 unsigned long timestamp
; /* timestamp of last wrap around */
174 struct mbuff_entry entry
[1]; /* buffer entries (holder) */
177 typedef struct monitor_buffer
* monitor_buffer_t
;
180 /* ===================
181 * Event strains/flags
182 * ===================
183 */ /* | |t|b|e|k|u|m|s|r|w| | | | | */
184 /* ----------------------------- */
185 #define WRITE_LOCK 0x10 /* | | | | | | | | | |1| | | | | */
186 #define READ_LOCK 0x20 /* | | | | | | | | |1| | | | | | */
187 #define COMPLEX_LOCK 0x30 /* | | | | | | | | |1|1| | | | | */
188 #define SPIN_LOCK 0x40 /* | | | | | | | |1| | | | | | | */
189 #define MUTEX_LOCK 0x80 /* | | | | | | |1| | | | | | | | */
190 #define USER_EVENT 0x100 /* | | | | | |1| | | | | | | | | */
191 #define KERNEL_EVENT 0x200 /* | | | | |1| | | | | | | | | | */
192 #define EVENT_END 0x400 /* | | | |1| | | | | | | | | | | */
193 #define EVENT_BEGIN 0x800 /* | | |1| | | | | | | | | | | | */
194 #define SYSCALL_TRAP 0x1000 /* | |1| | | | | | | | | | | | | */
197 /* =========================
198 * Event trace status values
199 * =========================
200 */ /* | | | | | | | | | | |M|M|C|C| */
201 /* | | | | | | | | | | |d|c|d|c| */
202 /* ----------------------------- */
203 #define CUM_CONTENTION 0x1 /* | | | | | | | | | | | | | |1| */
204 #define CUM_DURATION 0x2 /* | | | | | | | | | | | | |1| | */
205 #define MON_CONTENTION 0x4 /* | | | | | | | | | | | |1| | | */
206 #define MON_DURATION 0x8 /* | | | | | | | | | | |1| | | | */
208 #define ETAP_TRACE_ON 0xf /* | | | | | | | | | | |1|1|1|1| */
209 #define ETAP_TRACE_OFF 0x0 /* | | | | | | | | | | | | | | | */
212 /* ==================
219 #define ETAP_CUMULATIVE 0x3 /* | | | | | | | | | | | | |1|1| */
220 #define ETAP_MONITORED 0xc /* | | | | | | | | | | |1|1| | | */
221 #define ETAP_RESET 0xf0f0
225 #define ETAP_CONTENTION 0x5 /* | | | | | | | | | | | |1| |1| */
226 #define ETAP_DURATION 0xa /* | | | | | | | | | | |1| |1| | */
229 /* ===============================
230 * Buffer/Table flavor definitions
231 * ===============================
234 #define ETAP_TABLE_EVENT 0
235 #define ETAP_TABLE_SUBSYSTEM 1
236 #define ETAP_BUFFER_CUMULATIVE 2
237 #define ETAP_BUFFER_MONITORED 3
239 /* ==========================
240 * ETAP function declarations
241 * ==========================
245 kern_return_t
etap_trace_event(
250 unsigned short args
[]);
253 kern_return_t
etap_probe(
254 unsigned short eventno
,
255 unsigned short event_id
,
256 unsigned int data_size
,
259 /* =================================================================
260 * convienience user probe macro - only used if DO_PROBE is #defined
261 * =================================================================
264 #define PROBE_DATA(subsys, tag, data0, data1, data2, data3) \
267 _mmmm[0] = (u_int)data0; \
268 _mmmm[1] = (u_int)data1; \
269 _mmmm[2] = (u_int)data2; \
270 _mmmm[3] = (u_int)data3; \
271 etap_probe(subsys, tag, sizeof (etap_data_t), &_mmmm); \
274 #define PROBE_DATA(type, tag, data0, data1, data2, data3)
275 #endif /* DO_PROBE */
276 #endif /* _MACH_ETAP_H_ */