]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/kpc.h
2 * Copyright (c) 2012 Apple 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@
29 #ifndef __KERN_KPC_H__
30 #define __KERN_KPC_H__
32 /** kernel interfaces to KPC PMC infrastructure **/
34 #include <machine/machine_kpc.h>
36 /* cross-platform class constants */
37 #define KPC_CLASS_FIXED (0)
38 #define KPC_CLASS_CONFIGURABLE (1)
39 #define KPC_CLASS_POWER (2)
41 #define KPC_CLASS_FIXED_MASK (1<<KPC_CLASS_FIXED)
42 #define KPC_CLASS_CONFIGURABLE_MASK (1<<KPC_CLASS_CONFIGURABLE)
44 #define KPC_ALL_CPUS (1 << 31)
47 extern void kpc_init(void);
49 /* Get the bitmask of available classes */
50 extern uint32_t kpc_get_classes(void);
52 /* Get the bitmask of currently running counter classes */
53 extern uint32_t kpc_get_running(void);
55 /* Set the bitmask of currently running counter classes. Specify
56 * classes = 0 to stop counters
58 extern int kpc_set_running(uint32_t classes
);
60 /* Read CPU counters */
61 extern int kpc_get_cpu_counters(boolean_t all_cpus
, uint32_t classes
,
62 int *curcpu
, uint64_t *buf
);
64 /* Read shadow counters */
65 extern int kpc_get_shadow_counters( boolean_t all_cpus
, uint32_t classes
,
66 int *curcpu
, uint64_t *buf
);
68 /* Read current thread's counter accumulations */
69 extern int kpc_get_curthread_counters(uint32_t *inoutcount
, uint64_t *buf
);
71 /* Given a config, how many counters and config registers there are */
72 extern uint32_t kpc_get_counter_count(uint32_t classes
);
73 extern uint32_t kpc_get_config_count(uint32_t classes
);
75 /* enable/disable thread counting */
76 extern uint32_t kpc_get_thread_counting(void);
77 extern int kpc_set_thread_counting(uint32_t classes
);
79 /* get and set config registers */
80 extern int kpc_get_config(uint32_t classes
, kpc_config_t
*current_config
);
81 extern int kpc_set_config(uint32_t classes
, kpc_config_t
*new_config
);
83 /* get and set PMI period */
84 extern int kpc_get_period(uint32_t classes
, uint64_t *period
);
85 extern int kpc_set_period(uint32_t classes
, uint64_t *period
);
87 /* get and set kperf actionid */
88 extern int kpc_get_actionid(uint32_t classes
, uint32_t *actionid
);
89 extern int kpc_set_actionid(uint32_t classes
, uint32_t *actionid
);
91 /* hooks on thread create and delete */
92 extern void kpc_thread_create(thread_t thread
);
93 extern void kpc_thread_destroy(thread_t thread
);
95 /* allocate a buffer big enough for all counters */
96 extern uint64_t *kpc_counterbuf_alloc(void);
97 extern void kpc_counterbuf_free(uint64_t*);
99 /* whether we're currently accounting into threads */
100 extern int kpc_threads_counting
;
102 /* AST callback for KPC */
103 extern void kpc_thread_ast_handler( thread_t thread
);
105 /* context switch accounting between two threads */
106 extern void kpc_switch_context( thread_t old
, thread_t
new );
108 /* disable/enable whitelist of allowed events */
109 extern int kpc_get_whitelist_disabled( void );
110 extern int kpc_disable_whitelist( int val
);
112 /* allow PM to register a handler to disable it's use of perf counters */
113 extern boolean_t
kpc_register_pm_handler(void (*handler
)(boolean_t
));
116 extern void kpc_idle(void);
117 extern void kpc_idle_exit(void);
121 extern uint32_t kpc_actionid
[KPC_MAX_COUNTERS
];
123 struct kpc_config_remote
126 kpc_config_t
*configv
;
129 extern int kpc_get_fixed_counters(uint64_t *counterv
);
130 extern int kpc_get_configurable_counters(uint64_t *counterv
);
131 extern boolean_t
kpc_is_running_fixed(void);
132 extern boolean_t
kpc_is_running_configurable(void);
133 extern uint32_t kpc_fixed_count(void);
134 extern uint32_t kpc_configurable_count(void);
135 extern uint32_t kpc_fixed_config_count(void);
136 extern uint32_t kpc_configurable_config_count(void);
137 extern int kpc_get_fixed_config(kpc_config_t
*configv
);
138 extern int kpc_get_configurable_config(kpc_config_t
*configv
);
139 extern uint64_t kpc_fixed_max(void);
140 extern uint64_t kpc_configurable_max(void);
141 extern int kpc_set_config_arch(struct kpc_config_remote
*mp_config
);
142 extern int kpc_set_period_arch(struct kpc_config_remote
*mp_config
);
143 extern void kpc_sample_kperf(uint32_t actionid
);
145 /* Interface for kexts to publish a kpc interface */
148 uint32_t (*get_classes
)(void);
149 uint32_t (*get_running
)(void);
150 int (*set_running
)(uint32_t classes
);
151 int (*get_cpu_counters
)(boolean_t all_cpus
, uint32_t classes
,
152 int *curcpu
, uint64_t *buf
);
153 int (*get_curthread_counters
)(uint32_t *inoutcount
, uint64_t *buf
);
154 uint32_t (*get_counter_count
)(uint32_t classes
);
155 uint32_t (*get_config_count
)(uint32_t classes
);
156 int (*get_config
)(uint32_t classes
, kpc_config_t
*current_config
);
157 int (*set_config
)(uint32_t classes
, kpc_config_t
*new_config
);
158 int (*get_period
)(uint32_t classes
, uint64_t *period
);
159 int (*set_period
)(uint32_t classes
, uint64_t *period
);
162 #endif /* __KERN_KPC_H__ */