From d2b82b47c77ffbabcaa6f2661b1f0d5d66b859d1 Mon Sep 17 00:00:00 2001 From: xuxiao Date: Wed, 11 Oct 2023 11:59:04 +0800 Subject: [PATCH] feat(wifi): optimize iperf performance (Backport V5.0) --- components/esp_system/include/esp_task.h | 2 +- components/lwip/Kconfig | 17 ++++++++++++ components/lwip/linker.lf | 27 ++++++++++--------- components/lwip/port/esp32/include/lwipopts.h | 6 +++++ examples/wifi/iperf/main/cmd_wifi.c | 1 + examples/wifi/iperf/sdkconfig.defaults | 6 +++++ 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/components/esp_system/include/esp_task.h b/components/esp_system/include/esp_task.h index a0bf28361f..b8e8604ffe 100644 --- a/components/esp_system/include/esp_task.h +++ b/components/esp_system/include/esp_task.h @@ -52,7 +52,7 @@ #else #define ESP_TASKD_EVENT_STACK (CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #endif /* CONFIG_LWIP_TCPIP_CORE_LOCKING */ -#define ESP_TASK_TCPIP_PRIO (ESP_TASK_PRIO_MAX - 7) +#define ESP_TASK_TCPIP_PRIO (CONFIG_LWIP_TCPIP_TASK_PRIO) #define ESP_TASK_TCPIP_STACK (CONFIG_LWIP_TCPIP_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) #define ESP_TASK_MAIN_PRIO (ESP_TASK_PRIO_MIN + 1) #define ESP_TASK_MAIN_STACK (CONFIG_ESP_MAIN_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index f6a6487d6e..3fa5456060 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -15,6 +15,14 @@ menu "LWIP" could be used to convert network interface index to name instead of IDF specific esp-netif APIs (such as esp_netif_get_netif_impl_name()) + config LWIP_TCPIP_TASK_PRIO + int "LWIP TCP/IP Task Priority" + default 18 + range 1 24 + help + LWIP tcpip task priority. In case of high throughput, this parameter + could be changed up to (configMAX_PRIORITIES-1). + config LWIP_TCPIP_CORE_LOCKING bool "Enable tcpip core locking" default n @@ -26,6 +34,15 @@ menu "LWIP" If disable tcpip core locking,TCP IP will perform tasks through context switching + config LWIP_TCPIP_CORE_LOCKING_INPUT + bool "Enable tcpip core locking input" + depends on LWIP_TCPIP_CORE_LOCKING + default n + help + when LWIP_TCPIP_CORE_LOCKING is enabled, this lets tcpip_input() grab the + mutex for input packets as well, instead of allocating a message and passing + it to tcpip_thread. + config LWIP_CHECK_THREAD_SAFETY bool "Checks that lwip API runs in expected context" default n diff --git a/components/lwip/linker.lf b/components/lwip/linker.lf index 2341386b46..a3bb80e53b 100644 --- a/components/lwip/linker.lf +++ b/components/lwip/linker.lf @@ -3,24 +3,15 @@ archive: liblwip.a entries: if LWIP_IRAM_OPTIMIZATION = y: sockets:get_socket (noflash_text) - sockets:tryget_socket (noflash_text) - sockets:tryget_socket_unconn (noflash_text) - sockets:sock_inc_used (noflash_text) - sockets:tryget_socket_unconn_nouse (noflash_text) sockets:tryget_socket_unconn_locked (noflash_text) sockets:done_socket (noflash_text) sockets:lwip_recvfrom (noflash_text) sockets:lwip_recv_tcp (noflash_text) - sockets:lwip_recv_tcp_from (noflash_text) - sockets:lwip_recvfrom_udp_raw (noflash_text) sockets:lwip_send (noflash_text) sockets:lwip_sendto (noflash_text) sockets:event_callback (noflash_text) sockets:lwip_select (noflash_text) - sockets:select_check_waiters (noflash_text) - api_lib:netconn_apimsg (noflash_text) api_lib:netconn_recv_data (noflash_text) - api_lib:netconn_tcp_recvd_msg (noflash_text) api_lib:netconn_tcp_recvd (noflash_text) api_lib:netconn_recv_data_tcp (noflash_text) api_lib:netconn_recv_tcp_pbuf_flags (noflash_text) @@ -35,7 +26,6 @@ entries: netbuf:netbuf_alloc (noflash_text) netbuf:netbuf_free (noflash_text) tcpip:tcpip_thread (noflash_text) - tcpip:tcpip_thread_handle_msg (noflash_text) tcpip:tcpip_inpkt (noflash_text) tcpip:tcpip_input (noflash_text) tcpip:tcpip_callback (noflash_text) @@ -55,14 +45,11 @@ entries: ip4:ip4_output_if_opt_src (noflash_text) ip4:ip4_output (noflash_text) pbuf:pbuf_alloc (noflash_text) - pbuf:pbuf_add_header_impl (noflash_text) pbuf:pbuf_add_header (noflash_text) pbuf:pbuf_remove_header (noflash_text) - pbuf:pbuf_header_impl (noflash_text) pbuf:pbuf_header (noflash_text) pbuf:pbuf_free (noflash_text) pbuf:pbuf_alloced_custom (noflash_text) - pbuf:pbuf_init_alloced_pbuf (noflash_text) udp:udp_input_local_match (noflash_text) udp:udp_input (noflash_text) udp:udp_send (noflash_text) @@ -79,6 +66,20 @@ entries: sys_arch:sys_mbox_trypost (noflash_text) sys_arch:sys_arch_mbox_fetch (noflash_text) lwip_default_hooks:ip4_route_src_hook (noflash_text) + if COMPILER_OPTIMIZATION_DEBUG = y: + sockets:tryget_socket_unconn (noflash_text) + sockets:tryget_socket (noflash_text) + sockets:lwip_recvfrom_udp_raw (noflash_text) + sockets:tryget_socket_unconn_nouse (noflash_text) + sockets:sock_inc_used (noflash_text) + tcpip:tcpip_thread_handle_msg (noflash_text) + api_lib:netconn_apimsg (noflash_text) + sockets:lwip_recv_tcp_from (noflash_text) + sockets:select_check_waiters (noflash_text) + api_lib:netconn_tcp_recvd_msg (noflash_text) + pbuf:pbuf_header_impl (noflash_text) + pbuf:pbuf_add_header_impl (noflash_text) + pbuf:pbuf_init_alloced_pbuf (noflash_text) if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: * (extram_bss) diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index 14b82c5aff..e588949166 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -47,6 +47,11 @@ extern "C" { */ #ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING #define LWIP_TCPIP_CORE_LOCKING 1 +#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING_INPUT +#define LWIP_TCPIP_CORE_LOCKING_INPUT 1 +#else +#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 +#endif #define LOCK_TCPIP_CORE() do { sys_mutex_lock(&lock_tcpip_core); sys_thread_tcpip(LWIP_CORE_LOCK_MARK_HOLDER); } while(0) #define UNLOCK_TCPIP_CORE() do { sys_thread_tcpip(LWIP_CORE_LOCK_UNMARK_HOLDER); sys_mutex_unlock(&lock_tcpip_core); } while(0) #ifdef CONFIG_LWIP_CHECK_THREAD_SAFETY @@ -55,6 +60,7 @@ extern "C" { #else #define LWIP_TCPIP_CORE_LOCKING 0 +#define LWIP_TCPIP_CORE_LOCKING_INPUT 0 #ifdef CONFIG_LWIP_CHECK_THREAD_SAFETY #define LWIP_ASSERT_CORE_LOCKED() do { LWIP_ASSERT("Required to run in TCPIP context!", sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)); } while(0) #endif /* CONFIG_LWIP_CHECK_THREAD_SAFETY */ diff --git a/examples/wifi/iperf/main/cmd_wifi.c b/examples/wifi/iperf/main/cmd_wifi.c index 69593faa6f..745158cb3b 100644 --- a/examples/wifi/iperf/main/cmd_wifi.c +++ b/examples/wifi/iperf/main/cmd_wifi.c @@ -202,6 +202,7 @@ static int wifi_cmd_sta(int argc, char **argv) } ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]); + ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0]); return 0; } diff --git a/examples/wifi/iperf/sdkconfig.defaults b/examples/wifi/iperf/sdkconfig.defaults index e7f0fde749..ddf0e6be20 100644 --- a/examples/wifi/iperf/sdkconfig.defaults +++ b/examples/wifi/iperf/sdkconfig.defaults @@ -10,3 +10,9 @@ CONFIG_ESP_TASK_WDT_EN=n CONFIG_LWIP_ETHARP_TRUST_IP_MAC=n CONFIG_LWIP_IRAM_OPTIMIZATION=y + +CONFIG_LWIP_TCPIP_TASK_PRIO=23 + +CONFIG_LWIP_TCPIP_CORE_LOCKING=y +CONFIG_LWIP_TCPIP_CORE_LOCKING_INPUT=y +CONFIG_COMPILER_OPTIMIZATION_PERF=y