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@
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 extern vm_map_t kernel_map
;
102 /* MACRO set_pbuf_value
104 ** enters the value 'val' in the buffer 'pbuf' and returns the following
105 ** indications: 0: means that a fatal error occured: the buffer was full
106 ** (it hasn't been sent yet)
107 ** 1: means that a value has been inserted successfully
108 ** 2: means that we'v just entered the last value causing
109 ** the current buffer to be full.(must switch to
110 ** another buffer and signal the sender to send it)
115 #define set_pbuf_value(pbuf, val) \
117 register buffer_t a = &((pbuf)->prof_area[(pbuf)->prof_index]); \
119 register boolean_t f = a->p_full; \
126 a->p_zone[i] = *(val); \
127 if (i == SIZE_PROF_BUFFER-1) { \
136 #define reset_pbuf_area(pbuf) \
139 (pbuf)->prof_index = ((pbuf)->prof_index + 1) % NB_PROF_BUFFER; \
140 i = (pbuf)->prof_index; \
141 (pbuf)->prof_area[i].p_index = 0; \
142 (pbuf)->prof_area[i].p_dropped = 0; \
145 #endif /* MACH_PROF */
148 ** Global variable: the head of the queue of buffers to send
149 ** It is a queue with locks (uses macros from queue.h) and it
150 ** is shared by hardclock() and the sender_thread()
153 mpqueue_head_t prof_queue
;
156 natural_t pc
, /* program counter */
157 prof_data_t pbuf
); /* trace/prof data area */
161 #define task_prof_init(task) \
162 task->task_profiled = FALSE; \
163 task->profil_buffer = NULLPROFDATA;
165 #define act_prof_init(thr_act, task) \
166 thr_act->act_profiled = task->task_profiled; \
167 thr_act->profil_buffer = task->profil_buffer;
169 #define task_prof_deallocate(task) \
170 if (task->profil_buffer) \
171 task_sample(task, MACH_PORT_NULL); \
173 #define act_prof_deallocate(thr_act) \
174 if (thr_act->act_profiled_own && thr_act->profil_buffer) \
175 thread_sample(thr_act, MACH_PORT_NULL); \
177 extern kern_return_t thread_sample(thread_act_t, ipc_port_t);
178 extern kern_return_t
task_sample(task_t
, ipc_port_t
);
180 #else /* !MACH_PROT */
182 #define task_prof_init(task)
183 #define act_prof_init(thr_act, task)
184 #define task_prof_deallocate(task)
185 #define act_prof_deallocate(thr_act)
188 #endif /* !MACH_PROF */
190 #endif /* _KERN_PROFILE_H */