]>
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 * 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@
28 * Revision 1.1.1.1 1998/09/22 21:05:49 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.1.1.1 1998/03/07 02:26:08 wsanchez
32 * Import of OSF Mach kernel (~mburg)
34 * Revision 1.1.5.1 1995/01/06 19:54:04 devrcs
35 * mk6 CR668 - 1.3b26 merge
37 * [1994/10/12 22:25:34 dwm]
39 * Revision 1.1.2.1 1994/04/08 17:52:05 meissner
40 * Add callback function to _profile_kgmon.
41 * [1994/02/16 22:38:31 meissner]
43 * _profile_kgmon now returns pointer to area, doesn't do move itself.
44 * [1994/02/11 16:52:17 meissner]
46 * Move all printfs into if (pv->debug) { ... } blocks.
47 * Add debug printfs protected by if (pv->debug) for all error conditions.
48 * Add code to reset profiling information.
49 * Add code to get/set debug flag.
51 * [1994/02/07 12:41:14 meissner]
53 * Add support to copy arbitrary regions.
54 * Delete several of the KGMON_GET commands, now that arb. regions are supported.
55 * Explicitly call _profile_update_stats before dumping vars or stats.
56 * [1994/02/03 00:59:05 meissner]
58 * Combine _profile_{vars,stats,md}; Allow more than one _profile_vars.
59 * [1994/02/01 12:04:09 meissner]
61 * CR 10198 - Initial version.
62 * [1994/01/28 23:33:37 meissner]
67 #include <profiling/profile-internal.h>
70 #include <profiling/machine/profile-md.h>
74 #define PROFILE_VARS(cpu) (&_profile_vars)
77 extern int printf(const char *, ...);
81 * Kgmon interface. This returns the count of bytes moved if everything was ok,
82 * or -1 if there were errors.
86 _profile_kgmon(int write
,
91 void (*control_func
)(kgmon_control_t
))
93 kgmon_control_t kgmon
;
97 struct profile_vars
*pv
;
98 static struct callback dummy_callback
;
103 * If the number passed is not within bounds, just copy the data directly.
106 if (!LEGAL_KGMON(indx
)) {
107 *p_ptr
= (void *)indx
;
109 if (PROFILE_VARS(0)->debug
) {
110 printf("_profile_kgmon: copy %5ld bytes, from 0x%lx\n",
116 if (PROFILE_VARS(0)->debug
) {
117 printf("_profile_kgmon: copy %5ld bytes, to 0x%lx\n",
127 * Decode the record number into the component pieces.
130 DECODE_KGMON(indx
, kgmon
, cpu
);
132 if (PROFILE_VARS(0)->debug
) {
133 printf("_profile_kgmon: start: kgmon control = %2d, cpu = %d, count = %ld\n",
134 kgmon
, cpu
, (long)count
);
137 /* Validate the CPU number */
138 if (cpu
< 0 || cpu
>= max_cpus
) {
139 if (PROFILE_VARS(0)->debug
) {
140 printf("KGMON, bad cpu %d\n", cpu
);
146 pv
= PROFILE_VARS(cpu
);
151 if (PROFILE_VARS(0)->debug
) {
152 printf("Unknown KGMON read command\n");
158 case KGMON_GET_STATUS
: /* return whether or not profiling is active */
160 if (PROFILE_VARS(0)->debug
) {
161 printf("KGMON_GET_STATUS: cpu = %d\n", cpu
);
168 if (count
!= sizeof(pv
->active
)) {
169 if (PROFILE_VARS(0)->debug
) {
170 printf("KGMON_GET_STATUS: count = %ld, should be %ld\n",
172 (long)sizeof(pv
->active
));
179 *p_ptr
= (void *)&pv
->active
;
182 case KGMON_GET_DEBUG
: /* return whether or not debugging is active */
184 if (PROFILE_VARS(0)->debug
) {
185 printf("KGMON_GET_DEBUG: cpu = %d\n", cpu
);
192 if (count
!= sizeof(pv
->debug
)) {
193 if (PROFILE_VARS(0)->debug
) {
194 printf("KGMON_GET_DEBUG: count = %ld, should be %ld\n",
196 (long)sizeof(pv
->active
));
203 *p_ptr
= (void *)&pv
->debug
;
206 case KGMON_GET_PROFILE_VARS
: /* return the _profile_vars structure */
207 if (count
!= sizeof(struct profile_vars
)) {
208 if (PROFILE_VARS(0)->debug
) {
209 printf("KGMON_GET_PROFILE_VARS: count = %ld, should be %ld\n",
211 (long)sizeof(struct profile_vars
));
218 _profile_update_stats(pv
);
222 case KGMON_GET_PROFILE_STATS
: /* return the _profile_stats structure */
223 if (count
!= sizeof(struct profile_stats
)) {
224 if (PROFILE_VARS(0)->debug
) {
225 printf("KGMON_GET_PROFILE_STATS: count = %ld, should be = %ld\n",
227 (long)sizeof(struct profile_stats
));
234 _profile_update_stats(pv
);
235 *p_ptr
= (void *)&pv
->stats
;
242 if (PROFILE_VARS(0)->debug
) {
243 printf("Unknown KGMON write command\n");
249 case KGMON_SET_PROFILE_ON
: /* turn on profiling */
251 if (PROFILE_VARS(0)->debug
) {
252 printf("KGMON_SET_PROFILE_ON, cpu = %d\n", cpu
);
259 if (!PROFILE_VARS(0)->active
) {
260 for (i
= 0; i
< max_cpus
; i
++) {
261 PROFILE_VARS(i
)->active
= 1;
265 (*control_func
)(kgmon
);
274 case KGMON_SET_PROFILE_OFF
: /* turn off profiling */
276 if (PROFILE_VARS(0)->debug
) {
277 printf("KGMON_SET_PROFILE_OFF, cpu = %d\n", cpu
);
284 if (PROFILE_VARS(0)->active
) {
285 for (i
= 0; i
< max_cpus
; i
++) {
286 PROFILE_VARS(i
)->active
= 0;
292 (*control_func
)(kgmon
);
299 case KGMON_SET_PROFILE_RESET
: /* reset profiling */
301 if (PROFILE_VARS(0)->debug
) {
302 printf("KGMON_SET_PROFILE_RESET, cpu = %d\n", cpu
);
309 for (i
= 0; i
< max_cpus
; i
++) {
310 _profile_reset(PROFILE_VARS(i
));
314 (*control_func
)(kgmon
);
320 case KGMON_SET_DEBUG_ON
: /* turn on profiling */
322 if (PROFILE_VARS(0)->debug
) {
323 printf("KGMON_SET_DEBUG_ON, cpu = %d\n", cpu
);
330 if (!PROFILE_VARS(0)->debug
) {
331 for (i
= 0; i
< max_cpus
; i
++) {
332 PROFILE_VARS(i
)->debug
= 1;
336 (*control_func
)(kgmon
);
343 case KGMON_SET_DEBUG_OFF
: /* turn off profiling */
345 if (PROFILE_VARS(0)->debug
) {
346 printf("KGMON_SET_DEBUG_OFF, cpu = %d\n", cpu
);
353 if (PROFILE_VARS(0)->debug
) {
354 for (i
= 0; i
< max_cpus
; i
++) {
355 PROFILE_VARS(i
)->debug
= 0;
359 (*control_func
)(kgmon
);
370 if (PROFILE_VARS(0)->debug
) {
371 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, error = %d\n",
378 if (PROFILE_VARS(0)->debug
) {
379 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, count = %ld\n",
380 kgmon
, cpu
, (long)count
);