From ca98b82c8df1e00c65cd0837022fdd1d07b10cfa Mon Sep 17 00:00:00 2001 From: David Greenman Date: Thu, 3 Apr 1997 05:14:45 +0000 Subject: [PATCH] Reorganize elements of the inpcb struct to take better advantage of cache lines. Removed the struct ip proto since only a couple of chars were actually being used in it. Changed the order of compares in the PCB hash lookup to take advantage of partial cache line fills (on PPro). Discussed-with: wollman --- sys/netinet/in_pcb.c | 7 ++++--- sys/netinet/in_pcb.h | 18 ++++++++++++------ sys/netinet/ip_divert.c | 4 ++-- sys/netinet/ip_output.c | 10 +++++----- sys/netinet/raw_ip.c | 8 ++++---- sys/netinet/tcp_output.c | 6 +++--- sys/netinet/tcp_subr.c | 4 ++-- sys/netinet/tcp_timewait.c | 4 ++-- sys/netinet/udp_usrreq.c | 8 ++++---- 9 files changed, 38 insertions(+), 31 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 81409cea6508..d7136aa15348 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 - * $Id: in_pcb.c,v 1.28 1997/03/03 09:23:33 davidg Exp $ + * $Id: in_pcb.c,v 1.29 1997/03/24 11:24:50 bde Exp $ */ #include @@ -688,8 +688,9 @@ in_pcblookuphash(pcbinfo, faddr, fport_arg, laddr, lport_arg, wildcard) head = &pcbinfo->hashbase[INP_PCBHASH(faddr.s_addr, lport, fport, pcbinfo->hashmask)]; for (inp = head->lh_first; inp != NULL; inp = inp->inp_hash.le_next) { if (inp->inp_faddr.s_addr == faddr.s_addr && - inp->inp_fport == fport && inp->inp_lport == lport && - inp->inp_laddr.s_addr == laddr.s_addr) + inp->inp_laddr.s_addr == laddr.s_addr && + inp->inp_fport == fport && + inp->inp_lport == lport) goto found; } if (wildcard) { diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 6adad916d8ec..5a5d69d4de66 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 - * $Id: in_pcb.h,v 1.18 1997/02/22 09:41:29 peter Exp $ + * $Id: in_pcb.h,v 1.19 1997/03/03 09:23:34 davidg Exp $ */ #ifndef _NETINET_IN_PCB_H_ @@ -51,18 +51,24 @@ LIST_HEAD(inpcbhead, inpcb); struct inpcb { LIST_ENTRY(inpcb) inp_list; /* list for all PCBs of this proto */ LIST_ENTRY(inpcb) inp_hash; /* hash list */ - struct inpcbinfo *inp_pcbinfo; + struct inpcbinfo *inp_pcbinfo; /* PCB list info */ struct in_addr inp_faddr; /* foreign host table entry */ - u_short inp_fport; /* foreign port */ struct in_addr inp_laddr; /* local host table entry */ + u_short inp_fport; /* foreign port */ u_short inp_lport; /* local port */ - struct socket *inp_socket; /* back pointer to socket */ caddr_t inp_ppcb; /* pointer to per-protocol pcb */ + struct socket *inp_socket; /* back pointer to socket */ + struct mbuf *inp_options; /* IP options */ struct route inp_route; /* placeholder for routing entry */ int inp_flags; /* generic IP/datagram flags */ - struct ip inp_ip; /* header prototype; should have more */ - struct mbuf *inp_options; /* IP options */ + u_char inp_ip_tos; /* type of service proto */ + u_char inp_ip_ttl; /* time to live proto */ + u_char inp_ip_p; /* protocol proto */ + u_char pad[1]; /* alignment */ struct ip_moptions *inp_moptions; /* IP multicast options */ +#if 0 /* Someday, perhaps... */ + struct ip inp_ip; /* header prototype; should have more */ +#endif }; struct inpcbinfo { diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 8cfd0ffefa14..335ed5179db2 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ip_divert.c,v 1.6 1997/02/22 09:41:31 peter Exp $ + * $Id: ip_divert.c,v 1.7 1997/03/03 09:23:34 davidg Exp $ */ #include @@ -280,7 +280,7 @@ div_usrreq(so, req, m, nam, control) (error = in_pcballoc(so, &divcbinfo))) break; inp = (struct inpcb *)so->so_pcb; - inp->inp_ip.ip_p = (int)nam; /* XXX */ + inp->inp_ip_p = (int)nam; /* XXX */ inp->inp_flags |= INP_HDRINCL; /* The socket is always "connected" because we always know "where" to send the packet */ diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 0ca3ee200736..b70802577c50 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 - * $Id: ip_output.c,v 1.51 1997/02/22 09:41:36 peter Exp $ + * $Id: ip_output.c,v 1.52 1997/02/28 19:40:48 fenner Exp $ */ #define _IP_VHL @@ -658,11 +658,11 @@ ip_ctloutput(op, so, level, optname, mp) switch (optname) { case IP_TOS: - inp->inp_ip.ip_tos = optval; + inp->inp_ip_tos = optval; break; case IP_TTL: - inp->inp_ip.ip_ttl = optval; + inp->inp_ip_ttl = optval; break; #define OPTSET(bit) \ if (optval) \ @@ -761,11 +761,11 @@ ip_ctloutput(op, so, level, optname, mp) switch (optname) { case IP_TOS: - optval = inp->inp_ip.ip_tos; + optval = inp->inp_ip_tos; break; case IP_TTL: - optval = inp->inp_ip.ip_ttl; + optval = inp->inp_ip_ttl; break; #define OPTBIT(bit) (inp->inp_flags & bit ? 1 : 0) diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 7f50216ff408..1e3a35d63a68 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95 - * $Id: raw_ip.c,v 1.42 1997/02/18 20:46:29 wollman Exp $ + * $Id: raw_ip.c,v 1.43 1997/03/03 09:23:35 davidg Exp $ */ #include @@ -114,7 +114,7 @@ rip_input(m, iphlen) ripsrc.sin_addr = ip->ip_src; for (inp = ripcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) { - if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != ip->ip_p) + if (inp->inp_ip_p && inp->inp_ip_p != ip->ip_p) continue; if (inp->inp_laddr.s_addr && inp->inp_laddr.s_addr != ip->ip_dst.s_addr) @@ -187,7 +187,7 @@ rip_output(m, so, dst) ip = mtod(m, struct ip *); ip->ip_tos = 0; ip->ip_off = 0; - ip->ip_p = inp->inp_ip.ip_p; + ip->ip_p = inp->inp_ip_p; ip->ip_len = m->m_pkthdr.len; ip->ip_src = inp->inp_laddr; ip->ip_dst.s_addr = dst; @@ -402,7 +402,7 @@ rip_attach(struct socket *so, int proto) (error = in_pcballoc(so, &ripcbinfo))) return error; inp = (struct inpcb *)so->so_pcb; - inp->inp_ip.ip_p = proto; + inp->inp_ip_p = proto; return 0; } diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index e86317fdc7bf..8d4358988660 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95 - * $Id$ + * $Id: tcp_output.c,v 1.23 1997/02/22 09:41:40 peter Exp $ */ #include @@ -673,8 +673,8 @@ tcp_output(tp) struct rtentry *rt; #endif ((struct ip *)ti)->ip_len = m->m_pkthdr.len; - ((struct ip *)ti)->ip_ttl = tp->t_inpcb->inp_ip.ip_ttl; /* XXX */ - ((struct ip *)ti)->ip_tos = tp->t_inpcb->inp_ip.ip_tos; /* XXX */ + ((struct ip *)ti)->ip_ttl = tp->t_inpcb->inp_ip_ttl; /* XXX */ + ((struct ip *)ti)->ip_tos = tp->t_inpcb->inp_ip_tos; /* XXX */ #if 1 /* * See if we should do MTU discovery. We do it only if the following diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index f7b4469ea454..7987789ff583 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 - * $Id: tcp_subr.c,v 1.34 1997/02/22 09:41:41 peter Exp $ + * $Id: tcp_subr.c,v 1.35 1997/03/03 09:23:36 davidg Exp $ */ #include @@ -276,7 +276,7 @@ tcp_newtcpcb(inp) tp->t_rxtcur = TCPTV_RTOBASE; tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT; tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; - inp->inp_ip.ip_ttl = ip_defttl; + inp->inp_ip_ttl = ip_defttl; inp->inp_ppcb = (caddr_t)tp; return (tp); } diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c index f7b4469ea454..7987789ff583 100644 --- a/sys/netinet/tcp_timewait.c +++ b/sys/netinet/tcp_timewait.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 - * $Id: tcp_subr.c,v 1.34 1997/02/22 09:41:41 peter Exp $ + * $Id: tcp_subr.c,v 1.35 1997/03/03 09:23:36 davidg Exp $ */ #include @@ -276,7 +276,7 @@ tcp_newtcpcb(inp) tp->t_rxtcur = TCPTV_RTOBASE; tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT; tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; - inp->inp_ip.ip_ttl = ip_defttl; + inp->inp_ip_ttl = ip_defttl; inp->inp_ppcb = (caddr_t)tp; return (tp); } diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 56a84acccd13..fe1a8fc67c28 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 - * $Id: udp_usrreq.c,v 1.35 1997/02/24 20:31:25 wollman Exp $ + * $Id: udp_usrreq.c,v 1.36 1997/03/03 09:23:37 davidg Exp $ */ #include @@ -435,8 +435,8 @@ udp_output(inp, m, addr, control) ui->ui_sum = 0xffff; } ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; - ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */ - ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */ + ((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl; /* XXX */ + ((struct ip *)ui)->ip_tos = inp->inp_ip_tos; /* XXX */ udpstat.udps_opackets++; error = ip_output(m, inp->inp_options, &inp->inp_route, inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST), @@ -497,7 +497,7 @@ udp_attach(struct socket *so, int proto) error = soreserve(so, udp_sendspace, udp_recvspace); if (error) return error; - ((struct inpcb *) so->so_pcb)->inp_ip.ip_ttl = ip_defttl; + ((struct inpcb *) so->so_pcb)->inp_ip_ttl = ip_defttl; return 0; }