]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/profile.h
xnu-792.6.22.tar.gz
[apple/xnu.git] / osfmk / kern / profile.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
A
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.
1c79356b 11 *
e5568f75
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
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.
1c79356b
A
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 Software.Distribution@CS.CMU.EDU
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
65struct 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
83typedef struct prof_data *prof_data_t;
84#define NULLPROFDATA ((prof_data_t) 0)
85typedef 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
1c79356b
A
100/* MACRO set_pbuf_value
101**
102** enters the value 'val' in the buffer 'pbuf' and returns the following
91447636 103** indications: 0: means that a fatal error occurred: the buffer was full
1c79356b
A
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)
109*/
110
111#if MACH_PROF
112
113#define set_pbuf_value(pbuf, val) \
114 { \
115 register buffer_t a = &((pbuf)->prof_area[(pbuf)->prof_index]); \
116 register int i ;\
117 register boolean_t f = a->p_full; \
118 \
119 if (f == TRUE ) {\
120 a->p_dropped++; \
121 *(val) = 0L; \
122 } else { \
123 i = a->p_index++; \
124 a->p_zone[i] = *(val); \
125 if (i == SIZE_PROF_BUFFER-1) { \
126 a->p_full = TRUE; \
127 *(val) = 2; \
128 } \
129 else \
130 *(val) = 1; \
131 } \
132 }
133
134#define reset_pbuf_area(pbuf) \
135 { \
136 int i; \
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; \
141 }
142
143#endif /* MACH_PROF */
144
145/*
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()
149*/
150
151mpqueue_head_t prof_queue;
152
153extern void profile(
154 natural_t pc, /* program counter */
155 prof_data_t pbuf); /* trace/prof data area */
156
157#if MACH_PROF
158
159#define task_prof_init(task) \
160 task->task_profiled = FALSE; \
161 task->profil_buffer = NULLPROFDATA;
162
91447636
A
163#define thread_prof_init(thread, task) \
164 thread->profiled = task->profiled; \
165 thread->profil_buffer = task->profil_buffer;
1c79356b
A
166
167#define task_prof_deallocate(task) \
168 if (task->profil_buffer) \
169 task_sample(task, MACH_PORT_NULL); \
170
91447636
A
171#define thread_prof_deallocate(thread) \
172 if (thread->profiled_own && thread->profil_buffer) \
173 thread_sample(thread, MACH_PORT_NULL); \
1c79356b 174
91447636 175extern kern_return_t thread_sample(thread_t, ipc_port_t);
1c79356b
A
176extern kern_return_t task_sample(task_t, ipc_port_t);
177
178#else /* !MACH_PROT */
179
180#define task_prof_init(task)
91447636 181#define thread_prof_init(thread, task)
1c79356b 182#define task_prof_deallocate(task)
91447636 183#define thread_prof_deallocate(thread)
1c79356b
A
184
185#endif /* !MACH_PROF */
186
187#endif /* _KERN_PROFILE_H */