Do a bit less work in every context switch.

This commit is contained in:
Andreas Kling 2018-11-01 11:57:36 +01:00
parent 5891691640
commit f76fcd1e62

View file

@ -720,13 +720,13 @@ bool scheduleNewTask()
static bool contextSwitch(Task* t) static bool contextSwitch(Task* t)
{ {
//kprintf("c_s to %s (same:%u)\n", t->name().characters(), current == t);
t->setTicksLeft(5); t->setTicksLeft(5);
t->didSchedule(); t->didSchedule();
if (current == t) if (current == t)
return false; return false;
#ifdef SCHEDULER_DEBUG
// Some sanity checking to force a crash earlier. // Some sanity checking to force a crash earlier.
auto csRPL = t->tss().cs & 3; auto csRPL = t->tss().cs & 3;
auto ssRPL = t->tss().ss & 3; auto ssRPL = t->tss().ss & 3;
@ -740,6 +740,7 @@ static bool contextSwitch(Task* t)
kprintf(" stk: %w:%x\n", t->tss().ss, t->tss().esp); kprintf(" stk: %w:%x\n", t->tss().ss, t->tss().esp);
ASSERT(csRPL == ssRPL); ASSERT(csRPL == ssRPL);
} }
#endif
if (current) { if (current) {
// If the last task hasn't blocked (still marked as running), // If the last task hasn't blocked (still marked as running),
@ -751,24 +752,21 @@ static bool contextSwitch(Task* t)
current = t; current = t;
t->setState(Task::Running); t->setState(Task::Running);
if (!t->selector()) if (!t->selector()) {
t->setSelector(allocateGDTEntry()); t->setSelector(allocateGDTEntry());
auto& descriptor = getGDTEntry(t->selector());
descriptor.setBase(&t->tss());
descriptor.setLimit(0xffff);
descriptor.dpl = 0;
descriptor.segment_present = 1;
descriptor.granularity = 1;
descriptor.zero = 0;
descriptor.operation_size = 1;
descriptor.descriptor_type = 0;
}
auto& tssDescriptor = getGDTEntry(t->selector()); auto& descriptor = getGDTEntry(t->selector());
descriptor.type = 11; // Busy TSS
tssDescriptor.limit_hi = 0;
tssDescriptor.limit_lo = 0xFFFF;
tssDescriptor.base_lo = (DWORD)(&t->tss()) & 0xFFFF;
tssDescriptor.base_hi = ((DWORD)(&t->tss()) >> 16) & 0xFF;
tssDescriptor.base_hi2 = ((DWORD)(&t->tss()) >> 24) & 0xFF;
tssDescriptor.dpl = 0;
tssDescriptor.segment_present = 1;
tssDescriptor.granularity = 1;
tssDescriptor.zero = 0;
tssDescriptor.operation_size = 1;
tssDescriptor.descriptor_type = 0;
tssDescriptor.type = 11; // Busy TSS
flushGDT(); flushGDT();
return true; return true;
} }