How to identify and resolve the issue causing the task to miss its deadline?

@Middleware & OS Hey guys In my FreeRTOS application, a specific task occasionally misses its deadline, causing system instability. I would like to know what tools or techniques I can use to monitor, profile, or adjust the priority of this task to identify the root cause and prevent these deadline misses from happening. Here is the code for the task with the deadline misses: void vTask1(void *pvParameters) { for(;;) { // Simulate work vTaskDelay(pdMS_TO_TICKS(200)); } }
I have also added a task to monitor the execution time:

void vTaskMonitor(void *pvParameters) {
TickType_t xLastWakeTime;
for(;;) {
xLastWakeTime = xTaskGetTickCount();
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(1000));

if (xLastWakeTime > pdMS_TO_TICKS(1000)) {
printf("Task missed its deadline\n");
}
}
}
I have also added a task to monitor the execution time:

void vTaskMonitor(void *pvParameters) {
TickType_t xLastWakeTime;
for(;;) {
xLastWakeTime = xTaskGetTickCount();
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(1000));

if (xLastWakeTime > pdMS_TO_TICKS(1000)) {
printf("Task missed its deadline\n");
}
}
}
here is how I created and started the tasks: void main(void) { xTaskCreate(vTask1, "Task 1", 1000, NULL, 1, NULL); xTaskCreate(vTaskMonitor, "Task Monitor", 1000, NULL, 2, NULL); vTaskStartScheduler(); } Can anyone please provide guidance on how to identify and resolve the issue causing the task to miss its deadline?
4 Replies
Dtynin
Dtynin7mo ago
Hi @Boss lady You can use an RTOS profiler to measure the execution time of each function within your task. This will help you analyze any code sections that are taking longer than expected and potentially causing delays.
Enthernet Code
Enthernet Code7mo ago
you can monitor task execution time like you have already implemented a task vTaskMonitor to monitor the execution time. However, the implementation is not correct for deadline monitoring. Instead of using xLastWakeTime you should use xTaskGetTickCount() to compare with the deadline. @Boss lady
Boss lady
Boss lady7mo ago
@Enthernet Code Thanks I tried it out void vTaskMonitor(void *pvParameters) { TickType_t xLastDeadline = 0; for (;;) { vTaskDelay(pdMS_TO_TICKS(1000)); TickType_t xCurrentTime = xTaskGetTickCount(); if (xCurrentTime > xLastDeadline) { printf("Task missed its deadline\n"); } xLastDeadline = xCurrentTime + pdMS_TO_TICKS(1000); } }
youcef_ali
youcef_ali7mo ago
what device are you using ?
Want results from more Discord servers?
Add your server