On Wed, Nov 28, 2018 at 2:18 PM Waldek Kozaczuk <[email protected]> wrote:
> On Nov 28, 2018, at 03:58, Nadav Har'El <[email protected]> wrote: > > > The situation is different with involuntary context switches. When an > asynchronous event, e.g., an interrupt, occurs, the user thread is in a > random position in the code. It may be using all its registers, and the FPU > state (including the old-style FPU and the new SSE and AVX registers). > Because our interrupt handler (which may do anything from running the > scheduler to reading a page from disk on page fault) may need to use any of > these registers, all of them, including the FPU, need to be saved on > interrupt time. The interrupt has a separate stack, and the FPU is saved on > this stack (see fpu_lock use in interrupt()). When the interrupt finishes, > this FPU is restored. This includes involuntary context switching: thread A > receives an interrupt, saves the FPU, does something and decides to switch > to thread B, and a while later we switch back to thread A at which point > the interrupt handler "returns" and restores the FPU state. > > Does involuntary case include scenario when enough time designated for > current thread by scheduler expires? I would imaging this would qualify as > interrupt? > Indeed. We set a timer to when this thread's runtime quota will expire, and this timer generates an interrupt. Check out interrupt() - after saving the FPU state and acknowledging the interrupt (EOI), it calls the scheduler (sched::preempt()). This will decide which thread to run next - it may run the same thread again, or a different thread. When sched::preempt() returns - possibly a long time later, it means the scheduler decided to run *this* thread again. At that point, interrupt() returns and just before returning it restores the FPU state automatically. -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
