Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 5 months ago.
How to tell if an EventQueue is starved?
Great talk on Event Queues, sorry I missed the live feed.
One question that occurred to me, is there any mechanism or method to indicate if an EventQueue is being starved for execution?
The queue.call_every(1000, printf, "called every 1 seconds\n");
call within the example code of the EventQueue reference page got me thinking down this path.
Below is a scenario which would cause timing violation of the "call_every()" which would be useful to be able to detect or be aware of:
Example_EventQueue_Starvation
#include "mbed.h" #include "mbed_events.h" #include <stdio.h> void main_action(){ // Do something that takes longer than desired call_every time... wait(1.5); // something like this printf("trying to call every 1 second\n"); } int main() { // creates a queue with the default size EventQueue queue; // events are simple callbacks queue.call_every(1000, main_action); // events are executed by the dispatch method queue.dispatch(); }
Question relating to:
1 Answer
6 years, 5 months ago.
Hello Mark,
I think one method could be to measure the actual interval of event execution. For example as below:
#include "mbed.h" #include "mbed_events.h" #include <stdio.h> Timer timer; void main_action(){ int interval = timer.read_ms(); timer.reset(); // Do something that takes longer than desired call_every time... wait(1.5); // something like this printf("trying to call every 1 second\r\n"); printf("but actually called after %d ms\r\n", interval); } int main() { // creates a queue with the default size EventQueue queue; // events are simple callbacks queue.call_every(1000, main_action); timer.start(); // events are executed by the dispatch method queue.dispatch(); }
Great answer Zoltan, this is the best API we have for checking for starvation. You can also use a LowPowerTimer if you want to make sure the device can enter low-power states, at the cost of losing microsecond accuracy.
In this case, I'm not sure the event queue could provide a better API, and using an external timer would give you more control over what condition you want to check for.
posted by 04 Jun 2018