]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | /* |
2 | * Copyright (c) 2007 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 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * @APPLE_FREE_COPYRIGHT@ | |
33 | */ | |
34 | /* | |
35 | * File: etimer.c | |
36 | * Purpose: Routines for handling the machine independent | |
37 | * event timer. | |
38 | */ | |
39 | ||
40 | #include <mach/mach_types.h> | |
41 | ||
42 | #include <kern/clock.h> | |
43 | #include <kern/thread.h> | |
44 | #include <kern/processor.h> | |
45 | #include <kern/macro_help.h> | |
46 | #include <kern/spl.h> | |
47 | #include <kern/timer_queue.h> | |
48 | #include <kern/timer_call.h> | |
49 | ||
50 | #include <machine/commpage.h> | |
51 | #include <machine/machine_routines.h> | |
52 | ||
53 | #include <sys/kdebug.h> | |
54 | #include <arm/cpu_data.h> | |
55 | #include <arm/cpu_data_internal.h> | |
56 | #include <arm/cpu_internal.h> | |
57 | ||
58 | /* | |
0a7de745 | 59 | * Event timer interrupt. |
5ba3f43e A |
60 | * |
61 | * XXX a drawback of this implementation is that events serviced earlier must not set deadlines | |
62 | * that occur before the entire chain completes. | |
63 | * | |
64 | * XXX a better implementation would use a set of generic callouts and iterate over them | |
65 | */ | |
66 | void | |
67 | timer_intr(__unused int inuser, __unused uint64_t iaddr) | |
68 | { | |
69 | uint64_t abstime, new_idle_timeout_ticks; | |
70 | rtclock_timer_t *mytimer; | |
71 | cpu_data_t *cpu_data_ptr; | |
72 | ||
73 | cpu_data_ptr = getCpuDatap(); | |
0a7de745 A |
74 | mytimer = &cpu_data_ptr->rtclock_timer; /* Point to the event timer */ |
75 | abstime = mach_absolute_time(); /* Get the time now */ | |
5ba3f43e A |
76 | |
77 | /* is it time for an idle timer event? */ | |
78 | if ((cpu_data_ptr->idle_timer_deadline > 0) && (cpu_data_ptr->idle_timer_deadline <= abstime)) { | |
79 | cpu_data_ptr->idle_timer_deadline = 0x0ULL; | |
80 | new_idle_timeout_ticks = 0x0ULL; | |
81 | ||
82 | KERNEL_DEBUG_CONSTANT_IST(KDEBUG_COMMON, MACHDBG_CODE(DBG_MACH_EXCP_DECI, 3) | DBG_FUNC_START, 0, 0, 0, 0, 0); | |
83 | ((idle_timer_t)cpu_data_ptr->idle_timer_notify)(cpu_data_ptr->idle_timer_refcon, &new_idle_timeout_ticks); | |
84 | KERNEL_DEBUG_CONSTANT_IST(KDEBUG_COMMON, MACHDBG_CODE(DBG_MACH_EXCP_DECI, 3) | DBG_FUNC_END, 0, 0, 0, 0, 0); | |
85 | ||
86 | /* if a new idle timeout was requested set the new idle timer deadline */ | |
87 | if (new_idle_timeout_ticks != 0x0ULL) { | |
88 | clock_absolutetime_interval_to_deadline(new_idle_timeout_ticks, &cpu_data_ptr->idle_timer_deadline); | |
89 | } | |
90 | ||
0a7de745 | 91 | abstime = mach_absolute_time(); /* Get the time again since we ran a bit */ |
5ba3f43e A |
92 | } |
93 | ||
94 | /* has a pending clock timer expired? */ | |
0a7de745 A |
95 | if (mytimer->deadline <= abstime) { /* Have we expired the |
96 | * deadline? */ | |
97 | mytimer->has_expired = TRUE; /* Remember that we popped */ | |
98 | mytimer->deadline = EndOfAllTime; /* Set timer request to | |
99 | * the end of all time | |
100 | * in case we have no | |
101 | * more events */ | |
5ba3f43e A |
102 | mytimer->deadline = timer_queue_expire(&mytimer->queue, abstime); |
103 | mytimer->has_expired = FALSE; | |
104 | abstime = mach_absolute_time(); /* Get the time again since we ran a bit */ | |
105 | } | |
106 | ||
107 | uint64_t quantum_deadline = cpu_data_ptr->quantum_timer_deadline; | |
108 | /* is it the quantum timer expiration? */ | |
109 | if ((quantum_deadline <= abstime) && (quantum_deadline > 0)) { | |
110 | cpu_data_ptr->quantum_timer_deadline = 0; | |
111 | quantum_timer_expire(abstime); | |
112 | } | |
113 | ||
114 | /* Force reload our next deadline */ | |
115 | cpu_data_ptr->rtcPop = EndOfAllTime; | |
116 | /* schedule our next deadline */ | |
117 | timer_resync_deadlines(); | |
118 | } | |
119 | ||
120 | /* | |
121 | * Set the clock deadline | |
122 | */ | |
0a7de745 | 123 | void |
5ba3f43e A |
124 | timer_set_deadline(uint64_t deadline) |
125 | { | |
126 | rtclock_timer_t *mytimer; | |
127 | spl_t s; | |
128 | cpu_data_t *cpu_data_ptr; | |
129 | ||
0a7de745 | 130 | s = splclock(); /* no interruptions */ |
5ba3f43e A |
131 | cpu_data_ptr = getCpuDatap(); |
132 | ||
0a7de745 A |
133 | mytimer = &cpu_data_ptr->rtclock_timer; /* Point to the timer itself */ |
134 | mytimer->deadline = deadline; /* Set the new expiration time */ | |
5ba3f43e A |
135 | |
136 | timer_resync_deadlines(); | |
137 | ||
138 | splx(s); | |
139 | } | |
140 | ||
141 | void | |
142 | quantum_timer_set_deadline(uint64_t deadline) | |
143 | { | |
144 | cpu_data_t *cpu_data_ptr; | |
145 | ||
146 | /* We should've only come into this path with interrupts disabled */ | |
147 | assert(ml_get_interrupts_enabled() == FALSE); | |
148 | ||
149 | cpu_data_ptr = getCpuDatap(); | |
150 | cpu_data_ptr->quantum_timer_deadline = deadline; | |
151 | timer_resync_deadlines(); | |
152 | } | |
153 | ||
154 | /* | |
155 | * Re-evaluate the outstanding deadlines and select the most proximate. | |
156 | * | |
157 | * Should be called at splclock. | |
158 | */ | |
159 | void | |
160 | timer_resync_deadlines(void) | |
161 | { | |
162 | uint64_t deadline; | |
163 | rtclock_timer_t *mytimer; | |
0a7de745 | 164 | spl_t s = splclock(); /* No interruptions please */ |
5ba3f43e A |
165 | cpu_data_t *cpu_data_ptr; |
166 | ||
167 | cpu_data_ptr = getCpuDatap(); | |
168 | ||
169 | deadline = 0; | |
170 | ||
171 | /* if we have a clock timer set sooner, pop on that */ | |
0a7de745 A |
172 | mytimer = &cpu_data_ptr->rtclock_timer; /* Point to the timer itself */ |
173 | if ((!mytimer->has_expired) && (mytimer->deadline > 0)) { | |
5ba3f43e | 174 | deadline = mytimer->deadline; |
0a7de745 | 175 | } |
5ba3f43e A |
176 | |
177 | /* if we have a idle timer event coming up, how about that? */ | |
178 | if ((cpu_data_ptr->idle_timer_deadline > 0) | |
0a7de745 | 179 | && (cpu_data_ptr->idle_timer_deadline < deadline)) { |
5ba3f43e | 180 | deadline = cpu_data_ptr->idle_timer_deadline; |
0a7de745 | 181 | } |
5ba3f43e A |
182 | |
183 | /* If we have the quantum timer setup, check that */ | |
184 | if ((cpu_data_ptr->quantum_timer_deadline > 0) | |
0a7de745 | 185 | && (cpu_data_ptr->quantum_timer_deadline < deadline)) { |
5ba3f43e | 186 | deadline = cpu_data_ptr->quantum_timer_deadline; |
0a7de745 | 187 | } |
5ba3f43e A |
188 | |
189 | if ((deadline == EndOfAllTime) | |
190 | || ((deadline > 0) && (cpu_data_ptr->rtcPop != deadline))) { | |
191 | int decr; | |
192 | ||
193 | decr = setPop(deadline); | |
194 | ||
0a7de745 A |
195 | KERNEL_DEBUG_CONSTANT_IST(KDEBUG_TRACE, |
196 | MACHDBG_CODE(DBG_MACH_EXCP_DECI, 1) | DBG_FUNC_NONE, | |
5ba3f43e A |
197 | decr, 2, 0, 0, 0); |
198 | } | |
199 | splx(s); | |
200 | } | |
201 | ||
cb323159 A |
202 | void |
203 | timer_queue_expire_local( | |
204 | __unused void *arg) | |
205 | { | |
206 | rtclock_timer_t *mytimer = &getCpuDatap()->rtclock_timer; | |
207 | uint64_t abstime; | |
208 | ||
209 | abstime = mach_absolute_time(); | |
210 | mytimer->has_expired = TRUE; | |
211 | mytimer->deadline = timer_queue_expire(&mytimer->queue, abstime); | |
212 | mytimer->has_expired = FALSE; | |
213 | ||
214 | timer_resync_deadlines(); | |
215 | } | |
5ba3f43e A |
216 | |
217 | boolean_t | |
0a7de745 A |
218 | timer_resort_threshold(__unused uint64_t skew) |
219 | { | |
220 | return FALSE; | |
5ba3f43e A |
221 | } |
222 | ||
223 | mpqueue_head_t * | |
224 | timer_queue_assign( | |
0a7de745 | 225 | uint64_t deadline) |
5ba3f43e | 226 | { |
0a7de745 A |
227 | cpu_data_t *cpu_data_ptr = getCpuDatap(); |
228 | mpqueue_head_t *queue; | |
5ba3f43e A |
229 | |
230 | if (cpu_data_ptr->cpu_running) { | |
231 | queue = &cpu_data_ptr->rtclock_timer.queue; | |
232 | ||
0a7de745 | 233 | if (deadline < cpu_data_ptr->rtclock_timer.deadline) { |
5ba3f43e | 234 | timer_set_deadline(deadline); |
0a7de745 A |
235 | } |
236 | } else { | |
5ba3f43e | 237 | queue = &cpu_datap(master_cpu)->rtclock_timer.queue; |
0a7de745 | 238 | } |
5ba3f43e | 239 | |
0a7de745 | 240 | return queue; |
5ba3f43e A |
241 | } |
242 | ||
243 | void | |
244 | timer_queue_cancel( | |
0a7de745 A |
245 | mpqueue_head_t *queue, |
246 | uint64_t deadline, | |
247 | uint64_t new_deadline) | |
5ba3f43e A |
248 | { |
249 | if (queue == &getCpuDatap()->rtclock_timer.queue) { | |
0a7de745 | 250 | if (deadline < new_deadline) { |
5ba3f43e | 251 | timer_set_deadline(new_deadline); |
0a7de745 | 252 | } |
5ba3f43e A |
253 | } |
254 | } | |
255 | ||
256 | mpqueue_head_t * | |
257 | timer_queue_cpu(int cpu) | |
258 | { | |
259 | return &cpu_datap(cpu)->rtclock_timer.queue; | |
260 | } | |
261 | ||
262 | void | |
263 | timer_call_cpu(int cpu, void (*fn)(void *), void *arg) | |
264 | { | |
265 | cpu_signal(cpu_datap(cpu), SIGPxcall, (void *) fn, arg); | |
266 | } | |
267 | ||
268 | void | |
269 | timer_call_nosync_cpu(int cpu, void (*fn)(void *), void *arg) | |
270 | { | |
271 | /* XXX Needs error checking and retry */ | |
272 | cpu_signal(cpu_datap(cpu), SIGPxcall, (void *) fn, arg); | |
273 | } | |
274 | ||
275 | ||
276 | static timer_coalescing_priority_params_ns_t tcoal_prio_params_init = | |
277 | { | |
278 | .idle_entry_timer_processing_hdeadline_threshold_ns = 5000ULL * NSEC_PER_USEC, | |
279 | .interrupt_timer_coalescing_ilat_threshold_ns = 30ULL * NSEC_PER_USEC, | |
280 | .timer_resort_threshold_ns = 50 * NSEC_PER_MSEC, | |
281 | .timer_coalesce_rt_shift = 0, | |
282 | .timer_coalesce_bg_shift = -5, | |
283 | .timer_coalesce_kt_shift = 3, | |
284 | .timer_coalesce_fp_shift = 3, | |
285 | .timer_coalesce_ts_shift = 3, | |
286 | .timer_coalesce_rt_ns_max = 0ULL, | |
287 | .timer_coalesce_bg_ns_max = 100 * NSEC_PER_MSEC, | |
288 | .timer_coalesce_kt_ns_max = 1 * NSEC_PER_MSEC, | |
289 | .timer_coalesce_fp_ns_max = 1 * NSEC_PER_MSEC, | |
290 | .timer_coalesce_ts_ns_max = 1 * NSEC_PER_MSEC, | |
291 | .latency_qos_scale = {3, 2, 1, -2, -15, -15}, | |
0a7de745 A |
292 | .latency_qos_ns_max = {1 * NSEC_PER_MSEC, 5 * NSEC_PER_MSEC, 20 * NSEC_PER_MSEC, |
293 | 75 * NSEC_PER_MSEC, 10000 * NSEC_PER_MSEC, 10000 * NSEC_PER_MSEC}, | |
5ba3f43e A |
294 | .latency_tier_rate_limited = {FALSE, FALSE, FALSE, FALSE, TRUE, TRUE}, |
295 | }; | |
0a7de745 A |
296 | timer_coalescing_priority_params_ns_t * |
297 | timer_call_get_priority_params(void) | |
5ba3f43e A |
298 | { |
299 | return &tcoal_prio_params_init; | |
300 | } |