]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
13 | * file. | |
14 | * | |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | */ | |
28 | /* | |
29 | * Mach Operating System | |
30 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
31 | * All Rights Reserved. | |
32 | * | |
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. | |
38 | * | |
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. | |
42 | * | |
43 | * Carnegie Mellon requests users of this software to return to | |
44 | * | |
45 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
46 | * School of Computer Science | |
47 | * Carnegie Mellon University | |
48 | * Pittsburgh PA 15213-3890 | |
49 | * | |
50 | * any improvements or extensions that they make and grant Carnegie Mellon | |
51 | * the rights to redistribute these changes. | |
52 | */ | |
53 | ||
54 | /* | |
55 | */ | |
56 | ||
57 | #ifndef _KERN_PROFILE_H | |
58 | #define _KERN_PROFILE_H | |
59 | ||
60 | #include <mach/boolean.h> | |
61 | #include <vm/vm_kern.h> | |
62 | ||
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 */ | |
66 | /* profiled thread */ | |
67 | ||
68 | struct prof_data { | |
69 | struct ipc_port *prof_port; /* where to send a full buffer */ | |
70 | ||
71 | struct buffer { | |
72 | queue_chain_t p_list; | |
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]; | |
80 | ||
81 | int prof_index; /* index of the buffer structure */ | |
82 | /* currently in use */ | |
83 | ||
84 | }; | |
85 | ||
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) | |
90 | ||
91 | /* Macros */ | |
92 | ||
93 | #define set_pbuf_nb(pbuf, nb) \ | |
94 | (((nb) >= 0 && (nb) < NB_PROF_BUFFER) \ | |
95 | ? (pbuf)->prof_index = (nb), 1 \ | |
96 | : 0) | |
97 | ||
98 | ||
99 | #define get_pbuf_nb(pbuf) \ | |
100 | (pbuf)->prof_index | |
101 | ||
102 | ||
103 | extern vm_map_t kernel_map; | |
104 | ||
105 | /* MACRO set_pbuf_value | |
106 | ** | |
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) | |
114 | */ | |
115 | ||
116 | #if MACH_PROF | |
117 | ||
118 | #define set_pbuf_value(pbuf, val) \ | |
119 | { \ | |
120 | register buffer_t a = &((pbuf)->prof_area[(pbuf)->prof_index]); \ | |
121 | register int i ;\ | |
122 | register boolean_t f = a->p_full; \ | |
123 | \ | |
124 | if (f == TRUE ) {\ | |
125 | a->p_dropped++; \ | |
126 | *(val) = 0L; \ | |
127 | } else { \ | |
128 | i = a->p_index++; \ | |
129 | a->p_zone[i] = *(val); \ | |
130 | if (i == SIZE_PROF_BUFFER-1) { \ | |
131 | a->p_full = TRUE; \ | |
132 | *(val) = 2; \ | |
133 | } \ | |
134 | else \ | |
135 | *(val) = 1; \ | |
136 | } \ | |
137 | } | |
138 | ||
139 | #define reset_pbuf_area(pbuf) \ | |
140 | { \ | |
141 | int i; \ | |
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; \ | |
146 | } | |
147 | ||
148 | #endif /* MACH_PROF */ | |
149 | ||
150 | /* | |
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() | |
154 | */ | |
155 | ||
156 | mpqueue_head_t prof_queue; | |
157 | ||
158 | extern void profile( | |
159 | natural_t pc, /* program counter */ | |
160 | prof_data_t pbuf); /* trace/prof data area */ | |
161 | ||
162 | #if MACH_PROF | |
163 | ||
164 | #define task_prof_init(task) \ | |
165 | task->task_profiled = FALSE; \ | |
166 | task->profil_buffer = NULLPROFDATA; | |
167 | ||
168 | #define act_prof_init(thr_act, task) \ | |
169 | thr_act->act_profiled = task->task_profiled; \ | |
170 | thr_act->profil_buffer = task->profil_buffer; | |
171 | ||
172 | #define task_prof_deallocate(task) \ | |
173 | if (task->profil_buffer) \ | |
174 | task_sample(task, MACH_PORT_NULL); \ | |
175 | ||
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); \ | |
179 | ||
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); | |
182 | ||
183 | #else /* !MACH_PROT */ | |
184 | ||
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) | |
189 | ||
190 | ||
191 | #endif /* !MACH_PROF */ | |
192 | ||
193 | #endif /* _KERN_PROFILE_H */ |