]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/etimer.c
2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * @APPLE_FREE_COPYRIGHT@
36 * Purpose: Routines for handling the machine independent
40 #include <mach/mach_types.h>
42 #include <kern/timer_queue.h>
43 #include <kern/clock.h>
44 #include <kern/thread.h>
45 #include <kern/processor.h>
46 #include <kern/macro_help.h>
48 #include <kern/etimer.h>
51 #include <machine/commpage.h>
52 #include <machine/machine_routines.h>
54 #include <sys/kdebug.h>
55 #include <i386/cpu_data.h>
56 #include <i386/cpu_topology.h>
57 #include <i386/cpu_threads.h>
60 * Event timer interrupt.
62 * XXX a drawback of this implementation is that events serviced earlier must not set deadlines
63 * that occur before the entire chain completes.
65 * XXX a better implementation would use a set of generic callouts and iterate over them
70 __unused
uint64_t iaddr
)
73 rtclock_timer_t
*mytimer
;
77 pp
= current_cpu_datap();
80 mytimer
= &pp
->rtclock_timer
; /* Point to the event timer */
81 abstime
= mach_absolute_time(); /* Get the time now */
83 /* is it time for power management state change? */
84 if (pmCPUGetDeadline(pp
) <= abstime
) {
85 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI
, 3) | DBG_FUNC_START
, 0, 0, 0, 0, 0);
87 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI
, 3) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
89 abstime
= mach_absolute_time(); /* Get the time again since we ran a bit */
92 /* has a pending clock timer expired? */
93 if (mytimer
->deadline
<= abstime
) { /* Have we expired the deadline? */
94 mytimer
->has_expired
= TRUE
; /* Remember that we popped */
95 mytimer
->deadline
= timer_queue_expire(&mytimer
->queue
, abstime
);
96 mytimer
->has_expired
= FALSE
;
99 /* schedule our next deadline */
100 lcpu
->rtcPop
= EndOfAllTime
; /* any real deadline will be earlier */
101 etimer_resync_deadlines();
105 * Set the clock deadline.
107 void etimer_set_deadline(uint64_t deadline
)
109 rtclock_timer_t
*mytimer
;
113 s
= splclock(); /* no interruptions */
114 pp
= current_cpu_datap();
116 mytimer
= &pp
->rtclock_timer
; /* Point to the timer itself */
117 mytimer
->deadline
= deadline
; /* Set the new expiration time */
119 etimer_resync_deadlines();
125 * Re-evaluate the outstanding deadlines and select the most proximate.
127 * Should be called at splclock.
130 etimer_resync_deadlines(void)
134 rtclock_timer_t
*mytimer
;
135 spl_t s
= splclock();
139 pp
= current_cpu_datap();
144 * If we have a clock timer set sooner, pop on that.
146 mytimer
= &pp
->rtclock_timer
;
147 if (!mytimer
->has_expired
&& mytimer
->deadline
> 0)
148 deadline
= mytimer
->deadline
;
151 * If we have a power management deadline, see if that's earlier.
153 pmdeadline
= pmCPUGetDeadline(pp
);
154 if (pmdeadline
> 0 && pmdeadline
< deadline
)
155 deadline
= pmdeadline
;
158 * Go and set the "pop" event.
164 now
= mach_absolute_time();
165 decr
= setPop(deadline
);
168 lcpu
->rtcPop
= now
+ decr
;
170 lcpu
->rtcPop
= deadline
;
172 lcpu
->rtcDeadline
= lcpu
->rtcPop
;
174 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI
, 1) | DBG_FUNC_NONE
, decr
, 2, 0, 0, 0);
179 void etimer_timer_expire(void *arg
);
185 rtclock_timer_t
*mytimer
;
190 pp
= current_cpu_datap();
193 mytimer
= &pp
->rtclock_timer
;
194 abstime
= mach_absolute_time();
196 mytimer
->has_expired
= TRUE
;
197 mytimer
->deadline
= timer_queue_expire(&mytimer
->queue
, abstime
);
198 mytimer
->has_expired
= FALSE
;
200 lcpu
->rtcPop
= EndOfAllTime
;
201 etimer_resync_deadlines();
208 cpu_data_t
*cdp
= current_cpu_datap();
209 rtclock_timer_t
*timer
;
211 if (cdp
->cpu_running
) {
212 timer
= &cdp
->rtclock_timer
;
214 if (deadline
< timer
->deadline
)
215 etimer_set_deadline(deadline
);
218 timer
= &cpu_datap(master_cpu
)->rtclock_timer
;
220 return (&timer
->queue
);
227 uint64_t new_deadline
)
229 if (queue
== ¤t_cpu_datap()->rtclock_timer
.queue
) {
230 if (deadline
< new_deadline
)
231 etimer_set_deadline(new_deadline
);