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@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
57 #ifndef _KERN_PROFILE_H
58 #define _KERN_PROFILE_H
60 #include <mach/boolean.h>
61 #include <vm/vm_kern.h>
63 #define NB_PROF_BUFFER 4 /* number of buffers servicing a */
64 #define SIZE_PROF_BUFFER 200 /* size of a profil buffer (in natural_t) */
65 /* -> at most 1 packet every 2 secs */
69 struct ipc_port
*prof_port
; /* where to send a full buffer */
73 natural_t
*p_zone
; /* points to the actual storage area */
74 int p_index
; /* next slot to be filled */
75 int p_dropped
; /* # dropped samples when full */
76 boolean_t p_full
; /* is the current buffer full ? */
77 struct prof_data
*p_prof
; /* base to get prof_port */
78 char p_wakeme
; /* do wakeup when sent */
79 } prof_area
[NB_PROF_BUFFER
];
81 int prof_index
; /* index of the buffer structure */
82 /* currently in use */
86 typedef struct prof_data
*prof_data_t
;
87 #define NULLPROFDATA ((prof_data_t) 0)
88 typedef struct buffer
*buffer_t
;
89 #define NULLPBUF ((buffer_t) 0)
93 #define set_pbuf_nb(pbuf, nb) \
94 (((nb) >= 0 && (nb) < NB_PROF_BUFFER) \
95 ? (pbuf)->prof_index = (nb), 1 \
99 #define get_pbuf_nb(pbuf) \
103 extern vm_map_t kernel_map
;
105 /* MACRO set_pbuf_value
107 ** enters the value 'val' in the buffer 'pbuf' and returns the following
108 ** indications: 0: means that a fatal error occured: the buffer was full
109 ** (it hasn't been sent yet)
110 ** 1: means that a value has been inserted successfully
111 ** 2: means that we'v just entered the last value causing
112 ** the current buffer to be full.(must switch to
113 ** another buffer and signal the sender to send it)
118 #define set_pbuf_value(pbuf, val) \
120 register buffer_t a = &((pbuf)->prof_area[(pbuf)->prof_index]); \
122 register boolean_t f = a->p_full; \
129 a->p_zone[i] = *(val); \
130 if (i == SIZE_PROF_BUFFER-1) { \
139 #define reset_pbuf_area(pbuf) \
142 (pbuf)->prof_index = ((pbuf)->prof_index + 1) % NB_PROF_BUFFER; \
143 i = (pbuf)->prof_index; \
144 (pbuf)->prof_area[i].p_index = 0; \
145 (pbuf)->prof_area[i].p_dropped = 0; \
148 #endif /* MACH_PROF */
151 ** Global variable: the head of the queue of buffers to send
152 ** It is a queue with locks (uses macros from queue.h) and it
153 ** is shared by hardclock() and the sender_thread()
156 mpqueue_head_t prof_queue
;
159 natural_t pc
, /* program counter */
160 prof_data_t pbuf
); /* trace/prof data area */
164 #define task_prof_init(task) \
165 task->task_profiled = FALSE; \
166 task->profil_buffer = NULLPROFDATA;
168 #define act_prof_init(thr_act, task) \
169 thr_act->act_profiled = task->task_profiled; \
170 thr_act->profil_buffer = task->profil_buffer;
172 #define task_prof_deallocate(task) \
173 if (task->profil_buffer) \
174 task_sample(task, MACH_PORT_NULL); \
176 #define act_prof_deallocate(thr_act) \
177 if (thr_act->act_profiled_own && thr_act->profil_buffer) \
178 thread_sample(thr_act, MACH_PORT_NULL); \
180 extern kern_return_t thread_sample(thread_act_t, ipc_port_t);
181 extern kern_return_t
task_sample(task_t
, ipc_port_t
);
183 #else /* !MACH_PROT */
185 #define task_prof_init(task)
186 #define act_prof_init(thr_act, task)
187 #define task_prof_deallocate(task)
188 #define act_prof_deallocate(thr_act)
191 #endif /* !MACH_PROF */
193 #endif /* _KERN_PROFILE_H */