From 513cc6576e09e78e9383b8e328b37841432c7647 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 15 Feb 2016 01:14:55 +0100 Subject: [PATCH] check the FPU owner before restoring the FPU registers --- hermit/kernel/tasks.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hermit/kernel/tasks.c b/hermit/kernel/tasks.c index 858452d49..350df94ea 100644 --- a/hermit/kernel/tasks.c +++ b/hermit/kernel/tasks.c @@ -127,6 +127,16 @@ void fpu_handler(struct state *s) uint32_t core_id = CORE_ID; clts(); // clear the TS flag of cr0 + task->flags |= TASK_FPU_USED; + + if (!(task->flags & TASK_FPU_INIT)) { + // use the FPU at the first time => Initialize FPU + fpu_init(&task->fpu); + task->flags |= TASK_FPU_INIT; + } + + if (readyqueues[core_id].fpu_owner == task->id) + return; spinlock_irqsave_lock(&readyqueues[core_id].lock); // did another already use the the FPU? => save FPU state @@ -136,14 +146,7 @@ void fpu_handler(struct state *s) } spinlock_irqsave_unlock(&readyqueues[core_id].lock); - if (BUILTIN_EXPECT(!(task->flags & TASK_FPU_INIT), 0)) { - // use the FPU at the first time => Initialize FPU - fpu_init(&task->fpu); - task->flags |= TASK_FPU_INIT; - } - restore_fpu_state(&task->fpu); - task->flags |= TASK_FPU_USED; } int set_idle_task(void)