From 9c1df6951ff968a632f4c6d04de59842857a9ec9 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Fri, 6 Aug 2004 02:08:31 +0000 Subject: [PATCH] When iterating the UDP inpcb list processing an inbound broadcast or multicast packet, we don't need to acquire the inpcb mutex unless we are actually using inpcb fields other than the bound port and address. Since we hold the pcbinfo lock already, these can't change. Defer acquiring the inpcb mutex until we have a high chance of a match. This avoids about 120 mutex operations per UDP broadcast packet received on one of my work systems. Reviewed by: sam --- sys/netinet/udp_usrreq.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index fc146d4ac41b..dc95f4bd2cb8 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -287,26 +287,23 @@ udp_input(m, off) */ last = NULL; LIST_FOREACH(inp, &udb, inp_list) { - INP_LOCK(inp); - if (inp->inp_lport != uh->uh_dport) { - docontinue: - INP_UNLOCK(inp); + if (inp->inp_lport != uh->uh_dport) continue; - } #ifdef INET6 if ((inp->inp_vflag & INP_IPV4) == 0) - goto docontinue; + continue; #endif if (inp->inp_laddr.s_addr != INADDR_ANY) { if (inp->inp_laddr.s_addr != ip->ip_dst.s_addr) - goto docontinue; + continue; } if (inp->inp_faddr.s_addr != INADDR_ANY) { if (inp->inp_faddr.s_addr != ip->ip_src.s_addr || inp->inp_fport != uh->uh_sport) - goto docontinue; + continue; } + INP_LOCK(inp); /* * Check multicast packets to make sure they are only @@ -327,8 +324,10 @@ udp_input(m, off) break; } } - if (foundmship == 0) - goto docontinue; + if (foundmship == 0) { + INP_UNLOCK(inp); + continue; + } } #undef NMSHIPS #undef MSHIP