]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kperf/kperf_kpc.c
2 * Copyright (c) 2013 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@
30 /* Sample KPC data into kperf */
32 #include <mach/mach_types.h>
33 #include <kern/thread.h> /* thread_* */
34 #include <kern/debug.h> /* panic */
35 // #include <sys/proc.h>
37 #include <chud/chud_xnu.h>
38 #include <kperf/kperf.h>
40 #include <kperf/buffer.h>
41 #include <kperf/context.h>
43 #include <kperf/kperf_kpc.h>
45 /* If we have kperf enabled, but not KPC */
49 kperf_kpc_cpu_sample( struct kpcdata
*kpcd
, int sample_config
)
51 kpcd
->running
= kpc_get_running();
52 kpcd
->counterc
= kpc_get_cpu_counters(0, kpcd
->running
,
53 &kpcd
->curcpu
, kpcd
->counterv
);
58 kpcd
->configc
= kpc_get_config_count(kpcd
->running
);
59 kpc_get_config(kpcd
->running
, kpcd
->configv
);
65 kperf_kpc_cpu_log( struct kpcdata
*kpcd
)
69 /* cut a config for instruments -- what's running and
70 * how many fixed counters there are
72 BUF_DATA(PERF_KPC_CONFIG
,
75 kpc_get_counter_count(KPC_CLASS_FIXED_MASK
),
79 /* config registers, if they were asked for */
80 for (i
= 0; i
< ((kpcd
->configc
+3) / 4); i
++) {
81 BUF_DATA( PERF_KPC_CFG_REG
,
82 kpcd
->configv
[0 + i
* 4],
83 kpcd
->configv
[1 + i
* 4],
84 kpcd
->configv
[2 + i
* 4],
85 kpcd
->configv
[3 + i
* 4] );
88 /* and the actual data -- 64-bit trace entries */
89 for (i
= 0; i
< ((kpcd
->counterc
+3) / 4); i
++) {
90 BUF_DATA( PERF_KPC_DATA
,
91 kpcd
->counterv
[0 + i
* 4],
92 kpcd
->counterv
[1 + i
* 4],
93 kpcd
->counterv
[2 + i
* 4],
94 kpcd
->counterv
[3 + i
* 4] );
98 /* config registers, if requested */
99 for (i
= 0; i
< ((kpcd
->configc
+1) / 2); i
++) {
100 BUF_DATA( PERF_KPC_CFG_REG32
,
101 (kpcd
->configv
[0 + i
* 2] >> 32ULL),
102 kpcd
->configv
[0 + i
* 2] & 0xffffffffULL
,
103 (kpcd
->configv
[1 + i
* 2] >> 32ULL),
104 kpcd
->configv
[1 + i
* 2] & 0xffffffffULL
);
107 /* and the actual data -- two counters per tracepoint */
108 for (i
= 0; i
< ((kpcd
->counterc
+1) / 2); i
++) {
109 BUF_DATA( PERF_KPC_DATA32
,
110 (kpcd
->counterv
[0 + i
* 2] >> 32ULL),
111 kpcd
->counterv
[0 + i
* 2] & 0xffffffffULL
,
112 (kpcd
->counterv
[1 + i
* 2] >> 32ULL),
113 kpcd
->counterv
[1 + i
* 2] & 0xffffffffULL
);