]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/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/clock.h>
43 #include <kern/thread.h>
44 #include <kern/timer_queue.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 <ppc/exception.h>
58 * Event timer interrupt.
60 * XXX a drawback of this implementation is that events serviced earlier must not set deadlines
61 * that occur before the entire chain completes.
63 * XXX a better implementation would use a set of generic callouts and iterate over them
68 __unused
uint64_t iaddr
)
71 rtclock_timer_t
*mytimer
;
72 struct per_proc_info
*pp
;
76 mytimer
= &pp
->rtclock_timer
; /* Point to the event timer */
78 abstime
= mach_absolute_time(); /* Get the time now */
80 /* is it time for power management state change? */
81 if (pp
->pms
.pmsPop
<= abstime
) {
82 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI
, 3) | DBG_FUNC_START
, 0, 0, 0, 0, 0);
83 pmsStep(1); /* Yes, advance step */
84 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI
, 3) | DBG_FUNC_END
, 0, 0, 0, 0, 0);
86 abstime
= mach_absolute_time(); /* Get the time again since we ran a bit */
89 /* has a pending clock timer expired? */
90 if (mytimer
->deadline
<= abstime
) { /* Have we expired the deadline? */
91 mytimer
->has_expired
= TRUE
; /* Remember that we popped */
92 mytimer
->deadline
= timer_queue_expire(&mytimer
->queue
, abstime
);
93 mytimer
->has_expired
= FALSE
;
96 /* schedule our next deadline */
97 pp
->rtcPop
= EndOfAllTime
; /* any real deadline will be earlier */
98 etimer_resync_deadlines();
102 * Set the clock deadline.
104 void etimer_set_deadline(uint64_t deadline
)
106 rtclock_timer_t
*mytimer
;
108 struct per_proc_info
*pp
;
110 s
= splclock(); /* no interruptions */
113 mytimer
= &pp
->rtclock_timer
; /* Point to the timer itself */
114 mytimer
->deadline
= deadline
; /* Set the new expiration time */
116 etimer_resync_deadlines();
123 * Re-evaluate the outstanding deadlines and select the most proximate.
125 * Should be called at splclock.
128 etimer_resync_deadlines(void)
131 rtclock_timer_t
*mytimer
;
132 spl_t s
= splclock(); /* No interruptions please */
133 struct per_proc_info
*pp
;
139 /* if we have a clock timer set sooner, pop on that */
140 mytimer
= &pp
->rtclock_timer
; /* Point to the timer itself */
141 if (!mytimer
->has_expired
&& mytimer
->deadline
> 0)
142 deadline
= mytimer
->deadline
;
144 /* if we have a power management event coming up, how about that? */
145 if (pp
->pms
.pmsPop
> 0 && pp
->pms
.pmsPop
< deadline
)
146 deadline
= pp
->pms
.pmsPop
;
149 if (deadline
> 0 && deadline
<= pp
->rtcPop
) {
153 now
= mach_absolute_time();
154 decr
= setPop(deadline
);
157 pp
->rtcPop
= now
+ decr
;
159 pp
->rtcPop
= deadline
;
161 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_DECI
, 1) | DBG_FUNC_NONE
, decr
, 2, 0, 0, 0);
170 struct per_proc_info
*pp
= getPerProc();
171 rtclock_timer_t
*timer
;
174 timer
= &pp
->rtclock_timer
;
176 if (deadline
< timer
->deadline
)
177 etimer_set_deadline(deadline
);
180 timer
= &PerProcTable
[master_cpu
].ppe_vaddr
->rtclock_timer
;
182 return (&timer
->queue
);
189 uint64_t new_deadline
)
191 if (queue
== &getPerProc()->rtclock_timer
.queue
) {
192 if (deadline
< new_deadline
)
193 etimer_set_deadline(new_deadline
);