Skip to content

Commit 2242bf9

Browse files
committed
lwip/esp32/examples: wifi throughput optimizations
1. Put some lwip udp rx/tx relating functions to IRAM 2. Put some wifi rx/tx relating functions to IRAMa 3. Reduce wifi dynamic malloc from 4 to 1 for each ebuf 4. Update iperf example accordingly 5. Update libphy.a to v383
1 parent 5b1f869 commit 2242bf9

File tree

22 files changed

+97
-72
lines changed

22 files changed

+97
-72
lines changed

components/esp32/ld/esp32.common.ld

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ SECTIONS
8989
*libesp32.a:core_dump.o(.literal .text .literal.* .text.*)
9090
*libapp_trace.a:(.literal .text .literal.* .text.*)
9191
*libxtensa-debug-module.a:eri.o(.literal .text .literal.* .text.*)
92-
*libphy.a:(.literal .text .literal.* .text.*)
9392
*librtc.a:(.literal .text .literal.* .text.*)
9493
*libsoc.a:(.literal .text .literal.* .text.*)
9594
*libhal.a:(.literal .text .literal.* .text.*)
@@ -116,7 +115,6 @@ SECTIONS
116115
*(.jcr)
117116
*(.dram1 .dram1.*)
118117
*libesp32.a:panic.o(.rodata .rodata.*)
119-
*libphy.a:(.rodata .rodata.*)
120118
*libsoc.a:rtc_clk.o(.rodata .rodata.*)
121119
*libapp_trace.a:(.rodata .rodata.*)
122120
*libgcov.a:(.rodata .rodata.*)

components/lwip/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ config L2_TO_L3_COPY
1616
Please make sure you fully understand the impact of this feature before
1717
enabling it.
1818

19+
config LWIP_IRAM_OPTIMIZATION
20+
bool "Enable LWIP IRAM optimization"
21+
default n
22+
help
23+
If this feature is enabled, some functions relating to RX/TX in LWIP will be
24+
put into IRAM, it can improve UDP/TCP throughput by >10% for single core mode,
25+
it doesn't help too much for dual core mode. On the other hand, it needs about
26+
10KB IRAM for these optimizations.
27+
28+
If this feature is disabled, all lwip functions will be put into FLASH.
29+
1930
config LWIP_MAX_SOCKETS
2031
int "Max number of open sockets"
2132
range 1 32

components/lwip/api/api_lib.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static err_t netconn_close_shutdown(struct netconn *conn, u8_t how);
7272
* @param apimsg a struct containing the function to call and its parameters
7373
* @return ERR_OK if the function was called, another err_t if not
7474
*/
75-
static err_t
75+
static err_t ESP_IRAM_ATTR
7676
tcpip_apimsg(struct api_msg *apimsg)
7777
{
7878
#if LWIP_DEBUG
@@ -432,7 +432,7 @@ netconn_accept(struct netconn *conn, struct netconn **new_conn)
432432
* @return ERR_OK if data has been received, an error code otherwise (timeout,
433433
* memory error or another error)
434434
*/
435-
static err_t
435+
static err_t ESP_IRAM_ATTR
436436
netconn_recv_data(struct netconn *conn, void **new_buf)
437437
{
438438
void *buf = NULL;
@@ -566,7 +566,7 @@ netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf)
566566
* @return ERR_OK if data has been received, an error code otherwise (timeout,
567567
* memory error or another error)
568568
*/
569-
err_t
569+
err_t ESP_IRAM_ATTR
570570
netconn_recv(struct netconn *conn, struct netbuf **new_buf)
571571
{
572572
#if LWIP_TCP
@@ -678,7 +678,7 @@ netconn_sendto(struct netconn *conn, struct netbuf *buf, const ip_addr_t *addr,
678678
* @param buf a netbuf containing the data to send
679679
* @return ERR_OK if data was sent, any other err_t on error
680680
*/
681-
err_t
681+
err_t ESP_IRAM_ATTR
682682
netconn_send(struct netconn *conn, struct netbuf *buf)
683683
{
684684
API_MSG_VAR_DECLARE(msg);

components/lwip/api/api_msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ lwip_netconn_do_listen(void *m)
14401440
*
14411441
* @param msg the api_msg_msg pointing to the connection
14421442
*/
1443-
void
1443+
void ESP_IRAM_ATTR
14441444
lwip_netconn_do_send(void *m)
14451445
{
14461446
struct api_msg_msg *msg = (struct api_msg_msg*)m;

components/lwip/api/netbuf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ netbuf_delete(struct netbuf *buf)
103103
* @return pointer to the allocated memory
104104
* NULL if no memory could be allocated
105105
*/
106-
void *
106+
void * ESP_IRAM_ATTR
107107
netbuf_alloc(struct netbuf *buf, u16_t size)
108108
{
109109
LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
@@ -127,7 +127,7 @@ netbuf_alloc(struct netbuf *buf, u16_t size)
127127
*
128128
* @param buf pointer to the netbuf which contains the packet buffer to free
129129
*/
130-
void
130+
void ESP_IRAM_ATTR
131131
netbuf_free(struct netbuf *buf)
132132
{
133133
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);

components/lwip/api/sockets.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ lwip_socket_thread_cleanup(void)
491491
* @param s externally used socket index
492492
* @return struct lwip_sock for the socket or NULL if not found
493493
*/
494-
static struct lwip_sock *
494+
static struct lwip_sock * ESP_IRAM_ATTR
495495
get_socket(int s)
496496
{
497497
struct lwip_sock *sock;
@@ -962,7 +962,7 @@ lwip_listen(int s, int backlog)
962962
return 0;
963963
}
964964

965-
int
965+
int ESP_IRAM_ATTR
966966
lwip_recvfrom(int s, void *mem, size_t len, int flags,
967967
struct sockaddr *from, socklen_t *fromlen)
968968
{
@@ -1340,7 +1340,7 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags)
13401340
#endif /* LWIP_UDP || LWIP_RAW */
13411341
}
13421342

1343-
int
1343+
int ESP_IRAM_ATTR
13441344
lwip_sendto(int s, const void *data, size_t size, int flags,
13451345
const struct sockaddr *to, socklen_t tolen)
13461346
{
@@ -1817,7 +1817,7 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
18171817
* Callback registered in the netconn layer for each socket-netconn.
18181818
* Processes recvevent (data available) and wakes up tasks waiting for select.
18191819
*/
1820-
static void
1820+
static void ESP_IRAM_ATTR
18211821
event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
18221822
{
18231823
int s;
@@ -3159,7 +3159,7 @@ static void lwip_socket_drop_registered_memberships(int s)
31593159

31603160
#if ESP_THREAD_SAFE
31613161

3162-
int
3162+
int ESP_IRAM_ATTR
31633163
lwip_sendto_r(int s, const void *data, size_t size, int flags,
31643164
const struct sockaddr *to, socklen_t tolen)
31653165
{
@@ -3176,7 +3176,7 @@ lwip_send_r(int s, const void *data, size_t size, int flags)
31763176
LWIP_API_UNLOCK();
31773177
}
31783178

3179-
int
3179+
int ESP_IRAM_ATTR
31803180
lwip_recvfrom_r(int s, void *mem, size_t len, int flags,
31813181
struct sockaddr *from, socklen_t *fromlen)
31823182
{

components/lwip/api/tcpip.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ sys_mutex_t lock_tcpip_core;
7777
*
7878
* @param arg unused argument
7979
*/
80-
static void
80+
static void ESP_IRAM_ATTR
8181
tcpip_thread(void *arg)
8282
{
8383

@@ -195,7 +195,7 @@ tcpip_thread(void *arg)
195195
* @param inp the network interface on which the packet was received
196196
* @param input_fn input function to call
197197
*/
198-
err_t
198+
err_t ESP_IRAM_ATTR
199199
tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
200200
{
201201
#if LWIP_TCPIP_CORE_LOCKING_INPUT
@@ -244,7 +244,7 @@ tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
244244
* NETIF_FLAG_ETHERNET flags)
245245
* @param inp the network interface on which the packet was received
246246
*/
247-
err_t
247+
err_t ESP_IRAM_ATTR
248248
tcpip_input(struct pbuf *p, struct netif *inp)
249249
{
250250
#if LWIP_ETHERNET
@@ -363,7 +363,7 @@ tcpip_untimeout(sys_timeout_handler h, void *arg)
363363
* @param sem semaphore to wait on
364364
* @return ERR_OK if the function was called, another err_t if not
365365
*/
366-
err_t
366+
err_t ESP_IRAM_ATTR
367367
tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem)
368368
{
369369
LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem));

components/lwip/core/inet_chksum.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ lwip_standard_chksum(const void *dataptr, int len)
259259
#endif
260260

261261
/** Parts of the pseudo checksum which are common to IPv4 and IPv6 */
262-
static u16_t
262+
static u16_t ESP_IRAM_ATTR
263263
inet_cksum_pseudo_base(struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc)
264264
{
265265
struct pbuf *q;
@@ -309,7 +309,7 @@ inet_cksum_pseudo_base(struct pbuf *p, u8_t proto, u16_t proto_len, u32_t acc)
309309
* @param proto_len length of the ip data part (used for checksum of pseudo header)
310310
* @return checksum (as u16_t) to be saved directly in the protocol header
311311
*/
312-
u16_t
312+
u16_t ESP_IRAM_ATTR
313313
inet_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
314314
const ip4_addr_t *src, const ip4_addr_t *dest)
315315
{
@@ -378,7 +378,7 @@ ip6_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
378378
* @param proto_len length of the ip data part (used for checksum of pseudo header)
379379
* @return checksum (as u16_t) to be saved directly in the protocol header
380380
*/
381-
u16_t
381+
u16_t ESP_IRAM_ATTR
382382
ip_chksum_pseudo(struct pbuf *p, u8_t proto, u16_t proto_len,
383383
const ip_addr_t *src, const ip_addr_t *dest)
384384
{

components/lwip/core/ipv4/ip4.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool ip4_netif_exist(const ip4_addr_t *src, const ip4_addr_t *dest)
136136
* Source based IPv4 routing hook function. This function works only
137137
* when destination IP is broadcast IP.
138138
*/
139-
struct netif *
139+
struct netif * ESP_IRAM_ATTR
140140
ip4_route_src_hook(const ip4_addr_t *dest, const ip4_addr_t *src)
141141
{
142142
struct netif *netif = NULL;
@@ -162,7 +162,7 @@ ip4_route_src_hook(const ip4_addr_t *dest, const ip4_addr_t *src)
162162
* Source based IPv4 routing must be fully implemented in
163163
* LWIP_HOOK_IP4_ROUTE_SRC(). This function only provides the parameters.
164164
*/
165-
struct netif *
165+
struct netif * ESP_IRAM_ATTR
166166
ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)
167167
{
168168
if (src != NULL) {
@@ -189,7 +189,7 @@ ip4_route_src(const ip4_addr_t *dest, const ip4_addr_t *src)
189189
* @param dest the destination IP address for which to find the route
190190
* @return the netif on which to send to reach dest
191191
*/
192-
struct netif *
192+
struct netif * ESP_IRAM_ATTR
193193
ip4_route(const ip4_addr_t *dest)
194194
{
195195
struct netif *netif;
@@ -410,7 +410,7 @@ ip4_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
410410
* @return ERR_OK if the packet was processed (could return ERR_* if it wasn't
411411
* processed, but currently always returns ERR_OK)
412412
*/
413-
err_t
413+
err_t ESP_IRAM_ATTR
414414
ip4_input(struct pbuf *p, struct netif *inp)
415415
{
416416
struct ip_hdr *iphdr;
@@ -818,7 +818,7 @@ ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
818818
* Same as ip_output_if() but 'src' address is not replaced by netif address
819819
* when it is 'any'.
820820
*/
821-
err_t
821+
err_t ESP_IRAM_ATTR
822822
ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
823823
u8_t ttl, u8_t tos,
824824
u8_t proto, struct netif *netif)
@@ -831,7 +831,7 @@ ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
831831
* Same as ip_output_if_opt() but 'src' address is not replaced by netif address
832832
* when it is 'any'.
833833
*/
834-
err_t
834+
err_t ESP_IRAM_ATTR
835835
ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
836836
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
837837
u16_t optlen)

0 commit comments

Comments
 (0)