From owner-svn-src-all@freebsd.org Wed Jan 27 00:45:48 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 293E5A6E73C; Wed, 27 Jan 2016 00:45:48 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 05112F75; Wed, 27 Jan 2016 00:45:47 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0R0jlHW032754; Wed, 27 Jan 2016 00:45:47 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0R0jkfl032745; Wed, 27 Jan 2016 00:45:46 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201601270045.u0R0jkfl032745@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Wed, 27 Jan 2016 00:45:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294869 - in head: sys/dev/cxgbe/tom sys/netinet usr.bin/systat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jan 2016 00:45:48 -0000 Author: glebius Date: Wed Jan 27 00:45:46 2016 New Revision: 294869 URL: https://svnweb.freebsd.org/changeset/base/294869 Log: Augment struct tcpstat with tcps_states[], which is used for book-keeping the amount of TCP connections by state. Provides a cheap way to get connection count without traversing the whole pcb list. Sponsored by: Netflix Modified: head/sys/dev/cxgbe/tom/t4_cpl_io.c head/sys/netinet/tcp_offload.c head/sys/netinet/tcp_subr.c head/sys/netinet/tcp_syncache.c head/sys/netinet/tcp_timewait.c head/sys/netinet/tcp_usrreq.c head/sys/netinet/tcp_var.h head/usr.bin/systat/netstat.c Modified: head/sys/dev/cxgbe/tom/t4_cpl_io.c ============================================================================== --- head/sys/dev/cxgbe/tom/t4_cpl_io.c Wed Jan 27 00:24:24 2016 (r294868) +++ head/sys/dev/cxgbe/tom/t4_cpl_io.c Wed Jan 27 00:45:46 2016 (r294869) @@ -45,10 +45,10 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #define TCPSTATES #include #include +#include #include #include "common/common.h" Modified: head/sys/netinet/tcp_offload.c ============================================================================== --- head/sys/netinet/tcp_offload.c Wed Jan 27 00:24:24 2016 (r294868) +++ head/sys/netinet/tcp_offload.c Wed Jan 27 00:45:46 2016 (r294869) @@ -42,10 +42,10 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #define TCPOUTFLAGS #include +#include #include int registered_toedevs; Modified: head/sys/netinet/tcp_subr.c ============================================================================== --- head/sys/netinet/tcp_subr.c Wed Jan 27 00:24:24 2016 (r294868) +++ head/sys/netinet/tcp_subr.c Wed Jan 27 00:45:46 2016 (r294869) @@ -1468,6 +1468,7 @@ tcp_close(struct tcpcb *tp) #endif in_pcbdrop(inp); TCPSTAT_INC(tcps_closed); + TCPSTAT_DEC(tcps_states[tp->t_state]); KASSERT(inp->inp_socket != NULL, ("tcp_close: inp_socket NULL")); so = inp->inp_socket; soisdisconnected(so); @@ -2910,6 +2911,8 @@ tcp_state_change(struct tcpcb *tp, int n int pstate = tp->t_state; #endif + TCPSTAT_DEC(tcps_states[tp->t_state]); + TCPSTAT_INC(tcps_states[newstate]); tp->t_state = newstate; TCP_PROBE6(state__change, NULL, tp, NULL, tp, NULL, pstate); } Modified: head/sys/netinet/tcp_syncache.c ============================================================================== --- head/sys/netinet/tcp_syncache.c Wed Jan 27 00:24:24 2016 (r294868) +++ head/sys/netinet/tcp_syncache.c Wed Jan 27 00:45:46 2016 (r294869) @@ -351,6 +351,7 @@ syncache_insert(struct syncache *sc, str SCH_UNLOCK(sch); + TCPSTAT_INC(tcps_states[TCPS_SYN_RECEIVED]); TCPSTAT_INC(tcps_sc_added); } @@ -364,6 +365,7 @@ syncache_drop(struct syncache *sc, struc SCH_LOCK_ASSERT(sch); + TCPSTAT_DEC(tcps_states[TCPS_SYN_RECEIVED]); TAILQ_REMOVE(&sch->sch_bucket, sc, sc_hash); sch->sch_length--; @@ -992,7 +994,16 @@ syncache_expand(struct in_conninfo *inc, goto failed; } } else { - /* Pull out the entry to unlock the bucket row. */ + /* + * Pull out the entry to unlock the bucket row. + * + * NOTE: We must decrease TCPS_SYN_RECEIVED count here, not + * tcp_state_change(). The tcpcb is not existent at this + * moment. A new one will be allocated via syncache_socket-> + * sonewconn->tcp_usr_attach in TCPS_CLOSED state, then + * syncache_socket() will change it to TCPS_SYN_RECEIVED. + */ + TCPSTAT_DEC(tcps_states[TCPS_SYN_RECEIVED]); TAILQ_REMOVE(&sch->sch_bucket, sc, sc_hash); sch->sch_length--; #ifdef TCP_OFFLOAD Modified: head/sys/netinet/tcp_timewait.c ============================================================================== --- head/sys/netinet/tcp_timewait.c Wed Jan 27 00:24:24 2016 (r294868) +++ head/sys/netinet/tcp_timewait.c Wed Jan 27 00:45:46 2016 (r294869) @@ -660,6 +660,7 @@ tcp_tw_2msl_stop(struct tcptw *tw, int r if (!reuse) uma_zfree(V_tcptw_zone, tw); + TCPSTAT_DEC(tcps_states[TCPS_TIME_WAIT]); } struct tcptw * Modified: head/sys/netinet/tcp_usrreq.c ============================================================================== --- head/sys/netinet/tcp_usrreq.c Wed Jan 27 00:24:24 2016 (r294868) +++ head/sys/netinet/tcp_usrreq.c Wed Jan 27 00:45:46 2016 (r294869) @@ -1883,6 +1883,7 @@ tcp_attach(struct socket *so) tp->t_state = TCPS_CLOSED; INP_WUNLOCK(inp); INP_INFO_RUNLOCK(&V_tcbinfo); + TCPSTAT_INC(tcps_states[TCPS_CLOSED]); return (0); } Modified: head/sys/netinet/tcp_var.h ============================================================================== --- head/sys/netinet/tcp_var.h Wed Jan 27 00:24:24 2016 (r294868) +++ head/sys/netinet/tcp_var.h Wed Jan 27 00:45:46 2016 (r294869) @@ -34,6 +34,7 @@ #define _NETINET_TCP_VAR_H_ #include +#include #ifdef _KERNEL #include @@ -587,6 +588,9 @@ struct tcpstat { uint64_t tcps_sig_err_sigopt; /* No signature expected by socket */ uint64_t tcps_sig_err_nosigopt; /* No signature provided by segment */ + /* Running connection count. */ + uint64_t tcps_states[TCP_NSTATES]; + uint64_t _pad[12]; /* 6 UTO, 6 TBD */ }; Modified: head/usr.bin/systat/netstat.c ============================================================================== --- head/usr.bin/systat/netstat.c Wed Jan 27 00:24:24 2016 (r294868) +++ head/usr.bin/systat/netstat.c Wed Jan 27 00:45:46 2016 (r294869) @@ -59,10 +59,10 @@ static const char sccsid[] = "@(#)netsta #include #include #include -#include #define TCPSTATES #include #include +#include #include #include #include