diff options
author | rwatson <rwatson@FreeBSD.org> | 2004-06-26 19:10:39 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2004-06-26 19:10:39 +0000 |
commit | 758f90deb8956a64f2e2336aa6bd1f8252df3aa9 (patch) | |
tree | 0215a39aaab05d8f4180c75adc66451aa52aac5c /sys/netinet/tcp_input.c | |
parent | 11da9eaee1fdbe9e6c047dd1d81374f90e0359b3 (diff) | |
download | FreeBSD-src-758f90deb8956a64f2e2336aa6bd1f8252df3aa9.zip FreeBSD-src-758f90deb8956a64f2e2336aa6bd1f8252df3aa9.tar.gz |
Reduce the number of unnecessary unlock-relocks on socket buffer mutexes
associated with performing a wakeup on the socket buffer:
- When performing an sbappend*() followed by a so[rw]wakeup(), explicitly
acquire the socket buffer lock and use the _locked() variants of both
calls. Note that the _locked() sowakeup() versions unlock the mutex on
return. This is done in uipc_send(), divert_packet(), mroute
socket_send(), raw_append(), tcp_reass(), tcp_input(), and udp_append().
- When the socket buffer lock is dropped before a sowakeup(), remove the
explicit unlock and use the _locked() sowakeup() variant. This is done
in soisdisconnecting(), soisdisconnected() when setting the can't send/
receive flags and dropping data, and in uipc_rcvd() which adjusting
back-pressure on the sockets.
For UNIX domain sockets running mpsafe with a contention-intensive SMP
mysql benchmark, this results in a 1.6% query rate improvement due to
reduce mutex costs.
Diffstat (limited to 'sys/netinet/tcp_input.c')
-rw-r--r-- | sys/netinet/tcp_input.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 5b37327..ee6d3ce 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -353,22 +353,24 @@ present: q = LIST_FIRST(&tp->t_segq); if (!q || q->tqe_th->th_seq != tp->rcv_nxt) return (0); + SOCKBUF_LOCK(&so->so_rcv); do { tp->rcv_nxt += q->tqe_len; flags = q->tqe_th->th_flags & TH_FIN; nq = LIST_NEXT(q, tqe_q); LIST_REMOVE(q, tqe_q); + /* Unlocked read. */ if (so->so_rcv.sb_state & SBS_CANTRCVMORE) m_freem(q->tqe_m); else - sbappendstream(&so->so_rcv, q->tqe_m); + sbappendstream_locked(&so->so_rcv, q->tqe_m); uma_zfree(tcp_reass_zone, q); tp->t_segqlen--; tcp_reass_qsize--; q = nq; } while (q && q->tqe_th->th_seq == tp->rcv_nxt); ND6_HINT(tp); - sorwakeup(so); + sorwakeup_locked(so); return (flags); } @@ -1262,13 +1264,15 @@ after_listen: #endif * Add data to socket buffer. */ + /* Unlocked read. */ + SOCKBUF_LOCK(&so->so_rcv); if (so->so_rcv.sb_state & SBS_CANTRCVMORE) { m_freem(m); } else { m_adj(m, drop_hdrlen); /* delayed header drop */ - sbappendstream(&so->so_rcv, m); + sbappendstream_locked(&so->so_rcv, m); } - sorwakeup(so); + sorwakeup_locked(so); if (DELAY_ACK(tp)) { tp->t_flags |= TF_DELACK; } else { @@ -2153,8 +2157,7 @@ process_ACK: tp->snd_wnd -= acked; ourfinisacked = 0; } - SOCKBUF_UNLOCK(&so->so_snd); - sowwakeup(so); + sowwakeup_locked(so); /* detect una wraparound */ if ((tcp_do_newreno || tp->sack_enable) && !IN_FASTRECOVERY(tp) && @@ -2363,11 +2366,13 @@ dodata: /* XXX */ tcpstat.tcps_rcvpack++; tcpstat.tcps_rcvbyte += tlen; ND6_HINT(tp); + /* Unlocked read. */ + SOCKBUF_LOCK(&so->so_rcv); if (so->so_rcv.sb_state & SBS_CANTRCVMORE) m_freem(m); else - sbappendstream(&so->so_rcv, m); - sorwakeup(so); + sbappendstream_locked(&so->so_rcv, m); + sorwakeup_locked(so); } else { thflags = tcp_reass(tp, th, &tlen, m); tp->t_flags |= TF_ACKNOW; |