Conversation
22f2ce2 to
eac0255
Compare
|
I've pushed a commit that makes the dispatching optional on selecting the module |
fjmolinas
left a comment
There was a problem hiding this comment.
Code looks good, some nitpicks below. Will start testing.
cpu/cortexm_common/thread_arch.c
Outdated
| /* skip context saving if sched_active_thread == NULL */ | ||
| "ldr r1, =sched_active_thread \n" /* r1 = &sched_active_thread */ | ||
| "ldr r1, [r1] \n" /* r1 = sched_active_thread */ | ||
| "cmp r1, #0 \n" /* if r1 == NULL: */ | ||
| "beq context_restore \n" /* goto context_restore */ |
There was a problem hiding this comment.
Skipping context switching depending on sched_active_thread should go into its own commit.
There was a problem hiding this comment.
ok, will re-shuffle when squashing
|
Bench-marking
In general they are all running faster. Only openmote-b had a .8% increase. |
|
|
Aehm, the benchmark counts context switch per second, so lower is better ;) edit sorry for adding my own confusion, higher numbers are better. I'm seeing a slight improvement on nucleo-f401re. |
Well then iotlab-m3 is slower. |
|
Hm, I'm seeing different behavior gcc vs llvm, and gcc versions in our toolchain vs. 9.3.0, on both nucleo-f401re and samr21-xpro. llvm is always slightly slower on master (both current llvm and the one in our container). gcc in our container is slightly slower with this pr. current gcc is slightly faster with this pr. :-/ |
When using |
|
So, with llvm, PR is faster. With gcc, this PR is generally slower. It might get faster with PR on newer gcc releases. As we don't have an actual use case ATM, I guess we have to wait. No need to slow down context switches for nothing. |
726303a to
d804d7a
Compare
|
@leandrolanzieri @jia200x can you take a look if I added the feature to Kconfig correctly? |
Yes, LGTM! |
|
This is now a requirement for #14224. IMO that makes the slight performance drop for some compilers / MCUs acceptable... |
Actually, now is the perfect time to add some features coming at the price of reduced performance: The |
fjmolinas
left a comment
There was a problem hiding this comment.
It seems there is an agreement on that this feature is useful, and that its sideffects have been mitigated by the inline-able irq api. <1% decrease here vs 22% in the inline irq api. Also running the same bench mark on #14224 vs this PR also yields a ~1% increase on context switches, so IMO there is nothing blocking this anymore.
The code hasn't changed since the last time I tested except for the kconfig FEATURE part. Since this touches core I would still like to get a second ACK here, maybe @maribu @bergzand?
|
I would like to see a run of all tests here as well. |
2009977 to
ab28db7
Compare
|
Test failures are in esp32, so unrelated, I'll re-trigger without them |
|
Now a rebase is needed. |
ab28db7 to
8466946
Compare
|
No one has said anything for while so GO! |
Thanks for reviewing! |
Contribution description
Currently, the Cortex-M "supervisor call exception" SVC (think system call entry point) is completely blocked by being defined to be tail-called by PendSV, in order to call
sched_run()and restore the context fromsched_active_thread. This makes it unusable for any other use butcpu_switch_context_exit().This PR refactors
PendSVto include the previous SVC routine (run scheduler, restore thread context), but before that, only conditionally stores the current context only ifsched_active_threadis non-null.An SVC dispatch function is added. SVC 1 maps to the original function by handing over to PendSV.
This is the first step to implement system calls using SVC, which can now be used in combination with the MPU to provide some memory protected "user space" that still interacts with the kernel.
Performance wise, context switches are slightly faster on Cortex-M3 onwards, and slightly slower on CM0(+), but both times less than 0.5%. Crude measuring shows ~50b increase in code size.
I've tested this only on particle-xenon (Cortex-M4F) and nucleo-f072rb (Cortex-M0+).
Testing procedure
Being quite central with a lot of opportunities for weird error cases, this should get somewhat extensive review and testing, especially anything involving context switching on different Cortex-M.
Issues/PRs references