* the cpu clock counted by the timestamp MSR.
*/
-#include <platforms.h>
#include <mach/mach_types.h>
#include <i386/rtclock_protos.h>
#define UI_CPUFREQ_ROUNDING_FACTOR 10000000
-int rtclock_config(void);
-
int rtclock_init(void);
uint64_t tsc_rebase_abs_time = 0;
*nanosecs = (clock_usec_t)(abstime % (uint64_t)NSEC_PER_SEC);
}
-/*
- * Configure the real-time clock device. Return success (1)
- * or failure (0).
- */
-
-int
-rtclock_config(void)
-{
- /* nothing to do */
- return (1);
-}
-
-
/*
* Nanotime/mach_absolutime_time
* -----------------------------
uint64_t base)
{
/* Set fixed configuration for lapic timers */
- rtc_timer->config();
+ rtc_timer->rtc_config();
/*
* Reset nanotime.
rtc_nanotime_init(base);
}
+/*
+ * rtclock_early_init() is called very early at boot to
+ * establish mach_absolute_time() and set it to zero.
+ */
+void
+rtclock_early_init(void)
+{
+ assert(tscFreq);
+ rtc_set_timescale(tscFreq);
+}
+
/*
* Initialize the real-time clock device.
* In addition, various variables used to support the clock are initialized.
if (cpu_number() == master_cpu) {
assert(tscFreq);
- rtc_set_timescale(tscFreq);
/*
* Adjust and set the exported cpu speed.
}
/* Set fixed configuration for lapic timers */
- rtc_timer->config();
+ rtc_timer->rtc_config();
rtc_timer_start();
return (1);
cycles <<= 1;
}
- if ( shift != 0 )
- printf("Slow TSC, rtc_nanotime.shift == %d\n", shift);
-
rntp->scale = (uint32_t)(((uint64_t)NSEC_PER_SEC << 32) / cycles);
rntp->shift = shift;
+ /*
+ * On some platforms, the TSC is not reset at warm boot. But the
+ * rebase time must be relative to the current boot so we can't use
+ * mach_absolute_time(). Instead, we convert the TSC delta since boot
+ * to nanoseconds.
+ */
if (tsc_rebase_abs_time == 0)
- tsc_rebase_abs_time = mach_absolute_time();
+ tsc_rebase_abs_time = _rtc_tsc_to_nanoseconds(
+ rdtsc64() - tsc_at_boot, rntp);
rtc_nanotime_init(0);
}
static uint64_t
rtc_export_speed(uint64_t cyc_per_sec)
{
+ pal_rtc_nanotime_t *rntp = &pal_rtc_nanotime_info;
uint64_t cycles;
+ if (rntp->shift != 0 )
+ printf("Slow TSC, rtc_nanotime.shift == %d\n", rntp->shift);
+
/* Round: */
cycles = ((cyc_per_sec + (UI_CPUFREQ_ROUNDING_FACTOR/2))
/ UI_CPUFREQ_ROUNDING_FACTOR)
*/
uint64_t
-setPop(
- uint64_t time)
+setPop(uint64_t time)
{
uint64_t now;
uint64_t pop;
if (time == 0 || time == EndOfAllTime ) {
time = EndOfAllTime;
now = 0;
- pop = rtc_timer->set(0, 0);
+ pop = rtc_timer->rtc_set(0, 0);
} else {
now = rtc_nanotime_read(); /* The time in nanoseconds */
- pop = rtc_timer->set(time, now);
+ pop = rtc_timer->rtc_set(time, now);
}
/* Record requested and actual deadlines set */
_absolutetime_to_microtime(abstime, secs, microsecs);
}
-void
-absolutetime_to_nanotime(
- uint64_t abstime,
- clock_sec_t *secs,
- clock_nsec_t *nanosecs)
-{
- _absolutetime_to_nanotime(abstime, secs, nanosecs);
-}
-
void
nanotime_to_absolutetime(
clock_sec_t secs,