From 70070989f07af2b3f64c1156352f6e71ba96921a Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 17 Oct 2022 15:30:20 +0200 Subject: [PATCH] freertos: Enable configUSE_PORT_OPTIMISED_TASK_SELECTION for RISC-V targets This commit enables the config option configUSE_PORT_OPTIMISED_TASK_SELECTION on RISC-V targets for legacy FreeRTOS (IDF-FreeRTOS). --- .../riscv/include/freertos/FreeRTOSConfig_arch.h | 4 ++++ .../portable/riscv/include/freertos/portmacro.h | 13 +++++++++++++ components/freertos/Kconfig | 5 ++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/FreeRTOSConfig_arch.h b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/FreeRTOSConfig_arch.h index 2adf8c0d24b3..f7a8110521d3 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/FreeRTOSConfig_arch.h +++ b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/FreeRTOSConfig_arch.h @@ -17,7 +17,11 @@ // ------------------ Scheduler Related -------------------- +#ifdef CONFIG_FREERTOS_OPTIMIZED_SCHEDULER +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 +#else #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 +#endif #define configMAX_API_CALL_INTERRUPT_PRIORITY 0 /* ------------------------------------------------ ESP-IDF Additions -------------------------------------------------- diff --git a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h index 82446da53614..65110e7e2cc9 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h +++ b/components/freertos/FreeRTOS-Kernel/portable/riscv/include/freertos/portmacro.h @@ -399,6 +399,19 @@ FORCE_INLINE_ATTR BaseType_t xPortGetCoreID(void) #define portALT_GET_RUN_TIME_COUNTER_VALUE(x) do {x = (uint32_t)esp_timer_get_time();} while(0) #endif +// -------------- Optimized Task Selection ----------------- + +#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 +/* Check the configuration. */ +#if( configMAX_PRIORITIES > 32 ) +#error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 different priorities as tasks that share a priority will time slice. +#endif + +/* Store/clear the ready priorities in a bit map. */ +#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) +#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) +#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __builtin_clz( ( uxReadyPriorities ) ) ) +#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ /* --------------------------------------------- Inline Implementations ------------------------------------------------ diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index 8e578c998278..9b3c15002bdb 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -38,13 +38,12 @@ menu "FreeRTOS" details). config FREERTOS_OPTIMIZED_SCHEDULER - # Todo: Not available in SMP FREERTOS (IDF-4986) - # Todo: Rename to CONFIG_FREERTOS_USE_PORT_OPTIMISED_TASK_SELECTION (IDF-4986) + # Todo: Not available in SMP FREERTOS (IDF-3733) bool "configUSE_PORT_OPTIMISED_TASK_SELECTION" depends on FREERTOS_UNICORE default y help - Enables port specific task selection method. This option can will speed up the search of ready tasks + Enables port specific task selection method. This option can speed up the search of ready tasks when scheduling (see configUSE_PORT_OPTIMISED_TASK_SELECTION documentation for more details). choice FREERTOS_CHECK_STACKOVERFLOW