]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/rtclock_native.c
xnu-4570.51.1.tar.gz
[apple/xnu.git] / osfmk / i386 / rtclock_native.c
index 5ffaf91d85e320d68fcf10a797c8256be6ff8a9f..13cde8e79ff765720fb954895b8660f6076644ae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -29,8 +29,6 @@
  * @OSF_COPYRIGHT@
  */
 
-#include <platforms.h>
-#include <mach_kdb.h>
 
 #include <mach/mach_types.h>
 
@@ -50,7 +48,7 @@
 #include <i386/tsc.h>
 #include <i386/rtclock_protos.h>
 #include <i386/pal_routines.h>
-#include <kern/etimer.h>
+#include <kern/timer_queue.h>
 
 static uint64_t        rtc_decrementer_min;
 static uint64_t        rtc_decrementer_max;
@@ -70,21 +68,6 @@ deadline_to_decrementer(
        }
 }
 
-static inline uint64_t
-_absolutetime_to_tsc(uint64_t ns)
-{
-       uint32_t        generation;
-       uint64_t        tsc;
-
-       do {
-               generation =  pal_rtc_nanotime_info.generation;
-               tsc = tmrCvt(ns - pal_rtc_nanotime_info.ns_base, tscFCvtn2t)
-                       + pal_rtc_nanotime_info.tsc_base;
-       } while (generation == 0 ||
-                generation != pal_rtc_nanotime_info.generation);
-
-       return tsc;
-}
 
 /*
  * Regular local APIC timer case:
@@ -111,6 +94,13 @@ rtc_lapic_set_timer(uint64_t deadline, uint64_t now)
        } else {
                lapic_set_timer(FALSE, one_shot, divide_by_1, 0);
        }
+
+       KERNEL_DEBUG_CONSTANT(
+               DECR_SET_APIC_DEADLINE | DBG_FUNC_NONE,
+               now, deadline,
+               set, LAPIC_READ(TIMER_CURRENT_COUNT),
+               0);
+
        return set;
 }
 
@@ -125,14 +115,19 @@ rtc_lapic_config_tsc_deadline_timer(void)
 static uint64_t
 rtc_lapic_set_tsc_deadline_timer(uint64_t deadline, uint64_t now)
 {
-       uint64_t        set = 0;
+       uint64_t delta;
+       uint64_t delta_tsc;
+       uint64_t tsc = rdtsc64();
+       uint64_t set = 0;
 
        if (deadline > 0) {
                /*
                 * Convert to TSC
                 */
-               set = now + deadline_to_decrementer(deadline, now);
-               lapic_set_tsc_deadline_timer(_absolutetime_to_tsc(set));
+               delta = deadline_to_decrementer(deadline, now);
+               set = now + delta;
+               delta_tsc = tmrCvt(delta, tscFCvtn2t);
+               lapic_set_tsc_deadline_timer(tsc + delta_tsc);
        } else {
                lapic_set_tsc_deadline_timer(0);
        }
@@ -140,7 +135,7 @@ rtc_lapic_set_tsc_deadline_timer(uint64_t deadline, uint64_t now)
        KERNEL_DEBUG_CONSTANT(
                DECR_SET_TSC_DEADLINE | DBG_FUNC_NONE,
                now, deadline,
-               rdtsc64(), lapic_get_tsc_deadline_timer(),
+               tsc, lapic_get_tsc_deadline_timer(),
                0);
 
        return set;