Skip to content

Commit 30f6061

Browse files
chinglee-iotaggarg
andauthored
Not using pxIndex to iterate ready list in trace utility (#1000)
* pxIndex should only be used when selecting next task. Altering pxIndex of a ready list will cause the scheduler to be unable to select the right task to run. Using a for loop if traversing the list for trace utility is required. * Not defining listGET_OWNER_OF_NEXT_ENTRY when using SMP scheduler --------- Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
1 parent cff947a commit 30f6061

File tree

2 files changed

+61
-131
lines changed

2 files changed

+61
-131
lines changed

include/list.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ typedef struct xLIST
282282
* \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
283283
* \ingroup LinkedList
284284
*/
285-
#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
285+
#if ( configNUMBER_OF_CORES == 1 )
286+
#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
286287
do { \
287288
List_t * const pxConstList = ( pxList ); \
288289
/* Increment the index to the next item and return the item, ensuring */ \
@@ -294,6 +295,13 @@ typedef struct xLIST
294295
} \
295296
( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \
296297
} while( 0 )
298+
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
299+
300+
/* This function is not required in SMP. FreeRTOS SMP scheduler doesn't use
301+
* pxIndex and it should always point to the xListEnd. Not defining this macro
302+
* here to prevent updating pxIndex.
303+
*/
304+
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
297305

298306
/*
299307
* Version of uxListRemove() that does not return a value. Provided as a slight

tasks.c

Lines changed: 52 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,147 +4177,72 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery )
41774177
/*-----------------------------------------------------------*/
41784178

41794179
#if ( INCLUDE_xTaskGetHandle == 1 )
4180+
static TCB_t * prvSearchForNameWithinSingleList( List_t * pxList,
4181+
const char pcNameToQuery[] )
4182+
{
4183+
TCB_t * pxReturn = NULL;
4184+
UBaseType_t x;
4185+
char cNextChar;
4186+
BaseType_t xBreakLoop;
4187+
const ListItem_t * pxEndMarker = listGET_END_MARKER( pxList );
4188+
ListItem_t * pxIterator;
41804189

4181-
#if ( configNUMBER_OF_CORES == 1 )
4182-
static TCB_t * prvSearchForNameWithinSingleList( List_t * pxList,
4183-
const char pcNameToQuery[] )
4184-
{
4185-
TCB_t * pxNextTCB;
4186-
TCB_t * pxFirstTCB;
4187-
TCB_t * pxReturn = NULL;
4188-
UBaseType_t x;
4189-
char cNextChar;
4190-
BaseType_t xBreakLoop;
4191-
4192-
/* This function is called with the scheduler suspended. */
4190+
/* This function is called with the scheduler suspended. */
41934191

4194-
if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )
4192+
if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )
4193+
{
4194+
for( pxIterator = listGET_HEAD_ENTRY( pxList ); pxIterator != pxEndMarker; pxIterator = listGET_NEXT( pxIterator ) )
41954195
{
41964196
/* MISRA Ref 11.5.3 [Void pointer assignment] */
41974197
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
41984198
/* coverity[misra_c_2012_rule_11_5_violation] */
4199-
listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );
4199+
TCB_t * pxTCB = listGET_LIST_ITEM_OWNER( pxIterator );
42004200

4201-
do
4202-
{
4203-
/* MISRA Ref 11.5.3 [Void pointer assignment] */
4204-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
4205-
/* coverity[misra_c_2012_rule_11_5_violation] */
4206-
listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );
4201+
/* Check each character in the name looking for a match or
4202+
* mismatch. */
4203+
xBreakLoop = pdFALSE;
42074204

4208-
/* Check each character in the name looking for a match or
4209-
* mismatch. */
4210-
xBreakLoop = pdFALSE;
4205+
for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )
4206+
{
4207+
cNextChar = pxTCB->pcTaskName[ x ];
42114208

4212-
for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )
4209+
if( cNextChar != pcNameToQuery[ x ] )
42134210
{
4214-
cNextChar = pxNextTCB->pcTaskName[ x ];
4215-
4216-
if( cNextChar != pcNameToQuery[ x ] )
4217-
{
4218-
/* Characters didn't match. */
4219-
xBreakLoop = pdTRUE;
4220-
}
4221-
else if( cNextChar == ( char ) 0x00 )
4222-
{
4223-
/* Both strings terminated, a match must have been
4224-
* found. */
4225-
pxReturn = pxNextTCB;
4226-
xBreakLoop = pdTRUE;
4227-
}
4228-
else
4229-
{
4230-
mtCOVERAGE_TEST_MARKER();
4231-
}
4232-
4233-
if( xBreakLoop != pdFALSE )
4234-
{
4235-
break;
4236-
}
4211+
/* Characters didn't match. */
4212+
xBreakLoop = pdTRUE;
42374213
}
4238-
4239-
if( pxReturn != NULL )
4214+
else if( cNextChar == ( char ) 0x00 )
42404215
{
4241-
/* The handle has been found. */
4242-
break;
4216+
/* Both strings terminated, a match must have been
4217+
* found. */
4218+
pxReturn = pxTCB;
4219+
xBreakLoop = pdTRUE;
42434220
}
4244-
} while( pxNextTCB != pxFirstTCB );
4245-
}
4246-
else
4247-
{
4248-
mtCOVERAGE_TEST_MARKER();
4249-
}
4250-
4251-
return pxReturn;
4252-
}
4253-
#else /* if ( configNUMBER_OF_CORES == 1 ) */
4254-
static TCB_t * prvSearchForNameWithinSingleList( List_t * pxList,
4255-
const char pcNameToQuery[] )
4256-
{
4257-
TCB_t * pxReturn = NULL;
4258-
UBaseType_t x;
4259-
char cNextChar;
4260-
BaseType_t xBreakLoop;
4261-
const ListItem_t * pxEndMarker = listGET_END_MARKER( pxList );
4262-
ListItem_t * pxIterator;
4263-
4264-
/* This function is called with the scheduler suspended. */
4265-
4266-
if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )
4267-
{
4268-
for( pxIterator = listGET_HEAD_ENTRY( pxList ); pxIterator != pxEndMarker; pxIterator = listGET_NEXT( pxIterator ) )
4269-
{
4270-
/* MISRA Ref 11.5.3 [Void pointer assignment] */
4271-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
4272-
/* coverity[misra_c_2012_rule_11_5_violation] */
4273-
TCB_t * pxTCB = listGET_LIST_ITEM_OWNER( pxIterator );
4274-
4275-
/* Check each character in the name looking for a match or
4276-
* mismatch. */
4277-
xBreakLoop = pdFALSE;
4278-
4279-
for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )
4221+
else
42804222
{
4281-
cNextChar = pxTCB->pcTaskName[ x ];
4282-
4283-
if( cNextChar != pcNameToQuery[ x ] )
4284-
{
4285-
/* Characters didn't match. */
4286-
xBreakLoop = pdTRUE;
4287-
}
4288-
else if( cNextChar == ( char ) 0x00 )
4289-
{
4290-
/* Both strings terminated, a match must have been
4291-
* found. */
4292-
pxReturn = pxTCB;
4293-
xBreakLoop = pdTRUE;
4294-
}
4295-
else
4296-
{
4297-
mtCOVERAGE_TEST_MARKER();
4298-
}
4299-
4300-
if( xBreakLoop != pdFALSE )
4301-
{
4302-
break;
4303-
}
4223+
mtCOVERAGE_TEST_MARKER();
43044224
}
43054225

4306-
if( pxReturn != NULL )
4226+
if( xBreakLoop != pdFALSE )
43074227
{
4308-
/* The handle has been found. */
43094228
break;
43104229
}
43114230
}
4312-
}
4313-
else
4314-
{
4315-
mtCOVERAGE_TEST_MARKER();
4316-
}
43174231

4318-
return pxReturn;
4232+
if( pxReturn != NULL )
4233+
{
4234+
/* The handle has been found. */
4235+
break;
4236+
}
4237+
}
43194238
}
4320-
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
4239+
else
4240+
{
4241+
mtCOVERAGE_TEST_MARKER();
4242+
}
4243+
4244+
return pxReturn;
4245+
}
43214246

43224247
#endif /* INCLUDE_xTaskGetHandle */
43234248
/*-----------------------------------------------------------*/
@@ -6330,30 +6255,27 @@ static void prvCheckTasksWaitingTermination( void )
63306255
List_t * pxList,
63316256
eTaskState eState )
63326257
{
6333-
configLIST_VOLATILE TCB_t * pxNextTCB;
6334-
configLIST_VOLATILE TCB_t * pxFirstTCB;
6258+
configLIST_VOLATILE TCB_t * pxTCB;
63356259
UBaseType_t uxTask = 0;
6260+
const ListItem_t * pxEndMarker = listGET_END_MARKER( pxList );
6261+
ListItem_t * pxIterator;
63366262

63376263
if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )
63386264
{
6339-
/* MISRA Ref 11.5.3 [Void pointer assignment] */
6340-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
6341-
/* coverity[misra_c_2012_rule_11_5_violation] */
6342-
listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );
6343-
63446265
/* Populate an TaskStatus_t structure within the
63456266
* pxTaskStatusArray array for each task that is referenced from
63466267
* pxList. See the definition of TaskStatus_t in task.h for the
63476268
* meaning of each TaskStatus_t structure member. */
6348-
do
6269+
for( pxIterator = listGET_HEAD_ENTRY( pxList ); pxIterator != pxEndMarker; pxIterator = listGET_NEXT( pxIterator ) )
63496270
{
63506271
/* MISRA Ref 11.5.3 [Void pointer assignment] */
63516272
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
63526273
/* coverity[misra_c_2012_rule_11_5_violation] */
6353-
listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );
6354-
vTaskGetInfo( ( TaskHandle_t ) pxNextTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState );
6274+
pxTCB = listGET_LIST_ITEM_OWNER( pxIterator );
6275+
6276+
vTaskGetInfo( ( TaskHandle_t ) pxTCB, &( pxTaskStatusArray[ uxTask ] ), pdTRUE, eState );
63556277
uxTask++;
6356-
} while( pxNextTCB != pxFirstTCB );
6278+
}
63576279
}
63586280
else
63596281
{

0 commit comments

Comments
 (0)