]>
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_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
36 * Revision 1.1.1.1 1998/09/22 21:05:49 wsanchez
37 * Import of Mac OS X kernel (~semeria)
39 * Revision 1.1.1.1 1998/03/07 02:26:08 wsanchez
40 * Import of OSF Mach kernel (~mburg)
42 * Revision 1.1.5.1 1995/01/06 19:54:04 devrcs
43 * mk6 CR668 - 1.3b26 merge
45 * [1994/10/12 22:25:34 dwm]
47 * Revision 1.1.2.1 1994/04/08 17:52:05 meissner
48 * Add callback function to _profile_kgmon.
49 * [1994/02/16 22:38:31 meissner]
51 * _profile_kgmon now returns pointer to area, doesn't do move itself.
52 * [1994/02/11 16:52:17 meissner]
54 * Move all printfs into if (pv->debug) { ... } blocks.
55 * Add debug printfs protected by if (pv->debug) for all error conditions.
56 * Add code to reset profiling information.
57 * Add code to get/set debug flag.
59 * [1994/02/07 12:41:14 meissner]
61 * Add support to copy arbitrary regions.
62 * Delete several of the KGMON_GET commands, now that arb. regions are supported.
63 * Explicitly call _profile_update_stats before dumping vars or stats.
64 * [1994/02/03 00:59:05 meissner]
66 * Combine _profile_{vars,stats,md}; Allow more than one _profile_vars.
67 * [1994/02/01 12:04:09 meissner]
69 * CR 10198 - Initial version.
70 * [1994/01/28 23:33:37 meissner]
75 #include <profiling/profile-internal.h>
78 #include <profiling/machine/profile-md.h>
82 #define PROFILE_VARS(cpu) (&_profile_vars)
85 extern int printf(const char *, ...);
89 * Kgmon interface. This returns the count of bytes moved if everything was ok,
90 * or -1 if there were errors.
94 _profile_kgmon(int write
,
99 void (*control_func
)(kgmon_control_t
))
101 kgmon_control_t kgmon
;
105 struct profile_vars
*pv
;
106 static struct callback dummy_callback
;
111 * If the number passed is not within bounds, just copy the data directly.
114 if (!LEGAL_KGMON(indx
)) {
115 *p_ptr
= (void *)indx
;
117 if (PROFILE_VARS(0)->debug
) {
118 printf("_profile_kgmon: copy %5ld bytes, from 0x%lx\n",
124 if (PROFILE_VARS(0)->debug
) {
125 printf("_profile_kgmon: copy %5ld bytes, to 0x%lx\n",
135 * Decode the record number into the component pieces.
138 DECODE_KGMON(indx
, kgmon
, cpu
);
140 if (PROFILE_VARS(0)->debug
) {
141 printf("_profile_kgmon: start: kgmon control = %2d, cpu = %d, count = %ld\n",
142 kgmon
, cpu
, (long)count
);
145 /* Validate the CPU number */
146 if (cpu
< 0 || cpu
>= max_cpus
) {
147 if (PROFILE_VARS(0)->debug
) {
148 printf("KGMON, bad cpu %d\n", cpu
);
154 pv
= PROFILE_VARS(cpu
);
159 if (PROFILE_VARS(0)->debug
) {
160 printf("Unknown KGMON read command\n");
166 case KGMON_GET_STATUS
: /* return whether or not profiling is active */
168 if (PROFILE_VARS(0)->debug
) {
169 printf("KGMON_GET_STATUS: cpu = %d\n", cpu
);
176 if (count
!= sizeof(pv
->active
)) {
177 if (PROFILE_VARS(0)->debug
) {
178 printf("KGMON_GET_STATUS: count = %ld, should be %ld\n",
180 (long)sizeof(pv
->active
));
187 *p_ptr
= (void *)&pv
->active
;
190 case KGMON_GET_DEBUG
: /* return whether or not debugging is active */
192 if (PROFILE_VARS(0)->debug
) {
193 printf("KGMON_GET_DEBUG: cpu = %d\n", cpu
);
200 if (count
!= sizeof(pv
->debug
)) {
201 if (PROFILE_VARS(0)->debug
) {
202 printf("KGMON_GET_DEBUG: count = %ld, should be %ld\n",
204 (long)sizeof(pv
->active
));
211 *p_ptr
= (void *)&pv
->debug
;
214 case KGMON_GET_PROFILE_VARS
: /* return the _profile_vars structure */
215 if (count
!= sizeof(struct profile_vars
)) {
216 if (PROFILE_VARS(0)->debug
) {
217 printf("KGMON_GET_PROFILE_VARS: count = %ld, should be %ld\n",
219 (long)sizeof(struct profile_vars
));
226 _profile_update_stats(pv
);
230 case KGMON_GET_PROFILE_STATS
: /* return the _profile_stats structure */
231 if (count
!= sizeof(struct profile_stats
)) {
232 if (PROFILE_VARS(0)->debug
) {
233 printf("KGMON_GET_PROFILE_STATS: count = %ld, should be = %ld\n",
235 (long)sizeof(struct profile_stats
));
242 _profile_update_stats(pv
);
243 *p_ptr
= (void *)&pv
->stats
;
250 if (PROFILE_VARS(0)->debug
) {
251 printf("Unknown KGMON write command\n");
257 case KGMON_SET_PROFILE_ON
: /* turn on profiling */
259 if (PROFILE_VARS(0)->debug
) {
260 printf("KGMON_SET_PROFILE_ON, cpu = %d\n", cpu
);
267 if (!PROFILE_VARS(0)->active
) {
268 for (i
= 0; i
< max_cpus
; i
++) {
269 PROFILE_VARS(i
)->active
= 1;
273 (*control_func
)(kgmon
);
282 case KGMON_SET_PROFILE_OFF
: /* turn off profiling */
284 if (PROFILE_VARS(0)->debug
) {
285 printf("KGMON_SET_PROFILE_OFF, cpu = %d\n", cpu
);
292 if (PROFILE_VARS(0)->active
) {
293 for (i
= 0; i
< max_cpus
; i
++) {
294 PROFILE_VARS(i
)->active
= 0;
300 (*control_func
)(kgmon
);
307 case KGMON_SET_PROFILE_RESET
: /* reset profiling */
309 if (PROFILE_VARS(0)->debug
) {
310 printf("KGMON_SET_PROFILE_RESET, cpu = %d\n", cpu
);
317 for (i
= 0; i
< max_cpus
; i
++) {
318 _profile_reset(PROFILE_VARS(i
));
322 (*control_func
)(kgmon
);
328 case KGMON_SET_DEBUG_ON
: /* turn on profiling */
330 if (PROFILE_VARS(0)->debug
) {
331 printf("KGMON_SET_DEBUG_ON, cpu = %d\n", cpu
);
338 if (!PROFILE_VARS(0)->debug
) {
339 for (i
= 0; i
< max_cpus
; i
++) {
340 PROFILE_VARS(i
)->debug
= 1;
344 (*control_func
)(kgmon
);
351 case KGMON_SET_DEBUG_OFF
: /* turn off profiling */
353 if (PROFILE_VARS(0)->debug
) {
354 printf("KGMON_SET_DEBUG_OFF, cpu = %d\n", cpu
);
361 if (PROFILE_VARS(0)->debug
) {
362 for (i
= 0; i
< max_cpus
; i
++) {
363 PROFILE_VARS(i
)->debug
= 0;
367 (*control_func
)(kgmon
);
378 if (PROFILE_VARS(0)->debug
) {
379 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, error = %d\n",
386 if (PROFILE_VARS(0)->debug
) {
387 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, count = %ld\n",
388 kgmon
, cpu
, (long)count
);