]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/kpc.h
xnu-2782.1.97.tar.gz
[apple/xnu.git] / osfmk / kern / kpc.h
1 /*
2 * Copyright (c) 2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef __KERN_KPC_H__
30 #define __KERN_KPC_H__
31
32 /* Kernel interfaces to KPC PMC infrastructure. */
33
34 #include <machine/machine_kpc.h>
35
36 /* cross-platform class constants */
37 #define KPC_CLASS_FIXED (0)
38 #define KPC_CLASS_CONFIGURABLE (1)
39 #define KPC_CLASS_POWER (2)
40 #define KPC_CLASS_RAWPMU (3)
41
42 #define KPC_CLASS_FIXED_MASK (1u << KPC_CLASS_FIXED)
43 #define KPC_CLASS_CONFIGURABLE_MASK (1u << KPC_CLASS_CONFIGURABLE)
44 #define KPC_CLASS_POWER_MASK (1u << KPC_CLASS_POWER)
45 #define KPC_CLASS_RAWPMU_MASK (1u << KPC_CLASS_RAWPMU)
46
47 #define KPC_ALL_CPUS (1u << 31)
48
49 /* bootstrap */
50 extern void kpc_init(void);
51
52 /* Architecture specific initialisation */
53 extern void kpc_arch_init(void);
54
55 /* Get the bitmask of available classes */
56 extern uint32_t kpc_get_classes(void);
57
58 /* Get the bitmask of currently running counter classes */
59 extern uint32_t kpc_get_running(void);
60
61 /* Set the bitmask of currently running counter classes. Specify
62 * classes = 0 to stop counters
63 */
64 extern int kpc_set_running(uint32_t classes);
65
66 /* Read CPU counters */
67 extern int kpc_get_cpu_counters(boolean_t all_cpus, uint32_t classes,
68 int *curcpu, uint64_t *buf);
69
70 /* Read shadow counters */
71 extern int kpc_get_shadow_counters( boolean_t all_cpus, uint32_t classes,
72 int *curcpu, uint64_t *buf );
73
74 /* Read current thread's counter accumulations */
75 extern int kpc_get_curthread_counters(uint32_t *inoutcount, uint64_t *buf);
76
77 /* Given a config, how many counters and config registers there are */
78 extern uint32_t kpc_get_counter_count(uint32_t classes);
79 extern uint32_t kpc_get_config_count(uint32_t classes);
80
81 /* enable/disable thread counting */
82 extern uint32_t kpc_get_thread_counting(void);
83 extern int kpc_set_thread_counting(uint32_t classes);
84
85 /* get and set config registers */
86 extern int kpc_get_config(uint32_t classes, kpc_config_t *current_config);
87 extern int kpc_set_config(uint32_t classes, kpc_config_t *new_config);
88
89 /* get and set PMI period */
90 extern int kpc_get_period(uint32_t classes, uint64_t *period);
91 extern int kpc_set_period(uint32_t classes, uint64_t *period);
92
93 /* get and set kperf actionid */
94 extern int kpc_get_actionid(uint32_t classes, uint32_t *actionid);
95 extern int kpc_set_actionid(uint32_t classes, uint32_t *actionid);
96
97 /* hooks on thread create and delete */
98 extern void kpc_thread_create(thread_t thread);
99 extern void kpc_thread_destroy(thread_t thread);
100
101 /* allocate a buffer big enough for all counters */
102 extern uint64_t *kpc_counterbuf_alloc(void);
103 extern void kpc_counterbuf_free(uint64_t*);
104
105 /* whether we're currently accounting into threads */
106 extern int kpc_threads_counting;
107
108 /* AST callback for KPC */
109 extern void kpc_thread_ast_handler( thread_t thread );
110
111 /* context switch accounting between two threads */
112 extern void kpc_switch_context( thread_t old, thread_t new );
113
114 /* acquire/release the counters used by the Power Manager */
115 extern int kpc_force_all_ctrs( task_t task, int val );
116 extern int kpc_get_force_all_ctrs( void );
117
118 /* arch-specific routine for acquire/release the counters used by the Power Manager */
119 extern int kpc_force_all_ctrs_arch( task_t task, int val );
120
121 extern int kpc_set_sw_inc( uint32_t mask );
122
123 /* disable/enable whitelist of allowed events */
124 extern int kpc_get_whitelist_disabled( void );
125 extern int kpc_disable_whitelist( int val );
126
127 /*
128 * Allow the Power Manager to register for KPC notification when the counters
129 * are acquired/released by a task. The argument is equal to true if the Power
130 * Manager can use the counters, otherwise it is equal to false.
131 */
132 extern boolean_t kpc_register_pm_handler(void (*handler)(boolean_t));
133
134 /*
135 * Is the PMU used by both the power manager and userspace?
136 *
137 * This is true when the power manager has been registered. It disables certain
138 * counter configurations (like RAWPMU) that are incompatible with sharing
139 * counters.
140 */
141 extern boolean_t kpc_multiple_clients(void);
142
143 /*
144 * Is kpc controlling the fixed counters?
145 *
146 * This returns false when the power manager has requested custom configuration
147 * control.
148 */
149 extern boolean_t kpc_controls_fixed_counters(void);
150
151 extern void kpc_idle(void);
152 extern void kpc_idle_exit(void);
153
154
155 /* KPC PRIVATE */
156 extern uint32_t kpc_actionid[KPC_MAX_COUNTERS];
157 /* mp operations */
158 struct kpc_config_remote
159 {
160 uint32_t classes;
161 kpc_config_t *configv;
162 };
163
164 extern int kpc_get_fixed_counters(uint64_t *counterv);
165 extern int kpc_get_configurable_counters(uint64_t *counterv);
166 extern boolean_t kpc_is_running_fixed(void);
167 extern boolean_t kpc_is_running_configurable(void);
168 extern uint32_t kpc_fixed_count(void);
169 extern uint32_t kpc_configurable_count(void);
170 extern uint32_t kpc_fixed_config_count(void);
171 extern uint32_t kpc_configurable_config_count(void);
172 extern uint32_t kpc_rawpmu_config_count(void);
173 extern int kpc_get_fixed_config(kpc_config_t *configv);
174 extern int kpc_get_configurable_config(kpc_config_t *configv);
175 extern int kpc_get_rawpmu_config(kpc_config_t *configv);
176 extern uint64_t kpc_fixed_max(void);
177 extern uint64_t kpc_configurable_max(void);
178 extern int kpc_set_config_arch(struct kpc_config_remote *mp_config);
179 extern int kpc_set_period_arch(struct kpc_config_remote *mp_config);
180 extern void kpc_sample_kperf(uint32_t actionid);
181
182 /* Interface for kexts to publish a kpc interface */
183 struct kpc_driver
184 {
185 uint32_t (*get_classes)(void);
186 uint32_t (*get_running)(void);
187 int (*set_running)(uint32_t classes);
188 int (*get_cpu_counters)(boolean_t all_cpus, uint32_t classes,
189 int *curcpu, uint64_t *buf);
190 int (*get_curthread_counters)(uint32_t *inoutcount, uint64_t *buf);
191 uint32_t (*get_counter_count)(uint32_t classes);
192 uint32_t (*get_config_count)(uint32_t classes);
193 int (*get_config)(uint32_t classes, kpc_config_t *current_config);
194 int (*set_config)(uint32_t classes, kpc_config_t *new_config);
195 int (*get_period)(uint32_t classes, uint64_t *period);
196 int (*set_period)(uint32_t classes, uint64_t *period);
197 };
198
199 #endif /* __KERN_KPC_H__ */