]>
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_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 * Revision 1.1.1.1 1998/09/22 21:05:49 wsanchez
35 * Import of Mac OS X kernel (~semeria)
37 * Revision 1.1.1.1 1998/03/07 02:26:08 wsanchez
38 * Import of OSF Mach kernel (~mburg)
40 * Revision 1.1.5.1 1995/01/06 19:54:04 devrcs
41 * mk6 CR668 - 1.3b26 merge
43 * [1994/10/12 22:25:34 dwm]
45 * Revision 1.1.2.1 1994/04/08 17:52:05 meissner
46 * Add callback function to _profile_kgmon.
47 * [1994/02/16 22:38:31 meissner]
49 * _profile_kgmon now returns pointer to area, doesn't do move itself.
50 * [1994/02/11 16:52:17 meissner]
52 * Move all printfs into if (pv->debug) { ... } blocks.
53 * Add debug printfs protected by if (pv->debug) for all error conditions.
54 * Add code to reset profiling information.
55 * Add code to get/set debug flag.
57 * [1994/02/07 12:41:14 meissner]
59 * Add support to copy arbitrary regions.
60 * Delete several of the KGMON_GET commands, now that arb. regions are supported.
61 * Explicitly call _profile_update_stats before dumping vars or stats.
62 * [1994/02/03 00:59:05 meissner]
64 * Combine _profile_{vars,stats,md}; Allow more than one _profile_vars.
65 * [1994/02/01 12:04:09 meissner]
67 * CR 10198 - Initial version.
68 * [1994/01/28 23:33:37 meissner]
73 #include <profiling/profile-internal.h>
76 #include <profiling/machine/profile-md.h>
80 #define PROFILE_VARS(cpu) (&_profile_vars)
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",
118 if (PROFILE_VARS(0)->debug
) {
119 printf("_profile_kgmon: copy %5ld bytes, to 0x%lx\n",
129 * Decode the record number into the component pieces.
132 DECODE_KGMON(indx
, kgmon
, cpu
);
134 if (PROFILE_VARS(0)->debug
) {
135 printf("_profile_kgmon: start: kgmon control = %2d, cpu = %d, count = %ld\n",
136 kgmon
, cpu
, (long)count
);
139 /* Validate the CPU number */
140 if (cpu
< 0 || cpu
>= max_cpus
) {
141 if (PROFILE_VARS(0)->debug
) {
142 printf("KGMON, bad cpu %d\n", cpu
);
147 pv
= PROFILE_VARS(cpu
);
152 if (PROFILE_VARS(0)->debug
) {
153 printf("Unknown KGMON read command\n");
159 case KGMON_GET_STATUS
: /* return whether or not profiling is active */
161 if (PROFILE_VARS(0)->debug
) {
162 printf("KGMON_GET_STATUS: cpu = %d\n", cpu
);
169 if (count
!= sizeof(pv
->active
)) {
170 if (PROFILE_VARS(0)->debug
) {
171 printf("KGMON_GET_STATUS: count = %ld, should be %ld\n",
173 (long)sizeof(pv
->active
));
180 *p_ptr
= (void *)&pv
->active
;
183 case KGMON_GET_DEBUG
: /* return whether or not debugging is active */
185 if (PROFILE_VARS(0)->debug
) {
186 printf("KGMON_GET_DEBUG: cpu = %d\n", cpu
);
193 if (count
!= sizeof(pv
->debug
)) {
194 if (PROFILE_VARS(0)->debug
) {
195 printf("KGMON_GET_DEBUG: count = %ld, should be %ld\n",
197 (long)sizeof(pv
->active
));
204 *p_ptr
= (void *)&pv
->debug
;
207 case KGMON_GET_PROFILE_VARS
: /* return the _profile_vars structure */
208 if (count
!= sizeof(struct profile_vars
)) {
209 if (PROFILE_VARS(0)->debug
) {
210 printf("KGMON_GET_PROFILE_VARS: count = %ld, should be %ld\n",
212 (long)sizeof(struct profile_vars
));
219 _profile_update_stats(pv
);
223 case KGMON_GET_PROFILE_STATS
: /* return the _profile_stats structure */
224 if (count
!= sizeof(struct profile_stats
)) {
225 if (PROFILE_VARS(0)->debug
) {
226 printf("KGMON_GET_PROFILE_STATS: count = %ld, should be = %ld\n",
228 (long)sizeof(struct profile_stats
));
235 _profile_update_stats(pv
);
236 *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
);