From 0d045234e2e76d04176ae2d38f65a5951e2f64c0 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Mon, 10 Jul 2023 12:04:53 +0800 Subject: [PATCH 1/4] Update uxTaskGetSystemState to sync with eTaskGetState * Task in pending ready list is in eReady state no matter what state list the task is in. --- tasks.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tasks.c b/tasks.c index e2861dd94aa..fb8ef1dbe19 100644 --- a/tasks.c +++ b/tasks.c @@ -2566,6 +2566,15 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady ); } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ + /* Fill in an TaskStatus_t structure with information on each + * task in the pending ready list. Tasks in pending ready list are + * in eReady state. */ + taskENTER_CRITICAL(); + { + uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xPendingReadyList, eReady ); + } + taskEXIT_CRITICAL(); + /* Fill in an TaskStatus_t structure with information on each * task in the Blocked state. */ uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked ); @@ -3874,7 +3883,6 @@ static void prvCheckTasksWaitingTermination( void ) /*-----------------------------------------------------------*/ #if ( configUSE_TRACE_FACILITY == 1 ) - static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t * pxTaskStatusArray, List_t * pxList, eTaskState eState ) @@ -3894,8 +3902,26 @@ static void prvCheckTasksWaitingTermination( void ) do { listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ - vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); - uxTask++; + + /* Tasks in pending ready list are in eReady state regardless of + * what list the task's state list item is currently placed on. + * Thus, these tasks can be enumerated in this function directly. */ + if( pxList == &xPendingReadyList ) + { + vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); + uxTask++; + } + else + { + /* Tasks may be in pending ready list and other state list at + * the same time. These tasks should be enumuerated in xPendingReadyList + * only. */ + if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxNextTCB->xEventListItem ) ) == pdFALSE ) + { + vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); + uxTask++; + } + } } while( pxNextTCB != pxFirstTCB ); } else From dd5c918b27b97a0fceacb75b9b76a11f9601d480 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Mon, 10 Jul 2023 12:44:54 +0800 Subject: [PATCH 2/4] Enumerate the task in the state list only --- tasks.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/tasks.c b/tasks.c index fb8ef1dbe19..5a3062ef0fc 100644 --- a/tasks.c +++ b/tasks.c @@ -2566,15 +2566,6 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &( pxReadyTasksLists[ uxQueue ] ), eReady ); } while( uxQueue > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */ - /* Fill in an TaskStatus_t structure with information on each - * task in the pending ready list. Tasks in pending ready list are - * in eReady state. */ - taskENTER_CRITICAL(); - { - uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), &xPendingReadyList, eReady ); - } - taskEXIT_CRITICAL(); - /* Fill in an TaskStatus_t structure with information on each * task in the Blocked state. */ uxTask += prvListTasksWithinSingleList( &( pxTaskStatusArray[ uxTask ] ), ( List_t * ) pxDelayedTaskList, eBlocked ); @@ -3889,6 +3880,7 @@ static void prvCheckTasksWaitingTermination( void ) { configLIST_VOLATILE TCB_t * pxNextTCB; configLIST_VOLATILE TCB_t * pxFirstTCB; + List_t const * pxEventList; UBaseType_t uxTask = 0; if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 ) @@ -3903,24 +3895,24 @@ static void prvCheckTasksWaitingTermination( void ) { listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ - /* Tasks in pending ready list are in eReady state regardless of - * what list the task's state list item is currently placed on. - * Thus, these tasks can be enumerated in this function directly. */ - if( pxList == &xPendingReadyList ) + taskENTER_CRITICAL(); { - vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); + pxEventList = listLIST_ITEM_CONTAINER( &( pxNextTCB->xEventListItem ) ); + } + taskEXIT_CRITICAL(); + + /* Tasks can be in pending ready list and other state list at + * the same time. These tasks are in ready state no matter what state list + * the task is in. */ + if( pxEventList == &xPendingReadyList ) + { + vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eReady ); uxTask++; } else { - /* Tasks may be in pending ready list and other state list at - * the same time. These tasks should be enumuerated in xPendingReadyList - * only. */ - if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxNextTCB->xEventListItem ) ) == pdFALSE ) - { - vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); - uxTask++; - } + vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); + uxTask++; } } while( pxNextTCB != pxFirstTCB ); } From 3e7e73e99d4183527213ef0470c246b3033cf85e Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Mon, 10 Jul 2023 13:25:09 +0800 Subject: [PATCH 3/4] Revert "Update uxTaskGetSystemState to sync with eTaskGetState" This reverts commit 0d045234e2e76d04176ae2d38f65a5951e2f64c0. --- tasks.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/tasks.c b/tasks.c index 5a3062ef0fc..e2861dd94aa 100644 --- a/tasks.c +++ b/tasks.c @@ -3874,13 +3874,13 @@ static void prvCheckTasksWaitingTermination( void ) /*-----------------------------------------------------------*/ #if ( configUSE_TRACE_FACILITY == 1 ) + static UBaseType_t prvListTasksWithinSingleList( TaskStatus_t * pxTaskStatusArray, List_t * pxList, eTaskState eState ) { configLIST_VOLATILE TCB_t * pxNextTCB; configLIST_VOLATILE TCB_t * pxFirstTCB; - List_t const * pxEventList; UBaseType_t uxTask = 0; if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 ) @@ -3894,26 +3894,8 @@ static void prvCheckTasksWaitingTermination( void ) do { listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList ); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */ - - taskENTER_CRITICAL(); - { - pxEventList = listLIST_ITEM_CONTAINER( &( pxNextTCB->xEventListItem ) ); - } - taskEXIT_CRITICAL(); - - /* Tasks can be in pending ready list and other state list at - * the same time. These tasks are in ready state no matter what state list - * the task is in. */ - if( pxEventList == &xPendingReadyList ) - { - vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eReady ); - uxTask++; - } - else - { - vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); - uxTask++; - } + vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState ); + uxTask++; } while( pxNextTCB != pxFirstTCB ); } else From 6101da50bbcedc96ac4c451531f015d23f3a1847 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Mon, 10 Jul 2023 13:27:58 +0800 Subject: [PATCH 4/4] Update uxTaskGetSystemState to sync with eTaskGetState * Update in vTaskGetInfo for tasks in pending ready list should be in ready state. --- tasks.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tasks.c b/tasks.c index e2861dd94aa..ed3cd1ee2ed 100644 --- a/tasks.c +++ b/tasks.c @@ -3843,6 +3843,18 @@ static void prvCheckTasksWaitingTermination( void ) } } #endif /* INCLUDE_vTaskSuspend */ + + /* Tasks can be in pending ready list and other state list at the + * same time. These tasks are in ready state no matter what state + * list the task is in. */ + taskENTER_CRITICAL(); + { + if( listIS_CONTAINED_WITHIN( &xPendingReadyList, &( pxTCB->xEventListItem ) ) != pdFALSE ) + { + pxTaskStatus->eCurrentState = eReady; + } + } + taskEXIT_CRITICAL(); } } else