]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/monotonic.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / kern / monotonic.h
CommitLineData
5ba3f43e 1/*
cb323159 2 * Copyright (c) 2017-2019 Apple Inc. All rights reserved.
5ba3f43e
A
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#ifndef KERN_MONOTONIC_H
29#define KERN_MONOTONIC_H
30
cb323159
A
31#if MONOTONIC
32
5ba3f43e
A
33#include <stdbool.h>
34#include <stdint.h>
d9a64523
A
35#include <sys/cdefs.h>
36
37__BEGIN_DECLS
5ba3f43e
A
38
39extern bool mt_debug;
40extern _Atomic uint64_t mt_pmis;
41extern _Atomic uint64_t mt_retrograde;
42
43void mt_fixed_counts(uint64_t *counts);
44void mt_cur_thread_fixed_counts(uint64_t *counts);
45void mt_cur_task_fixed_counts(uint64_t *counts);
46uint64_t mt_cur_cpu_instrs(void);
47uint64_t mt_cur_cpu_cycles(void);
48uint64_t mt_cur_thread_instrs(void);
49uint64_t mt_cur_thread_cycles(void);
50
d9a64523
A
51__END_DECLS
52
5ba3f43e
A
53#if MACH_KERNEL_PRIVATE
54
55#include <kern/thread.h>
56#include <kern/task.h>
57#include <stdbool.h>
58
d9a64523
A
59__BEGIN_DECLS
60
5ba3f43e
A
61#if defined(__arm__) || defined(__arm64__)
62#include <arm/cpu_data_internal.h>
63#elif defined(__x86_64__)
64#include <i386/cpu_data.h>
65#else /* !defined(__arm__) && !defined(__arm64__) && !defined(__x86_64__) */
66#error unsupported architecture
67#endif /* !defined(__arm__) && !defined(__arm64__) && !defined(__x86_64__) */
68
5ba3f43e
A
69void mt_update_fixed_counts(void);
70void mt_update_task(task_t task, thread_t thread);
71bool mt_update_thread(thread_t thread);
72int mt_fixed_thread_counts(thread_t thread, uint64_t *counts_out);
73int mt_fixed_task_counts(task_t task, uint64_t *counts_out);
74
75/*
d9a64523 76 * Private API for the platform layers.
5ba3f43e 77 */
5ba3f43e
A
78
79/*
d9a64523
A
80 * Called once early in boot, before CPU initialization occurs (where
81 * `mt_cpu_up` is called).
82 *
83 * This allows monotonic to detect if the hardware supports performance counters
84 * and install the global PMI handler.
5ba3f43e 85 */
d9a64523 86void mt_early_init(void);
5ba3f43e
A
87
88/*
89 * Called when a core is idling and exiting from idle.
90 */
91void mt_cpu_idle(cpu_data_t *cpu);
92void mt_cpu_run(cpu_data_t *cpu);
93
94/*
95 * Called when a core is shutting down or powering up.
96 */
97void mt_cpu_down(cpu_data_t *cpu);
98void mt_cpu_up(cpu_data_t *cpu);
99
100/*
d9a64523 101 * Called while single-threaded when the system is going to sleep.
5ba3f43e
A
102 */
103void mt_sleep(void);
d9a64523
A
104
105/*
106 * Called on each CPU as the system is waking from sleep.
107 */
108void mt_wake_per_core(void);
109
d9a64523
A
110/*
111 * "Up-call" to the Mach layer to update counters from a PMI.
112 */
113uint64_t mt_cpu_update_count(cpu_data_t *cpu, unsigned int ctr);
114
115/*
116 * Private API for the scheduler.
117 */
118
119/*
120 * Called when a thread is switching off-core or expires its quantum.
121 */
122void mt_sched_update(thread_t thread);
123
124/*
125 * Called when a thread is terminating to save its counters into the task. The
126 * task lock must be held and the thread should be removed from the task's
127 * thread list in that same critical section.
128 */
129void mt_terminate_update(task_t task, thread_t thread);
5ba3f43e
A
130
131/*
132 * Private API for the performance controller callout.
133 */
134void mt_perfcontrol(uint64_t *instrs, uint64_t *cycles);
135
136/*
137 * Private API for stackshot.
138 */
139void mt_stackshot_thread(thread_t thread, uint64_t *instrs, uint64_t *cycles);
140void mt_stackshot_task(task_t task, uint64_t *instrs, uint64_t *cycles);
141
d9a64523
A
142/*
143 * Private API for microstackshot.
144 */
145typedef void (*mt_pmi_fn)(bool user_mode, void *ctx);
146int mt_microstackshot_start(unsigned int ctr, uint64_t period, mt_pmi_fn fn,
0a7de745 147 void *ctx);
d9a64523
A
148int mt_microstackshot_stop(void);
149
150__END_DECLS
151
5ba3f43e
A
152#endif /* MACH_KERNEL_PRIVATE */
153
cb323159
A
154#endif /* MONOTONIC */
155
5ba3f43e 156#endif /* !defined(KERN_MONOTONIC_H) */