From 8d18a9c614934c7de01f710960c71b46c41b80ee Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Wed, 14 Jul 2021 20:03:54 +0800 Subject: [PATCH 1/2] emac: optimise iperf performane --- components/esp_eth/include/esp_eth_mac.h | 2 +- components/esp_eth/src/esp_eth_mac_esp.c | 2 +- components/hal/emac_hal.c | 8 ++++---- components/hal/esp32/include/hal/emac_ll.h | 4 ++-- examples/ethernet/iperf/sdkconfig.defaults | 2 ++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/components/esp_eth/include/esp_eth_mac.h b/components/esp_eth/include/esp_eth_mac.h index f1e790c756..db462728a1 100644 --- a/components/esp_eth/include/esp_eth_mac.h +++ b/components/esp_eth/include/esp_eth_mac.h @@ -391,7 +391,7 @@ typedef struct { #define ETH_MAC_DEFAULT_CONFIG() \ { \ .sw_reset_timeout_ms = 100, \ - .rx_task_stack_size = 4096, \ + .rx_task_stack_size = 2048, \ .rx_task_prio = 15, \ .smi_mdc_gpio_num = 23, \ .smi_mdio_gpio_num = 18, \ diff --git a/components/esp_eth/src/esp_eth_mac_esp.c b/components/esp_eth/src/esp_eth_mac_esp.c index 1de969d7a6..bc4e414c6b 100644 --- a/components/esp_eth/src/esp_eth_mac_esp.c +++ b/components/esp_eth/src/esp_eth_mac_esp.c @@ -353,7 +353,7 @@ static esp_err_t emac_esp32_init(esp_eth_mac_t *mac) } ESP_GOTO_ON_FALSE(to < emac->sw_reset_timeout_ms / 10, ESP_ERR_TIMEOUT, err, TAG, "reset timeout"); /* set smi clock */ - emac_hal_set_csr_clock_range(&emac->hal, esp_clk_apb_freq()); + emac_hal_set_csr_clock_range(&emac->hal, esp_clk_apb_freq() / 1e6); /* reset descriptor chain */ emac_hal_reset_desc_chain(&emac->hal); /* init mac registers by default */ diff --git a/components/hal/emac_hal.c b/components/hal/emac_hal.c index bd202edb34..652e83e753 100644 --- a/components/hal/emac_hal.c +++ b/components/hal/emac_hal.c @@ -141,7 +141,7 @@ void emac_hal_init(emac_hal_context_t *hal, void *descriptors, void emac_hal_set_csr_clock_range(emac_hal_context_t *hal, int freq) { - /* Tell MAC system clock Frequency, which will determine the frequency range of MDC(1MHz~2.5MHz) */ + /* Tell MAC system clock Frequency in MHz, which will determine the frequency range of MDC(1MHz~2.5MHz) */ if (freq >= 20 && freq < 35) { emac_ll_set_csr_clock_division(hal->mac_regs, 2); // CSR clock/16 } else if (freq >= 35 && freq < 60) { @@ -150,7 +150,7 @@ void emac_hal_set_csr_clock_range(emac_hal_context_t *hal, int freq) emac_ll_set_csr_clock_division(hal->mac_regs, 0); // CSR clock/42 } else if (freq >= 100 && freq < 150) { emac_ll_set_csr_clock_division(hal->mac_regs, 1); // CSR clock/62 - } else if (freq > 150 && freq < 250) { + } else if (freq >= 150 && freq < 250) { emac_ll_set_csr_clock_division(hal->mac_regs, 4); // CSR clock/102 } else { emac_ll_set_csr_clock_division(hal->mac_regs, 5); // CSR clock/124 @@ -281,8 +281,8 @@ void emac_hal_init_dma_default(emac_hal_context_t *hal) emac_ll_recv_store_forward_enable(hal->dma_regs, true); /* Enable Flushing of Received Frames because of the unavailability of receive descriptors or buffers */ emac_ll_flush_recv_frame_enable(hal->dma_regs, true); - /* Enable Transmit Store Forward */ - emac_ll_trans_store_forward_enable(hal->dma_regs, true); + /* Disable Transmit Store Forward */ + emac_ll_trans_store_forward_enable(hal->dma_regs, false); /* Flush Transmit FIFO */ emac_ll_flush_trans_fifo_enable(hal->dma_regs, true); /* Transmit Threshold Control */ diff --git a/components/hal/esp32/include/hal/emac_ll.h b/components/hal/esp32/include/hal/emac_ll.h index dff803b5a9..625687b6a0 100644 --- a/components/hal/esp32/include/hal/emac_ll.h +++ b/components/hal/esp32/include/hal/emac_ll.h @@ -137,7 +137,7 @@ extern "C" { #define EMAC_LL_INTR_OVERFLOW_ENABLE 0x00000010U #define EMAC_LL_INTR_UNDERFLOW_ENABLE 0x00000020U #define EMAC_LL_INTR_RECEIVE_ENABLE 0x00000040U -#define EMAC_LL_INTR_REVEIVE_BUFF_UNAVAILABLE_ENABLE 0x00000080U +#define EMAC_LL_INTR_RECEIVE_BUFF_UNAVAILABLE_ENABLE 0x00000080U #define EMAC_LL_INTR_RECEIVE_STOP_ENABLE 0x00000100U #define EMAC_LL_INTR_RECEIVE_TIMEOUT_ENABLE 0x00000200U #define EMAC_LL_INTR_TRANSMIT_FIRST_BYTE_ENABLE 0x00000400U @@ -406,7 +406,7 @@ static inline void emac_ll_flush_recv_frame_enable(emac_dma_dev_t *dma_regs, boo static inline void emac_ll_trans_store_forward_enable(emac_dma_dev_t *dma_regs, bool enable) { - dma_regs->dmaoperation_mode.tx_str_fwd = !enable; + dma_regs->dmaoperation_mode.tx_str_fwd = enable; } static inline void emac_ll_flush_trans_fifo_enable(emac_dma_dev_t *dma_regs, bool enable) diff --git a/examples/ethernet/iperf/sdkconfig.defaults b/examples/ethernet/iperf/sdkconfig.defaults index 9ef48f281a..d478e33a60 100644 --- a/examples/ethernet/iperf/sdkconfig.defaults +++ b/examples/ethernet/iperf/sdkconfig.defaults @@ -12,4 +12,6 @@ CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESP_TASK_WDT=n + CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n From 04970fe4873ac94ce5c12954be3c03ad29bf4ba1 Mon Sep 17 00:00:00 2001 From: laokaiyao Date: Wed, 25 Aug 2021 13:31:34 +0800 Subject: [PATCH 2/2] iperfUtility: add udp rx bandwidth scan --- .gitlab/ci/target-test.yml | 2 +- components/esp_eth/src/esp_eth_mac_esp.c | 2 +- components/hal/emac_hal.c | 10 +++--- examples/ethernet/iperf/sdkconfig.defaults | 5 +++ .../idf_iperf_test_util/IperfUtility.py | 33 +++++++++++-------- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 8b4ecfaba9..8138264e11 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -129,7 +129,7 @@ example_test_002: - ESP32 - Example_ShieldBox_Basic -example_test_enternet: +example_test_ethernet: extends: .example_test_esp32_template tags: - ESP32 diff --git a/components/esp_eth/src/esp_eth_mac_esp.c b/components/esp_eth/src/esp_eth_mac_esp.c index bc4e414c6b..1de969d7a6 100644 --- a/components/esp_eth/src/esp_eth_mac_esp.c +++ b/components/esp_eth/src/esp_eth_mac_esp.c @@ -353,7 +353,7 @@ static esp_err_t emac_esp32_init(esp_eth_mac_t *mac) } ESP_GOTO_ON_FALSE(to < emac->sw_reset_timeout_ms / 10, ESP_ERR_TIMEOUT, err, TAG, "reset timeout"); /* set smi clock */ - emac_hal_set_csr_clock_range(&emac->hal, esp_clk_apb_freq() / 1e6); + emac_hal_set_csr_clock_range(&emac->hal, esp_clk_apb_freq()); /* reset descriptor chain */ emac_hal_reset_desc_chain(&emac->hal); /* init mac registers by default */ diff --git a/components/hal/emac_hal.c b/components/hal/emac_hal.c index 652e83e753..ef6318ff7e 100644 --- a/components/hal/emac_hal.c +++ b/components/hal/emac_hal.c @@ -142,15 +142,15 @@ void emac_hal_init(emac_hal_context_t *hal, void *descriptors, void emac_hal_set_csr_clock_range(emac_hal_context_t *hal, int freq) { /* Tell MAC system clock Frequency in MHz, which will determine the frequency range of MDC(1MHz~2.5MHz) */ - if (freq >= 20 && freq < 35) { + if (freq >= 20000000 && freq < 35000000) { emac_ll_set_csr_clock_division(hal->mac_regs, 2); // CSR clock/16 - } else if (freq >= 35 && freq < 60) { + } else if (freq >= 35000000 && freq < 60000000) { emac_ll_set_csr_clock_division(hal->mac_regs, 3); // CSR clock/26 - } else if (freq >= 60 && freq < 100) { + } else if (freq >= 60000000 && freq < 100000000) { emac_ll_set_csr_clock_division(hal->mac_regs, 0); // CSR clock/42 - } else if (freq >= 100 && freq < 150) { + } else if (freq >= 100000000 && freq < 150000000) { emac_ll_set_csr_clock_division(hal->mac_regs, 1); // CSR clock/62 - } else if (freq >= 150 && freq < 250) { + } else if (freq >= 150000000 && freq < 250000000) { emac_ll_set_csr_clock_division(hal->mac_regs, 4); // CSR clock/102 } else { emac_ll_set_csr_clock_division(hal->mac_regs, 5); // CSR clock/124 diff --git a/examples/ethernet/iperf/sdkconfig.defaults b/examples/ethernet/iperf/sdkconfig.defaults index d478e33a60..3b0e1692f9 100644 --- a/examples/ethernet/iperf/sdkconfig.defaults +++ b/examples/ethernet/iperf/sdkconfig.defaults @@ -10,8 +10,13 @@ CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv" CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y +# Run FreeRTOS only on the first core +CONFIG_FREERTOS_UNICORE=y + CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# Disable watch dog +CONFIG_ESP_INT_WDT=n CONFIG_ESP_TASK_WDT=n CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n diff --git a/tools/ci/python_packages/idf_iperf_test_util/IperfUtility.py b/tools/ci/python_packages/idf_iperf_test_util/IperfUtility.py index 165c232140..3ff645124e 100644 --- a/tools/ci/python_packages/idf_iperf_test_util/IperfUtility.py +++ b/tools/ci/python_packages/idf_iperf_test_util/IperfUtility.py @@ -14,7 +14,7 @@ except ImportError: pass # configurations -TEST_TIME = TEST_TIMEOUT = 60 +TEST_TIME = TEST_TIMEOUT = 66 WAIT_AP_POWER_ON_TIMEOUT = 90 SCAN_TIMEOUT = 3 SCAN_RETRY_COUNT = 3 @@ -96,6 +96,7 @@ class TestResult(object): """ fall_to_0_recorded = 0 throughput_list = [] + throughput = 0.0 result_list = self.PC_BANDWIDTH_LOG_PATTERN.findall(raw_data) if not result_list: # failed to find raw data by PC pattern, it might be DUT pattern @@ -106,6 +107,7 @@ class TestResult(object): # this could be summary, ignore this continue throughput_list.append(float(result[2])) + throughput = (throughput if (throughput > float(result[2])) else float(result[2])) if float(result[2]) == 0 and rssi > self.ZERO_POINT_THRESHOLD \ and fall_to_0_recorded < 1: # throughput fall to 0 error. we only record 1 records for one test @@ -113,9 +115,7 @@ class TestResult(object): .format(ap_ssid, att, rssi, result[0], result[1])) fall_to_0_recorded += 1 - if len(throughput_list) > self.THROUGHPUT_QUALIFY_COUNT: - throughput = sum(throughput_list) / len(throughput_list) - else: + if len(throughput_list) < self.THROUGHPUT_QUALIFY_COUNT: throughput = 0.0 if throughput == 0 and rssi > self.ZERO_THROUGHPUT_THRESHOLD: @@ -330,6 +330,12 @@ class IperfTestUtility(object): process = subprocess.Popen(['iperf', '-c', dut_ip, '-t', str(TEST_TIME), '-f', 'm'], stdout=f, stderr=f) + for _ in range(TEST_TIMEOUT): + if process.poll() is not None: + break + time.sleep(1) + else: + process.terminate() else: self.dut.write('iperf -s -u -i 1 -t {}'.format(TEST_TIME)) # wait until DUT TCP server created @@ -338,16 +344,15 @@ class IperfTestUtility(object): except DUT.ExpectTimeout: # compatible with old iperf example binary Utility.console_log('create iperf udp server fail') - process = subprocess.Popen(['iperf', '-c', dut_ip, '-u', '-b', '100M', - '-t', str(TEST_TIME), '-f', 'm'], - stdout=f, stderr=f) - - for _ in range(TEST_TIMEOUT): - if process.poll() is not None: - break - time.sleep(1) - else: - process.terminate() + for bandwidth in range(50, 101, 5): + process = subprocess.Popen(['iperf', '-c', dut_ip, '-u', '-b', str(bandwidth) + 'm', + '-t', str(TEST_TIME / 11), '-f', 'm'], stdout=f, stderr=f) + for _ in range(TEST_TIMEOUT): + if process.poll() is not None: + break + time.sleep(1) + else: + process.terminate() server_raw_data = self.dut.read() with open(PC_IPERF_TEMP_LOG_FILE, 'r') as f: