lwip timer and core locking
Posted: Thu Jun 17, 2021 2:19 pm
Hello,
for past year I'm using liwp in my application running on STM32F4xx. I have a few services running like dhcp, httpd, sntp, all running fine only until I added mqtt client. Then my application started to misbehave, looking into problems I found out that lwip needs for sure a core locking that is enabled by defaults in chibios port static_lwipopts.h but not implemented. If there is not so many processes running lwip runs for a while even without it, but adding frequent mqtt publish messages take it down.
Second is I think a bug in lwip port file sys_arch.c. Since lwip timer needs when calling sys_now() a u32_t counter. When using OSAL_ST_FREQUENCY other then exactly 1000 seems not to work, since it does not overflow on 32 bit boundary. Like me, using default OSAL_ST_FREQUENCY=10000 all lwip timers stop to work after 4.9 days. Causing various error on not clearing closed packets, DHCP and so on. It took me quite some time to wait 5 days for every change to show, until I realized it is sys ticks
I'm including my proposed changes.
Also it is needed to add to end of every project lwipopts.h
And of course to start to use the LOCK_TCPIP_CORE / UNLOCK_TCPIP_CORE, like:
whenever the lwip function needs a core lock.
for past year I'm using liwp in my application running on STM32F4xx. I have a few services running like dhcp, httpd, sntp, all running fine only until I added mqtt client. Then my application started to misbehave, looking into problems I found out that lwip needs for sure a core locking that is enabled by defaults in chibios port static_lwipopts.h but not implemented. If there is not so many processes running lwip runs for a while even without it, but adding frequent mqtt publish messages take it down.
Second is I think a bug in lwip port file sys_arch.c. Since lwip timer needs when calling sys_now() a u32_t counter. When using OSAL_ST_FREQUENCY other then exactly 1000 seems not to work, since it does not overflow on 32 bit boundary. Like me, using default OSAL_ST_FREQUENCY=10000 all lwip timers stop to work after 4.9 days. Causing various error on not clearing closed packets, DHCP and so on. It took me quite some time to wait 5 days for every change to show, until I realized it is sys ticks
I'm including my proposed changes.
Also it is needed to add to end of every project lwipopts.h
Code: Select all
#if LWIP_TCPIP_CORE_LOCKING
void lwip_assert_core_locked(void);
#define LWIP_ASSERT_CORE_LOCKED() lwip_assert_core_locked();
#endifAnd of course to start to use the LOCK_TCPIP_CORE / UNLOCK_TCPIP_CORE, like:
Code: Select all
LOCK_TCPIP_CORE();
httpd_init();
UNLOCK_TCPIP_CORE();whenever the lwip function needs a core lock.