X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdevices%2Ftimer.c;h=ecf6c5aacdfee97c6577c8b60912475ef99e4e77;hb=64f0952217e8b1a53461f5a98a070cb2da266171;hp=200d58f8251e0b660bd3a4fa49367b337a882857;hpb=208fb587faa75eaa0e740db9b605ff3d7ba24905;p=pintos-anon diff --git a/src/devices/timer.c b/src/devices/timer.c index 200d58f..ecf6c5a 100644 --- a/src/devices/timer.c +++ b/src/devices/timer.c @@ -1,10 +1,14 @@ #include "devices/timer.h" #include +#include #include +#include #include "threads/interrupt.h" #include "threads/io.h" #include "threads/thread.h" +/* See [8254] for hardware details of the 8254 timer chip. */ + #if TIMER_FREQ < 19 #error 8254 timer requires TIMER_FREQ >= 19 #endif @@ -21,7 +25,7 @@ static volatile int64_t ticks; static intr_handler_func timer_interrupt; -/* Sets up the 8254 Programmable Interrupt Timer (PIT) to +/* Sets up the 8254 Programmable Interval Timer (PIT) to interrupt PIT_FREQ times per second, and registers the corresponding interrupt. */ void @@ -62,9 +66,9 @@ timer_sleep (int64_t ticks) { int64_t start = timer_ticks (); + ASSERT (intr_get_level () == INTR_ON); while (timer_elapsed (start) < ticks) - if (intr_get_level () == INTR_ON) - thread_yield (); + thread_yield (); } /* Returns MS milliseconds in timer ticks, rounding up. */ @@ -91,12 +95,20 @@ timer_ns2ticks (int64_t ns) { return DIV_ROUND_UP (ns * TIMER_FREQ, 1000000000); } + +/* Prints timer statistics. */ +void +timer_print_stats (void) +{ + printf ("Timer: %"PRId64" ticks\n", ticks); +} /* Timer interrupt handler. */ static void timer_interrupt (struct intr_frame *args UNUSED) { ticks++; + thread_tick (); if (ticks % TIME_SLICE == 0) intr_yield_on_return (); }