]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/monotonic.h
xnu-4570.1.46.tar.gz
[apple/xnu.git] / osfmk / kern / monotonic.h
CommitLineData
5ba3f43e
A
1/*
2 * Copyright (c) 2017 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#ifndef KERN_MONOTONIC_H
29#define KERN_MONOTONIC_H
30
31#include <stdbool.h>
32#include <stdint.h>
33
34extern bool mt_debug;
35extern _Atomic uint64_t mt_pmis;
36extern _Atomic uint64_t mt_retrograde;
37
38void mt_fixed_counts(uint64_t *counts);
39void mt_cur_thread_fixed_counts(uint64_t *counts);
40void mt_cur_task_fixed_counts(uint64_t *counts);
41uint64_t mt_cur_cpu_instrs(void);
42uint64_t mt_cur_cpu_cycles(void);
43uint64_t mt_cur_thread_instrs(void);
44uint64_t mt_cur_thread_cycles(void);
45
46#if MACH_KERNEL_PRIVATE
47
48#include <kern/thread.h>
49#include <kern/task.h>
50#include <stdbool.h>
51
52#if defined(__arm__) || defined(__arm64__)
53#include <arm/cpu_data_internal.h>
54#elif defined(__x86_64__)
55#include <i386/cpu_data.h>
56#else /* !defined(__arm__) && !defined(__arm64__) && !defined(__x86_64__) */
57#error unsupported architecture
58#endif /* !defined(__arm__) && !defined(__arm64__) && !defined(__x86_64__) */
59
60void mt_init(void);
61void mt_update_fixed_counts(void);
62void mt_update_task(task_t task, thread_t thread);
63bool mt_update_thread(thread_t thread);
64int mt_fixed_thread_counts(thread_t thread, uint64_t *counts_out);
65int mt_fixed_task_counts(task_t task, uint64_t *counts_out);
66
67/*
68 * Called when a thread is switching off-core or expires its quantum.
69 */
70void mt_sched_update(thread_t thread);
71
72/*
73 * Called when a thread is terminating to save its counters into the task. The
74 * task lock must be held and the thread should be removed from the task's
75 * thread list in that same critical section.
76 */
77void mt_terminate_update(task_t task, thread_t thread);
78
79/*
80 * Called when a core receives a PMI.
81 */
82void mt_cpu_pmi(cpu_data_t *cpu, uint64_t pmsr);
83uint64_t mt_cpu_update_count(cpu_data_t *cpu, unsigned int ctr);
84
85/*
86 * Called when a core is idling and exiting from idle.
87 */
88void mt_cpu_idle(cpu_data_t *cpu);
89void mt_cpu_run(cpu_data_t *cpu);
90
91/*
92 * Called when a core is shutting down or powering up.
93 */
94void mt_cpu_down(cpu_data_t *cpu);
95void mt_cpu_up(cpu_data_t *cpu);
96
97/*
98 * Called while single-threaded when the system is going to sleep and waking up.
99 */
100void mt_sleep(void);
101void mt_wake(void);
102
103/*
104 * Private API for the performance controller callout.
105 */
106void mt_perfcontrol(uint64_t *instrs, uint64_t *cycles);
107
108/*
109 * Private API for stackshot.
110 */
111void mt_stackshot_thread(thread_t thread, uint64_t *instrs, uint64_t *cycles);
112void mt_stackshot_task(task_t task, uint64_t *instrs, uint64_t *cycles);
113
114#endif /* MACH_KERNEL_PRIVATE */
115
116#endif /* !defined(KERN_MONOTONIC_H) */