Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/smp granular locks v4 #1154

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
279 changes: 262 additions & 17 deletions event_groups.c

Large diffs are not rendered by default.

411 changes: 411 additions & 0 deletions granular_locks_v4.md

Large diffs are not rendered by default.

124 changes: 112 additions & 12 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@
#define portCRITICAL_NESTING_IN_TCB 0
#endif

#ifndef portUSING_GRANULAR_LOCKS
#define portUSING_GRANULAR_LOCKS 0
#endif

#ifndef configMAX_TASK_NAME_LEN
#define configMAX_TASK_NAME_LEN 16
#endif
Expand Down Expand Up @@ -444,44 +448,68 @@

#ifndef portRELEASE_TASK_LOCK

#if ( configNUMBER_OF_CORES == 1 )
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) || ( configNUMBER_OF_CORES == 1 ) )
#define portRELEASE_TASK_LOCK( xCoreID )
#else
#error portRELEASE_TASK_LOCK is required in SMP
#error portRELEASE_TASK_LOCK is required in SMP without granular locking feature enabled
#endif

#endif /* portRELEASE_TASK_LOCK */

#ifndef portGET_TASK_LOCK

#if ( configNUMBER_OF_CORES == 1 )
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) || ( configNUMBER_OF_CORES == 1 ) )
#define portGET_TASK_LOCK( xCoreID )
#else
#error portGET_TASK_LOCK is required in SMP
#error portGET_TASK_LOCK is required in SMP without granular locking feature enabled
#endif

#endif /* portGET_TASK_LOCK */

#ifndef portRELEASE_ISR_LOCK

#if ( configNUMBER_OF_CORES == 1 )
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) || ( configNUMBER_OF_CORES == 1 ) )
#define portRELEASE_ISR_LOCK( xCoreID )
#else
#error portRELEASE_ISR_LOCK is required in SMP
#error portRELEASE_ISR_LOCK is required in SMP without granular locking feature enabled
#endif

#endif /* portRELEASE_ISR_LOCK */

#ifndef portGET_ISR_LOCK

#if ( configNUMBER_OF_CORES == 1 )
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) || ( configNUMBER_OF_CORES == 1 ) )
#define portGET_ISR_LOCK( xCoreID )
#else
#error portGET_ISR_LOCK is required in SMP
#error portGET_ISR_LOCK is required in SMP without granular locking feature enabled
#endif

#endif /* portGET_ISR_LOCK */

#ifndef portRELEASE_SPINLOCK

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portRELEASE_SPINLOCK is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portGET_SPINLOCK

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portGET_SPINLOCK is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portCHECK_IF_IN_ISR

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portCHECK_IF_IN_ISR is required for granular locking
#endif

#endif

#ifndef portENTER_CRITICAL_FROM_ISR

#if ( configNUMBER_OF_CORES > 1 )
Expand All @@ -498,6 +526,62 @@

#endif

#ifndef portENTER_CRITICAL_DATA_GROUP

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portENTER_CRITICAL_DATA_GROUP is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portEXIT_CRITICAL_DATA_GROUP

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portEXIT_CRITICAL_DATA_GROUP is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portENTER_CRITICAL_DATA_GROUP_FROM_ISR

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portENTER_CRITICAL_DATA_GROUP_FROM_ISR is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portEXIT_CRITICAL_DATA_GROUP_FROM_ISR

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portEXIT_CRITICAL_DATA_GROUP_FROM_ISR is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portSPINLOCK_TYPE

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portSPINLOCK_TYPE is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portINIT_SPINLOCK

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portINIT_SPINLOCK is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef portINIT_SPINLOCK_STATIC

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#error portINIT_SPINLOCK_STATIC is required for SMP with granular locking feature enabled
#endif

#endif

#ifndef configUSE_CORE_AFFINITY
#define configUSE_CORE_AFFINITY 0
#endif /* configUSE_CORE_AFFINITY */
Expand Down Expand Up @@ -2905,11 +2989,16 @@
/* Either variables of tick type cannot be read atomically, or
* portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when
* the tick count is returned to the standard critical section macros. */
#define portTICK_TYPE_ENTER_CRITICAL() portENTER_CRITICAL()
#define portTICK_TYPE_EXIT_CRITICAL() portEXIT_CRITICAL()
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
#define portTICK_TYPE_ENTER_CRITICAL() portENTER_CRITICAL_DATA_GROUP( &xTaskSpinlock, &xISRSpinlock )
#define portTICK_TYPE_EXIT_CRITICAL() portEXIT_CRITICAL_DATA_GROUP( &xTaskSpinlock, &xISRSpinlock )
#else /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
#define portTICK_TYPE_ENTER_CRITICAL() portENTER_CRITICAL()
#define portTICK_TYPE_EXIT_CRITICAL() portEXIT_CRITICAL()
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
#define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
#define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( ( x ) )
#else
#else /* if ( portTICK_TYPE_IS_ATOMIC == 0 ) */

/* The tick type can be read atomically, so critical sections used when the
* tick count is returned can be defined away. */
Expand Down Expand Up @@ -3179,7 +3268,7 @@ typedef struct xSTATIC_TCB
#endif
uint8_t ucDummy7[ configMAX_TASK_NAME_LEN ];
#if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
BaseType_t xDummy25;
UBaseType_t xDummy25;
#endif
#if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
void * pxDummy8;
Expand Down Expand Up @@ -3261,6 +3350,10 @@ typedef struct xSTATIC_QUEUE
UBaseType_t uxDummy8;
uint8_t ucDummy9;
#endif

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
portSPINLOCK_TYPE xDummySpinlock[ 2 ];
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
} StaticQueue_t;
typedef StaticQueue_t StaticSemaphore_t;

Expand Down Expand Up @@ -3290,6 +3383,10 @@ typedef struct xSTATIC_EVENT_GROUP
#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
uint8_t ucDummy4;
#endif

#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
portSPINLOCK_TYPE xDummySpinlock[ 2 ];
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
} StaticEventGroup_t;

/*
Expand Down Expand Up @@ -3345,6 +3442,9 @@ typedef struct xSTATIC_STREAM_BUFFER
void * pvDummy5[ 2 ];
#endif
UBaseType_t uxDummy6;
#if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
portSPINLOCK_TYPE xDummySpinlock[ 2 ];
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */
} StaticStreamBuffer_t;

/* Message buffers are built on stream buffers. */
Expand Down
8 changes: 8 additions & 0 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -3755,6 +3755,14 @@ void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNC
void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus );
#endif

/*
* Checks whether a yield is required after portUNLOCK_DATA_GROUP() returns.
* To be called while data group is locked.
*/
#if ( configNUMBER_OF_CORES > 1 )
BaseType_t xTaskUnlockCanYield( void );
#endif /* #if ( ( portUSING_GRANULAR_LOCKS == 1 ) && ( configNUMBER_OF_CORES > 1 ) ) */

#if ( portUSING_MPU_WRAPPERS == 1 )

/*
Expand Down
Loading