Skip to content

Commit 0f9e6e5

Browse files
authored
Remove prvSelectHighestPriorityTask call in vTaskSuspend (#610)
* 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
1 parent 8128208 commit 0f9e6e5

File tree

2 files changed

+19
-45
lines changed

2 files changed

+19
-45
lines changed

.github/workflows/kernel-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Tool Setup
1212
uses: actions/setup-python@v2
1313
with:
14-
python-version: 3.7.10
14+
python-version: 3.11.0
1515
architecture: x64
1616
env:
1717
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tasks.c

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static void prvYieldForTask( TCB_t * pxTCB,
438438
/*
439439
* Selects the highest priority available task
440440
*/
441-
static BaseType_t prvSelectHighestPriorityTask( const BaseType_t xCoreID );
441+
static void prvSelectHighestPriorityTask( const BaseType_t xCoreID );
442442

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

820820
#if ( configUSE_PORT_OPTIMISED_TASK_SELECTION == 0 )
821821

822-
static BaseType_t prvSelectHighestPriorityTask( const BaseType_t xCoreID )
822+
static void prvSelectHighestPriorityTask( const BaseType_t xCoreID )
823823
{
824824
UBaseType_t uxCurrentPriority = uxTopReadyPriority;
825825
BaseType_t xTaskScheduled = pdFALSE;
@@ -832,6 +832,9 @@ static void prvYieldForTask( TCB_t * pxTCB,
832832
BaseType_t xPriorityDropped = pdFALSE;
833833
#endif
834834

835+
/* This function should be called when scheduler is running. */
836+
configASSERT( xSchedulerRunning == pdTRUE );
837+
835838
while( xTaskScheduled == pdFALSE )
836839
{
837840
#if ( ( configRUN_MULTIPLE_PRIORITIES == 0 ) && ( configNUM_CORES > 1 ) )
@@ -947,14 +950,9 @@ static void prvYieldForTask( TCB_t * pxTCB,
947950
}
948951
}
949952

950-
/* This function can get called by vTaskSuspend() before the scheduler is started.
951-
* In that case, since the idle tasks have not yet been created it is possible that we
952-
* won't find a new task to schedule. Return pdFALSE in this case. */
953-
if( ( xSchedulerRunning == pdFALSE ) && ( uxCurrentPriority == tskIDLE_PRIORITY ) && ( xTaskScheduled == pdFALSE ) )
954-
{
955-
return pdFALSE;
956-
}
957-
953+
/* Theare are configNUMBER_OF_CORES Idle tasks created when scheduler started.
954+
* The scheduler should be able to select a task to run when uxCurrentPriority
955+
* is tskIDLE_PRIORITY. */
958956
configASSERT( ( uxCurrentPriority > tskIDLE_PRIORITY ) || ( xTaskScheduled == pdTRUE ) );
959957
uxCurrentPriority--;
960958
}
@@ -1034,8 +1032,6 @@ static void prvYieldForTask( TCB_t * pxTCB,
10341032
}
10351033
#endif /* if ( configUSE_CORE_AFFINITY == 1 ) */
10361034
#endif /* if ( configNUM_CORES > 1 ) */
1037-
1038-
return pdTRUE;
10391035
}
10401036

10411037
#else /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
@@ -2480,45 +2476,23 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB )
24802476
{
24812477
prvYieldCore( xTaskRunningOnCore );
24822478
}
2483-
2484-
taskEXIT_CRITICAL();
24852479
}
24862480
else
24872481
{
2488-
taskEXIT_CRITICAL();
2489-
2490-
configASSERT( pxTCB == pxCurrentTCBs[ xTaskRunningOnCore ] );
2491-
2492-
/* The scheduler is not running, but the task that was pointed
2493-
* to by pxCurrentTCB has just been suspended and pxCurrentTCB
2494-
* must be adjusted to point to a different task. */
2495-
if( listCURRENT_LIST_LENGTH( &xSuspendedTaskList ) == uxCurrentNumberOfTasks ) /*lint !e931 Right has no side effect, just volatile. */
2496-
{
2497-
/* No other tasks are ready, so set the core's TCB back to
2498-
* NULL so when the next task is created the core's TCB will
2499-
* be able to be set to point to it no matter what its relative
2500-
* priority is. */
2501-
pxTCB->xTaskRunState = taskTASK_NOT_RUNNING;
2502-
pxCurrentTCBs[ xTaskRunningOnCore ] = NULL;
2503-
}
2504-
else
2505-
{
2506-
/* Attempt to switch in a new task. This could fail since the idle tasks
2507-
* haven't been created yet. If it does then set the core's TCB back to
2508-
* NULL. */
2509-
if( prvSelectHighestPriorityTask( xTaskRunningOnCore ) == pdFALSE )
2510-
{
2511-
pxTCB->xTaskRunState = taskTASK_NOT_RUNNING;
2512-
pxCurrentTCBs[ xTaskRunningOnCore ] = NULL;
2513-
}
2514-
}
2482+
/* This code path is not possible because only Idle tasks are
2483+
* assigned a core before the scheduler is started ( i.e.
2484+
* taskTASK_IS_RUNNING is only true for idle tasks before
2485+
* the scheduler is started ) and idle tasks cannot be
2486+
* suspended. */
2487+
mtCOVERAGE_TEST_MARKER();
25152488
}
25162489
}
25172490
else
25182491
{
2519-
taskEXIT_CRITICAL();
2492+
mtCOVERAGE_TEST_MARKER();
25202493
}
2521-
} /* taskEXIT_CRITICAL() - already exited in one of three cases above */
2494+
}
2495+
taskEXIT_CRITICAL();
25222496
}
25232497

25242498
#endif /* INCLUDE_vTaskSuspend */
@@ -3940,7 +3914,7 @@ void vTaskSwitchContext( BaseType_t xCoreID )
39403914

39413915
/* Select a new task to run using either the generic C or port
39423916
* optimised asm code. */
3943-
( void ) prvSelectHighestPriorityTask( xCoreID );
3917+
prvSelectHighestPriorityTask( xCoreID );
39443918
traceTASK_SWITCHED_IN();
39453919

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

0 commit comments

Comments
 (0)