Make sure loops_per_tick doesn't overflow to zero.
[pintos-anon] / src / devices / timer.c
index 24eede0e247e8c1f389be38f129dda96d81ffb80..662e0c6f5645be139fde64f9f300bcd0f17d9c52 100644 (file)
@@ -57,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;
@@ -123,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 ());
 }
 \f
 /* Timer interrupt handler. */
@@ -162,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;