+ /* 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)
+{
+ return DIV_ROUND_UP (ns * TIMER_FREQ, 1000000000);
+}
+\f
+/* Timer interrupt handler. */
+static void
+timer_interrupt (struct intr_frame *args UNUSED)
+{
+ ticks++;
+ if (ticks % TIME_SLICE == 0)
+ intr_yield_on_return ();