projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update.
[pintos-anon]
/
src
/
devices
/
timer.c
diff --git
a/src/devices/timer.c
b/src/devices/timer.c
index 8f4838f048e04ec80d0060fc10cd1a3d77da3216..ec9778321e3339aa2f32bb5496ece5e71a5ea969 100644
(file)
--- a/
src/devices/timer.c
+++ b/
src/devices/timer.c
@@
-1,9
+1,14
@@
#include "devices/timer.h"
#include <debug.h>
#include "devices/timer.h"
#include <debug.h>
+#include <inttypes.h>
#include <round.h>
#include <round.h>
+#include <stdio.h>
#include "threads/interrupt.h"
#include "threads/io.h"
#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
#if TIMER_FREQ < 19
#error 8254 timer requires TIMER_FREQ >= 19
#endif
@@
-20,7
+25,7
@@
static volatile int64_t ticks;
static intr_handler_func timer_interrupt;
static intr_handler_func timer_interrupt;
-/* Sets up the 8254 Programmable Inter
rupt
Timer (PIT) to
+/* Sets up the 8254 Programmable Inter
val
Timer (PIT) to
interrupt PIT_FREQ times per second, and registers the
corresponding interrupt. */
void
interrupt PIT_FREQ times per second, and registers the
corresponding interrupt. */
void
@@
-55,14
+60,15
@@
timer_elapsed (int64_t then)
return timer_ticks () - then;
}
return timer_ticks () - then;
}
-/* Suspends execution
s
for approximately TICKS timer ticks. */
+/* Suspends execution for approximately TICKS timer ticks. */
void
timer_sleep (int64_t ticks)
{
int64_t start = timer_ticks ();
while (timer_elapsed (start) < ticks)
void
timer_sleep (int64_t ticks)
{
int64_t start = timer_ticks ();
while (timer_elapsed (start) < ticks)
- continue;
+ if (intr_get_level () == INTR_ON)
+ thread_yield ();
}
/* Returns MS milliseconds in timer ticks, rounding up. */
}
/* Returns MS milliseconds in timer ticks, rounding up. */
@@
-89,12
+95,20
@@
timer_ns2ticks (int64_t ns)
{
return DIV_ROUND_UP (ns * TIMER_FREQ, 1000000000);
}
{
return DIV_ROUND_UP (ns * TIMER_FREQ, 1000000000);
}
+
+/* Prints timer statistics. */
+void
+timer_print_stats (void)
+{
+ printf ("Timer: %"PRId64" ticks\n", ticks);
+}
\f
/* Timer interrupt handler. */
static void
timer_interrupt (struct intr_frame *args UNUSED)
{
ticks++;
\f
/* Timer interrupt handler. */
static void
timer_interrupt (struct intr_frame *args UNUSED)
{
ticks++;
+ thread_tick ();
if (ticks % TIME_SLICE == 0)
intr_yield_on_return ();
}
if (ticks % TIME_SLICE == 0)
intr_yield_on_return ();
}