From 77bf1ff1c0f841218ab51403d6075a3dbd3689ed Mon Sep 17 00:00:00 2001 From: Felipe Neves Date: Wed, 6 Nov 2019 16:59:16 +0800 Subject: [PATCH] freertos/tests: added test to evaluate scheduling time freertos/Kconfig: fix trailing space on optimized scheduler option freertos/tests: moved test context variables inside of test task. The public variables used on scheduling time test now were packed into a structure allocated on test case task stack and passed to tasks as arguments saving RAM comsumption. --- components/freertos/Kconfig | 4 +- .../freertos/include/freertos/portmacro.h | 4 -- .../test/test_freertos_scheduling_time.c | 58 +++++++++++++++++++ components/idf_test/include/idf_performance.h | 2 + 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 components/freertos/test/test_freertos_scheduling_time.c diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index 06f84e70b2..102ed95df9 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -44,8 +44,8 @@ menu "FreeRTOS" default y help On most platforms there are instructions can speedup the ready task - searching. Enabling this option the FreeRTOS with this instructions - support will be built + searching. Enabling this option the FreeRTOS with this instructions + support will be built. config FREERTOS_HZ int "Tick rate (Hz)" diff --git a/components/freertos/include/freertos/portmacro.h b/components/freertos/include/freertos/portmacro.h index eaa2d6603d..b96bd8ff23 100644 --- a/components/freertos/include/freertos/portmacro.h +++ b/components/freertos/include/freertos/portmacro.h @@ -472,10 +472,6 @@ void vApplicationSleep( TickType_t xExpectedIdleTime ); /*-----------------------------------------------------------*/ /* Architecture specific optimisations. */ -#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION - #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 -#endif - #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 /* Check the configuration. */ diff --git a/components/freertos/test/test_freertos_scheduling_time.c b/components/freertos/test/test_freertos_scheduling_time.c new file mode 100644 index 0000000000..68f8468003 --- /dev/null +++ b/components/freertos/test/test_freertos_scheduling_time.c @@ -0,0 +1,58 @@ +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" +#include "freertos/xtensa_api.h" +#include "esp_intr_alloc.h" +#include "xtensa/hal.h" +#include "unity.h" +#include "soc/cpu.h" +#include "test_utils.h" + +typedef struct { + uint32_t noof_runs; + SemaphoreHandle_t end_sema; + uint32_t before_sched; + uint32_t cycles_to_sched; +} test_context_t; + +static void test_task_1(void *arg) { + test_context_t *context = (test_context_t *)arg; + + for(context->noof_runs = 0 ;context->noof_runs < 10000; ) { + context->before_sched = portGET_RUN_TIME_COUNTER_VALUE(); + vPortYield(); + } + + vTaskDelete(NULL); +} + +static void test_task_2(void *arg) { + test_context_t *context = (test_context_t *)arg; + + for( ; context->noof_runs < 10000; context->noof_runs++) { + context->cycles_to_sched += (portGET_RUN_TIME_COUNTER_VALUE() - context->before_sched); + vPortYield(); + } + + context->cycles_to_sched /= 10000; + xSemaphoreGive(context->end_sema); + vTaskDelete(NULL); +} + +TEST_CASE("scheduling time test", "[freertos]") +{ + test_context_t context; + + context.end_sema = xSemaphoreCreateBinary(); + TEST_ASSERT(context.end_sema != NULL); + + xTaskCreatePinnedToCore(test_task_1, "test1" , 4096, &context, 1, NULL,1); + xTaskCreatePinnedToCore(test_task_2, "test2" , 4096, &context, 1, NULL,1); + + BaseType_t result = xSemaphoreTake(context.end_sema, portMAX_DELAY); + TEST_ASSERT_EQUAL_HEX32(pdTRUE, result); + TEST_PERFORMANCE_LESS_THAN(SCHEDULING_TIME , "scheduling time %d cycles" ,context.cycles_to_sched); +} \ No newline at end of file diff --git a/components/idf_test/include/idf_performance.h b/components/idf_test/include/idf_performance.h index ac3d1e97f2..f5ddd9a145 100644 --- a/components/idf_test/include/idf_performance.h +++ b/components/idf_test/include/idf_performance.h @@ -76,3 +76,5 @@ #endif //CONFIG_IDF_TARGET_ESP32S2BETA +//time to perform the task selection plus context switch (from task) +#define IDF_PERFORMANCE_MAX_SCHEDULING_TIME 4500