Skip to content

Commit bca0ea0

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 d0a2b81 commit bca0ea0

File tree

2 files changed

+456
-288
lines changed

2 files changed

+456
-288
lines changed

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
@@ -3733,7 +3719,7 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
37333719
* It should be used in the implementation of portENTER_CRITICAL if port is running a
37343720
* multiple core FreeRTOS.
37353721
*/
3736-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3722+
#if ( ( portCRITICAL_NESTING_IN_TCB == 1 ) || ( configNUMBER_OF_CORES > 1 ) )
37373723
void vTaskEnterCritical( void );
37383724
#endif
37393725

@@ -3745,7 +3731,7 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
37453731
* It should be used in the implementation of portEXIT_CRITICAL if port is running a
37463732
* multiple core FreeRTOS.
37473733
*/
3748-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3734+
#if ( ( portCRITICAL_NESTING_IN_TCB == 1 ) || ( configNUMBER_OF_CORES > 1 ) )
37493735
void vTaskExitCritical( void );
37503736
#endif
37513737

@@ -3755,7 +3741,7 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
37553741
* should be used in the implementation of portENTER_CRITICAL_FROM_ISR if port is
37563742
* running a multiple core FreeRTOS.
37573743
*/
3758-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3744+
#if ( configNUMBER_OF_CORES > 1 )
37593745
UBaseType_t vTaskEnterCriticalFromISR( void );
37603746
#endif
37613747

@@ -3765,12 +3751,12 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
37653751
* should be used in the implementation of portEXIT_CRITICAL_FROM_ISR if port is
37663752
* running a multiple core FreeRTOS.
37673753
*/
3768-
#if !( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
3754+
#if ( configNUMBER_OF_CORES > 1 )
37693755
void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus );
37703756
#endif
37713757

37723758
/*
3773-
* Checks whether a yield is required after taskUNLOCK_DATA_GROUP() returns.
3759+
* Checks whether a yield is required after portUNLOCK_DATA_GROUP() returns.
37743760
* To be called while data group is locked.
37753761
*/
37763762
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )

0 commit comments

Comments
 (0)