Why do_swap() sets cpu.current before context switch?


Katsuhiro Suzuki
 

Hello kernel guys,

I have question about newer version of context switching (CONFIG_USE_SWITCH=y).

Newer switching sets NEW thread handle into _current_cpu.current BEFORE calling arch_switch().
This implementation will face a problem in RISC-V environment if thread calls do_swap() explicitly and switch to thread B (use FPU) from thread A (not use FPU) because...

- If _current_cpu.current has FPU flag, interrupt handler will save all FPU regs to stack
- At older switching
- _current_cpu.current is pointing thread A (not use FPU)
- The handler will skip saving
- But at newer switching
- _current_cpu.current is thread B (use FPU)
- The handler try to save FPU regs using FPU instructions
- But we haven't switching thread yet and thread A is prohibited to use FPU
- The handler will face illegal instruction exception (and going to hang...)

I don't know why newer switching sets thread B into _current_cpu.current such timing.
Does anyone know the reason about this implementation?

Best Regards,
Katsuhiro Suzuki

Join devel@lists.zephyrproject.org to automatically receive all group messages.