lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Out of heap in high iperf loads, any mechanism to wait/retr


From: Vivek p
Subject: [lwip-users] Out of heap in high iperf loads, any mechanism to wait/retry on netbuf_alloc failures ?
Date: Mon, 11 Jun 2018 10:37:17 -0700

Hi,

We are using LwIP + FreeRTOS on a STM32 (Cortex M7) based MCU + Wifi Chip (802.11 ac)
connected through SDIO.

On high iperf loads, we are running out of heap, and netbuf_alloc fails.
The reason seems to be because application thread keeps on queueing TX packets,
even if the driver cannot send them as fast, and the application thread eats up all the heap,
as the TX packets are alloced from PBUF_RAM, and we are using libc malloc for mem_malloc.

Any suggestions on how to resolve this issue,
or if someone has faced similar issue before and resolved it in LWIP ?
searching through the archives, I could not find any similar issues.

One possible solution is to allocate netbuf's from RX/TX pool, instead of PBUF_RAM and,
wait if the allocation fails, this would limit the size/number of netbufs that can be allocated
at any time and in case all the netbufs are allocated, the alloc would wait till one of the netbufs
is freed instead of returning error back to application.

This solution is working for us, but it needs modification to LWIP code and will need maintenance
each time we upgrade to a newer LWIP version.

Following is a brief description of the threads and code/data flow when we hit the issue.

The app_thread keeps allocating the netbufs and tcpip_thread adds them to a queue,
which is processed by the network thread.

Network thread can send out the packets queued by tcpip_thread only if
the WLAN chip indicates it can process them.
(there is SW based flow control between the network thread running on STM32 MCU and WLAN chip)

A slow WLAN chip/SDIO bus interface between STM32 MCU and WLAN chip would not prevent
the app_thread to run and keep queueing packets,and ultimately running out of all the heap.

app_thread (priority 4)
while(1) {
  /* Create a packet to send */
  lwip_write()
    lwip_send()
      lwip_sendto()
        netconn_send()
          netconn_apimsg()
            tcpip_send_msg_wait_sem();
              sys_mbox_post(&mbox, &TCPIP_MSG_VAR_REF(msg)); sys_arch_sem_wait(sem, 0);
}

tcpip_thread (priority 7)
while(1) {
  /* Receive message from mailbox, sent by app thread */
  /* Apply IP headers */
  /* Add packet to a queue of packets to be sent by network thread */
  /* Notify network thread */
  /* Release semaphore that app_thread is waiting on */
}

network_thread (priority 9)
while(1) {
  /* Receive packets */
  /* if enough credits to send packets, then send queued packets */
  /* Free pbuf after sending packet */
}

Thanks
VIvek

reply via email to

[Prev in Thread] Current Thread [Next in Thread]