|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
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.
11: *
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
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: * @OSF_COPYRIGHT@
24: */
25: /*
26: * Mach Operating System
27: * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28: * All Rights Reserved.
29: *
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.
35: *
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.
39: *
40: * Carnegie Mellon requests users of this software to return to
41: *
42: * Software Distribution Coordinator or [email protected]
43: * School of Computer Science
44: * Carnegie Mellon University
45: * Pittsburgh PA 15213-3890
46: *
47: * any improvements or extensions that they make and grant Carnegie Mellon
48: * the rights to redistribute these changes.
49: */
50:
51: /*
52: */
53:
54: #ifndef _KERN_PROFILE_H
55: #define _KERN_PROFILE_H
56:
57: #include <mach/boolean.h>
58: #include <vm/vm_kern.h>
59:
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 */
63: /* profiled thread */
64:
65: struct prof_data {
66: struct ipc_port *prof_port; /* where to send a full buffer */
67:
68: struct buffer {
69: queue_chain_t p_list;
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];
77:
78: int prof_index; /* index of the buffer structure */
79: /* currently in use */
80:
81: };
82:
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)
87:
88: /* Macros */
89:
90: #define set_pbuf_nb(pbuf, nb) \
91: (((nb) >= 0 && (nb) < NB_PROF_BUFFER) \
92: ? (pbuf)->prof_index = (nb), 1 \
93: : 0)
94:
95:
96: #define get_pbuf_nb(pbuf) \
97: (pbuf)->prof_index
98:
99:
100: extern vm_map_t kernel_map;
101:
102: /* MACRO set_pbuf_value
103: **
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)
111: */
112:
113: #if MACH_PROF
114:
115: #define set_pbuf_value(pbuf, val) \
116: { \
117: register buffer_t a = &((pbuf)->prof_area[(pbuf)->prof_index]); \
118: register int i ;\
119: register boolean_t f = a->p_full; \
120: \
121: if (f == TRUE ) {\
122: a->p_dropped++; \
123: *(val) = 0L; \
124: } else { \
125: i = a->p_index++; \
126: a->p_zone[i] = *(val); \
127: if (i == SIZE_PROF_BUFFER-1) { \
128: a->p_full = TRUE; \
129: *(val) = 2; \
130: } \
131: else \
132: *(val) = 1; \
133: } \
134: }
135:
136: #define reset_pbuf_area(pbuf) \
137: { \
138: int i; \
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; \
143: }
144:
145: #endif /* MACH_PROF */
146:
147: /*
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()
151: */
152:
153: mpqueue_head_t prof_queue;
154:
155: extern void profile(
156: natural_t pc, /* program counter */
157: prof_data_t pbuf); /* trace/prof data area */
158:
159: #if MACH_PROF
160:
161: #define task_prof_init(task) \
162: task->task_profiled = FALSE; \
163: task->profil_buffer = NULLPROFDATA;
164:
165: #define act_prof_init(thr_act, task) \
166: thr_act->act_profiled = task->task_profiled; \
167: thr_act->profil_buffer = task->profil_buffer;
168:
169: #define task_prof_deallocate(task) \
170: if (task->profil_buffer) \
171: task_sample(task, MACH_PORT_NULL); \
172:
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); \
176:
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);
179:
180: #else /* !MACH_PROT */
181:
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)
186:
187:
188: #endif /* !MACH_PROF */
189:
190: #endif /* _KERN_PROFILE_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.