Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jefftenney
Copy link
Contributor

@jefftenney jefftenney commented Apr 9, 2021

Remove support for tmrCOMMAND_START_DONT_TRACE

Description

This PR is a potential replacement for #303 and fixes the same issues but using a more direct approach.

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.

This PR also fixes one-shot timers that were not being marked as inactive:

  • when they expired before the start command could be processed
  • when the expiration was processed during the timer list switch

and also improves consistency:

  • Always reload auto-reload timers before calling the callback.
  • Always call traceTIMER_EXPIRED() just prior to the callback.

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.

Prior to this commit, the timer task used tmrCOMMAND_START_DONT_TRACE
to reload a "backlogged" auto-reload timer -- one for which a reload
operation would have started a period that had already elapsed.  If the
command queue contained a stop or delete command when
tmrCOMMAND_START_DONT_TRACE was put into the queue for a reload, the
timer unexpectedly restarted when the timer task processed
tmrCOMMAND_START_DONT_TRACE.  This commit implements a new method of
reloading auto-reload timers and eliminates support for
tmrCOMMAND_START_DONT_TRACE.  No other code sends this private command.

However, the symbol tmrCOMMAND_START_DONT_TRACE remains defined, with
its original command value, so as not to impact trace applications.

Also fix one-shot timers that were not reliably being marked as not
active:
- when they expired before the start command could be processed
- when the expiration was processed during the timer list switch

Also improve consistency:
- Always reload auto-reload timers *before* calling the callback.
- Always call traceTIMER_EXPIRED() just prior to the callback.
@codecov
Copy link

codecov bot commented Apr 9, 2021

Codecov Report

Merging #305 (5171474) into main (a22b438) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #305   +/-   ##
=======================================
  Coverage   90.60%   90.60%           
=======================================
  Files           3        3           
  Lines         532      532           
  Branches      142      142           
=======================================
  Hits          482      482           
  Misses         14       14           
  Partials       36       36           
Flag Coverage Δ
unittests 90.60% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a22b438...5171474. Read the comment docs.

@jefftenney jefftenney marked this pull request as ready for review April 10, 2021 00:16
@jefftenney jefftenney requested a review from a team as a code owner April 10, 2021 00:16
Change was intended to faithfully work through a backlog that spanned a
list switch, and before processing a stop or delete command.  But, (1)
it isn't important to do that, and (2) the code didn't accomplish the
intention when *two* auto-reload timers were backlogged across a list
switch.  Best to simply leave this part of the code as it was before.
@jefftenney jefftenney force-pushed the eliminate-start-dont-trace branch from ca1a166 to f275a66 Compare April 10, 2021 15:41
@n9wxu n9wxu merged commit 05ded5b into FreeRTOS:main Apr 13, 2021
@jefftenney jefftenney deleted the eliminate-start-dont-trace branch April 13, 2021 18:17
h2zero added a commit to h2zero/NimBLE-Arduino that referenced this pull request Nov 25, 2021
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4. 

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Nov 25, 2021
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request May 15, 2022
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
copybara-service bot pushed a commit to pigweed-project/pigweed that referenced this pull request Jul 25, 2023
After further research, it was determined that there was no race
condition. The actual issue is that xTimerIsTimerActive is unreliable in
certain circumstances in FreeRTOS before
FreeRTOS/FreeRTOS-Kernel#305.

Bug: b/291346908
Change-Id: I2d17045d536e9353934d1558fe3b0429f9ea354f
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/159231
Reviewed-by: Ewout van Bekkum <[email protected]>
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Feb 23, 2024
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Jun 10, 2024
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Feb 9, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Feb 9, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Feb 9, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 13, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 16, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 16, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 17, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 17, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 17, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 22, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
h2zero added a commit to h2zero/esp-nimble that referenced this pull request Apr 22, 2025
This adds a workaround for a bug in FreeRTOS xTimerIsTimerActive function that would return true when the timer has expired.

This bug was introduced in FreeRTOS V10.2.0, and fixed in V10.4.4.

See: FreeRTOS/FreeRTOS-Kernel#305
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants