xStreamBufferReset and Mutex is buggy
Posted by
seagull_kamome on June 15, 2018
I guess that my previous post got filtered. So, this is second post.
Hi FreeRTOS developer team.
I’m currently testing FreeRTOS kernel for our project. And, found
something weird.
1.
xStreamBufferReset doesn’t save a STATICALLY_ALLOCATED flag in ucFlags. So,
it will crashes our system at vStreamBufferDelete by calling free().
2.
xSemaphoreGet with Mutex doesn’t give priority back to that mutex holder
when timed out
Sorry. I can’t explain well in english so I’ll show the unit test code.
Task1
static SemaphoreHandle_t mx1;
static unsigned int volatile test_counter;
static TaskHandlet testtask;
static void testtaskmain_1(void* args __unused) {
xSemaphoreTake(mx1, 10); // will be fail.
++test_counter;
ulTaskNotifyTake(0, portMAX_DELAY);
++test_counter;
xSemaphoreTake(mx1, portMAX_DELAY);
++test_counter;
ulTaskNotifyTake(0, portMAX_DELAY);
++test_counter;
xSemaphoreGive(mx1);
vTaskDelete(NULL);
}
and test task. This task has priority (tskIDLE_PRIORITY + 2).
should_eq(xTaskGetCurrentTaskHandle(), xSemaphoreGetMutexHolder(mx1)); //
precondition check
shouldeq(tskIDLEPRIORITY + 2, uxTaskPriorityGet(NULL)); // precondition
check
test_counter = 0;
shouldeq(pdTRUE, xTaskCreate(testtaskmain1, “TSK”,
configMINIMALSTACKSIZE, NULL, tskIDLEPRIORITY + 3, &testtask));
shouldeq(tskIDLEPRIORITY + 3, uxTaskPriorityGet(NULL)); // OK. the
priority is inherited.
shouldeq(0, testcounter); // OK. the task still waiting.
vTaskDelay(11);
shouldeq(1, testcounter); // OK. the task already timed out
// All tests is OK until here.
// BUG? FreeRTOS never descent priority into base when the waiting task
got timeout.
shouldeq(tskIDLEPRIORITY + 2, uxTaskPriorityGet(NULL)); // Fail: actual
is tskIDLE_PRIORITY + 3
xTaskNotifyGive(test_task); // elevate again. the task will preempt control.
taskYIELD(); // but actually not.
shouldeq(2, testcounter); // OK. the task waiting again.
shouldeq(tskIDLEPRIORITY + 3, uxTaskPriorityGet(NULL)); // OK
should_eq(pdTRUE, xSemaphoreGive(mx1)); // OK
shouldeq(3, testcounter); // OK
shouldeq(testtask, xSemaphoreGetMutexHolder(mx1)); // OK
shouldeq(tskIDLEPRIORITY + 2, uxTaskPriorityGet(NULL)); // Fail:! I’m
still in tskIDLE_PRIORITY + 3!!!
Thanks
xStreamBufferReset and Mutex is buggy
Posted by
seagull_kamome on June 18, 2018
Finally. I found this comment .
/* Only disinherit if no other mutexes are held. This is a
simplification in the priority inheritance implementation. If
the task that holds the mutex is also holding other mutexes then
the other mutexes may have caused the priority inheritance. */