]>
Commit | Line | Data |
---|---|---|
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 | ||
34 | extern bool mt_debug; | |
35 | extern _Atomic uint64_t mt_pmis; | |
36 | extern _Atomic uint64_t mt_retrograde; | |
37 | ||
38 | void mt_fixed_counts(uint64_t *counts); | |
39 | void mt_cur_thread_fixed_counts(uint64_t *counts); | |
40 | void mt_cur_task_fixed_counts(uint64_t *counts); | |
41 | uint64_t mt_cur_cpu_instrs(void); | |
42 | uint64_t mt_cur_cpu_cycles(void); | |
43 | uint64_t mt_cur_thread_instrs(void); | |
44 | uint64_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 | ||
60 | void mt_init(void); | |
61 | void mt_update_fixed_counts(void); | |
62 | void mt_update_task(task_t task, thread_t thread); | |
63 | bool mt_update_thread(thread_t thread); | |
64 | int mt_fixed_thread_counts(thread_t thread, uint64_t *counts_out); | |
65 | int 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 | */ | |
70 | void 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 | */ | |
77 | void mt_terminate_update(task_t task, thread_t thread); | |
78 | ||
79 | /* | |
80 | * Called when a core receives a PMI. | |
81 | */ | |
82 | void mt_cpu_pmi(cpu_data_t *cpu, uint64_t pmsr); | |
83 | uint64_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 | */ | |
88 | void mt_cpu_idle(cpu_data_t *cpu); | |
89 | void mt_cpu_run(cpu_data_t *cpu); | |
90 | ||
91 | /* | |
92 | * Called when a core is shutting down or powering up. | |
93 | */ | |
94 | void mt_cpu_down(cpu_data_t *cpu); | |
95 | void 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 | */ | |
100 | void mt_sleep(void); | |
101 | void mt_wake(void); | |
102 | ||
103 | /* | |
104 | * Private API for the performance controller callout. | |
105 | */ | |
106 | void mt_perfcontrol(uint64_t *instrs, uint64_t *cycles); | |
107 | ||
108 | /* | |
109 | * Private API for stackshot. | |
110 | */ | |
111 | void mt_stackshot_thread(thread_t thread, uint64_t *instrs, uint64_t *cycles); | |
112 | void 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) */ |