-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix stop/delete of backlogged auto-reload timer #303
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
Fix stop/delete of backlogged auto-reload timer #303
Conversation
When reloading an auto-reload timer, the timer task sends the tmrCOMMAND_START_DONT_TRACE command if the new timer period has already elapsed. If the command queue already contains a stop or delete command for the timer, then prior to this commit the tmrCOMMAND_START_DONT_TRACE command is processed *after* the stop or delete command. Consequently the timer is restarted unexpectedly (in the stop case) or uses freed memory (in the delete case). After this commit, the tmrCOMMAND_START_DONT_TRACE command is processed before the stop or delete command.
Codecov Report
@@ Coverage Diff @@
## main #303 +/- ##
=======================================
Coverage 90.60% 90.60%
=======================================
Files 3 3
Lines 532 532
Branches 142 142
=======================================
Hits 482 482
Misses 14 14
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
This is not an easy thing to do because the memory used by the timer's structures is freed so could contain anything after the timer has been deleted. Even in the case of a timer being allocated statically, the statically allocated memory may be re-used to create another timer. There is an analogous problem with tasks. Kernel aware debuggers that display tasks had no idea if a task had been deleted and re-created since it last viewed the memory. In that situation we added a unique number to each task structure. If the kernel aware debugger saw a task structure (TCB) occupying the same memory location but with a different unique number it knows its a different task even if the task name and handle are the same (the handle just being a pointer to the TCB). I was wondering if we could do something similar with timers. If a timer is recognised from a combination of its handle and unique number contained within its structure - then a command operating on a timer that had a different unique number to that expected could be discarded. |
Agreed.
No, but let me fix this up a little bit to prompt developers in the future to consider any new command for sending to front. It would be too easy with the code as is for a developer not to consider the question. My first thought is to set a bit in each command value as a tag, either |
7364a41 to
3da78c6
Compare
And send priority commands to front even if the scheduler is disabled.
3da78c6 to
ce66916
Compare
You might have been right contemplating other solutions. Please see #305 for what I think is a better solution. Let me know which way you'd like to go. This solution (this PR, #303) does have the advantage of having fewer changes to the code. But it's awkward in its operation and not as clean in its design as the rest of FreeRTOS code. So sorry if you've wasted time on my waffling. Note also that in #305 I fixed a couple of other issues. Will gladly fix (or not fix) them here in this PR as you prefer. |
|
Closing this PR since #305 was better. |
* deleted old version wolfSSL before updating * updated wolfSSL to the latest version(v4.4.0) * updated wolfSSL to the latest version(v4.4.0) * added macros for timing resistance * Add wolfSSL-FIPS-Ready to Demo and Source * Add wolfSSL-FIPS-Ready to Demo and Source * Update README_wolfSSL_FIPS_Ready.md * Remove unused files * Update to wolfSSL-4.5.0-FIPS-Ready * Increase FIPS version number for the default * Update wolfSSL to the latest version(v.4.5.0) * Fix version number * Fix comments from github Co-authored-by: RichardBarry <[email protected]> Co-authored-by: Ming Yue <[email protected]> Co-authored-by: Aniruddha Kanhere <[email protected]> Co-authored-by: Cobus van Eeden <[email protected]> Co-authored-by: Alfred Gedeon <[email protected]>
Fix stop/delete backlogged auto-reload timer
Description
Prior to this PR, if an application attempts to stop or delete an auto-reload timer while it is backlogged, the timer unexpectedly restarts. A timer is "backlogged" when at the time of the auto-reload, the new timer period has already elapsed. In the case of a deleted timer, the timer continues running using freed memory which may eventually lead to a crash or failure of other unrelated timers when the memory is reallocated.
Test Steps
See FreeRTOS/FreeRTOS#553.
Related Issue
https://forums.freertos.org/t/freertos-time-correction/11856
https://forums.freertos.org/t/timer-start-dont-trace-race-condition/12168
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.