Skip to content

Commit

Permalink
Update for v4 test
Browse files Browse the repository at this point in the history
  • Loading branch information
chinglee-iot committed Aug 6, 2024
1 parent 9cc6ef7 commit 4a2a9db
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion FreeRTOS/Source
1 change: 1 addition & 0 deletions FreeRTOS/Test/Target/boards/pico/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
#define configRUN_MULTIPLE_PRIORITIES 1
#define configUSE_CORE_AFFINITY 1
#define configUSE_PASSIVE_IDLE_HOOK 0
#define configUSE_MINIMAL_IDLE_HOOK 0
#define configUSE_TASK_PREEMPTION_DISABLE 1

/* RP2040 specific */
Expand Down
12 changes: 7 additions & 5 deletions FreeRTOS/Test/Target/tests/smp/crit_speed/crit_speed.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* Test macros to be defined by each port
*/
#define portTEST_GET_TIME() ( ( UBaseType_t ) esp_cpu_get_cycle_count() )
#define portTEST_NUM_SAMPLES 128
#define portTEST_NUM_SAMPLES 2048
/*-----------------------------------------------------------*/

#endif /* UPSTREAM_BUILD */
Expand Down Expand Up @@ -83,17 +83,19 @@ static void Test_CriticalSectionSpeed( void )
{
/* Test taskENTER_CRITICAL() elapsed time */
uxTemp = portTEST_GET_TIME();
taskENTER_CRITICAL();

vTaskEnterCritical();
uxEntryElapsedCumulative += ( portTEST_GET_TIME() - uxTemp );

/* Test taskEXIT_CRITICAL elapsed time */
uxTemp = portTEST_GET_TIME();
taskEXIT_CRITICAL();

vTaskExitCritical();
uxExitElapsedCumulative += ( portTEST_GET_TIME() - uxTemp );
}

printf( "taskENTER_CRITICAL() average elapsed time: %u\n", uxEntryElapsedCumulative / portTEST_NUM_SAMPLES );
printf( "taskEXIT_CRITICAL() average elapsed time: %u\n", uxExitElapsedCumulative / portTEST_NUM_SAMPLES );
printf( "taskENTER_CRITICAL() accumulated elapsed time: %u\n", uxEntryElapsedCumulative );
printf( "taskEXIT_CRITICAL() accumulated elapsed time: %u\n", uxExitElapsedCumulative );
}
/*-----------------------------------------------------------*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@
#endif /* UPSTREAM_BUILD */

#if ( configNUMBER_OF_CORES < 2 )
#error This test is for FreeRTOS SMP and therefore, requires at least 2 cores.
// #error This test is for FreeRTOS SMP and therefore, requires at least 2 cores.
#endif /* if configNUMBER_OF_CORES != 2 */

#define testNUMBER_OF_CORES 2

#if ( configRUN_MULTIPLE_PRIORITIES != 1 )
#error configRUN_MULTIPLE_PRIORITIES must be set to 1 for this test.
#endif /* if ( configRUN_MULTIPLE_PRIORITIES != 1 ) */
Expand Down Expand Up @@ -104,31 +106,31 @@ static void prvConsumerTask( void * pvParameters );
/**
* @brief Handles of the queues accessed by each core
*/
static QueueHandle_t xQueueHandles[ configNUMBER_OF_CORES ];
static QueueHandle_t xQueueHandles[ testNUMBER_OF_CORES ];
/*-----------------------------------------------------------*/

/**
* @brief Handles of the producer tasks created for each core
*/
static TaskHandle_t xProducerTaskHandles[ configNUMBER_OF_CORES ];
static TaskHandle_t xProducerTaskHandles[ testNUMBER_OF_CORES ];
/*-----------------------------------------------------------*/

/**
* @brief Handles of the consumer tasks created for each core
*/
static TaskHandle_t xConsumerTaskHandles[ configNUMBER_OF_CORES ];
static TaskHandle_t xConsumerTaskHandles[ testNUMBER_OF_CORES ];
/*-----------------------------------------------------------*/

/**
* @brief Start times of each iteration for each core
*/
static UBaseType_t uxStartTimes[ configNUMBER_OF_CORES ];
static UBaseType_t uxStartTimes[ testNUMBER_OF_CORES ];
/*-----------------------------------------------------------*/

/**
* @brief Cumulative elapsed time of all iterations for each core
*/
static UBaseType_t uxElapsedCumulative[ configNUMBER_OF_CORES ];
static UBaseType_t uxElapsedCumulative[ testNUMBER_OF_CORES ];
/*-----------------------------------------------------------*/

/**
Expand Down Expand Up @@ -203,7 +205,7 @@ static void Test_LockContentionEndToEnd( void )
/* Run test for portTEST_NUM_SAMPLES number of iterations */
for( iIter = 0; iIter < portTEST_NUM_SAMPLES; iIter++ )
{
for( iCore = 0; iCore < configNUMBER_OF_CORES; iCore++ )
for( iCore = 0; iCore < testNUMBER_OF_CORES; iCore++ )
{
/* Start the consumer task, which in turn starts the producer task.
* Start them on the other cores first so that we don't get
Expand All @@ -217,15 +219,15 @@ static void Test_LockContentionEndToEnd( void )
xTaskNotifyGive( xConsumerTaskHandles[ portGET_CORE_ID() ] );

/* Wait until both cores have completed this iteration */
for( iCore = 0; iCore < configNUMBER_OF_CORES; iCore++ )
for( iCore = 0; iCore < testNUMBER_OF_CORES; iCore++ )
{
xSemaphoreTake( xIterDoneSem, portMAX_DELAY );
}
}

/* Print average results */
printf("Time taken to send %d items, averaged over %d samples\n", portTEST_NUM_ITEMS, portTEST_NUM_SAMPLES);
for( iCore = 0; iCore < configNUMBER_OF_CORES; iCore++ )
for( iCore = 0; iCore < testNUMBER_OF_CORES; iCore++ )
{
printf("Core %d: %d\n", iCore, ( uxElapsedCumulative[ iCore ] / portTEST_NUM_SAMPLES ) );
}
Expand All @@ -242,11 +244,11 @@ static void Test_LockContentionEndToEnd( void )
int i;

/* Create counting semaphore to indicate iteration completion */
xIterDoneSem = xSemaphoreCreateCounting( configNUMBER_OF_CORES, 0 );
xIterDoneSem = xSemaphoreCreateCounting( testNUMBER_OF_CORES, 0 );
TEST_ASSERT_NOT_NULL_MESSAGE( xIterDoneSem, "Failed to create counting semaphore");

/* Create separate queues and tasks for each core */
for( i = 0; i < configNUMBER_OF_CORES; i++ )
for( i = 0; i < testNUMBER_OF_CORES; i++ )
{
BaseType_t xRet;

Expand Down Expand Up @@ -291,7 +293,7 @@ static void Test_LockContentionEndToEnd( void )
vSemaphoreDelete( xIterDoneSem );

/* Delete tasks and queues */
for( i = 0; i < configNUMBER_OF_CORES; i++ )
for( i = 0; i < testNUMBER_OF_CORES; i++ )
{
vTaskDelete( xProducerTaskHandles[ i ] );
vTaskDelete( xConsumerTaskHandles[ i ] );
Expand Down

0 comments on commit 4a2a9db

Please sign in to comment.