-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Optimizing stack setup on SVC calls #230
Conversation
Hi @SenRamakri, Many thanks for your contribution. The current solution was implemented with all the xxxNew calls in mind. Only those are typically usable before osKernelStart, i.e. running on MSP. As soon as the Kernel runs we are in thread context using PSP. The new solution would save some code space per xxNew call used (sums up to 260 bytes max). But on the other hand it adds a common overhead of about 2 or 3 cycles for each and every SVC call (which is about 1-2% to the 100-200 cycles we currently need). So it is a trade of between code space and execution speed. What do you think? What does count more for you? 260 Bytes flash usage or 1-2% performance per SVC call? Cheers, |
Hi @JonatanAntoni, Thanks much for your time looking into this and reviewing. Regards, |
Only the osXxxNew Calls (and osKernelInitialize/Start) used the SVC macro with SVC_SETUP_PSP. So only those functions had a few cycles of overhead. More precise the osXxxNew functions (which already take quite some time) had the additional 5 cycles overhead (when called after osKernelStart). Summary: |
…ck detection in SVC_Handler
RTX5 has been updated as suggested: Stack setup for Cortex-M has been replaced with stack detection in SVC_Handler in order to save code space. |
Hi @SenRamakri, Robi changed the code according to your suggestions. May I ask you to double check if the latest version fits your expectation? Please close this PR if you don't have further remarks. Thanks for contributing, |
Hi @RobertRostohar and @JonatanAntoni, Thanks for your time looking into this and adopting the enhancements I suggested for SVC_Handler. -Senthil |
This is work in progress needing initial feedback on proposed changes.
The optimization we are proposing is to remove the SVC_SETUP_PSP on svc_indirect() calls and check for which stack(MSP or PSP) was active when SVC call was made and then using that stack pointer(MSP or PSP) accordingly in SVCHandler. By doing this we saved around 260 bytes of code space when I tried building a test with mbed-os and there will be some improvement in performance as well since calls to intrinsic macros like __get_CONTROL, __set_PSP, __get_MSP in SVC_SETUP_PSP can be avoided although I have not measured quantitatively. Adding @c1728p9 as well.