Skip to content

Commit 6bc7806

Browse files
committed
Update test for granular lock
* Update IntQueue test. Normally empty RX is not guranteed to receive with granular lock since task can run at the same time. There is still priority inversion problem in IntQueue demo for fix. * Update demo to add proper delay since task inheritance and higher priority task are not completed in the same critial section. Including GenQTest, IntSetTest, recmutex
1 parent f01bda6 commit 6bc7806

File tree

6 files changed

+108
-15
lines changed

6 files changed

+108
-15
lines changed

FreeRTOS/Demo/Common/Minimal/GenQTest.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,15 @@ static void prvSendFrontAndBackTest( void * pvParameters )
471471
* mutex, and block when it finds it cannot obtain it. */
472472
vTaskResume( xHighPriorityMutexTask );
473473

474+
#if ( portUSING_GRANULAR_LOCKS == 1 )
475+
{
476+
/* When using granular lock, priority inheritance and higher priority
477+
* blocked is not completed in the same critical section. Adding a
478+
* short delay here to ensure higher priority task blocks itself. */
479+
vTaskDelay( genqSHORT_BLOCK );
480+
}
481+
#endif
482+
474483
/* This task should now have inherited the priority of the high priority
475484
* task as by now the high priority task will have attempted to obtain the
476485
* mutex. */
@@ -484,6 +493,15 @@ static void prvSendFrontAndBackTest( void * pvParameters )
484493
* task has inherited a priority above it. */
485494
vTaskResume( xSecondMediumPriorityMutexTask );
486495

496+
#if ( portUSING_GRANULAR_LOCKS == 1 )
497+
{
498+
/* When using granular lock, priority inheritance and higher priority
499+
* blocked is not completed in the same critical section. Adding a
500+
* short delay here to ensure higher priority task blocks itself. */
501+
vTaskDelay( genqSHORT_BLOCK );
502+
}
503+
#endif
504+
487505
/* This task should still have the priority of the high priority task as
488506
* that had already been inherited as is the highest priority of the three
489507
* tasks using the mutex. */
@@ -601,6 +619,15 @@ static void prvSendFrontAndBackTest( void * pvParameters )
601619
xErrorDetected = pdTRUE;
602620
}
603621

622+
#if ( portUSING_GRANULAR_LOCKS == 1 )
623+
{
624+
/* When using granular lock, priority inheritance and higher priority
625+
* blocked is not completed in the same critical section. Adding a
626+
* short delay here to ensure higher priority task blocks itself. */
627+
vTaskDelay( genqSHORT_BLOCK );
628+
}
629+
#endif
630+
604631
/* This time, when the high priority task has its delay aborted and it
605632
* fails to obtain the mutex this task will immediately have its priority
606633
* lowered down to that of the highest priority task waiting on the mutex,
@@ -680,6 +707,13 @@ static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex,
680707
* suspended (as it would have done in versions up to V7.5.3). */
681708
#if ( INCLUDE_eTaskGetState == 1 )
682709
{
710+
#if ( portUSING_GRANULAR_LOCKS == 1 )
711+
{
712+
/* When using granular lock, priority inheritance and higher priority
713+
* blocked is not completed in the same critical section. */
714+
vTaskDelay( genqSHORT_BLOCK );
715+
}
716+
#endif
683717
configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
684718
}
685719
#endif /* INCLUDE_eTaskGetState */
@@ -813,6 +847,13 @@ static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex,
813847
* suspended (as it would have done in versions up to V7.5.3). */
814848
#if ( INCLUDE_eTaskGetState == 1 )
815849
{
850+
#if ( portUSING_GRANULAR_LOCKS == 1 )
851+
{
852+
/* When using granular lock, priority inheritance and higher priority
853+
* blocked is not completed in the same critical section. */
854+
vTaskDelay( genqSHORT_BLOCK );
855+
}
856+
#endif
816857
configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
817858
}
818859
#endif /* INCLUDE_eTaskGetState */

FreeRTOS/Demo/Common/Minimal/IntQueue.c

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,26 @@
129129

130130
/* Receive a value from the normally empty queue. This is called from within
131131
* an interrupt. */
132-
#define timerNORMALLY_EMPTY_RX() \
133-
if( xQueueReceiveFromISR( xNormallyEmptyQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) != pdPASS ) \
134-
{ \
135-
prvQueueAccessLogError( __LINE__ ); \
136-
} \
137-
else \
132+
#if ( portUSING_GRANULAR_LOCKS == 1 )
133+
/* Queue doens't share kernel critical section when granular lock feature is enabled.
134+
* Therefore, it is possible that a task can contend with the ISR to receive from
135+
* the queue at the same time. */
136+
#define timerNORMALLY_EMPTY_RX() \
137+
if( xQueueReceiveFromISR( xNormallyEmptyQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) == pdPASS ) \
138138
{ \
139139
prvRecordValue_NormallyEmpty( uxRxedValue, intqSECOND_INTERRUPT ); \
140140
}
141+
#else
142+
#define timerNORMALLY_EMPTY_RX() \
143+
if( xQueueReceiveFromISR( xNormallyEmptyQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) != pdPASS ) \
144+
{ \
145+
prvQueueAccessLogError( __LINE__ ); \
146+
} \
147+
else \
148+
{ \
149+
prvRecordValue_NormallyEmpty( uxRxedValue, intqSECOND_INTERRUPT ); \
150+
}
151+
#endif
141152

142153
/* Receive a value from the normally full queue. This is called from within
143154
* an interrupt. */
@@ -407,12 +418,19 @@ static void prvLowerPriorityNormallyEmptyTask( void * pvParameters )
407418
{
408419
if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqONE_TICK_DELAY ) != errQUEUE_EMPTY )
409420
{
410-
/* A value should only be obtained when the high priority task is
411-
* suspended. */
412-
if( eTaskGetState( xHighPriorityNormallyEmptyTask1 ) != eSuspended )
421+
#if ( portUSING_GRANULAR_LOCKS == 0 )
413422
{
414-
prvQueueAccessLogError( __LINE__ );
423+
/* FIXME : Preemption disable won't check for run status with granular
424+
* locks. lower priority waiting task can enter the critical section
425+
* without yield for higher priority task waiting for the queue. */
426+
/* A value should only be obtained when the high priority task is
427+
* suspended. */
428+
if( eTaskGetState( xHighPriorityNormallyEmptyTask1 ) != eSuspended )
429+
{
430+
prvQueueAccessLogError( __LINE__ );
431+
}
415432
}
433+
#endif
416434

417435
prvRecordValue_NormallyEmpty( uxRxed, intqLOW_PRIORITY_TASK );
418436

@@ -608,11 +626,18 @@ static void prvLowerPriorityNormallyFullTask( void * pvParameters )
608626
{
609627
if( xQueueSend( xNormallyFullQueue, &uxTxed, intqONE_TICK_DELAY ) != errQUEUE_FULL )
610628
{
611-
/* Should only succeed when the higher priority task is suspended */
612-
if( eTaskGetState( xHighPriorityNormallyFullTask1 ) != eSuspended )
629+
#if ( portUSING_GRANULAR_LOCKS == 0 )
613630
{
614-
prvQueueAccessLogError( __LINE__ );
631+
/* FIXME : Preemption disable won't check for run status with granular
632+
* locks. lower priority waiting task can enter the critical section
633+
* without yield for higher priority task waiting for the queue. */
634+
/* Should only succeed when the higher priority task is suspended */
635+
if( eTaskGetState( xHighPriorityNormallyFullTask1 ) != eSuspended )
636+
{
637+
prvQueueAccessLogError( __LINE__ );
638+
}
615639
}
640+
#endif
616641

617642
vTaskResume( xHighPriorityNormallyFullTask1 );
618643
uxLowPriorityLoops2++;

FreeRTOS/Demo/Common/Minimal/IntSemTest.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
/* The priorities of the test tasks. */
4646
#define intsemMASTER_PRIORITY ( tskIDLE_PRIORITY )
4747
#define intsemSLAVE_PRIORITY ( tskIDLE_PRIORITY + 1 )
48+
#define intsemSHORT_BLOCK ( pdMS_TO_TICKS( 2 ) )
49+
4850

4951
/* The rate at which the tick hook will give the mutex. */
5052
#define intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ( 100 )
@@ -201,6 +203,14 @@ static void prvTakeAndGiveInTheSameOrder( void )
201203
* blocked on the semaphore. */
202204
#if ( INCLUDE_eTaskGetState == 1 )
203205
{
206+
#if ( portUSING_GRANULAR_LOCKS == 1 )
207+
{
208+
/* When using granular lock, priority inheritance and higher priority
209+
* blocked is not completed in the same critical section. Adding a
210+
* short delay here to ensure higher priority task blocks itself. */
211+
vTaskDelay( intsemSHORT_BLOCK );
212+
}
213+
#endif
204214
configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
205215
}
206216
#endif /* INCLUDE_eTaskGetState */
@@ -303,6 +313,14 @@ static void prvTakeAndGiveInTheOppositeOrder( void )
303313
* blocked on the semaphore. */
304314
#if ( INCLUDE_eTaskGetState == 1 )
305315
{
316+
#if ( portUSING_GRANULAR_LOCKS == 1 )
317+
{
318+
/* When using granular lock, priority inheritance and higher priority
319+
* blocked is not completed in the same critical section. Adding a
320+
* short delay here to ensure higher priority task blocks itself. */
321+
vTaskDelay( intsemSHORT_BLOCK );
322+
}
323+
#endif
306324
configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
307325
}
308326
#endif /* INCLUDE_eTaskGetState */

FreeRTOS/Demo/Common/Minimal/recmutex.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#define recmuMAX_COUNT ( 10 )
8181

8282
/* Misc. */
83+
#define recmuQUICK_CHECK_DELAY ( pdMS_TO_TICKS( 2 ) )
8384
#define recmuSHORT_DELAY ( pdMS_TO_TICKS( 20 ) )
8485
#define recmuNO_DELAY ( ( TickType_t ) 0 )
8586
#define recmu15ms_DELAY ( pdMS_TO_TICKS( 15 ) )
@@ -333,6 +334,14 @@ static void prvRecursiveMutexPollingTask( void * pvParameters )
333334

334335
#if ( INCLUDE_eTaskGetState == 1 )
335336
{
337+
#if ( portUSING_GRANULAR_LOCKS == 1 )
338+
{
339+
/* When using granular lock, priority inheritance and higher priority
340+
* blocked is not completed in the same critical section. Adding a
341+
* short delay here to ensure higher priority task blocks itself. */
342+
vTaskDelay( recmuQUICK_CHECK_DELAY );
343+
}
344+
#endif
336345
configASSERT( eTaskGetState( xControllingTaskHandle ) == eBlocked );
337346
configASSERT( eTaskGetState( xBlockingTaskHandle ) == eBlocked );
338347
}

0 commit comments

Comments
 (0)