X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdevices%2Ftimer.c;h=662e0c6f5645be139fde64f9f300bcd0f17d9c52;hb=2ce1eb4d6c0adc209f56789920362d455cca443e;hp=3724abf944ab4fbf7d53936cdbe822a2a7b9a5a5;hpb=a40483c415f3b61066ddcc4890c0aedfca723f26;p=pintos-anon diff --git a/src/devices/timer.c b/src/devices/timer.c index 3724abf..662e0c6 100644 --- a/src/devices/timer.c +++ b/src/devices/timer.c @@ -16,10 +16,6 @@ #error TIMER_FREQ <= 1000 recommended #endif -/* Number of timer ticks that a process gets before being - preempted. */ -#define TIME_SLICE 1 - /* Number of timer ticks since OS booted. */ static volatile int64_t ticks; @@ -46,7 +42,7 @@ timer_init (void) outb (0x40, count & 0xff); outb (0x40, count >> 8); - intr_register (0x20, 0, INTR_OFF, timer_interrupt, "8254 Timer"); + intr_register_ext (0x20, timer_interrupt, "8254 Timer"); } /* Calibrates loops_per_tick, used to implement brief delays. */ @@ -61,8 +57,11 @@ timer_calibrate (void) /* Approximate loops_per_tick as the largest power-of-two still less than one timer tick. */ loops_per_tick = 1u << 10; - while (!too_many_loops (loops_per_tick << 1)) - loops_per_tick <<= 1; + while (!too_many_loops (loops_per_tick << 1)) + { + loops_per_tick <<= 1; + ASSERT (loops_per_tick != 0); + } /* Refine the next 8 bits of loops_per_tick. */ high_bit = loops_per_tick; @@ -127,7 +126,7 @@ timer_nsleep (int64_t ns) void timer_print_stats (void) { - printf ("Timer: %"PRId64" ticks\n", ticks); + printf ("Timer: %"PRId64" ticks\n", timer_ticks ()); } /* Timer interrupt handler. */ @@ -136,8 +135,6 @@ timer_interrupt (struct intr_frame *args UNUSED) { ticks++; thread_tick (); - if (ticks % TIME_SLICE == 0) - intr_yield_on_return (); } /* Returns true if LOOPS iterations waits for more than one timer @@ -168,7 +165,7 @@ too_many_loops (unsigned loops) differently in different places the results would be difficult to predict. */ static void NO_INLINE -busy_wait (int64_t loops) +busy_wait (volatile int64_t loops) { while (loops-- > 0) continue;