It took me a few days of debugging with a logic analyzer to find out why my delays were not working as expected before I found the answers in these posts:
vTaskDelay and vTaskDelayUntil Strange Behavior
Does vTaskdelay(1) delay up to one tick or circa one tick?
If I summarize:
vTaskDelay(n) will delay a task by a minimum of n-1 ticks. It could be more depending on scheduling, but it can certainly be less than n.
May I propose to update the documentation on the website to reflect this behavior ?
The documentation currently states:
Delay a task for a given number of ticks. The actual time that the task remains blocked depends on the tick rate. The constant…
I recommend something along the lines of:
Delay a task for a given number of ticks. The actual time that the task remains blocked depends on the tick rate and the moment in the tick when the function is called. The minimum time the task will block is could be shorter by up to 1 tick. The constant…
What do you think ?
Thanks for brining this up @maharvey! I’m going to check with a few folks on the team - notably @rtel - and will get back to you.
Overall I love the suggestion.
We can certainly update the vTaskDelay() documentation - but this behaviour isn’t specific to vTaskDelay() - any function that accepts a block time in ticks (reading from or writing to a queue, stream buffer, message buffer, semaphore, mutex, etc.) has the resolution of the tick frequency, which is an integer. So it may be better to either introduce another section on the website, perhaps under “task states” where it talks about entering the Blocked state, or in the book, if that doens’t already mention it (maybe section 3.7 “Time Measurement and the Tick Interrupt”).
Maybe similar to this description: embOS Real-Time Operating System User Guide & Reference Manual
I think some kind of drawing always helps.
This has also bitten me in the past until I realized that all functions that take a block time n (in ticks) blocks up to n ticks (and when you realize, it’s pretty obvious why). To put it another way, if you block/delay for 1 tick, it blocks until the next tick occurs, and so forth.
I think it would be a good idea to document this somewhere where it’s unlikely people will miss it.
The big problem is that the only place people can’t miss it is to repeat it every time it is mentioned (or at least add a reference note each time it is mentioned) which gets very repetitive.
People historically show that they are very bad at looking at general overview sections because they want to just get coding.
Glad to see that I’m not the only one who struggled with this. I think @rtel’s suggestion might be the best here:
So it may be better to either introduce another section on the website, perhaps under “task states” where it talks about entering the Blocked state
My suggestion is the following then
- To have a short dedicated page on the website that explains that on all APIs with delays or timeouts, the first tick is a actual the fraction of a tick (small diagram would help here)
- In each API reference page where such delay of timeout parameter is used, have a blanket statement with a link to the dedicated page. “More info on ticks resolution in the blocked state”
Hello @maharvey! I realize it’s been a while, but I want to let you know I’ve applied your feedback to the FreeRTOS documentation. You can find a detailed page on the tick resolution here as well as a dedicated FAQ item linking to this here.
If you feel like something needs to be better worded or diagrams corrected, don’t hesitate to use the ‘Report and Error on this page’ option.