SSE / FPU instructions in scheduler code
Posted: Thu Jul 04, 2024 1:35 pm
Hi everyone,
I recently implemented FPU / SSE context management (save / restore) using the NM exception to prevent useless save and restore.
However, in my scheduling routine, I have some FPU code, so I ends up triggering the NM during scheduling.
Thing is, I don't have nested interrupt capability in my kernel. I could implement it, but what's the point if the scheduling itself uses SIMD, I would just end-up saving / restoring the context at every task switch anyway.
I have the following solutions in my head and I was wondering is someone with more experience could help me choose:
1. Modify a bit my thread virtual CPU to use the thread's stack to save context so I can have nested interrupts.
2. Always save/restore FPU/SSE context on task switch, don't use NM exception.
3. At the moment all interrupts / exceptions generate a scheduling, should I decouple that and only schedule when the timer triggers, otherwise return from interrupt with the same thread? (here I only talk about IRQs, a thread might be asking to actually schedule itself, because it got blocked on a semaphore for instance).
4. Force the scheduler code to avoid FPU / SSE. I am doing 64 bits divisions to compute the current CPU load, maybe I could do something better here? -> That is what I went with for the moment. BUT what if an interrupt handler uses FPU / SSE code? (maybe 3. would be the second part of the solution?)
Sorry for the long text, I hope it is clear enough
Thanks!
Alexy
I recently implemented FPU / SSE context management (save / restore) using the NM exception to prevent useless save and restore.
However, in my scheduling routine, I have some FPU code, so I ends up triggering the NM during scheduling.
Thing is, I don't have nested interrupt capability in my kernel. I could implement it, but what's the point if the scheduling itself uses SIMD, I would just end-up saving / restoring the context at every task switch anyway.
I have the following solutions in my head and I was wondering is someone with more experience could help me choose:
1. Modify a bit my thread virtual CPU to use the thread's stack to save context so I can have nested interrupts.
2. Always save/restore FPU/SSE context on task switch, don't use NM exception.
3. At the moment all interrupts / exceptions generate a scheduling, should I decouple that and only schedule when the timer triggers, otherwise return from interrupt with the same thread? (here I only talk about IRQs, a thread might be asking to actually schedule itself, because it got blocked on a semaphore for instance).
4. Force the scheduler code to avoid FPU / SSE. I am doing 64 bits divisions to compute the current CPU load, maybe I could do something better here? -> That is what I went with for the moment. BUT what if an interrupt handler uses FPU / SSE code? (maybe 3. would be the second part of the solution?)
Sorry for the long text, I hope it is clear enough
Thanks!
Alexy