From 0fb2ab9f5cefd84da023008e120703dc676c8443 Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Mon, 2 Jan 2017 20:03:10 +0800 Subject: [PATCH] lwip/freertos/esp32: add throughput optimization related code 1. Update wifi lib which contains ampdu and other optimizations 2. Add throughput code debug code 3. Other misc modification about throughput optimization --- components/esp32/include/esp_wifi_types.h | 2 +- components/esp32/lib | 2 +- components/freertos/Kconfig | 2 + components/freertos/port.c | 6 +++ components/lwip/api/api_lib.c | 4 ++ components/lwip/api/api_msg.c | 4 ++ components/lwip/api/sockets.c | 1 + components/lwip/api/tcpip.c | 15 +++----- components/lwip/include/lwip/lwip/opt.h | 2 +- components/lwip/include/lwip/port/lwipopts.h | 39 ++++++++++++++------ components/lwip/netif/ethernet.c | 4 ++ components/lwip/port/netif/ethernetif.c | 4 -- components/lwip/port/netif/wlanif.c | 3 -- 13 files changed, 58 insertions(+), 30 deletions(-) diff --git a/components/esp32/include/esp_wifi_types.h b/components/esp32/include/esp_wifi_types.h index ac7642829f..be3183ba5d 100755 --- a/components/esp32/include/esp_wifi_types.h +++ b/components/esp32/include/esp_wifi_types.h @@ -121,7 +121,7 @@ typedef enum { #define WIFI_PROTOCOL_11N 4 typedef enum { - WIFI_BW_HT20 = 0, /* Bandwidth is HT20 */ + WIFI_BW_HT20 = 1, /* Bandwidth is HT20 */ WIFI_BW_HT40, /* Bandwidth is HT40 */ } wifi_bandwidth_t; diff --git a/components/esp32/lib b/components/esp32/lib index 02232f974b..074303d74f 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit 02232f974b0ff1568ddd6d7015a41fb4f4870994 +Subproject commit 074303d74fc9c68823adee0a38fc1e8de42943b6 diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index fc4cf56061..fe7e6afd88 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -187,6 +187,7 @@ config FREERTOS_PORTMUX_DEBUG If enabled, debug information (including integrity checks) will be printed to UART for the port-specific MUX implementation. +if !FREERTOS_UNICORE config FREERTOS_PORTMUX_DEBUG_RECURSIVE bool "Debug portMUX Recursion" depends on FREERTOS_PORTMUX_DEBUG @@ -194,6 +195,7 @@ config FREERTOS_PORTMUX_DEBUG_RECURSIVE help If enabled, additional debug information will be printed for recursive portMUX usage. +endif #FREERTOS_UNICORE endif # FREERTOS_DEBUG_INTERNALS diff --git a/components/freertos/port.c b/components/freertos/port.c index 25480ed475..e5898038bc 100644 --- a/components/freertos/port.c +++ b/components/freertos/port.c @@ -282,6 +282,7 @@ void vPortCPUAcquireMutex(portMUX_TYPE *mux, const char *fnName, int line) { #else void vPortCPUAcquireMutex(portMUX_TYPE *mux) { #endif +#if !CONFIG_FREERTOS_UNICORE uint32_t res; uint32_t recCnt; unsigned int irqStatus; @@ -324,6 +325,7 @@ void vPortCPUAcquireMutex(portMUX_TYPE *mux) { } #endif portEXIT_CRITICAL_NESTED(irqStatus); +#endif } /* @@ -335,6 +337,7 @@ portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux, const char *fnName, int li #else portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux) { #endif +#if !CONFIG_FREERTOS_UNICORE uint32_t res=0; uint32_t recCnt; unsigned int irqStatus; @@ -379,6 +382,9 @@ portBASE_TYPE vPortCPUReleaseMutex(portMUX_TYPE *mux) { } portEXIT_CRITICAL_NESTED(irqStatus); return ret; +#else //!CONFIG_FREERTOS_UNICORE + return 0; +#endif } #if CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG diff --git a/components/lwip/api/api_lib.c b/components/lwip/api/api_lib.c index ecebf4f813..86ee5576ab 100755 --- a/components/lwip/api/api_lib.c +++ b/components/lwip/api/api_lib.c @@ -508,6 +508,10 @@ netconn_recv_data(struct netconn *conn, void **new_buf) } #endif /* (LWIP_UDP || LWIP_RAW) */ +#ifdef ESP_PERF + if (len > DBG_PERF_FILTER_LEN) { DBG_PERF_PATH_SET(DBG_PERF_DIR_RX, DBG_PERF_POINT_SOC_IN); } +#endif + #if LWIP_SO_RCVBUF SYS_ARCH_DEC(conn->recv_avail, len); #endif /* LWIP_SO_RCVBUF */ diff --git a/components/lwip/api/api_msg.c b/components/lwip/api/api_msg.c index 2d98734b67..87e5aeb8e5 100755 --- a/components/lwip/api/api_msg.c +++ b/components/lwip/api/api_msg.c @@ -202,6 +202,10 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p, #endif /* LWIP_NETBUF_RECVINFO */ } +#ifdef ESP_PERF + if (p->len > DBG_PERF_FILTER_LEN) DBG_PERF_PATH_SET(DBG_PERF_DIR_RX, DBG_PERF_POINT_LWIP_OUT); +#endif + len = p->tot_len; if (sys_mbox_trypost(&conn->recvmbox, buf) != ERR_OK) { ESP_STATS_INC(esp.rx_udpmbox_post_fail); diff --git a/components/lwip/api/sockets.c b/components/lwip/api/sockets.c index 4acf518cc9..c163b3ac0b 100755 --- a/components/lwip/api/sockets.c +++ b/components/lwip/api/sockets.c @@ -1438,6 +1438,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags, err = netbuf_ref(&buf, data, short_size); #endif /* LWIP_NETIF_TX_SINGLE_PBUF */ if (err == ERR_OK) { + DBG_PERF_PATH_SET(DBG_PERF_DIR_TX, DBG_PERF_POINT_SOC_OUT); /* send the data */ err = netconn_send(sock->conn, &buf); } diff --git a/components/lwip/api/tcpip.c b/components/lwip/api/tcpip.c index 72de714e2a..dfb235718b 100755 --- a/components/lwip/api/tcpip.c +++ b/components/lwip/api/tcpip.c @@ -219,6 +219,12 @@ tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn) msg->msg.inp.p = p; msg->msg.inp.netif = inp; msg->msg.inp.input_fn = input_fn; +#ifdef ESP_PERF + if (p->len > DBG_PERF_FILTER_LEN) { + DBG_PERF_PATH_SET(DBG_PERF_DIR_RX, DBG_PERF_POINT_WIFI_OUT); + } +#endif + if (sys_mbox_trypost(&mbox, msg) != ERR_OK) { ESP_STATS_INC(esp.tcpip_inpkt_post_fail); memp_free(MEMP_TCPIP_MSG_INPKT, msg); @@ -492,20 +498,11 @@ tcpip_init(tcpip_init_done_fn initfunc, void *arg) #endif /* LWIP_TCPIP_CORE_LOCKING */ -#if ESP_LWIP -#if ESP_DUAL_CORE - sys_thread_t xLwipTaskHandle = 0; - xTaskCreatePinnedToCore(tcpip_thread, TCPIP_THREAD_NAME, TCPIP_THREAD_STACKSIZE, NULL, TCPIP_THREAD_PRIO, NULL, 1); -#else sys_thread_t xLwipTaskHandle = sys_thread_new(TCPIP_THREAD_NAME , tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO); -#endif printf("tcpip_task_hdlxxx : %x, prio:%d,stack:%d\n", (u32_t)xLwipTaskHandle,TCPIP_THREAD_PRIO,TCPIP_THREAD_STACKSIZE); -#else - sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO); -#endif } diff --git a/components/lwip/include/lwip/lwip/opt.h b/components/lwip/include/lwip/lwip/opt.h index c42f3cd735..4d8d6bf70c 100755 --- a/components/lwip/include/lwip/lwip/opt.h +++ b/components/lwip/include/lwip/lwip/opt.h @@ -1665,7 +1665,7 @@ * LWIP_STATS==1: Enable statistics collection in lwip_stats. */ #ifndef LWIP_STATS -#define LWIP_STATS 1 +#define LWIP_STATS 0 #endif #if LWIP_STATS diff --git a/components/lwip/include/lwip/port/lwipopts.h b/components/lwip/include/lwip/port/lwipopts.h index 5000d63ba9..933d55a510 100755 --- a/components/lwip/include/lwip/port/lwipopts.h +++ b/components/lwip/include/lwip/port/lwipopts.h @@ -572,21 +572,37 @@ #define ESP_LIGHT_SLEEP 1 #define ESP_L2_TO_L3_COPY CONFIG_L2_TO_L3_COPY #define ESP_CNT_DEBUG 0 -#define ESP_DUAL_CORE 0 -#define TCP_WND_DEFAULT (4*TCP_MSS) -#define TCP_SND_BUF_DEFAULT (2*TCP_MSS) +#define TCP_WND_DEFAULT (4*TCP_MSS) +#define TCP_SND_BUF_DEFAULT (2*TCP_MSS) -#if ESP_PER_SOC_TCP_WND -#define TCP_WND(pcb) (pcb->per_soc_tcp_wnd) -#define TCP_SND_BUF(pcb) (pcb->per_soc_tcp_snd_buf) -#else #if ESP_PERF -extern unsigned char misc_prof_get_tcpw(void); -extern unsigned char misc_prof_get_tcp_snd_buf(void); -#define TCP_WND(pcb) (misc_prof_get_tcpw()*TCP_MSS) -#define TCP_SND_BUF(pcb) (misc_prof_get_tcp_snd_buf()*TCP_MSS) +#define DBG_PERF_PATH_SET(dir, point) +#define DBG_PERF_FILTER_LEN 1000 + +enum { + DBG_PERF_DIR_RX = 0, + DBG_PERF_DIR_TX, +}; + +enum { + DBG_PERF_POINT_INT = 0, + DBG_PERF_POINT_WIFI_IN = 1, + DBG_PERF_POINT_WIFI_OUT = 2, + DBG_PERF_POINT_LWIP_IN = 3, + DBG_PERF_POINT_LWIP_OUT = 4, + DBG_PERF_POINT_SOC_IN = 5, + DBG_PERF_POINT_SOC_OUT = 6, +}; + +#else +#define DBG_PERF_PATH_SET(dir, point) +#define DBG_PERF_FILTER_LEN 1000 #endif + +#if ESP_PER_SOC_TCP_WND +#define TCP_WND(pcb) (pcb->per_soc_tcp_wnd) +#define TCP_SND_BUF(pcb) (pcb->per_soc_tcp_snd_buf) #endif /** @@ -595,6 +611,7 @@ extern unsigned char misc_prof_get_tcp_snd_buf(void); #define DHCP_DEBUG LWIP_DBG_OFF #define LWIP_DEBUG LWIP_DBG_OFF #define TCP_DEBUG LWIP_DBG_OFF +#define ESP_STATS 0 #define CHECKSUM_CHECK_UDP 0 #define CHECKSUM_CHECK_IP 0 diff --git a/components/lwip/netif/ethernet.c b/components/lwip/netif/ethernet.c index 6d843913da..5d618f6a31 100755 --- a/components/lwip/netif/ethernet.c +++ b/components/lwip/netif/ethernet.c @@ -72,6 +72,10 @@ ethernet_input(struct pbuf *p, struct netif *netif) s16_t ip_hdr_offset = SIZEOF_ETH_HDR; #endif /* LWIP_ARP || ETHARP_SUPPORT_VLAN */ +#ifdef ESP_PERF + if (p->len > DBG_PERF_FILTER_LEN) DBG_PERF_PATH_SET(DBG_PERF_DIR_RX, DBG_PERF_POINT_LWIP_IN); +#endif + if (p->len <= SIZEOF_ETH_HDR) { /* a packet with only an ethernet header (or less) is not valid for us */ ETHARP_STATS_INC(etharp.proterr); diff --git a/components/lwip/port/netif/ethernetif.c b/components/lwip/port/netif/ethernetif.c index 79f21f6b3f..6b1245e2e6 100755 --- a/components/lwip/port/netif/ethernetif.c +++ b/components/lwip/port/netif/ethernetif.c @@ -56,9 +56,6 @@ #define IFNAME1 'n' static char hostname[16]; -#if ESP_PERF -uint32_t g_rx_alloc_pbuf_fail_cnt = 0; -#endif /** * In this function, the hardware should be initialized. @@ -163,7 +160,6 @@ ethernetif_input(struct netif *netif, void *buffer, uint16_t len) #if CONFIG_EMAC_L2_TO_L3_RX_BUF_MODE p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM); if (p == NULL) { - //g_rx_alloc_pbuf_fail_cnt++; return; } memcpy(p->payload, buffer, len); diff --git a/components/lwip/port/netif/wlanif.c b/components/lwip/port/netif/wlanif.c index fea163f8cc..e114105f30 100755 --- a/components/lwip/port/netif/wlanif.c +++ b/components/lwip/port/netif/wlanif.c @@ -57,9 +57,6 @@ #define IFNAME1 'n' static char hostname[16]; -#if ESP_PERF -uint32_t g_rx_alloc_pbuf_fail_cnt = 0; -#endif /** * In this function, the hardware should be initialized. -- 2.40.0