X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fdevices%2Ftimer.c;h=8f47c810ffc8af5a1c6804933fad710929450318;hb=34a1a2cf11500505e74ae5796e88de0d8de00958;hp=200d58f8251e0b660bd3a4fa49367b337a882857;hpb=208fb587faa75eaa0e740db9b605ff3d7ba24905;p=pintos-anon diff --git a/src/devices/timer.c b/src/devices/timer.c index 200d58f..8f47c81 100644 --- a/src/devices/timer.c +++ b/src/devices/timer.c @@ -1,6 +1,8 @@ #include "devices/timer.h" #include +#include #include +#include #include "threads/interrupt.h" #include "threads/io.h" #include "threads/thread.h" @@ -21,7 +23,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 @@ -91,12 +93,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 (); }