From b28cd02149371632aef74016fdb59c84a924a1ab Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 30 Nov 2007 09:44:18 +0000 Subject: [PATCH] task #7497: Sort lists (pcb, netif, ...) for faster access UDP: move a (connected) pcb selected for input to the front of the list of pcbs so that it is found faster next time. Same for RAW pcbs that have eaten a packet. --- CHANGELOG | 6 ++++++ src/core/raw.c | 11 ++++++++++- src/core/udp.c | 13 ++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 42559db2..4235ce91 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,12 @@ HISTORY ++ New features: + 2007-11-30 Simon Goldschmidt + * udp.c, raw.c: task #7497: Sort lists (pcb, netif, ...) for faster access + UDP: move a (connected) pcb selected for input to the front of the list of + pcbs so that it is found faster next time. Same for RAW pcbs that have eaten + a packet. + 2007-11-28 Simon Goldschmidt * etharp.c, stats.c, stats.h, opt.h: Introduced ETHARP_STATS diff --git a/src/core/raw.c b/src/core/raw.c index 4ee3fc0e..5131c702 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -77,7 +77,7 @@ static struct raw_pcb *raw_pcbs; u8_t raw_input(struct pbuf *p, struct netif *inp) { - struct raw_pcb *pcb; + struct raw_pcb *pcb, *prev; struct ip_hdr *iphdr; s16_t proto; u8_t eaten = 0; @@ -87,6 +87,7 @@ raw_input(struct pbuf *p, struct netif *inp) iphdr = p->payload; proto = IPH_PROTO(iphdr); + prev = NULL; pcb = raw_pcbs; /* loop through all raw pcbs until the packet is eaten by one */ /* this allows multiple pcbs to match against the packet by design */ @@ -100,11 +101,19 @@ raw_input(struct pbuf *p, struct netif *inp) /* receive function ate the packet */ p = NULL; eaten = 1; + if (prev != NULL) { + /* move the pcb to the front of raw_pcbs so that is + found faster next time */ + prev->next = pcb->next; + pcb->next = raw_pcbs; + raw_pcbs = pcb; + } } } /* no receive callback function was set for this raw PCB */ /* drop the packet */ } + prev = pcb; pcb = pcb->next; } return eaten; diff --git a/src/core/udp.c b/src/core/udp.c index 7368d2a0..a2c19bf0 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -85,7 +85,7 @@ void udp_input(struct pbuf *p, struct netif *inp) { struct udp_hdr *udphdr; - struct udp_pcb *pcb; + struct udp_pcb *pcb, *prev; struct udp_pcb *uncon_pcb; struct ip_hdr *iphdr; u16_t src, dest; @@ -149,6 +149,7 @@ udp_input(struct pbuf *p, struct netif *inp) } else #endif /* LWIP_DHCP */ { + prev = NULL; local_match = 0; uncon_pcb = NULL; /* Iterate through the UDP pcb list for a matching pcb. @@ -187,8 +188,18 @@ udp_input(struct pbuf *p, struct netif *inp) (ip_addr_isany(&pcb->remote_ip) || ip_addr_cmp(&(pcb->remote_ip), &(iphdr->src)))) { /* the first fully matching PCB */ + if (prev != NULL) { + /* move the pcb to the front of udp_pcbs so that is + found faster next time */ + prev->next = pcb->next; + pcb->next = udp_pcbs; + udp_pcbs = pcb; + } else { + UDP_STATS_INC(udp.cachehit); + } break; } + prev = pcb; } /* no fully matching pcb found? then look for an unconnected pcb */ if (pcb == NULL) {