]>
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 * 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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
29 * Revision 1.1.1.1 1998/09/22 21:05:49 wsanchez
30 * Import of Mac OS X kernel (~semeria)
32 * Revision 1.1.1.1 1998/03/07 02:26:08 wsanchez
33 * Import of OSF Mach kernel (~mburg)
35 * Revision 1.1.5.1 1995/01/06 19:54:04 devrcs
36 * mk6 CR668 - 1.3b26 merge
38 * [1994/10/12 22:25:34 dwm]
40 * Revision 1.1.2.1 1994/04/08 17:52:05 meissner
41 * Add callback function to _profile_kgmon.
42 * [1994/02/16 22:38:31 meissner]
44 * _profile_kgmon now returns pointer to area, doesn't do move itself.
45 * [1994/02/11 16:52:17 meissner]
47 * Move all printfs into if (pv->debug) { ... } blocks.
48 * Add debug printfs protected by if (pv->debug) for all error conditions.
49 * Add code to reset profiling information.
50 * Add code to get/set debug flag.
52 * [1994/02/07 12:41:14 meissner]
54 * Add support to copy arbitrary regions.
55 * Delete several of the KGMON_GET commands, now that arb. regions are supported.
56 * Explicitly call _profile_update_stats before dumping vars or stats.
57 * [1994/02/03 00:59:05 meissner]
59 * Combine _profile_{vars,stats,md}; Allow more than one _profile_vars.
60 * [1994/02/01 12:04:09 meissner]
62 * CR 10198 - Initial version.
63 * [1994/01/28 23:33:37 meissner]
68 #include <profiling/profile-internal.h>
71 #include <profiling/machine/profile-md.h>
75 #define PROFILE_VARS(cpu) (&_profile_vars)
78 extern int printf(const char *, ...);
82 * Kgmon interface. This returns the count of bytes moved if everything was ok,
83 * or -1 if there were errors.
87 _profile_kgmon(int write
,
92 void (*control_func
)(kgmon_control_t
))
94 kgmon_control_t kgmon
;
98 struct profile_vars
*pv
;
99 static struct callback dummy_callback
;
104 * If the number passed is not within bounds, just copy the data directly.
107 if (!LEGAL_KGMON(indx
)) {
108 *p_ptr
= (void *)indx
;
110 if (PROFILE_VARS(0)->debug
) {
111 printf("_profile_kgmon: copy %5ld bytes, from 0x%lx\n",
117 if (PROFILE_VARS(0)->debug
) {
118 printf("_profile_kgmon: copy %5ld bytes, to 0x%lx\n",
128 * Decode the record number into the component pieces.
131 DECODE_KGMON(indx
, kgmon
, cpu
);
133 if (PROFILE_VARS(0)->debug
) {
134 printf("_profile_kgmon: start: kgmon control = %2d, cpu = %d, count = %ld\n",
135 kgmon
, cpu
, (long)count
);
138 /* Validate the CPU number */
139 if (cpu
< 0 || cpu
>= max_cpus
) {
140 if (PROFILE_VARS(0)->debug
) {
141 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
;
243 if (PROFILE_VARS(0)->debug
) {
244 printf("Unknown KGMON write command\n");
250 case KGMON_SET_PROFILE_ON
: /* turn on profiling */
252 if (PROFILE_VARS(0)->debug
) {
253 printf("KGMON_SET_PROFILE_ON, cpu = %d\n", cpu
);
260 if (!PROFILE_VARS(0)->active
) {
261 for (i
= 0; i
< max_cpus
; i
++) {
262 PROFILE_VARS(i
)->active
= 1;
266 (*control_func
)(kgmon
);
275 case KGMON_SET_PROFILE_OFF
: /* turn off profiling */
277 if (PROFILE_VARS(0)->debug
) {
278 printf("KGMON_SET_PROFILE_OFF, cpu = %d\n", cpu
);
285 if (PROFILE_VARS(0)->active
) {
286 for (i
= 0; i
< max_cpus
; i
++) {
287 PROFILE_VARS(i
)->active
= 0;
293 (*control_func
)(kgmon
);
300 case KGMON_SET_PROFILE_RESET
: /* reset profiling */
302 if (PROFILE_VARS(0)->debug
) {
303 printf("KGMON_SET_PROFILE_RESET, cpu = %d\n", cpu
);
310 for (i
= 0; i
< max_cpus
; i
++) {
311 _profile_reset(PROFILE_VARS(i
));
315 (*control_func
)(kgmon
);
321 case KGMON_SET_DEBUG_ON
: /* turn on profiling */
323 if (PROFILE_VARS(0)->debug
) {
324 printf("KGMON_SET_DEBUG_ON, cpu = %d\n", cpu
);
331 if (!PROFILE_VARS(0)->debug
) {
332 for (i
= 0; i
< max_cpus
; i
++) {
333 PROFILE_VARS(i
)->debug
= 1;
337 (*control_func
)(kgmon
);
344 case KGMON_SET_DEBUG_OFF
: /* turn off profiling */
346 if (PROFILE_VARS(0)->debug
) {
347 printf("KGMON_SET_DEBUG_OFF, cpu = %d\n", cpu
);
354 if (PROFILE_VARS(0)->debug
) {
355 for (i
= 0; i
< max_cpus
; i
++) {
356 PROFILE_VARS(i
)->debug
= 0;
360 (*control_func
)(kgmon
);
371 if (PROFILE_VARS(0)->debug
) {
372 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, error = %d\n",
379 if (PROFILE_VARS(0)->debug
) {
380 printf("_profile_kgmon: done: kgmon control = %2d, cpu = %d, count = %ld\n",
381 kgmon
, cpu
, (long)count
);