+/* Returns the number of timer ticks elapsed since THEN, which
+ should be a value once returned by timer_ticks(). */
+int64_t
+timer_elapsed (int64_t then)
+{
+ return timer_ticks () - then;
+}
+
+/* Suspends execution for approximately TICKS timer ticks. */
+void
+timer_sleep (int64_t ticks)
+{
+ int64_t start = timer_ticks ();
+
+ while (timer_elapsed (start) < ticks)
+ if (intr_get_level () == INTR_ON)
+ thread_yield ();
+}
+
+/* Returns MS milliseconds in timer ticks, rounding up. */
+int64_t
+timer_ms2ticks (int64_t ms)
+{
+ /* MS / 1000 s
+ ------------------------ = MS * TIMER_FREQ / 1000 ticks.
+ (1 / TIMER_FREQ) ticks/s
+ */
+ return DIV_ROUND_UP (ms * TIMER_FREQ, 1000);
+}
+
+/* Returns US microseconds in timer ticks, rounding up. */
+int64_t
+timer_us2ticks (int64_t us)
+{
+ return DIV_ROUND_UP (us * TIMER_FREQ, 1000000);
+}
+
+/* Returns NS nanoseconds in timer ticks, rounding up. */
+int64_t
+timer_ns2ticks (int64_t ns)