|
|
@ -6,13 +6,14 @@
|
|
|
|
// scheduling data:
|
|
|
|
// scheduling data:
|
|
|
|
ProcessControlBlock processes[PROCESS_COUNT];
|
|
|
|
ProcessControlBlock processes[PROCESS_COUNT];
|
|
|
|
int current_process_index = 1;
|
|
|
|
int current_process_index = 1;
|
|
|
|
|
|
|
|
unsigned long long int scheduling_interrupted_start;
|
|
|
|
|
|
|
|
unsigned long long int next_interrupt_scheduled_for;
|
|
|
|
|
|
|
|
|
|
|
|
void scheduler_run_next ()
|
|
|
|
void scheduler_run_next ()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
current_process_index = scheduler_select_free();
|
|
|
|
current_process_index = scheduler_select_free();
|
|
|
|
// set up timer interrupt
|
|
|
|
// set up timer interrupt
|
|
|
|
unsigned long long int mtimecmp = read_time() + TIME_SLICE_LEN;
|
|
|
|
set_next_interrupt();
|
|
|
|
write_mtimecmp(mtimecmp);
|
|
|
|
|
|
|
|
scheduler_switch_to(current_process_index);
|
|
|
|
scheduler_switch_to(current_process_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -22,9 +23,9 @@ void scheduler_try_return_to(ProcessControlBlock* pcb)
|
|
|
|
scheduler_run_next();
|
|
|
|
scheduler_run_next();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
current_process_index = scheduler_index_from_pid(pcb->pid);
|
|
|
|
current_process_index = scheduler_index_from_pid(pcb->pid);
|
|
|
|
//FIXME: this refreshes the processes time slice which we actually don't want!
|
|
|
|
// add time spent in ecall handler to the processes time slice
|
|
|
|
unsigned long long int mtimecmp = read_time() + TIME_SLICE_LEN;
|
|
|
|
next_interrupt_scheduled_for = next_interrupt_scheduled_for + (read_time() - scheduling_interrupted_start);
|
|
|
|
write_mtimecmp(mtimecmp);
|
|
|
|
write_mtimecmp(next_interrupt_scheduled_for);
|
|
|
|
scheduler_switch_to(current_process_index);
|
|
|
|
scheduler_switch_to(current_process_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -135,3 +136,14 @@ ProcessControlBlock* get_current_process()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return &processes[current_process_index];
|
|
|
|
return &processes[current_process_index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void set_next_interrupt()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
next_interrupt_scheduled_for = read_time() + TIME_SLICE_LEN;
|
|
|
|
|
|
|
|
write_mtimecmp(next_interrupt_scheduled_for);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void mark_ecall_entry()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
scheduling_interrupted_start = read_time();
|
|
|
|
|
|
|
|
}
|