changed PIT clock to have configurable values, see:
PIT_FREQUENCY_HZ
timeslice_period_ms
heartbeat_period_ms
@@ -14,9 +14,6 @@ const CHANNEL2: u16 = 0x42;
const COMMAND_REGISTER: u16 = 0x43;
-/// the chosen interrupt frequency (in Hertz) of the PIT clock
-const PIT_FREQUENCY_HZ: u32 = 100;
-
/// the timer's default frequency is 1.19 MHz
const PIT_DIVIDEND_HZ: u32 = 1193182;
@@ -44,6 +41,17 @@ pub fn init(freq_hertz: u32) {
}
+// these should be moved to a config file
+
+/// the chosen interrupt frequency (in Hertz) of the PIT clock
+const PIT_FREQUENCY_HZ: u64 = 100;
+
+/// the timeslice period in milliseconds
+const timeslice_period_ms: u64 = 100;
+
+/// the heartbeatperiod in milliseconds
+const heartbeat_period_ms: u64 = 10000;
+
/// this occurs on every PIT timer tick, which is currently 100 Hz
pub fn handle_timer_interrupt() {
let ticks = unsafe {
@@ -51,16 +59,17 @@ pub fn handle_timer_interrupt() {
TICKS
};
+
// preemption timeslice = 1sec (every 100 ticks)
- if (ticks % 10) == 0 {
+ if (ticks % (timeslice_period_ms * PIT_FREQUENCY_HZ / 1000)) == 0 {
// FIXME: if we call schedule() too frequently, like on every tick, the system locks up!
// Most likely because we acquire locks in the scheduler/context switching routines
schedule!();
}
- // heartbeat: print every 5 seconds
- if (ticks % 1000) == 0 {
- trace!("10 seconds have passed (ticks={})", ticks);
+ // heartbeat: print every 10 seconds
+ if (ticks % (heartbeat_period_ms * PIT_FREQUENCY_HZ / 1000)) == 0 {
+ trace!("[heartbeat] {} seconds have passed (ticks={})", heartbeat_period_ms/1000, ticks);
// info!("1 second has passed (ticks={})", ticks);
}
ticks;
