]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/profiling/profile-kgmon.c
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@
31 * Revision 1.1.1.1 1998/09/22 21:05:49 wsanchez
32 * Import of Mac OS X kernel (~semeria)
34 * Revision 1.1.1.1 1998/03/07 02:26:08 wsanchez
35 * Import of OSF Mach kernel (~mburg)
37 * Revision 1.1.5.1 1995/01/06 19:54:04 devrcs
38 * mk6 CR668 - 1.3b26 merge
40 * [1994/10/12 22:25:34 dwm]
42 * Revision 1.1.2.1 1994/04/08 17:52:05 meissner
43 * Add callback function to _profile_kgmon.
44 * [1994/02/16 22:38:31 meissner]
46 * _profile_kgmon now returns pointer to area, doesn't do move itself.
47 * [1994/02/11 16:52:17 meissner]
49 * Move all printfs into if (pv->debug) { ... } blocks.
50 * Add debug printfs protected by if (pv->debug) for all error conditions.
51 * Add code to reset profiling information.
52 * Add code to get/set debug flag.
54 * [1994/02/07 12:41:14 meissner]
56 * Add support to copy arbitrary regions.
57 * Delete several of the KGMON_GET commands, now that arb. regions are supported.
58 * Explicitly call _profile_update_stats before dumping vars or stats.
59 * [1994/02/03 00:59:05 meissner]
61 * Combine _profile_{vars,stats,md}; Allow more than one _profile_vars.
62 * [1994/02/01 12:04:09 meissner]
64 * CR 10198 - Initial version.
65 * [1994/01/28 23:33:37 meissner]
70 #include <profiling/profile-internal.h>
73 #include <profiling/machine/profile-md.h>
77 #define PROFILE_VARS(cpu) (&_profile_vars)
80 extern int printf(const char *, ...);
84 * Kgmon interface. This returns the count of bytes moved if everything was ok,
85 * or -1 if there were errors.
89 _profile_kgmon(int write
,
94 void (*control_func
)(kgmon_control_t
))
96 kgmon_control_t kgmon
;
100 struct profile_vars
*pv
;
101 static struct callback dummy_callback
;
106 * If the number passed is not within bounds, just copy the data directly.
109 if (!LEGAL_KGMON(indx
)) {
110 *p_ptr
= (void *)indx
;
112 if (PROFILE_VARS(0)->debug
) {
113 printf("_profile_kgmon: copy %5ld bytes, from 0x%lx\n",
119 if (PROFILE_VARS(0)->debug
) {
120 printf("_profile_kgmon: copy %5ld bytes, to 0x%lx\n",
130 * Decode the record number into the component pieces.
133 DECODE_KGMON(indx
, kgmon
, cpu
);
135 if (PROFILE_VARS(0)->debug
) {
136 printf("_profile_kgmon: start: kgmon control = %2d, cpu = %d, count = %ld\n",
137 kgmon
, cpu
, (long)count
);
140 /* Validate the CPU number */
141 if (cpu
< 0 || cpu
>= max_cpus
) {
142 if (PROFILE_VARS(0)->debug
) {
143 printf("KGMON, bad cpu %d\n", cpu
);
149 pv
= PROFILE_VARS(cpu
);
154 if (PROFILE_VARS(0)->debug
) {
155 printf("Unknown KGMON read command\n");
161 case KGMON_GET_STATUS
: /* return whether or not profiling is active */
163 if (PROFILE_VARS(0)->debug
) {
164 printf("KGMON_GET_STATUS: cpu = %d\n", cpu
);
171 if (count
!= sizeof(pv
->active
)) {
172 if (PROFILE_VARS(0)->debug
) {
173 printf("KGMON_GET_STATUS: count = %ld, should be %ld\n",
175 (long)sizeof(pv
->active
));
182 *p_ptr
= (void *)&pv
->active
;
185 case KGMON_GET_DEBUG
: /* return whether or not debugging is active */
187 if (PROFILE_VARS(0)->debug
) {
188 printf("KGMON_GET_DEBUG: cpu = %d\n", cpu
);
195 if (count
!= sizeof(pv
->debug
)) {
196 if (PROFILE_VARS(0)->debug
) {
197 printf("KGMON_GET_DEBUG: count = %ld, should be %ld\n",
199 (long)sizeof(pv
->active
));
206 *p_ptr
= (void *)&pv
->debug
;
209 case KGMON_GET_PROFILE_VARS
: /* return the _profile_vars structure */
210 if (count
!= sizeof(struct profile_vars
)) {
211 if (PROFILE_VARS(0)->debug
) {
212 printf("KGMON_GET_PROFILE_VARS: count = %ld, should be %ld\n",
214 (long)sizeof(struct profile_vars
));
221 _profile_update_stats(pv
);
225 case KGMON_GET_PROFILE_STATS
: /* return the _profile_stats structure */
226 if (count
!= sizeof(struct profile_stats
)) {
227 if (PROFILE_VARS(0)->debug
) {
228 printf("KGMON_GET_PROFILE_STATS: count = %ld, should be = %ld\n",
230 (long)sizeof(struct profile_stats
));
237 _profile_update_stats(pv
);
238 *p_ptr
= (void *)&pv
->stats
;
245 if (PROFILE_VARS(0)->debug
) {
246 printf("Unknown KGMON write command\n");
252 case KGMON_SET_PROFILE_ON
: /* turn on profiling */
254 if (PROFILE_VARS(0)->debug
) {
255 printf("KGMON_SET_PROFILE_ON, cpu = %d\n", cpu
);
262 if (!PROFILE_VARS(0)->active
) {
263 for (i
= 0; i
< max_cpus
; i
++) {
264 PROFILE_VARS(i
)->active
= 1;
268 (*control_func
)(kgmon
);
277 case KGMON_SET_PROFILE_OFF
: /* turn off profiling */
279 if (PROFILE_VARS(0)->debug
) {
280 printf("KGMON_SET_PROFILE_OFF, cpu = %d\n", cpu
);
287 if (PROFILE_VARS(0)->active
) {
288 for (i
= 0; i
< max_cpus
; i
++) {
289 PROFILE_VARS(i
)->active
= 0;
295 (*control_func
)(kgmon
);
302 case KGMON_SET_PROFILE_RESET
: /* reset profiling */
304 if (PROFILE_VARS(0)->debug
) {
305 printf("KGMON_SET_PROFILE_RESET, cpu = %d\n", cpu
);
312 for (i
= 0; i
< max_cpus
; i
++) {
313 _profile_reset(PROFILE_VARS(i
));
317 (*control_func
)(kgmon
);
323 case KGMON_SET_DEBUG_ON
: /* turn on profiling */
325 if (PROFILE_VARS(0)->debug
) {
326 printf("KGMON_SET_DEBUG_ON, cpu = %d\n", cpu
);
333 if (!PROFILE_VARS(0)->debug
) {
334 for (i
= 0; i
< max_cpus
; i
++) {
335 PROFILE_VARS(i
)->debug
= 1;
339 (*control_func
)(kgmon
);
346 case KGMON_SET_DEBUG_OFF
: /* turn off profiling */
348 if (PROFILE_VARS(0)->debug
) {
349 printf("KGMON_SET_DEBUG_OFF, cpu = %d\n", cpu
);
356 if (PROFILE_VARS(0)->debug
) {
357 for (i
= 0; i
< max_cpus
; i
++) {
358 PROFILE_VARS(i
)->debug
= 0;
362 (*control_func
)(kgmon
);
373 if (PROFILE_VARS(0)->debug
) {
374 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, error = %d\n",
381 if (PROFILE_VARS(0)->debug
) {
382 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, count = %ld\n",
383 kgmon
, cpu
, (long)count
);