From 8847eeec0cb7dc96ae8f86da571272b8db9a0cef Mon Sep 17 00:00:00 2001 From: Xu Xiao Date: Mon, 4 Sep 2023 14:34:54 +0800 Subject: [PATCH] feat(wifi): optimize esp32c6 iperf performance --- .../esp32c6/ld/esp32c6.rom.net80211.ld | 2 +- components/esp_system/include/esp_task.h | 1 - components/esp_wifi/Kconfig | 9 +++ components/esp_wifi/lib | 2 +- components/esp_wifi/linker.lf | 19 +++++ components/lwip/Kconfig | 25 ++++++ components/lwip/linker.lf | 78 +++++++++++++++---- components/lwip/port/include/lwipopts.h | 8 +- docs/en/api-guides/lwip.rst | 4 +- docs/en/api-guides/performance/speed.rst | 4 +- docs/zh_CN/api-guides/performance/speed.rst | 4 +- .../common_components/iperf/Kconfig.projbuild | 13 ++++ .../common_components/iperf/include/iperf.h | 4 +- examples/common_components/iperf/iperf.c | 8 +- examples/wifi/iperf/main/cmd_wifi.c | 2 + examples/wifi/iperf/sdkconfig.defaults | 7 ++ .../wifi/iperf/sdkconfig.defaults.esp32c6 | 17 ++-- 17 files changed, 171 insertions(+), 36 deletions(-) diff --git a/components/esp_rom/esp32c6/ld/esp32c6.rom.net80211.ld b/components/esp_rom/esp32c6/ld/esp32c6.rom.net80211.ld index 7ce7b8309f40..ba01cb666553 100644 --- a/components/esp_rom/esp32c6/ld/esp32c6.rom.net80211.ld +++ b/components/esp_rom/esp32c6/ld/esp32c6.rom.net80211.ld @@ -38,7 +38,7 @@ ieee80211_is_tx_allowed = 0x40000b8c; ieee80211_output_pending_eb = 0x40000b90; ieee80211_output_process = 0x40000b94; ieee80211_set_tx_desc = 0x40000b98; -sta_input = 0x40000b9c; +//sta_input = 0x40000b9c; wifi_get_macaddr = 0x40000ba0; wifi_rf_phy_disable = 0x40000ba4; wifi_rf_phy_enable = 0x40000ba8; diff --git a/components/esp_system/include/esp_task.h b/components/esp_system/include/esp_task.h index a0bf28361f82..f465c488806f 100644 --- a/components/esp_system/include/esp_task.h +++ b/components/esp_system/include/esp_task.h @@ -52,7 +52,6 @@ #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_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/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index bc42da9f2dda..5b6f9a758ae3 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -226,6 +226,15 @@ menu "Wi-Fi" When this option is disabled, more than 10Kbytes of IRAM memory will be saved but Wi-Fi throughput will be reduced. + config ESP_WIFI_EXTRA_IRAM_OPT + bool "WiFi EXTRA IRAM speed optimization" + default y if IDF_TARGET_ESP32C6 + default n + help + Select this option to place additional frequently called Wi-Fi library functions + in IRAM. When this option is disabled, more than 5Kbytes of IRAM memory will be saved + but Wi-Fi throughput will be reduced. + config ESP_WIFI_RX_IRAM_OPT bool "WiFi RX IRAM speed optimization" default n if (BT_ENABLED && SPIRAM && IDF_TARGET_ESP32) diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 470a8ed16ecb..5d67eba0abbf 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 470a8ed16ecbc56c20ec0d8d9235445b45f3d385 +Subproject commit 5d67eba0abbf6b7e8e59cf49f26c7973097914b1 diff --git a/components/esp_wifi/linker.lf b/components/esp_wifi/linker.lf index 99c7a0482ec2..f0ff4efb82e7 100644 --- a/components/esp_wifi/linker.lf +++ b/components/esp_wifi/linker.lf @@ -18,6 +18,10 @@ entries: entries: .wifislprxiram+ +[sections:wifi_extra_iram] +entries: + .wifiextrairam+ + [scheme:wifi_iram] entries: wifi_iram -> iram0_text @@ -43,6 +47,10 @@ entries: entries: wifi_slp_rx_iram -> iram0_text +[scheme:wifi_extra_iram] +entries: + wifi_extra_iram -> iram0_text + [sections:wifi_log_error] entries: .rodata_wlog_error+ @@ -70,6 +78,7 @@ entries: wifi_slp_rx_iram -> flash_text wifi_iram -> flash_text wifi_rx_iram -> flash_text + wifi_extra_iram -> flash_text if LOG_MAXIMUM_LEVEL <= 0: wifi_log_error -> rodata_noload else: @@ -117,6 +126,9 @@ entries: if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: * (extram_bss) + if ESP_WIFI_EXTRA_IRAM_OPT = y: + * (wifi_extra_iram) + [mapping:net80211] archive: libnet80211.a entries: @@ -135,9 +147,16 @@ entries: if ESP_WIFI_RX_IRAM_OPT || ESP_WIFI_SLP_IRAM_OPT: * (wifi_slp_rx_iram) + if ESP_WIFI_EXTRA_IRAM_OPT = y: + * (wifi_extra_iram) + [mapping:esp_wifi] archive: libesp_wifi.a entries: + if ESP_WIFI_IRAM_OPT = y: + esp_adapter:coex_pti_get_wrapper (noflash) + wifi_netif:wifi_sta_receive (noflash) + wifi_netif:wifi_transmit_wrap (noflash) if ESP_WIFI_SLP_IRAM_OPT =y: esp_adapter:wifi_clock_enable_wrapper (noflash) esp_adapter:wifi_clock_disable_wrapper (noflash) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 0f3a534a4437..f455c28fb7be 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 @@ -70,6 +87,14 @@ menu "LWIP" If this feature is disabled, all lwip functions will be put into FLASH. + config LWIP_EXTRA_IRAM_OPTIMIZATION + bool "Enable LWIP IRAM optimization for TCP part" + default n + help + If this feature is enabled, some tcp part functions relating to RX/TX in LWIP will be + put into IRAM, it can improve TCP throughput. On the other hand, it needs about 17KB + IRAM for these optimizations. + config LWIP_TIMERS_ONDEMAND bool "Enable LWIP Timers on demand" default y diff --git a/components/lwip/linker.lf b/components/lwip/linker.lf index 2341386b466b..055b2fc55be5 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,71 @@ 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 LWIP_EXTRA_IRAM_OPTIMIZATION = y: + api_msg:recv_udp (noflash_text) + inet_chksum:inet_chksum_pbuf (noflash_text) + inet_chksum:ip_chksum_pseudo (noflash_text) + inet_chksum:inet_chksum (noflash_text) + inet_chksum:lwip_standard_chksum (noflash_text) + pbuf:pbuf_copy (noflash_text) + pbuf:pbuf_copy_partial_pbuf (noflash_text) + pbuf:pbuf_clone (noflash_text) + tcp:tcp_fasttmr (noflash_text) + tcp:tcp_tmr (noflash_text) + tcp:tcp_update_rcv_ann_wnd (noflash_text) + tcp:tcp_recved (noflash_text) + tcp:tcp_slowtmr (noflash_text) + tcp:tcp_process_refused_data (noflash_text) + tcp:tcp_segs_free (noflash_text) + tcp:tcp_seg_free (noflash_text) + tcp:tcp_seg_copy (noflash_text) + tcp:tcp_recv_null (noflash_text) + tcp_in:tcp_input (noflash_text) + tcp_in:tcp_input_delayed_close (noflash_text) + tcp_in:tcp_oos_insert_segment (noflash_text) + tcp_in:tcp_receive (noflash_text) + tcp_in:tcp_parseopt (noflash_text) + tcp_out:tcp_route (noflash_text) + tcp_out:tcp_create_segment (noflash_text) + tcp_out:tcp_write (noflash_text) + tcp_out:tcp_split_unsent_seg (noflash_text) + tcp_out:tcp_rexmit_rto_prepare (noflash_text) + tcp_out:tcp_rexmit (noflash_text) + tcp_out:tcp_rexmit_fast (noflash_text) + tcp_out:tcp_output_control_segment (noflash_text) + tcp_out:tcp_rst (noflash_text) + tcp_out:tcp_send_empty_ack (noflash_text) + sys_arch:sys_arch_protect (noflash_text) + sys_arch:sys_arch_unprotect (noflash_text) + sys_arch:sys_thread_tcpip (noflash_text) + memp:memp_malloc (noflash_text) + mem:mem_malloc (noflash_text) + raw:raw_input (noflash_text) + if COMPILER_OPTIMIZATION_DEBUG = y: + tcp_in:tcp_free_acked_segments (noflash_text) + tcp_in:tcp_process (noflash_text) + tcp_out:tcp_output_segment (noflash_text) + tcp_out:tcp_output_fill_options (noflash_text) + tcp_out:tcp_output_alloc_header (noflash_text) + tcp_out:tcp_pbuf_prealloc (noflash_text) + tcp_out:tcp_write_checks (noflash_text) + raw:raw_input_local_match (noflash_text) + tcp_out:tcp_output_alloc_header_common (noflash_text) + memp:do_memp_malloc_pool (noflash_text) if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: * (extram_bss) diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index 283cd3fae54a..7dca4af288c2 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -43,6 +43,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 @@ -51,6 +56,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 */ @@ -787,7 +793,7 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) * The priority value itself is platform-dependent, but is passed to * sys_thread_new() when the thread is created. */ -#define TCPIP_THREAD_PRIO ESP_TASK_TCPIP_PRIO +#define TCPIP_THREAD_PRIO CONFIG_LWIP_TCPIP_TASK_PRIO /** * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages diff --git a/docs/en/api-guides/lwip.rst b/docs/en/api-guides/lwip.rst index 5720d7ea4620..c17e59d86289 100644 --- a/docs/en/api-guides/lwip.rst +++ b/docs/en/api-guides/lwip.rst @@ -428,11 +428,11 @@ The :example_file:`wifi/iperf/sdkconfig.defaults` file for the iperf example con .. important:: Suggest applying changes a few at a time and checking the performance each time with a particular application workload. -- If a lot of tasks are competing for CPU time on the system, consider that the lwIP task has configurable CPU affinity (:ref:`CONFIG_LWIP_TCPIP_TASK_AFFINITY`) and runs at fixed priority ``ESP_TASK_TCPIP_PRIO`` (18). Configure competing tasks to be pinned to a different core, or to run at a lower priority. See also :ref:`built-in-task-priorities`. +- If a lot of tasks are competing for CPU time on the system, consider that the lwIP task has configurable CPU affinity (:ref:`CONFIG_LWIP_TCPIP_TASK_AFFINITY`) and runs at fixed priority (18). Configure competing tasks to be pinned to a different core, or to run at a lower priority. See also :ref:`built-in-task-priorities`. - If using ``select()`` function with socket arguments only, disabling :ref:`CONFIG_VFS_SUPPORT_SELECT` will make ``select()`` calls faster. -- If there is enough free IRAM, select :ref:`CONFIG_LWIP_IRAM_OPTIMIZATION` to improve TX/RX throughput +- If there is enough free IRAM, select :ref:`CONFIG_LWIP_IRAM_OPTIMIZATION` and :ref:`CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION` to improve TX/RX throughput .. only:: SOC_WIFI_SUPPORTED diff --git a/docs/en/api-guides/performance/speed.rst b/docs/en/api-guides/performance/speed.rst index 76fb398cd2cd..24bac12cf7f1 100644 --- a/docs/en/api-guides/performance/speed.rst +++ b/docs/en/api-guides/performance/speed.rst @@ -166,7 +166,7 @@ Common priorities are: - :doc:`/api-reference/system/esp_timer` system task to manage timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``) - FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable `). - :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``). This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`. It is possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead. - - :doc:`/api-guides/lwip` TCP/IP task has high priority (18, ``ESP_TASK_TCPIP_PRIO``). + - :doc:`/api-guides/lwip` TCP/IP task has high priority (18). :SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` task has high priority (23). :SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2). :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` task has high priority (23, ``ESP_TASK_BT_CONTROLLER_PRIO``). The Bluetooth Controller needs to respond to requests with low latency, so it should always be among the highest priority task in the system. @@ -183,7 +183,7 @@ Common priorities are: - :doc:`/api-reference/system/esp_timer` system task to manage high precision timer events and execute callbacks has high priority (22, ``ESP_TASK_TIMER_PRIO``). This task is pinned to Core 0. - FreeRTOS Timer Task to handle FreeRTOS timer callbacks is created when the scheduler initializes and has minimum task priority (1, :ref:`configurable `). This task is pinned to Core 0. - :doc:`/api-reference/system/esp_event` system task to manage the default system event loop and execute callbacks has high priority (20, ``ESP_TASK_EVENT_PRIO``) and it is pinned to Core 0. This configuration is only used if the application calls :cpp:func:`esp_event_loop_create_default`, it is possible to call :cpp:func:`esp_event_loop_create` with a custom task configuration instead. - - :doc:`/api-guides/lwip` TCP/IP task has high priority (18, ``ESP_TASK_TCPIP_PRIO``) and is not pinned to any core (:ref:`configurable`). + - :doc:`/api-guides/lwip` TCP/IP task has high priority (18) and is not pinned to any core (:ref:`configurable`). :SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` task has high priority (23) and is pinned to Core 0 by default (:ref:`configurable`). :SOC_WIFI_SUPPORTED: - Wi-Fi wpa_supplicant component may create dedicated tasks while the Wi-Fi Protected Setup (WPS), WPA2 EAP-TLS, Device Provisioning Protocol (DPP) or BSS Transition Management (BTM) features are in use. These tasks all have low priority (2) and are not pinned to any core. :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` task has high priority (23, ``ESP_TASK_BT_CONTROLLER_PRIO``) and is pinned to Core 0 by default (:ref:`configurable <{IDF_TARGET_CONTROLLER_CORE_CONFIG}>`). The Bluetooth Controller needs to respond to requests with low latency, so it should always be among the highest priority task assigned to a single CPU. diff --git a/docs/zh_CN/api-guides/performance/speed.rst b/docs/zh_CN/api-guides/performance/speed.rst index 5d4e71b37699..f03b9daece20 100644 --- a/docs/zh_CN/api-guides/performance/speed.rst +++ b/docs/zh_CN/api-guides/performance/speed.rst @@ -165,7 +165,7 @@ ESP-IDF 启动的系统任务预设了固定优先级。启动时,一些任务 - 系统任务 :doc:`/api-reference/system/esp_timer` 用于管理定时器事件并执行回调函数,优先级较高 (22, ``ESP_TASK_TIMER_PRIO``)。 - FreeRTOS 初始化调度器时会创建定时器任务,用于处理 FreeRTOS 定时器的回调函数,优先级最低(1, :ref:`可配置 ` )。 - 系统任务 :doc:`/api-reference/system/esp_event` 用于管理默认的系统事件循环并执行回调函数,优先级较高 (20, ``ESP_TASK_EVENT_PRIO``)。仅在应用程序调用 :cpp:func:`esp_event_loop_create_default` 时使用此配置。可以调用 :cpp:func:`esp_event_loop_create` 添加自定义任务配置。 - - :doc:`/api-guides/lwip` TCP/IP 任务优先级较高 (18, ``ESP_TASK_TCPIP_PRIO``)。 + - :doc:`/api-guides/lwip` TCP/IP 任务优先级较高 (18)。 :SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` 任务优先级较高 (23). :SOC_WIFI_SUPPORTED: - 使用 Wi-Fi Protected Setup (WPS)、WPA2 EAP-TLS、Device Provisioning Protocol (DPP) 或 BSS Transition Management (BTM) 等功能时,Wi-Fi wpa_supplicant 组件可能会创建优先级较低的专用任务 (2)。 :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` 任务优先级较高 (23, ``ESP_TASK_BT_CONTROLLER_PRIO``)。蓝牙控制器需要以低延迟响应请求,因此其任务应始终为系统最高优先级的任务之一。 @@ -182,7 +182,7 @@ ESP-IDF 启动的系统任务预设了固定优先级。启动时,一些任务 - 系统任务 :doc:`/api-reference/system/esp_timer` 用于管理定时器事件并执行回调函数,优先级较高 (22, ``ESP_TASK_TIMER_PRIO``) 且固定在核心 0 上执行。 - FreeRTOS 初始化调度器时会创建定时器任务,用于处理 FreeRTOS 定时器的回调函数,优先级最低(1, :ref:`可配置 ` )且固定在核心 0 上执行。 - 系统任务 :doc:`/api-reference/system/esp_event` 用于管理默认的系统事件循环并执行回调函数,优先级较高 (20, ``ESP_TASK_EVENT_PRIO``) 且固定在核心 0 上执行。此配置仅在应用程序调用 :cpp:func:`esp_event_loop_create_default` 时使用。可以调用 :cpp:func:`esp_event_loop_create` 添加自定义任务配置。 - - :doc:`/api-guides/lwip` TCP/IP 任务优先级较高 (18, ``ESP_TASK_TCPIP_PRIO``) 且并未固定在特定核心上执行( :ref:`可配置 ` )。 + - :doc:`/api-guides/lwip` TCP/IP 任务优先级较高 (18) 且并未固定在特定核心上执行( :ref:`可配置 ` )。 :SOC_WIFI_SUPPORTED: - :doc:`/api-guides/wifi` 任务优先级较高 (23) 且默认固定在核心 0 上执行( :ref:`可配置 ` )。 :SOC_WIFI_SUPPORTED: - 使用 Wi-Fi Protected Setup (WPS)、WPA2 EAP-TLS、Device Provisioning Protocol (DPP) 或 BSS Transition Management (BTM) 等功能时,Wi-Fi wpa_supplicant 组件可能会创建优先级较低的专用任务 (2),这些任务并未固定在特定核心上执行。 :SOC_BT_SUPPORTED: - :doc:`/api-reference/bluetooth/controller_vhci` 任务优先级较高 (23, ``ESP_TASK_BT_CONTROLLER_PRIO``) 且默认固定在核心 0 上执行( :ref:`可配置 <{IDF_TARGET_CONTROLLER_CORE_CONFIG}>` )。蓝牙控制器需要以低延迟响应请求,因此其任务应始终为最高优先级的任务之一并分配给单个 CPU 执行。 diff --git a/examples/common_components/iperf/Kconfig.projbuild b/examples/common_components/iperf/Kconfig.projbuild index ab56acc76e6b..0a1fb3d45851 100644 --- a/examples/common_components/iperf/Kconfig.projbuild +++ b/examples/common_components/iperf/Kconfig.projbuild @@ -14,5 +14,18 @@ menu "Iperf Configuration" The value is used for iperf socket TCP tx timeout, iperf will be aborted and socket will be closed and shutdown. + config IPERF_TRAFFIC_TASK_PRIORITY + int "iperf traffic task priority" + default 4 + range 1 24 + help + The value is used for iperf traffic task priority. + + config IPERF_REPORT_TASK_PRIORITY + int "iperf result report task priority" + default 6 + range 1 24 + help + The value is used for iperf result report task priority. endmenu diff --git a/examples/common_components/iperf/include/iperf.h b/examples/common_components/iperf/include/iperf.h index 53aeca443f08..e856eefdedc1 100644 --- a/examples/common_components/iperf/include/iperf.h +++ b/examples/common_components/iperf/include/iperf.h @@ -36,10 +36,10 @@ extern "C" { #define IPERF_DEFAULT_NO_BW_LIMIT -1 #define IPERF_TRAFFIC_TASK_NAME "iperf_traffic" -#define IPERF_TRAFFIC_TASK_PRIORITY 4 +#define IPERF_TRAFFIC_TASK_PRIORITY CONFIG_IPERF_TRAFFIC_TASK_PRIORITY #define IPERF_TRAFFIC_TASK_STACK 4096 #define IPERF_REPORT_TASK_NAME "iperf_report" -#define IPERF_REPORT_TASK_PRIORITY 6 +#define IPERF_REPORT_TASK_PRIORITY CONFIG_IPERF_REPORT_TASK_PRIORITY #define IPERF_REPORT_TASK_STACK 4096 #define IPERF_UDP_TX_LEN (1470) diff --git a/examples/common_components/iperf/iperf.c b/examples/common_components/iperf/iperf.c index a798f98d5d5c..0f022dab29f3 100644 --- a/examples/common_components/iperf/iperf.c +++ b/examples/common_components/iperf/iperf.c @@ -118,7 +118,7 @@ static esp_err_t iperf_start_report(void) return ESP_OK; } -static void socket_recv(int recv_socket, struct sockaddr_storage listen_addr, uint8_t type) +static void IRAM_ATTR socket_recv(int recv_socket, struct sockaddr_storage listen_addr, uint8_t type) { bool iperf_recv_start = true; uint8_t *buffer; @@ -149,7 +149,7 @@ static void socket_recv(int recv_socket, struct sockaddr_storage listen_addr, ui } } -static void socket_send(int send_socket, struct sockaddr_storage dest_addr, uint8_t type, int bw_lim) +static void IRAM_ATTR socket_send(int send_socket, struct sockaddr_storage dest_addr, uint8_t type, int bw_lim) { uint8_t *buffer; int32_t *pkt_id_p; @@ -222,7 +222,7 @@ static void socket_send(int send_socket, struct sockaddr_storage dest_addr, uint } } -static esp_err_t IRAM_ATTR iperf_run_tcp_server(void) +static esp_err_t iperf_run_tcp_server(void) { int listen_socket = -1; int client_socket = -1; @@ -389,7 +389,7 @@ static esp_err_t iperf_run_tcp_client(void) return ret; } -static esp_err_t IRAM_ATTR iperf_run_udp_server(void) +static esp_err_t iperf_run_udp_server(void) { int listen_socket = -1; int opt = 1; diff --git a/examples/wifi/iperf/main/cmd_wifi.c b/examples/wifi/iperf/main/cmd_wifi.c index b85010b33779..c5c110b67779 100644 --- a/examples/wifi/iperf/main/cmd_wifi.c +++ b/examples/wifi/iperf/main/cmd_wifi.c @@ -243,6 +243,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], false); return 0; } @@ -276,6 +277,7 @@ static int wifi_cmd_sta_mcs89(int argc, char **argv) ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_protocol(0, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX)); ESP_ERROR_CHECK(esp_wifi_set_bandwidth(0, WIFI_BW_HT20)); + ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); ESP_LOGI(TAG, "sta connecting to '%s'", sta_args.ssid->sval[0]); wifi_cmd_sta_join(sta_args.ssid->sval[0], sta_args.password->sval[0], true); diff --git a/examples/wifi/iperf/sdkconfig.defaults b/examples/wifi/iperf/sdkconfig.defaults index fe213834c694..c6ce4ce0b5df 100644 --- a/examples/wifi/iperf/sdkconfig.defaults +++ b/examples/wifi/iperf/sdkconfig.defaults @@ -8,3 +8,10 @@ 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_IPERF_TRAFFIC_TASK_PRIORITY=23 +CONFIG_IPERF_REPORT_TASK_PRIORITY=24 +CONFIG_LWIP_TCPIP_CORE_LOCKING=y +CONFIG_LWIP_TCPIP_CORE_LOCKING_INPUT=y +CONFIG_COMPILER_OPTIMIZATION_PERF=y diff --git a/examples/wifi/iperf/sdkconfig.defaults.esp32c6 b/examples/wifi/iperf/sdkconfig.defaults.esp32c6 index 1b59d099198e..3690bcd7fc0b 100644 --- a/examples/wifi/iperf/sdkconfig.defaults.esp32c6 +++ b/examples/wifi/iperf/sdkconfig.defaults.esp32c6 @@ -1,17 +1,17 @@ # # ESP32C6-Specific # -CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=20 -CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=38 -CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=35 +CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=40 +CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=60 +CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=40 CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y -CONFIG_ESP_WIFI_TX_BA_WIN=20 +CONFIG_ESP_WIFI_TX_BA_WIN=32 CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y -CONFIG_ESP_WIFI_RX_BA_WIN=20 +CONFIG_ESP_WIFI_RX_BA_WIN=32 CONFIG_ESP_WIFI_NVS_ENABLED=n -CONFIG_LWIP_TCP_SND_BUF_DEFAULT=30000 -CONFIG_LWIP_TCP_WND_DEFAULT=34000 +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=51200 +CONFIG_LWIP_TCP_WND_DEFAULT=65535 CONFIG_LWIP_TCP_RECVMBOX_SIZE=64 CONFIG_LWIP_UDP_RECVMBOX_SIZE=64 CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64 @@ -20,3 +20,6 @@ CONFIG_LWIP_IP_REASS_MAX_PBUFS=15 CONFIG_ESP_WIFI_ENABLE_WIFI_RX_STATS=n CONFIG_ESP_WIFI_ENABLE_WIFI_TX_STATS=n +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION=y