From c33ac7f1704fb26533a532e09ee9010c73077920 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 2 Oct 2019 13:45:26 +0200 Subject: [PATCH] Kernel: Don't update Thread TSS if scheduler tick reschedules it If we didn't find anything else that wants to run, we don't need to update the current thread's TSS since we're just gonna return to the same thread anyway. --- Kernel/Scheduler.cpp | 50 +++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 310f9c2d14..b08b16532c 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -540,33 +540,35 @@ void Scheduler::timer_tick(RegisterDump& regs) if (current->tick()) return; - current->tss().gs = regs.gs; - current->tss().fs = regs.fs; - current->tss().es = regs.es; - current->tss().ds = regs.ds; - current->tss().edi = regs.edi; - current->tss().esi = regs.esi; - current->tss().ebp = regs.ebp; - current->tss().ebx = regs.ebx; - current->tss().edx = regs.edx; - current->tss().ecx = regs.ecx; - current->tss().eax = regs.eax; - current->tss().eip = regs.eip; - current->tss().cs = regs.cs; - current->tss().eflags = regs.eflags; - - // Compute process stack pointer. - // Add 12 for CS, EIP, EFLAGS (interrupt mechanic) - current->tss().esp = regs.esp + 12; - current->tss().ss = regs.ss; - - if ((current->tss().cs & 3) != 0) { - current->tss().ss = regs.ss_if_crossRing; - current->tss().esp = regs.esp_if_crossRing; - } + auto& outgoing_tss = current->tss(); if (!pick_next()) return; + + outgoing_tss.gs = regs.gs; + outgoing_tss.fs = regs.fs; + outgoing_tss.es = regs.es; + outgoing_tss.ds = regs.ds; + outgoing_tss.edi = regs.edi; + outgoing_tss.esi = regs.esi; + outgoing_tss.ebp = regs.ebp; + outgoing_tss.ebx = regs.ebx; + outgoing_tss.edx = regs.edx; + outgoing_tss.ecx = regs.ecx; + outgoing_tss.eax = regs.eax; + outgoing_tss.eip = regs.eip; + outgoing_tss.cs = regs.cs; + outgoing_tss.eflags = regs.eflags; + + // Compute process stack pointer. + // Add 12 for CS, EIP, EFLAGS (interrupt mechanic) + outgoing_tss.esp = regs.esp + 12; + outgoing_tss.ss = regs.ss; + + if ((outgoing_tss.cs & 3) != 0) { + outgoing_tss.ss = regs.ss_if_crossRing; + outgoing_tss.esp = regs.esp_if_crossRing; + } prepare_for_iret_to_new_process(); // Set the NT (nested task) flag.