]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kperf/kperf.h
xnu-4570.1.46.tar.gz
[apple/xnu.git] / osfmk / kperf / kperf.h
CommitLineData
1c79356b 1/*
316670eb 2 * Copyright (c) 2011 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 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.
8f6c56a5 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.
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
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.
8f6c56a5 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 35extern lck_grp_t kperf_lck_grp;
b0d623f7 36
39037602
A
37/* the trigger types supported by kperf */
38#define TRIGGER_TYPE_TIMER (0)
39#define TRIGGER_TYPE_PMI (1)
40#define TRIGGER_TYPE_KDEBUG (2)
1c79356b 41
39037602
A
42/* helpers to get and set AST flags on a thread */
43uint32_t kperf_get_thread_flags(thread_t thread);
44void kperf_set_thread_flags(thread_t thread, uint32_t flags);
1c79356b 45
39037602
A
46/*
47 * Get and set dirtiness of thread, so kperf can track whether the thread
48 * has been dispatched since it last looked.
49 */
50boolean_t kperf_thread_get_dirty(thread_t thread);
51void kperf_thread_set_dirty(thread_t thread, boolean_t dirty);
52
53/* possible states of kperf sampling */
54#define KPERF_SAMPLING_OFF (0)
55#define KPERF_SAMPLING_ON (1)
56#define KPERF_SAMPLING_SHUTDOWN (2)
57
58/*
59 * Initialize kperf. Must be called before use and can be called multiple times.
39236c6e 60 */
316670eb 61extern int kperf_init(void);
39236c6e 62
39037602 63/* get and set sampling status */
316670eb
A
64extern unsigned kperf_sampling_status(void);
65extern int kperf_sampling_enable(void);
66extern int kperf_sampling_disable(void);
39236c6e 67
39037602
A
68/* get a per-CPU sample buffer */
69struct kperf_sample *kperf_intr_sample_buffer(void);
70
71/*
72 * kperf AST handler
73 */
74extern __attribute__((noinline)) void kperf_thread_ast_handler(thread_t thread);
75
76/*
77 * thread on core callback
78 */
79
80/* controls whether the callback is called on context switch */
81extern boolean_t kperf_on_cpu_active;
82
83/* update whether the callback is set */
84void kperf_on_cpu_update(void);
85
86/* handle a thread being switched on */
87void kperf_on_cpu_internal(thread_t thread, thread_continue_t continuation,
88 uintptr_t *starting_fp);
89
90/* for scheduler threads switching threads on */
91static inline void
92kperf_on_cpu(thread_t thread, thread_continue_t continuation,
93 uintptr_t *starting_fp)
94{
95 if (__improbable(kperf_on_cpu_active)) {
96 kperf_on_cpu_internal(thread, continuation, starting_fp);
97 }
98}
99
100/*
101 * kdebug callback
39236c6e 102 */
39236c6e 103
39037602
A
104/* controls whether the kdebug callback is called */
105extern boolean_t kperf_kdebug_active;
106
107/* handle the kdebug event */
108void kperf_kdebug_callback_internal(uint32_t debugid);
109
110/* handle a kdebug event */
111void kperf_kdebug_handler(uint32_t debugid, uintptr_t *starting_fp);
112
113/* called inside of kernel_debug_internal */
114static inline void
115kperf_kdebug_callback(uint32_t debugid, uintptr_t *starting_fp)
116{
117 if (__improbable(kperf_kdebug_active)) {
118 kperf_kdebug_handler(debugid, starting_fp);
119 }
120}
121
122/*
123 * Used by ktrace to reset kperf. ktrace_lock must be held.
39236c6e 124 */
39037602 125extern void kperf_reset(void);
39236c6e 126
5ba3f43e
A
127/*
128 * Configure kperf from the kernel (e.g. during boot).
129 */
130void kperf_kernel_configure(const char *config);
131
39236c6e
A
132/* get and set whether we're recording stacks on interesting kdebug events */
133extern int kperf_kdbg_get_stacks(void);
134extern int kperf_kdbg_set_stacks(int);
135
39037602 136extern int kperf_kdebug_cswitch;
3e170ce0 137
39037602
A
138#if DEVELOPMENT || DEBUG
139extern _Atomic long long kperf_pending_ipis;
140#endif /* DEVELOPMENT || DEBUG */
3e170ce0
A
141
142/* get and set whether to output tracepoints on context-switch */
143extern int kperf_kdbg_cswitch_get(void);
144extern int kperf_kdbg_cswitch_set(int newval);
145
39236c6e
A
146/* given a task port, find out its pid */
147int kperf_port_to_pid(mach_port_name_t portname);
148
39037602 149#endif /* !defined(KPERF_H) */