From a7994b1a42538627a75330795c43553d2ca374e2 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 24 Dec 2020 09:44:03 +1100 Subject: [PATCH] freertos: Add some comments about deleting tasks when using SMP Some cases are not immediately obvious, so document them in comments. --- components/freertos/tasks.c | 5 ++++- components/freertos/test/test_freertos_task_delete.c | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/freertos/tasks.c b/components/freertos/tasks.c index 8acab5e232..07f1e2b387 100644 --- a/components/freertos/tasks.c +++ b/components/freertos/tasks.c @@ -1319,7 +1319,10 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB, TaskFunction_t pxTaskCode uxTaskNumber++; if( pxTCB == curTCB || + /* in SMP, we also can't immediately delete the task active on the other core */ (portNUM_PROCESSORS > 1 && pxTCB == pxCurrentTCB[ !core ]) || + /* ... and we can't delete a non-running task pinned to the other core, as + FPU cleanup has to happen on the same core */ (portNUM_PROCESSORS > 1 && pxTCB->xCoreID == (!core)) ) { /* A task is deleting itself. This cannot complete within the @@ -5690,7 +5693,7 @@ TickType_t xTimeToWake; const TickType_t xConstTickCount = xTickCount; if (portNUM_PROCESSORS > 1 && listIS_CONTAINED_WITHIN(&xTasksWaitingTermination, &( pxCurrentTCB[xCoreID]->xStateListItem))) { - /* vTaskDelete() has been called on this task. This would have happened from the other core while this task was spinning on xTaskQueueMutex, + /* vTaskDelete() has been called to delete this task. This would have happened from the other core while this task was spinning on xTaskQueueMutex, so don't move the running task to the delayed list - as soon as this core re-enables interrupts this task will be suspended permanently */ return; diff --git a/components/freertos/test/test_freertos_task_delete.c b/components/freertos/test/test_freertos_task_delete.c index 1a8460ab57..eb7428deb0 100644 --- a/components/freertos/test/test_freertos_task_delete.c +++ b/components/freertos/test/test_freertos_task_delete.c @@ -3,12 +3,11 @@ * check if the task memory is freed immediately under the correct conditions. * * The behavior of vTaskDelete() results in the immediate freeing of task memory - * and the immediate execution of deletion callbacks under the following conditions... - * - When deleting a task that is not currently running on either core - * - When deleting a task that is pinned to the same core (with respect to - * the core that calls vTaskDelete() + * and the immediate execution of deletion callbacks for tasks which are not + * running, provided they are not pinned to the other core (due to FPU cleanup + * requirements). * - * If the two conditions are not met, freeing of task memory and execution of + * If the condition is not met, freeing of task memory and execution of * deletion callbacks will still be carried out by the Idle Task. */ #include