-
Notifications
You must be signed in to change notification settings - Fork 3k
STM32: fix us ticker set event timestamp double ISR possibility #4632
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
Conversation
@0xc0170 this piece of code you're fixing here has been discussed in details in #4417 and the reasoning for the sequence is also explained in the PR / commit message of @monkiineko . Extract below:
By introducing your change, the risk exists to fall in the above case. I made the same comment that interrupt could be triggered twice and @monkiineko answered a full and detailed explanation to be read in #4417. The final argument being that
Isn't the last part about mbed ticker checking the time not valid anymore ? |
@LMESTM I might reread the entire thread, I remember some details of it. We are testing directly HAL ticker layer in the test referenced above. I don't think it is acceptable to generate two events, even though the above layer handles it. How can we prevent that from happening? Can we? I would assume that generating multiple events is possible if we are setting an event in far future, for instance using 16bit timer but having event with a period of waiting longer than that, it would genereate two interrupts then at least. In this case however what I have seen the event is in the past, thus should fire asap, and should be just one. What I am after is this bug that appeared recently for some platforms, this affects for instance as I recall odin in this case and also f429 as well http://mbedosci.cloudapp.net/results/pr/4163/625/FAIL/UBLOX_EVK_ODIN_W2/ARM/test_log_UBLOX_EVK_ODIN_W2_ARM.txt , basic rtos tests fails due to time drift. This will need to be investigated. |
I think it's better to generate 2 events with one being discarded in higher layer than missing an event. |
3b2d04d
to
12ca902
Compare
@LMESTM I updated the fix, this way it should generate just one. What do you think? |
@0xc0170 even though the risk is reduced now, there is still a chance that TIM_MST->CNT is read before reaching timestamp, then in the following clock cycles, during if/ else comparison it reaches TIM_MST->CNT .... in this case, interrupt would be missed. If you only keep the call to disable but keep the sequence like below, the the risk of missing interrupt disappears, and the risk of raising interrupt twice is minimized.
|
Hi @0xc0170 and @LMESTM , |
@monkiineko @0xc0170 ok indeed we would not miss the interrupt. |
Thanks for all the inputs ! 👍 This should be ready for CI. Update: I'll rebase to place the comment above enable IT as it was misplaced, no more code changes |
While we are handling new timestamp, disable ticker's interrupt.
12ca902
to
0591b2b
Compare
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
retest uvisor |
This fixes setting the new event for us ticker. As it was, the interrupt would
fire 2x. It should either fire ISR immediately or set it in the future.
Tested with ODIN target and a test case for setting events in the past that will come as a separate PR.
As I understood the code, we either generate event and enable it OR set new compare value and enable it. This fixes the failures we have seen in #4628 and possibly in our CI for basic timer tests.
before this patch:
after this patch:
This was the failure
[1498475248.69][CONN][RXD] Testing interrupt 0 us in the past [1498475248.77][CONN][RXD] :86::FAIL: Expected 1 Was 2
. we can see that first event in the past should produce just one IRQ call, but actually was 2x.Is this the same problem for 16 bit ticker, I can see negative delta handling but prior that we are again setting the new match value (timestamp), is that correct?
I can rebase this on top of the test addition, and t hen rebase once the test is integrated if that helps.
cc @bcostm @adustm @LMESTM @jeromecoutant @c1728p9 @andreaslarssonublox