Skip to content

Commit

Permalink
optimization lwip ip4 reassembly timer
Browse files Browse the repository at this point in the history
  • Loading branch information
freakyxue committed Nov 8, 2022
1 parent 6b0bfc2 commit ce1a709
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
run: |
cp ${CONTRIB}/examples/example_app/lwipcfg.h.example ${CONTRIB}/examples/example_app/lwipcfg.h
cd ${CONTRIB}/ports/unix/example_app
export CFLAGS="-DESP_LWIP=LWIP_NETCONN_FULLDUPLEX -DESP_LWIP_DNS_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_IGMP_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_MLD6_TIMERS_ONDEMAND=ESP_LWIP -DESP_DNS=ESP_LWIP -DESP_LWIP_ARP=ESP_LWIP"
export CFLAGS="-DESP_LWIP=LWIP_NETCONN_FULLDUPLEX -DESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_DNS_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_IGMP_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_MLD6_TIMERS_ONDEMAND=ESP_LWIP -DESP_DNS=ESP_LWIP -DESP_LWIP_ARP=ESP_LWIP"
export LWIPDIR=../../../../src/
make TESTFLAGS="-Wno-documentation" -j 4
chmod +x iteropts.sh && ./iteropts.sh
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ validate_opts:
- *get_contrib
- cp ${CONTRIB}/examples/example_app/lwipcfg.h.example ${CONTRIB}/examples/example_app/lwipcfg.h
- cd ${CONTRIB}/ports/unix/example_app
- export CFLAGS="-DESP_LWIP=LWIP_NETCONN_FULLDUPLEX -DESP_LWIP_DNS_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_IGMP_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_MLD6_TIMERS_ONDEMAND=ESP_LWIP -DESP_DNS=ESP_LWIP"
- export CFLAGS="-DESP_LWIP=LWIP_NETCONN_FULLDUPLEX -DESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_DNS_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_IGMP_TIMERS_ONDEMAND=ESP_LWIP -DESP_LWIP_MLD6_TIMERS_ONDEMAND=ESP_LWIP -DESP_DNS=ESP_LWIP"
- export LWIPDIR=../../../../src/
- chmod +x iteropts.sh && ./iteropts.sh

Expand Down
38 changes: 38 additions & 0 deletions src/core/ipv4/ip4_frag.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
#include <string.h>

#if IP_REASSEMBLY

#if ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
#include "lwip/timeouts.h"
#include "stdbool.h"
static bool s_is_tmr_start = false;
#endif /* ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND */

/**
* The IP reassembly code currently has the following limitations:
* - IP header options are not supported
Expand Down Expand Up @@ -118,6 +125,17 @@ static u16_t ip_reass_pbufcount;
static void ip_reass_dequeue_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev);
static int ip_reass_free_complete_datagram(struct ip_reassdata *ipr, struct ip_reassdata *prev);

#if ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
/**
* Wrapper function with matching prototype which calls the actual callback
*/
static void ip_reass_timeout_cb(void *arg)
{
LWIP_UNUSED_ARG(arg);
ip_reass_tmr();
}
#endif

/**
* Reassembly timer base function
* for both NO_SYS == 0 and 1 (!).
Expand All @@ -128,6 +146,9 @@ void
ip_reass_tmr(void)
{
struct ip_reassdata *r, *prev = NULL;
#if ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
bool tmr_restart = false;
#endif /* ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND */

r = reassdatagrams;
while (r != NULL) {
Expand All @@ -138,6 +159,9 @@ ip_reass_tmr(void)
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass_tmr: timer dec %"U16_F"\n", (u16_t)r->timer));
prev = r;
r = r->next;
#if ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
tmr_restart = true;
#endif /* ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND */
} else {
/* reassembly timed out */
struct ip_reassdata *tmp;
Expand All @@ -149,6 +173,14 @@ ip_reass_tmr(void)
ip_reass_free_complete_datagram(tmp, prev);
}
}
#if ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
if (tmr_restart) {
sys_timeout(IP_TMR_INTERVAL, ip_reass_timeout_cb, NULL);
} else {
sys_untimeout(ip_reass_timeout_cb, NULL);
s_is_tmr_start = false;
}
#endif/* ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND */
}

/**
Expand Down Expand Up @@ -672,6 +704,12 @@ ip4_reass(struct pbuf *p)
/* Return the pbuf chain */
return p;
}
#if ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
if (!s_is_tmr_start) {
sys_timeout(IP_TMR_INTERVAL, ip_reass_timeout_cb, NULL);
s_is_tmr_start = true;
}
#endif /* ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND */
/* the datagram is not (yet?) reassembled completely */
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass_pbufcount: %d out\n", ip_reass_pbufcount));
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/core/timeouts.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const struct lwip_cyclic_timer lwip_cyclic_timers[] = {
{TCP_TMR_INTERVAL, HANDLER(tcp_tmr)},
#endif /* LWIP_TCP */
#if LWIP_IPV4
#if IP_REASSEMBLY
#if IP_REASSEMBLY && !ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
{IP_TMR_INTERVAL, HANDLER(ip_reass_tmr)},
#endif /* IP_REASSEMBLY */
#if LWIP_ARP
Expand Down
3 changes: 3 additions & 0 deletions test/apps/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ void sys_thread_sem_deinit(void);
#define ESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND 1
#define ESP_LWIP_DNS_TIMERS_ONDEMAND 1
#define ESP_LWIP_MLD6_TIMERS_ONDEMAND 1
#if IP_REASSEMBLY
#define ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND 1
#endif /* IP_REASSEMBLY */
#define ESP_DNS 1
#define ESP_LWIP_ARP 1
#define LWIP_AUTOIP_MAX_CONFLICTS 10
Expand Down
5 changes: 5 additions & 0 deletions test/unit/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ u32_t esp_random(void);
#define ESP_LWIP_MLD6_TIMERS_ONDEMAND 1
#define ESP_LWIP_DHCP_FINE_TIMERS_ONDEMAND 1
#define ESP_LWIP_DNS_TIMERS_ONDEMAND 1
#define ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND 1

#else
#define ESP_LWIP 0
Expand All @@ -177,6 +178,10 @@ u32_t esp_random(void);
#define ESP_LWIP_DNS_TIMERS_ONDEMAND 0
#endif

#ifndef ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND
#define ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND 0
#endif /* ESP_LWIP_IP4_REASSEMBLY_TIMERS_ONDEMAND */

#endif /* ESP_LWIP */

#endif /* LWIP_HDR_LWIPOPTS_H */

0 comments on commit ce1a709

Please sign in to comment.