]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
d9a64523 | 2 | * Copyright (c) 2011-2018 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
d9a64523 | 5 | * |
2d21ac55 A |
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. | |
d9a64523 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
d9a64523 | 17 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
d9a64523 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b | 27 | */ |
1c79356b | 28 | |
39037602 A |
29 | #ifndef KPERF_H |
30 | #define KPERF_H | |
1c79356b | 31 | |
3e170ce0 | 32 | #include <kern/thread.h> |
39037602 | 33 | #include <kern/locks.h> |
3e170ce0 | 34 | |
39037602 | 35 | extern lck_grp_t kperf_lck_grp; |
b0d623f7 | 36 | |
39037602 | 37 | /* the trigger types supported by kperf */ |
d9a64523 A |
38 | #define TRIGGER_TYPE_TIMER (0) |
39 | #define TRIGGER_TYPE_PMI (1) | |
40 | #define TRIGGER_TYPE_KDEBUG (2) | |
41 | #define TRIGGER_TYPE_LAZY_WAIT (3) | |
42 | #define TRIGGER_TYPE_LAZY_CPU (3) | |
1c79356b | 43 | |
39037602 A |
44 | /* helpers to get and set AST flags on a thread */ |
45 | uint32_t kperf_get_thread_flags(thread_t thread); | |
46 | void kperf_set_thread_flags(thread_t thread, uint32_t flags); | |
1c79356b | 47 | |
39037602 A |
48 | /* |
49 | * Get and set dirtiness of thread, so kperf can track whether the thread | |
50 | * has been dispatched since it last looked. | |
51 | */ | |
52 | boolean_t kperf_thread_get_dirty(thread_t thread); | |
53 | void kperf_thread_set_dirty(thread_t thread, boolean_t dirty); | |
54 | ||
55 | /* possible states of kperf sampling */ | |
56 | #define KPERF_SAMPLING_OFF (0) | |
57 | #define KPERF_SAMPLING_ON (1) | |
58 | #define KPERF_SAMPLING_SHUTDOWN (2) | |
59 | ||
60 | /* | |
61 | * Initialize kperf. Must be called before use and can be called multiple times. | |
39236c6e | 62 | */ |
316670eb | 63 | extern int kperf_init(void); |
39236c6e | 64 | |
39037602 | 65 | /* get and set sampling status */ |
316670eb A |
66 | extern unsigned kperf_sampling_status(void); |
67 | extern int kperf_sampling_enable(void); | |
68 | extern int kperf_sampling_disable(void); | |
39236c6e | 69 | |
39037602 A |
70 | /* get a per-CPU sample buffer */ |
71 | struct kperf_sample *kperf_intr_sample_buffer(void); | |
72 | ||
73 | /* | |
d9a64523 | 74 | * Callbacks into kperf from other systems. |
39037602 | 75 | */ |
39037602 A |
76 | |
77 | /* | |
d9a64523 A |
78 | * kperf AST handler |
79 | * | |
80 | * Prevent inlining, since the sampling function allocates on the stack and | |
81 | * branches calling ast_taken (but never on a kperf AST) may blow their stacks. | |
39037602 | 82 | */ |
d9a64523 | 83 | extern __attribute__((noinline)) void kperf_thread_ast_handler(thread_t thread); |
39037602 A |
84 | |
85 | /* update whether the callback is set */ | |
86 | void kperf_on_cpu_update(void); | |
87 | ||
d9a64523 | 88 | /* for scheduler switching threads on */ |
39037602 A |
89 | static inline void |
90 | kperf_on_cpu(thread_t thread, thread_continue_t continuation, | |
0a7de745 | 91 | uintptr_t *starting_fp) |
39037602 | 92 | { |
d9a64523 A |
93 | extern boolean_t kperf_on_cpu_active; |
94 | void kperf_on_cpu_internal(thread_t thread, thread_continue_t continuation, | |
0a7de745 | 95 | uintptr_t *starting_fp); |
d9a64523 | 96 | |
39037602 A |
97 | if (__improbable(kperf_on_cpu_active)) { |
98 | kperf_on_cpu_internal(thread, continuation, starting_fp); | |
99 | } | |
100 | } | |
101 | ||
d9a64523 A |
102 | /* for scheduler switching threads off */ |
103 | static inline void | |
104 | kperf_off_cpu(thread_t thread) | |
105 | { | |
106 | extern unsigned int kperf_lazy_cpu_action; | |
107 | void kperf_lazy_off_cpu(thread_t thread); | |
108 | ||
109 | if (__improbable(kperf_lazy_cpu_action != 0)) { | |
110 | kperf_lazy_off_cpu(thread); | |
111 | } | |
112 | } | |
39236c6e | 113 | |
d9a64523 A |
114 | /* for scheduler making threads runnable */ |
115 | static inline void | |
116 | kperf_make_runnable(thread_t thread, int interrupt) | |
117 | { | |
118 | extern unsigned int kperf_lazy_cpu_action; | |
119 | void kperf_lazy_make_runnable(thread_t thread, bool interrupt); | |
39037602 | 120 | |
d9a64523 A |
121 | if (__improbable(kperf_lazy_cpu_action != 0)) { |
122 | kperf_lazy_make_runnable(thread, interrupt); | |
123 | } | |
124 | } | |
39037602 | 125 | |
d9a64523 A |
126 | /* for interrupt handler epilogue */ |
127 | static inline void | |
128 | kperf_interrupt(void) | |
129 | { | |
130 | extern unsigned int kperf_lazy_cpu_action; | |
131 | extern void kperf_lazy_cpu_sample(thread_t thread, unsigned int flags, | |
0a7de745 | 132 | bool interrupt); |
d9a64523 A |
133 | |
134 | if (__improbable(kperf_lazy_cpu_action != 0)) { | |
135 | kperf_lazy_cpu_sample(current_thread(), 0, true); | |
136 | } | |
137 | } | |
39037602 | 138 | |
d9a64523 | 139 | /* for kdebug on every traced event */ |
39037602 A |
140 | static inline void |
141 | kperf_kdebug_callback(uint32_t debugid, uintptr_t *starting_fp) | |
142 | { | |
d9a64523 A |
143 | extern boolean_t kperf_kdebug_active; |
144 | void kperf_kdebug_handler(uint32_t debugid, uintptr_t *starting_fp); | |
145 | ||
39037602 A |
146 | if (__improbable(kperf_kdebug_active)) { |
147 | kperf_kdebug_handler(debugid, starting_fp); | |
148 | } | |
149 | } | |
150 | ||
151 | /* | |
152 | * Used by ktrace to reset kperf. ktrace_lock must be held. | |
39236c6e | 153 | */ |
39037602 | 154 | extern void kperf_reset(void); |
39236c6e | 155 | |
5ba3f43e A |
156 | /* |
157 | * Configure kperf from the kernel (e.g. during boot). | |
158 | */ | |
159 | void kperf_kernel_configure(const char *config); | |
160 | ||
d9a64523 A |
161 | /* given a task port, find out its pid */ |
162 | int kperf_port_to_pid(mach_port_name_t portname); | |
3e170ce0 | 163 | |
39037602 A |
164 | #if DEVELOPMENT || DEBUG |
165 | extern _Atomic long long kperf_pending_ipis; | |
166 | #endif /* DEVELOPMENT || DEBUG */ | |
3e170ce0 | 167 | |
39037602 | 168 | #endif /* !defined(KPERF_H) */ |