]> git.saurik.com Git - apple/xnu.git/blob - osfmk/profiling/i386/profile-md.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / osfmk / profiling / i386 / profile-md.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * HISTORY
35 *
36 * Revision 1.1.1.1 1998/09/22 21:05:49 wsanchez
37 * Import of Mac OS X kernel (~semeria)
38 *
39 * Revision 1.1.1.1 1998/03/07 02:26:08 wsanchez
40 * Import of OSF Mach kernel (~mburg)
41 *
42 * Revision 1.1.5.2 1996/07/31 09:57:36 paire
43 * Added some more constraints to __asm__ functions for compilation
44 * under gcc2.7.1 for PROF_CNT_[L]{ADD|SUB} macros
45 * [96/06/14 paire]
46 *
47 * Revision 1.1.5.1 1995/01/06 19:53:52 devrcs
48 * mk6 CR668 - 1.3b26 merge
49 * new file for mk6
50 * [1994/10/12 22:25:27 dwm]
51 *
52 * Revision 1.1.2.2 1994/05/16 19:19:26 meissner
53 * Add {,L}PROF_CNT_{SUB,LSUB,OVERFLOW} macros for gprof command.
54 * [1994/05/10 10:36:06 meissner]
55 *
56 * Correct 64-bit integer asms to specify result values as inputs, and use =g instead of =m.
57 * Cast the integer argument to PROF_CNT_ADD to unsigned long, so a short register is widened.
58 * Add more support for writing the gprof command.
59 * PROF_CNT_{EQ,NE} should not use ^=, it just uses ^.
60 * Round PROF_CNT_DIGITS up to 24 bytes so it is word aligned.
61 * _profile_cnt_to_decimal now takes the low/high values as separate arguments.
62 * Delete _profile_cnt_to_hex.
63 * [1994/04/28 21:45:07 meissner]
64 *
65 * Add more 64 bit arithmetic macros to support writing gprof.
66 * [1994/04/20 15:47:05 meissner]
67 *
68 * Revision 1.1.2.1 1994/04/08 17:51:56 meissner
69 * Correct spelling on LPROF_CNT_TO_LDOUBLE macro.
70 * [1994/04/08 16:18:06 meissner]
71 *
72 * Make LHISTCOUNTER be 64 bits.
73 * Define LPROF_CNT_INC to increment LHISTCOUNTER.
74 * [1994/04/08 12:40:32 meissner]
75 *
76 * Make most stats 64 bits, except for things like memory allocation.
77 * [1994/04/02 14:58:34 meissner]
78 *
79 * Add overflow support for {gprof,prof,old,dummy}_mcount counters.
80 * [1994/03/17 20:13:37 meissner]
81 *
82 * Add gprof/prof overflow support
83 * [1994/03/17 14:56:56 meissner]
84 *
85 * Define LHISTCOUNTER.
86 * [1994/02/28 12:05:16 meissner]
87 *
88 * Set HISTFRACTION to 4, so new lprofil call takes the same space.
89 * [1994/02/24 16:15:34 meissner]
90 *
91 * Add too_low/too_high to profile_stats.
92 * [1994/02/16 22:38:23 meissner]
93 *
94 * Make prof_cnt_t unsigned long.
95 * [1994/02/11 16:52:09 meissner]
96 *
97 * Remember function unique ptr in gfuncs structure to reset profiling.
98 * Add support for range checking gprof arc {from,self}pc addresses.
99 * Add counter for # times acontext was locked.
100 * Expand copyright.
101 * [1994/02/07 12:41:08 meissner]
102 *
103 * Keep track of the number of times the kernel overflows the HISTCOUNTER counter.
104 * [1994/02/03 20:13:31 meissner]
105 *
106 * Add stats for {user,kernel,idle} mode in the kernel.
107 * [1994/02/03 15:17:36 meissner]
108 *
109 * No change.
110 * [1994/02/03 00:58:59 meissner]
111 *
112 * Combine _profile_{vars,stats,md}; Allow more than one _profile_vars.
113 * [1994/02/01 12:04:04 meissner]
114 *
115 * Split # records to # gprof and # prof records.
116 * Add my_cpu/max_cpu fields.
117 * [1994/01/28 23:33:30 meissner]
118 *
119 * Eliminate hash_{size,mask} from gfuncs structure.
120 * [1994/01/26 20:23:41 meissner]
121 *
122 * Add structure size fields to _profile_{vars,stats,md}.
123 * Add major/minor version number to _profile_md.
124 * Move allocation context block pointer to main structure.
125 * Delete shift count for allocation contexts.
126 * [1994/01/25 01:46:08 meissner]
127 *
128 * Add HASHFRACTION
129 * [1994/01/22 01:14:02 meissner]
130 *
131 * Split profile-md.h into profile-internal.h and profile-md.
132 * [1994/01/20 20:57:18 meissner]
133 *
134 * Fixup copyright.
135 * [1994/01/18 23:08:14 meissner]
136 *
137 * Make flags byte-sized.
138 * Add have_bb flag.
139 * Add init_format flag.
140 * [1994/01/18 21:57:18 meissner]
141 *
142 * CR 10198 - Initial version.
143 * [1994/01/18 19:44:59 meissner]
144 *
145 * $EndLog$
146 */
147
148 #ifndef _PROFILE_MD_H
149 #define _PROFILE_MD_H
150
151 #include <types.h>
152
153 /*
154 * Define the interfaces between the assembly language profiling support
155 * that is common between the kernel, mach servers, and user space library.
156 */
157
158 /*
159 * Integer types used.
160 */
161
162 typedef long prof_ptrint_t; /* hold either pointer or signed int */
163 typedef unsigned long prof_uptrint_t; /* hold either pointer or unsigned int */
164 typedef long prof_lock_t; /* lock word type */
165 typedef unsigned char prof_flag_t; /* type for boolean flags */
166
167 /*
168 * Double precision counter.
169 */
170
171 typedef struct prof_cnt_t {
172 prof_uptrint_t low; /* low 32 bits of counter */
173 prof_uptrint_t high; /* high 32 bits of counter */
174 } prof_cnt_t;
175
176 #if defined(__GNUC__) && !defined(lint)
177 #define PROF_CNT_INC(cnt) \
178 __asm__("addl $1,%0; adcl $0,%1" \
179 : "=g" ((cnt).low), "=g" ((cnt).high) \
180 : "0" ((cnt).low), "1" ((cnt).high))
181
182 #define PROF_CNT_ADD(cnt,val) \
183 __asm__("addl %2,%0; adcl $0,%1" \
184 : "=g,r" ((cnt).low), "=g,r" ((cnt).high) \
185 : "r,g" ((unsigned long)(val)), \
186 "0,0" ((cnt).low), "1,1" ((cnt).high))
187
188 #define PROF_CNT_LADD(cnt,val) \
189 __asm__("addl %2,%0; adcl %3,%1" \
190 : "=g,r" ((cnt).low), "=g,r" ((cnt).high) \
191 : "r,g" ((val).low), "r,g" ((val).high), \
192 "0,0" ((cnt).low), "1,1" ((cnt).high))
193
194 #define PROF_CNT_SUB(cnt,val) \
195 __asm__("subl %2,%0; sbbl $0,%1" \
196 : "=g,r" ((cnt).low), "=g,r" ((cnt).high) \
197 : "r,g" ((unsigned long)(val)), \
198 "0,0" ((cnt).low), "1,1" ((cnt).high))
199
200 #define PROF_CNT_LSUB(cnt,val) \
201 __asm__("subl %2,%0; sbbl %3,%1" \
202 : "=g,r" ((cnt).low), "=g,r" ((cnt).high) \
203 : "r,g" ((val).low), "r,g" ((val).high), \
204 "0,0" ((cnt).low), "1,1" ((cnt).high))
205
206 #else
207 #define PROF_CNT_INC(cnt) ((++((cnt).low) == 0) ? ++((cnt).high) : 0)
208 #define PROF_CNT_ADD(cnt,val) (((((cnt).low + (val)) < (val)) ? ((cnt).high++) : 0), ((cnt).low += (val)))
209 #define PROF_CNT_LADD(cnt,val) (PROF_CNT_ADD(cnt,(val).low), (cnt).high += (val).high)
210 #define PROF_CNT_SUB(cnt,val) (((((cnt).low - (val)) > (cnt).low) ? ((cnt).high--) : 0), ((cnt).low -= (val)))
211 #define PROF_CNT_LSUB(cnt,val) (PROF_CNT_SUB(cnt,(val).low), (cnt).high -= (val).high)
212 #endif
213
214 #define PROF_ULONG_TO_CNT(cnt,val) (((cnt).high = 0), ((cnt).low = val))
215 #define PROF_CNT_OVERFLOW(cnt,high,low) (((high) = (cnt).high), ((low) = (cnt).low))
216 #define PROF_CNT_TO_ULONG(cnt) (((cnt).high == 0) ? (cnt).low : 0xffffffffu)
217 #define PROF_CNT_TO_LDOUBLE(cnt) ((((long double)(cnt).high) * 4294967296.0L) + (long double)(cnt).low)
218 #define PROF_CNT_TO_DECIMAL(buf,cnt) _profile_cnt_to_decimal(buf, (cnt).low, (cnt).high)
219 #define PROF_CNT_EQ_0(cnt) (((cnt).high | (cnt).low) == 0)
220 #define PROF_CNT_NE_0(cnt) (((cnt).high | (cnt).low) != 0)
221 #define PROF_CNT_EQ(cnt1,cnt2) ((((cnt1).high ^ (cnt2).high) | ((cnt1).low ^ (cnt2).low)) == 0)
222 #define PROF_CNT_NE(cnt1,cnt2) ((((cnt1).high ^ (cnt2).high) | ((cnt1).low ^ (cnt2).low)) != 0)
223 #define PROF_CNT_GT(cnt1,cnt2) (((cnt1).high > (cnt2).high) || ((cnt1).low > (cnt2).low))
224 #define PROF_CNT_LT(cnt1,cnt2) (((cnt1).high < (cnt2).high) || ((cnt1).low < (cnt2).low))
225
226 /* max # digits + null to hold prof_cnt_t values (round up to multiple of 4) */
227 #define PROF_CNT_DIGITS 24
228
229 /*
230 * Types of the profil counter.
231 */
232
233 typedef unsigned short HISTCOUNTER; /* profil */
234 typedef prof_cnt_t LHISTCOUNTER; /* lprofil */
235
236 #define LPROF_ULONG_TO_CNT(cnt,val) PROF_ULONG_TO_CNT(cnt,val)
237 #define LPROF_CNT_INC(lp) PROF_CNT_INC(lp)
238 #define LPROF_CNT_ADD(lp,val) PROF_CNT_ADD(lp,val)
239 #define LPROF_CNT_LADD(lp,val) PROF_CNT_LADD(lp,val)
240 #define LPROF_CNT_SUB(lp,val) PROF_CNT_SUB(lp,val)
241 #define LPROF_CNT_LSUB(lp,val) PROF_CNT_LSUB(lp,val)
242 #define LPROF_CNT_OVERFLOW(lp,high,low) PROF_CNT_OVERFLOW(lp,high,low)
243 #define LPROF_CNT_TO_ULONG(lp) PROF_CNT_TO_ULONG(lp)
244 #define LPROF_CNT_TO_LDOUBLE(lp) PROF_CNT_TO_LDOUBLE(lp)
245 #define LPROF_CNT_TO_DECIMAL(buf,cnt) PROF_CNT_TO_DECIMAL(buf,cnt)
246 #define LPROF_CNT_EQ_0(cnt) PROF_CNT_EQ_0(cnt)
247 #define LPROF_CNT_NE_0(cnt) PROF_CNT_NE_0(cnt)
248 #define LPROF_CNT_EQ(cnt1,cnt2) PROF_CNT_EQ(cnt1,cnt2)
249 #define LPROF_CNT_NE(cnt1,cnt2) PROF_CNT_NE(cnt1,cnt2)
250 #define LPROF_CNT_GT(cnt1,cnt2) PROF_CNT_GT(cnt1,cnt2)
251 #define LPROF_CNT_LT(cnt1,cnt2) PROF_CNT_LT(cnt1,cnt2)
252 #define LPROF_CNT_DIGITS PROF_CNT_DIGITS
253
254 /*
255 * fraction of text space to allocate for histogram counters
256 */
257
258 #define HISTFRACTION 4
259
260 /*
261 * Fraction of text space to allocate for from hash buckets.
262 */
263
264 #define HASHFRACTION HISTFRACTION
265
266 /*
267 * Prof call count, external format.
268 */
269
270 struct prof_ext {
271 prof_uptrint_t cvalue; /* caller address */
272 prof_uptrint_t cncall; /* # of calls */
273 };
274
275 /*
276 * Prof call count, internal format.
277 */
278
279 struct prof_int {
280 struct prof_ext prof; /* external prof struct */
281 prof_uptrint_t overflow; /* # times prof counter overflowed */
282 };
283
284 /*
285 * Gprof arc, external format.
286 */
287
288 struct gprof_arc {
289 prof_uptrint_t frompc; /* caller's caller */
290 prof_uptrint_t selfpc; /* caller's address */
291 prof_uptrint_t count; /* # times arc traversed */
292 };
293
294 /*
295 * Gprof arc, internal format.
296 */
297
298 struct hasharc {
299 struct hasharc *next; /* next gprof record */
300 struct gprof_arc arc; /* gprof record */
301 prof_uptrint_t overflow; /* # times counter overflowed */
302 };
303
304 /*
305 * Linked list of all function profile blocks.
306 */
307
308 #define MAX_CACHE 3 /* # cache table entries */
309
310 struct gfuncs {
311 struct hasharc **hash_ptr; /* gprof hash table */
312 struct hasharc **unique_ptr; /* function unique pointer */
313 struct prof_int prof; /* -p stats for elf */
314 struct hasharc *cache_ptr[MAX_CACHE]; /* cache element pointers */
315 };
316
317 /*
318 * Profile information which might be written out in ELF {,g}mon.out files.
319 */
320
321 #define MAX_BUCKETS 9 /* max bucket chain to print out */
322
323 struct profile_stats { /* Debugging counters */
324 prof_uptrint_t major_version; /* major version number */
325 prof_uptrint_t minor_version; /* minor version number */
326 prof_uptrint_t stats_size; /* size of profile_vars structure */
327 prof_uptrint_t profil_buckets; /* # profil buckets */
328 prof_uptrint_t my_cpu; /* identify current cpu/thread */
329 prof_uptrint_t max_cpu; /* identify max cpu/thread */
330 prof_uptrint_t prof_records; /* # of functions profiled */
331 prof_uptrint_t gprof_records; /* # of gprof arcs */
332 prof_uptrint_t hash_buckets; /* # gprof hash buckets */
333 prof_uptrint_t bogus_count; /* # of bogus functions found in gprof */
334
335 prof_cnt_t cnt; /* # of calls to _{,g}prof_mcount */
336 prof_cnt_t dummy; /* # of calls to _dummy_mcount */
337 prof_cnt_t old_mcount; /* # of calls to old mcount */
338 prof_cnt_t hash_search; /* # hash buckets searched */
339 prof_cnt_t hash_num; /* # times hash table searched */
340 prof_cnt_t user_ticks; /* # ticks in user space */
341 prof_cnt_t kernel_ticks; /* # ticks in kernel space */
342 prof_cnt_t idle_ticks; /* # ticks in idle mode */
343 prof_cnt_t overflow_ticks; /* # ticks where HISTCOUNTER overflowed */
344 prof_cnt_t acontext_locked; /* # times an acontext was locked */
345 prof_cnt_t too_low; /* # times a histogram tick was too low */
346 prof_cnt_t too_high; /* # times a histogram tick was too high */
347 prof_cnt_t prof_overflow; /* # times a prof count field overflowed */
348 prof_cnt_t gprof_overflow; /* # times a gprof count field overflowed */
349
350 /* allocation statistics */
351 prof_uptrint_t num_alloc [(int)ACONTEXT_MAX]; /* # allocations */
352 prof_uptrint_t bytes_alloc[(int)ACONTEXT_MAX]; /* bytes allocated */
353 prof_uptrint_t num_context[(int)ACONTEXT_MAX]; /* # contexts */
354 prof_uptrint_t wasted [(int)ACONTEXT_MAX]; /* wasted bytes */
355 prof_uptrint_t overhead [(int)ACONTEXT_MAX]; /* overhead bytes */
356
357 prof_uptrint_t buckets[MAX_BUCKETS+1]; /* # hash indexes that have n buckets */
358 prof_cnt_t cache_hits[MAX_CACHE]; /* # times nth cache entry matched */
359
360 prof_cnt_t stats_unused[64]; /* reserved for future use */
361 };
362
363 #define PROFILE_MAJOR_VERSION 1
364 #define PROFILE_MINOR_VERSION 1
365
366 /*
367 * Machine dependent fields.
368 */
369
370 struct profile_md {
371 int major_version; /* major version number */
372 int minor_version; /* minor version number */
373 size_t md_size; /* size of profile_md structure */
374 struct hasharc **hash_ptr; /* gprof hash table */
375 size_t hash_size; /* size of hash table */
376 prof_uptrint_t num_cache; /* # of cache entries */
377 void (*save_mcount_ptr)(void); /* save for _mcount_ptr */
378 void (**mcount_ptr_ptr)(void); /* pointer to _mcount_ptr */
379 struct hasharc *dummy_ptr; /* pointer to dummy gprof record */
380 void *(*alloc_pages)(size_t); /* pointer to _profile_alloc_pages */
381 char num_buffer[PROF_CNT_DIGITS]; /* convert 64 bit ints to string */
382 long md_unused[58]; /* add unused fields */
383 };
384
385 /*
386 * Record information about each function call. Specify
387 * caller, caller's caller, and a unique label for use by
388 * the profiling routines.
389 */
390 extern void _prof_mcount(void);
391 extern void _gprof_mcount(void);
392 extern void _dummy_mcount(void);
393 extern void (*_mcount_ptr)(void);
394
395 /*
396 * Function in profile-md.c to convert prof_cnt_t to string format (decimal & hex).
397 */
398 extern char *_profile_cnt_to_decimal(char *, prof_uptrint_t, prof_uptrint_t);
399
400 #endif /* _PROFILE_MD_H */