littlekernel / lk

LK embedded kernel
MIT License
3.11k stars 611 forks source link

[arch][arm-m] simplify context switch #382

Closed fdischner closed 4 months ago

fdischner commented 1 year ago

The context switch is now always performed inside the PendSV handler, which greatly simplifies the code by reducing all switches to a single path. This should also eliminate any race conditions during the switch.

Because we always enter PendSV for a switch, there is a slight performance penalty in the case of switching from a non-preempted thread to another non-preempted thread (~40 cycles longer on an M4, compared to the previous implementation)

travisg commented 1 year ago

Very interesting, we talked about this before and I'm excited to see how well this works!

travisg commented 4 months ago

I pulled it in after some amount of testing. Seems to work here, though going to test a bit more on FPU based cortexes. Thanks!