[kernel] Fix scheduler clock bug

The fake clock in the scheduler wasn't getting initialized, so sleeps in
the test userspace programs were returning immediately.
This commit is contained in:
Justin C. Miller
2020-06-02 23:46:03 -07:00
parent 64ad65fa1b
commit ea1224e213
2 changed files with 10 additions and 9 deletions

View File

@@ -30,7 +30,8 @@ extern uint64_t idle_stack_end;
scheduler::scheduler(lapic *apic) : scheduler::scheduler(lapic *apic) :
m_apic(apic), m_apic(apic),
m_next_pid(1) m_next_pid(1),
m_clock(0)
{ {
auto *idle = new process_node; auto *idle = new process_node;
uint8_t last_pri = num_priorities - 1; uint8_t last_pri = num_priorities - 1;
@@ -261,9 +262,6 @@ void scheduler::prune(uint64_t now)
void void
scheduler::schedule() scheduler::schedule()
{ {
// TODO: lol a real clock
static uint64_t now = 0;
pid_t lastpid = m_current->pid; pid_t lastpid = m_current->pid;
m_runlists[m_current->priority].remove(m_current); m_runlists[m_current->priority].remove(m_current);
@@ -273,7 +271,7 @@ scheduler::schedule()
m_blocked.push_back(m_current); m_blocked.push_back(m_current);
} }
prune(++now); prune(++m_clock);
uint8_t pri = 0; uint8_t pri = 0;
while (m_runlists[pri].empty()) { while (m_runlists[pri].empty()) {
@@ -287,8 +285,8 @@ scheduler::schedule()
task_switch(m_current); task_switch(m_current);
bool loading = m_current->flags && process_flags::loading; bool loading = m_current->flags && process_flags::loading;
log::debug(logs::task, "Scheduler switched to process %d, priority %d%s.", log::debug(logs::task, "Scheduler switched to process %d, priority %d%s @ %lld.",
m_current->pid, m_current->priority, loading ? " (loading)" : ""); m_current->pid, m_current->priority, loading ? " (loading)" : "", m_clock);
} }
} }

View File

@@ -24,8 +24,8 @@ public:
/// How long the timer quantum is /// How long the timer quantum is
static const uint64_t quantum_micros = 1000; static const uint64_t quantum_micros = 1000;
/// How many quantums a process gets before being rescheduled /// How many quanta a process gets before being rescheduled
static const uint16_t process_quanta = 100; static const uint16_t process_quanta = 10;
/// Constructor. /// Constructor.
/// \arg apic Pointer to the local APIC object /// \arg apic Pointer to the local APIC object
@@ -88,5 +88,8 @@ private:
process_list m_blocked; process_list m_blocked;
process_list m_exited; process_list m_exited;
// TODO: lol a real clock
uint64_t m_clock = 0;
static scheduler s_instance; static scheduler s_instance;
}; };