-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Optimise mbed_ticker_api.c #12897
Optimise mbed_ticker_api.c #12897
Conversation
Do you have an example ? |
See the comments in Looking at the STM ones, it's a bit fiddly. One could make it easier by not attempting to get the fraction maximally simplified. That is not a requirement - you're allowed to just say "1000000/32768", you're not required to do "15625/512". More simplification should lead to more speed from early termination of multiply/divide, but it's sometimes hard to arrange with just the C preprocessor. I'm just about to tweak it to optimise the cases where just the numerator or denominator matches between USTICKER and LPTICKER. That would be another reason to consider not fully-simplifying each of them, for some platforms maybe. |
@kjbracey-arm, thank you for your changes. |
Could it fix #12880 ? |
I don't think so - there was already a fast path for the 1MHz case which it would have been going through on STM targets. Any non-C-library saving needs to be made in |
116ca5f
to
ac06508
Compare
CI started |
Test run: FAILEDSummary: 2 of 3 test jobs failed Failed test jobs:
|
CI started |
Test run: SUCCESSSummary: 6 of 6 test jobs passed |
@evedon @donatieng I think we need someone from either Hal or Core to review this ? |
Does it seem likely the greentea network test was a real failure? |
CI restarted |
Jenkins CI Test : ❌ FAILEDBuild Number: 6 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Jenkins CI Test : ✔️ SUCCESSBuild Number: 7 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
@MarceloSalazar Please review |
Hi Note that with this PR, hal-tests-tests-mbed_hal-common_tickers becomes FAIL with NUCLEO_F072RB:
|
This change seems to break UART on my STM32F030-based board (which to my knowledge doesn't have lpticker). Whenever I use a ticker, the UART stops properly receiving data. When I disable the ticker, UART works fine. I'm fairly certain ticker is the culprit, as the issue is not present in mbed 6.5 or lower and starts showing from mbed 6.6 and higher. |
@donatieng please check |
Do you have anything more specific than that? I'm can't immediately see a connection between this particular PR and the UART. Have you tried specifically reverting this PR, or doing a bisect? When you say "stops properly receiving data", are you talking occasional character drops, or severe/total loss? You say "ticker" - do you mean a C++ What happened about @jeromecoutant's reported lp ticker failure? Still failing? Any investigation? |
I'm going to check out how I can do this and report back.
The loss is severe enough that I can't properly receive my frames (about 40 bytes) most of the time, breaking proper functionality of my applictation.
Yes, using a C++ ticker object. I've replaced the ticker with a call_every on the event queue, which also resolved the issue but we would like to know the root cause of this issue. |
I've reverted the 4 commits in this PR. This seems to remove the issue and thus UART works fine. I'd assume the issue is somewhere in this PR. |
This is likely an interrupt latency issue, but if anything this PR should have decreased latency problems. Calculations are supposed to be simpler. Please create a proper issue to track this. Provide toolchain info there - also I'm interested to check if you're using microlib. |
Summary of changes
The generic code in mbed_ticker_api.c uses run-time polymorphism to handle different tickers, and has generic run-time calculations for different ticker widths and frequencies, with a single special-case for 1MHz.
Extend the run-time special casing to handle any conversion cases where either the multiply or divide can be done as a shift. This is a speed optimisation for certain platforms.
Add a new option
target.custom-tickers
. If turned off, it promises that only USTICKER and LPTICKER devices will be used. This then permits elimination and/or simplification of runtime calculations, saving size and speed. If either both USTICKER and LPTICKER have the same width, or the same period numerator or denominator, or only one of them exists, then operations can be hard-coded. This is a significant ROM space saving, and a minor speed and RAM saving.We get to optimise all the calculations, but the run-time polymorphism is retained even if there is only one ticker, as it doesn't significantly affect code size versus direct calls, and the existence of
lp_ticker_wrapper and various us_ticker optimisations requires it, even if only LPTICKER is available.
Impact of changes
LP_TICKER_XXX
defines to help the optimisation kick in.Migration actions required
None
Documentation
TBD
Pull request type
Test results
We'll also need a test that exercises the compile-time optimisation - I think building the
common_tickers
test withtarget.custom-tickers
overridden to false should suffice.Reviewers