-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
riot-rs-threads: always set threads.current_thread
in sched()
#262
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the compiler previously optimized the else
path away, which is now not possible anymore. I played around a bit, and when doing (on main) current_high_regs = core::hint::black_box(core::ptr::null())
in the else
path it also takes 259 cycles.
Either way, as you also said in our out-of-band discussion @kaspar030, with 2% I think this is acceptable.
With the added line in sched() after the loop (instead of putting it in both cases), it'd go up to 261 cycles.
I kinda dislike that we now set it in both branches, but agree that performance should take priority over readability.
Thanks for taking a look! |
With future-proof-iot#262, the `current_pid` is not set before the scheduler is triggered for the first time, and therefore `None` on the first run. The pointer to `current_high_regs` is therefore set to a null pointer. This causes nrf52840 to hard fault when trying to store registers r4-r11. To fix this, we now skip storing/ loading of r4-r11 if the pointer is zero, i.e. when there was no previously running thread whose context has to be saved.
With future-proof-iot#262, the `current_pid` is not set before the scheduler is triggered for the first time, and therefore `None` on the first run. The pointer to `current_high_regs` is therefore set to a null pointer. This causes nrf52840 to hard fault when trying to store registers r4-r11. To fix this, we now skip storing/ loading of r4-r11 if the pointer is zero, i.e. when there was no previously running thread whose context has to be saved.
With future-proof-iot#262, the `current_pid` is not set before the scheduler is triggered for the first time, and therefore `None` on the first run. The pointer to `current_high_regs` is therefore set to a null pointer. This causes nrf52840 to hard fault when trying to store registers r4-r11. To fix this, we now skip storing/ loading of r4-r11 if the pointer is zero, i.e. when there was no previously running thread whose context has to be saved.
This is taken from #182:
This changes makes the number of cycles needed for one context switch go up from 254 to 259 (according to tests/benchmarks/bench_sched_yield on nrf52840dk). With the added line in
sched()
after the loop (instead of putting it in both cases), it'd go up to 261 cycles.Fixes #148.