Skip to content

Commit

Permalink
Remove prvSelectHighestPriorityTask call in vTaskSuspend (#610)
Browse files Browse the repository at this point in the history
* Remove prvSelectHighestPriorityTask call in vTaskSuspend

* Every core starts with an idle task in SMP implementation and
  taskTASK_IS_RUNNING only return ture when the task is idle task before
  scheduler started. So prvSelectHighestPriorityTask won't be called in
  vTaskSuspend before scheduler started.
* Update prvSelectHighestPriorityTask to ensure that this function is
  called only when scheduler started.

* Fix kernel checker error
  • Loading branch information
chinglee-iot authored Jan 24, 2023
1 parent 8128208 commit 0f9e6e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kernel-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Tool Setup
uses: actions/setup-python@v2
with:
python-version: 3.7.10
python-version: 3.11.0
architecture: x64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
62 changes: 18 additions & 44 deletions tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
/*
* Selects the highest priority available task
*/
static BaseType_t prvSelectHighestPriorityTask( const BaseType_t xCoreID );
static void prvSelectHighestPriorityTask( const BaseType_t xCoreID );

/**
* Utility task that simply returns pdTRUE if the task referenced by xTask is
Expand Down Expand Up @@ -819,7 +819,7 @@ static void prvYieldForTask( TCB_t * pxTCB,

#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )

static BaseType_t prvSelectHighestPriorityTask( const BaseType_t xCoreID )
static void prvSelectHighestPriorityTask( const BaseType_t xCoreID )
{
UBaseType_t uxCurrentPriority = uxTopReadyPriority;
BaseType_t xTaskScheduled = pdFALSE;
Expand All @@ -832,6 +832,9 @@ static void prvYieldForTask( TCB_t * pxTCB,
BaseType_t xPriorityDropped = pdFALSE;
#endif

/* This function should be called when scheduler is running. */
configASSERT( xSchedulerRunning == pdTRUE );

while( xTaskScheduled == pdFALSE )
{
#if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) )
Expand Down Expand Up @@ -947,14 +950,9 @@ static void prvYieldForTask( TCB_t * pxTCB,
}
}

/* This function can get called by vTaskSuspend() before the scheduler is started.
* In that case, since the idle tasks have not yet been created it is possible that we
* won't find a new task to schedule. Return pdFALSE in this case. */
if( ( xSchedulerRunning == pdFALSE ) && ( uxCurrentPriority == tskIDLE_PRIORITY ) && ( xTaskScheduled == pdFALSE ) )
{
return pdFALSE;
}

/* Theare are configNUMBER_OF_CORES Idle tasks created when scheduler started.
* The scheduler should be able to select a task to run when uxCurrentPriority
* is tskIDLE_PRIORITY. */
configASSERT( ( uxCurrentPriority > tskIDLE_PRIORITY ) || ( xTaskScheduled == pdTRUE ) );
uxCurrentPriority--;
}
Expand Down Expand Up @@ -1034,8 +1032,6 @@ static void prvYieldForTask( TCB_t * pxTCB,
}
#endif /* if ( configUSE_CORE_AFFINITY == 1 ) */
#endif /* if ( configNUM_CORES > 1 ) */

return pdTRUE;
}

#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
Expand Down Expand Up @@ -2480,45 +2476,23 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
{
prvYieldCore( xTaskRunningOnCore );
}

taskEXIT_CRITICAL();
}
else
{
taskEXIT_CRITICAL();

configASSERT( pxTCB == pxCurrentTCBs[ xTaskRunningOnCore ] );

/* The scheduler is not running, but the task that was pointed
* to by pxCurrentTCB has just been suspended and pxCurrentTCB
* must be adjusted to point to a different task. */
if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks ) /*lint !e931 Right has no side effect, just volatile. */
{
/* No other tasks are ready, so set the core's TCB back to
* NULL so when the next task is created the core's TCB will
* be able to be set to point to it no matter what its relative
* priority is. */
pxTCB->xTaskRunState = taskTASK_NOT_RUNNING;
pxCurrentTCBs[ xTaskRunningOnCore ] = NULL;
}
else
{
/* Attempt to switch in a new task. This could fail since the idle tasks
* haven't been created yet. If it does then set the core's TCB back to
* NULL. */
if( prvSelectHighestPriorityTask( xTaskRunningOnCore ) == pdFALSE )
{
pxTCB->xTaskRunState = taskTASK_NOT_RUNNING;
pxCurrentTCBs[ xTaskRunningOnCore ] = NULL;
}
}
/* This code path is not possible because only Idle tasks are
* assigned a core before the scheduler is started ( i.e.
* taskTASK_IS_RUNNING is only true for idle tasks before
* the scheduler is started ) and idle tasks cannot be
* suspended. */
mtCOVERAGE_TEST_MARKER();
}
}
else
{
taskEXIT_CRITICAL();
mtCOVERAGE_TEST_MARKER();
}
} /* taskEXIT_CRITICAL() - already exited in one of three cases above */
}
taskEXIT_CRITICAL();
}

#endif /* INCLUDE_vTaskSuspend */
Expand Down Expand Up @@ -3940,7 +3914,7 @@ void vTaskSwitchContext( BaseType_t xCoreID )

/* Select a new task to run using either the generic C or port
* optimised asm code. */
( void ) prvSelectHighestPriorityTask( xCoreID );
prvSelectHighestPriorityTask( xCoreID );
traceTASK_SWITCHED_IN();

/* After the new task is switched in, update the global errno. */
Expand Down

0 comments on commit 0f9e6e5

Please sign in to comment.