2 * Copyright (c) 2000-2004 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@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
54 #ifndef _KERN_PROFILE_H
55 #define _KERN_PROFILE_H
57 #include <mach/boolean.h>
58 #include <vm/vm_kern.h>
60 #define NB_PROF_BUFFER 4 /* number of buffers servicing a */
61 #define SIZE_PROF_BUFFER 200 /* size of a profil buffer (in natural_t) */
62 /* -> at most 1 packet every 2 secs */
66 struct ipc_port
*prof_port
; /* where to send a full buffer */
70 natural_t
*p_zone
; /* points to the actual storage area */
71 int p_index
; /* next slot to be filled */
72 int p_dropped
; /* # dropped samples when full */
73 boolean_t p_full
; /* is the current buffer full ? */
74 struct prof_data
*p_prof
; /* base to get prof_port */
75 char p_wakeme
; /* do wakeup when sent */
76 } prof_area
[NB_PROF_BUFFER
];
78 int prof_index
; /* index of the buffer structure */
79 /* currently in use */
83 typedef struct prof_data
*prof_data_t
;
84 #define NULLPROFDATA ((prof_data_t) 0)
85 typedef struct buffer
*buffer_t
;
86 #define NULLPBUF ((buffer_t) 0)
90 #define set_pbuf_nb(pbuf, nb) \
91 (((nb) >= 0 && (nb) < NB_PROF_BUFFER) \
92 ? (pbuf)->prof_index = (nb), 1 \
96 #define get_pbuf_nb(pbuf) \
100 /* MACRO set_pbuf_value
102 ** enters the value 'val' in the buffer 'pbuf' and returns the following
103 ** indications: 0: means that a fatal error occurred: the buffer was full
104 ** (it hasn't been sent yet)
105 ** 1: means that a value has been inserted successfully
106 ** 2: means that we'v just entered the last value causing
107 ** the current buffer to be full.(must switch to
108 ** another buffer and signal the sender to send it)
113 #define set_pbuf_value(pbuf, val) \
115 register buffer_t a = &((pbuf)->prof_area[(pbuf)->prof_index]); \
117 register boolean_t f = a->p_full; \
124 a->p_zone[i] = *(val); \
125 if (i == SIZE_PROF_BUFFER-1) { \
134 #define reset_pbuf_area(pbuf) \
137 (pbuf)->prof_index = ((pbuf)->prof_index + 1) % NB_PROF_BUFFER; \
138 i = (pbuf)->prof_index; \
139 (pbuf)->prof_area[i].p_index = 0; \
140 (pbuf)->prof_area[i].p_dropped = 0; \
143 #endif /* MACH_PROF */
146 ** Global variable: the head of the queue of buffers to send
147 ** It is a queue with locks (uses macros from queue.h) and it
148 ** is shared by hardclock() and the sender_thread()
151 mpqueue_head_t prof_queue
;
154 natural_t pc
, /* program counter */
155 prof_data_t pbuf
); /* trace/prof data area */
159 #define task_prof_init(task) \
160 task->task_profiled = FALSE; \
161 task->profil_buffer = NULLPROFDATA;
163 #define thread_prof_init(thread, task) \
164 thread->profiled = task->profiled; \
165 thread->profil_buffer = task->profil_buffer;
167 #define task_prof_deallocate(task) \
168 if (task->profil_buffer) \
169 task_sample(task, MACH_PORT_NULL); \
171 #define thread_prof_deallocate(thread) \
172 if (thread->profiled_own && thread->profil_buffer) \
173 thread_sample(thread, MACH_PORT_NULL); \
175 extern kern_return_t thread_sample(thread_t, ipc_port_t);
176 extern kern_return_t
task_sample(task_t
, ipc_port_t
);
178 #else /* !MACH_PROT */
180 #define task_prof_init(task)
181 #define thread_prof_init(thread, task)
182 #define task_prof_deallocate(task)
183 #define thread_prof_deallocate(thread)
185 #endif /* !MACH_PROF */
187 #endif /* _KERN_PROFILE_H */