Skip to content

Commit bb6b054

Browse files
change(freertos/smp): Update tasks.c locking
Updated critical section macros with granular locks. Some tasks.c API relied on their callers to enter critical sections. This assumption no longer works under granular locking. Critical sections added to the following functions: - `vTaskInternalSetTimeOutState()` - `xTaskIncrementTick()` - `vTaskSwitchContext()` - `xTaskRemoveFromEventList()` - `vTaskInternalSetTimeOutState()` - `eTaskConfirmSleepModeStatus()` - `xTaskPriorityDisinherit()` - `pvTaskIncrementMutexHeldCount()` Added missing suspensions to the following functions: - `vTaskPlaceOnEventList()` - `vTaskPlaceOnUnorderedEventList()` - `vTaskPlaceOnEventListRestricted()` Fixed the locking in vTaskSwitchContext() vTaskSwitchContext() must aquire both kernel locks, viz., task lock and ISR lock. This is because, vTaskSwitchContext() can be called from either task context or ISR context. Also, vTaskSwitchContext() must not alter the interrupt state prematurely. Co-authored-by: Sudeep Mohanty <[email protected]>
1 parent eb7d86f commit bb6b054

File tree

3 files changed

+597
-306
lines changed

3 files changed

+597
-306
lines changed

include/FreeRTOS.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,9 @@ typedef struct xSTATIC_TCB
32383238
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
32393239
UBaseType_t xDummy25;
32403240
#endif
3241+
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
3242+
BaseType_t xDummy26;
3243+
#endif
32413244
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
32423245
void * pxDummy8;
32433246
#endif

include/task.h

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ typedef enum
213213
* \defgroup taskYIELD taskYIELD
214214
* \ingroup SchedulerControl
215215
*/
216-
#define taskYIELD() portYIELD()
216+
#define taskYIELD() portYIELD()
217217

218218
/**
219219
* task. h
@@ -227,19 +227,12 @@ typedef enum
227227
* \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
228228
* \ingroup SchedulerControl
229229
*/
230-
#define taskENTER_CRITICAL() portENTER_CRITICAL()
230+
#define taskENTER_CRITICAL() portENTER_CRITICAL()
231231
#if ( configNUMBER_OF_CORES == 1 )
232-
#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
232+
#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
233233
#else
234-
#define taskENTER_CRITICAL_FROM_ISR() portENTER_CRITICAL_FROM_ISR()
234+
#define taskENTER_CRITICAL_FROM_ISR() portENTER_CRITICAL_FROM_ISR()
235235
#endif
236-
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
237-
#define taskLOCK_DATA_GROUP( pxTaskSpinlock, pxISRSpinlock ) portLOCK_DATA_GROUP( ( portSPINLOCK_TYPE * ) pxTaskSpinlock, ( portSPINLOCK_TYPE * ) pxISRSpinlock )
238-
#define taskLOCK_DATA_GROUP_FROM_ISR( pxISRSpinlock ) portLOCK_DATA_GROUP_FROM_ISR( pxISRSpinlock )
239-
#else /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
240-
#define taskLOCK_DATA_GROUP( pxTaskSpinlock, pxISRSpinlock ) taskENTER_CRITICAL()
241-
#define taskLOCK_DATA_GROUP_FROM_ISR( pxISRSpinlock ) taskENTER_CRITICAL_FROM_ISR()
242-
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
243236

244237
/**
245238
* task. h
@@ -253,19 +246,12 @@ typedef enum
253246
* \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
254247
* \ingroup SchedulerControl
255248
*/
256-
#define taskEXIT_CRITICAL() portEXIT_CRITICAL()
249+
#define taskEXIT_CRITICAL() portEXIT_CRITICAL()
257250
#if ( configNUMBER_OF_CORES == 1 )
258-
#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
251+
#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
259252
#else
260-
#define taskEXIT_CRITICAL_FROM_ISR( x ) portEXIT_CRITICAL_FROM_ISR( x )
253+
#define taskEXIT_CRITICAL_FROM_ISR( x ) portEXIT_CRITICAL_FROM_ISR( x )
261254
#endif
262-
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
263-
#define taskUNLOCK_DATA_GROUP( pxTaskSpinlock, pxISRSpinlock ) portUNLOCK_DATA_GROUP( ( portSPINLOCK_TYPE * ) pxTaskSpinlock, ( portSPINLOCK_TYPE * ) pxISRSpinlock )
264-
#define taskUNLOCK_DATA_GROUP_FROM_ISR( x, pxISRSpinlock ) portUNLOCK_DATA_GROUP_FROM_ISR( x, pxISRSpinlock )
265-
#else /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
266-
#define taskUNLOCK_DATA_GROUP( pxTaskSpinlock, pxISRSpinlock ) taskEXIT_CRITICAL()
267-
#define taskUNLOCK_DATA_GROUP_FROM_ISR( x, pxISRSpinlock ) taskEXIT_CRITICAL_FROM_ISR( x )
268-
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
269255

270256
/**
271257
* task. h
@@ -3845,7 +3831,7 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
38453831
* It should be used in the implementation of portENTER_CRITICAL if port is running a
38463832
* multiple core FreeRTOS.
38473833
*/
3848-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3834+
#if ( ( portCRITICAL_NESTING_IN_TCB == 1 ) || ( configNUMBER_OF_CORES > 1 ) )
38493835
void vTaskEnterCritical( void );
38503836
#endif
38513837

@@ -3857,7 +3843,7 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
38573843
* It should be used in the implementation of portEXIT_CRITICAL if port is running a
38583844
* multiple core FreeRTOS.
38593845
*/
3860-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3846+
#if ( ( portCRITICAL_NESTING_IN_TCB == 1 ) || ( configNUMBER_OF_CORES > 1 ) )
38613847
void vTaskExitCritical( void );
38623848
#endif
38633849

@@ -3867,7 +3853,7 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
38673853
* should be used in the implementation of portENTER_CRITICAL_FROM_ISR if port is
38683854
* running a multiple core FreeRTOS.
38693855
*/
3870-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3856+
#if ( configNUMBER_OF_CORES > 1 )
38713857
UBaseType_t vTaskEnterCriticalFromISR( void );
38723858
#endif
38733859

@@ -3877,12 +3863,12 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
38773863
* should be used in the implementation of portEXIT_CRITICAL_FROM_ISR if port is
38783864
* running a multiple core FreeRTOS.
38793865
*/
3880-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3866+
#if ( configNUMBER_OF_CORES > 1 )
38813867
void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus );
38823868
#endif
38833869

38843870
/*
3885-
* Checks whether a yield is required after taskUNLOCK_DATA_GROUP() returns.
3871+
* Checks whether a yield is required after portUNLOCK_DATA_GROUP() returns.
38863872
* To be called while data group is locked.
38873873
*/
38883874
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )

0 commit comments

Comments
 (0)