From 6fd342dd0fdf0060f7f97f6dd256b1ab4942f377 Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Wed, 28 Nov 2018 16:16:10 +0800 Subject: [PATCH] feat(freertos): Add configuration to speed up task switch The global heap is 74332 bytes when connect to AP and get IP by DHCP. --- components/freertos/Kconfig | 11 ++++++++++- components/freertos/freertos/list.c | 4 ++-- components/freertos/freertos/tasks.c | 4 ++-- .../port/esp8266/include/freertos/FreeRTOSConfig.h | 6 ++++++ components/freertos/port/esp8266/os_cpu_a.S | 14 +++++++++++++- components/freertos/port/esp8266/port.c | 6 +++--- components/freertos/port/esp8266/xtensa_vectors.S | 4 ++++ 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index 114b9bcc..a247a34f 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -45,5 +45,14 @@ config FREERTOS_TIMER_STACKSIZE default 2048 help The size of the stack used by the timer in FreeRTOS. - + +config TASK_SWITCH_FASTER + bool "Task switch faster" + default y + help + Enable this option, linking task switch function and its father functions to IRAM + to speed up task switch. It is specific for faster I/O application and so on. + + But it may cost more 1KB IRAM, so user global heap may decrease 1KB. + endmenu diff --git a/components/freertos/freertos/list.c b/components/freertos/freertos/list.c index 758523a3..223daea8 100644 --- a/components/freertos/freertos/list.c +++ b/components/freertos/freertos/list.c @@ -71,7 +71,7 @@ void vListInitialiseItem( ListItem_t * const pxItem ) } /*-----------------------------------------------------------*/ -void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) +void TASK_SW_ATTR vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem ) { ListItem_t * const pxIndex = pxList->pxIndex; @@ -167,7 +167,7 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue; } /*-----------------------------------------------------------*/ -UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) +UBaseType_t TASK_SW_ATTR uxListRemove( ListItem_t * const pxItemToRemove ) { /* The list item knows which list it is in. Obtain the list from the list item. */ diff --git a/components/freertos/freertos/tasks.c b/components/freertos/freertos/tasks.c index 70e2eaa7..c86c1daa 100644 --- a/components/freertos/freertos/tasks.c +++ b/components/freertos/freertos/tasks.c @@ -2611,7 +2611,7 @@ implementations require configUSE_TICKLESS_IDLE to be set to a value other than #endif /* INCLUDE_xTaskAbortDelay */ /*----------------------------------------------------------*/ -BaseType_t xTaskIncrementTick( void ) +BaseType_t TASK_SW_ATTR xTaskIncrementTick( void ) { TCB_t * pxTCB; TickType_t xItemValue; @@ -2873,7 +2873,7 @@ BaseType_t xSwitchRequired = pdFALSE; #endif /* configUSE_APPLICATION_TASK_TAG */ /*-----------------------------------------------------------*/ -void vTaskSwitchContext( void ) +void TASK_SW_ATTR vTaskSwitchContext( void ) { if( uxSchedulerSuspended != ( UBaseType_t ) pdFALSE ) { diff --git a/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h b/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h index 5fda0652..bcc28c64 100644 --- a/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/port/esp8266/include/freertos/FreeRTOSConfig.h @@ -127,5 +127,11 @@ NVIC value of 255. */ /* add this to dump task stack information */ #define configRECORD_STACK_HIGH_ADDRESS 1 +#ifdef CONFIG_TASK_SWITCH_FASTER +#define TASK_SW_ATTR IRAM_ATTR +#else +#define TASK_SW_ATTR +#endif + #endif /* FREERTOS_CONFIG_H */ diff --git a/components/freertos/port/esp8266/os_cpu_a.S b/components/freertos/port/esp8266/os_cpu_a.S index a3e41eae..ae7c4c42 100644 --- a/components/freertos/port/esp8266/os_cpu_a.S +++ b/components/freertos/port/esp8266/os_cpu_a.S @@ -59,8 +59,12 @@ vPortYield: call0 _xt_int_enter call0 vPortEnterCritical +#ifndef CONFIG_TASK_SWITCH_FASTER movi a0, vTaskSwitchContext - callx0 a0 + callx0 a0 +#else + call0 vTaskSwitchContext +#endif call0 vPortExitCritical call0 _xt_int_exit @@ -239,8 +243,12 @@ _xt_timer_int: /* Call the uCOS-II tick handler. */ #ifdef __XTENSA_CALL0_ABI__ /* OSTimeTick() */ +#ifndef CONFIG_TASK_SWITCH_FASTER movi a0, xPortSysTickHandle callx0 a0 +#else + call0 xPortSysTickHandle +#endif #else call4 xTaskIncrementTick #endif @@ -281,8 +289,12 @@ _xt_timer_int1: #endif /* Call the uCOS-II tick handler. */ +#ifndef CONFIG_TASK_SWITCH_FASTER movi a0, vTaskSwitchContext callx0 a0 +#else + call0 vTaskSwitchContext +#endif #ifdef __XTENSA_CALL0_ABI__ /* Restore a2 and a3. */ diff --git a/components/freertos/port/esp8266/port.c b/components/freertos/port/esp8266/port.c index 70e077c4..3b7ad057 100644 --- a/components/freertos/port/esp8266/port.c +++ b/components/freertos/port/esp8266/port.c @@ -118,7 +118,7 @@ void IRAM_ATTR HDL_MAC_SIG_IN_LV1_ISR(void) extern portBASE_TYPE MacIsrSigPostDefHdl(void); -void SoftIsrHdl(void* arg) +void TASK_SW_ATTR SoftIsrHdl(void* arg) { ETS_NMI_LOCK(); @@ -137,7 +137,7 @@ void SoftIsrHdl(void* arg) ETS_NMI_UNLOCK(); } -void xPortSysTickHandle(void) +void TASK_SW_ATTR xPortSysTickHandle(void) { if (xTaskIncrementTick() != pdFALSE) { vTaskSwitchContext(); @@ -284,7 +284,7 @@ void _xt_isr_attach(uint8_t i, _xt_isr func, void* arg) isr[i].arg = arg; } -uint16_t _xt_isr_handler(uint16_t i) +uint16_t TASK_SW_ATTR _xt_isr_handler(uint16_t i) { uint8_t index; diff --git a/components/freertos/port/esp8266/xtensa_vectors.S b/components/freertos/port/esp8266/xtensa_vectors.S index 1dcc2060..046d96d9 100644 --- a/components/freertos/port/esp8266/xtensa_vectors.S +++ b/components/freertos/port/esp8266/xtensa_vectors.S @@ -927,8 +927,12 @@ _xt_user_entry1: s32i a1, a0, 0 mov a1, a0 +#ifndef CONFIG_TASK_SWITCH_FASTER movi a0, _xt_isr_handler callx0 a0 +#else + call0 _xt_isr_handler +#endif movi a0, _chip_interrupt_tmp l32i a1, a0, 0