]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/etimer.c
xnu-1504.7.4.tar.gz
[apple/xnu.git] / osfmk / i386 / etimer.c
index ddbd77ffcca26ef009c486ddac63f9b48d83772d..aacc02ebc12baf2502f6975d48267849ec39917f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -39,6 +39,7 @@
 
 #include <mach/mach_types.h>
 
+#include <kern/timer_queue.h>
 #include <kern/clock.h>
 #include <kern/thread.h>
 #include <kern/processor.h>
@@ -55,9 +56,6 @@
 #include <i386/cpu_topology.h>
 #include <i386/cpu_threads.h>
 
-/* XXX from <arch>/rtclock.c */
-clock_timer_func_t             rtclock_timer_expire;
-
 /*
  *     Event timer interrupt.
  *
@@ -94,8 +92,7 @@ __unused uint64_t iaddr)
        /* has a pending clock timer expired? */
        if (mytimer->deadline <= abstime) {                     /* Have we expired the deadline? */
                mytimer->has_expired = TRUE;                    /* Remember that we popped */
-               mytimer->deadline = EndOfAllTime;               /* Set timer request to the end of all time in case we have no more events */
-               (*rtclock_timer_expire)(abstime);               /* Process pop */
+               mytimer->deadline = timer_queue_expire(&mytimer->queue, abstime);
                mytimer->has_expired = FALSE;
        }
 
@@ -105,7 +102,7 @@ __unused uint64_t iaddr)
 }
 
 /*
- * Set the clock deadline; called by the thread scheduler.
+ * Set the clock deadline.
  */
 void etimer_set_deadline(uint64_t deadline)
 {
@@ -178,3 +175,59 @@ etimer_resync_deadlines(void)
        }
        splx(s);
 }
+
+void etimer_timer_expire(void  *arg);
+
+void
+etimer_timer_expire(
+__unused void                  *arg)
+{
+       rtclock_timer_t         *mytimer;
+       uint64_t                        abstime;
+       cpu_data_t                      *pp;
+       x86_lcpu_t                      *lcpu;
+
+       pp = current_cpu_datap();
+       lcpu = x86_lcpu();
+
+       mytimer = &pp->rtclock_timer;
+       abstime = mach_absolute_time();
+
+       mytimer->has_expired = TRUE;
+       mytimer->deadline = timer_queue_expire(&mytimer->queue, abstime);
+       mytimer->has_expired = FALSE;
+
+       lcpu->rtcPop = EndOfAllTime;
+       etimer_resync_deadlines();
+}
+
+queue_t
+timer_queue_assign(
+    uint64_t        deadline)
+{
+       cpu_data_t                      *cdp = current_cpu_datap();
+       rtclock_timer_t         *timer;
+
+       if (cdp->cpu_running) {
+               timer = &cdp->rtclock_timer;
+
+               if (deadline < timer->deadline)
+                       etimer_set_deadline(deadline);
+       }
+       else
+               timer = &cpu_datap(master_cpu)->rtclock_timer;
+
+    return (&timer->queue);
+}
+
+void
+timer_queue_cancel(
+    queue_t         queue,
+    uint64_t        deadline,
+    uint64_t        new_deadline)
+{
+    if (queue == &current_cpu_datap()->rtclock_timer.queue) {
+        if (deadline < new_deadline)
+            etimer_set_deadline(new_deadline);
+    }
+}