summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2016-01-27 00:45:46 +0000
committerglebius <glebius@FreeBSD.org>2016-01-27 00:45:46 +0000
commit9487eaf98f45a433931bad91a3463694f5423688 (patch)
treedd0b39d31460d52fec634711ce845f26d7406828
parent1a12f8d9a17a94b40aad848fb3fa61b3f0eb1acf (diff)
downloadFreeBSD-src-9487eaf98f45a433931bad91a3463694f5423688.zip
FreeBSD-src-9487eaf98f45a433931bad91a3463694f5423688.tar.gz
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
-rw-r--r--sys/dev/cxgbe/tom/t4_cpl_io.c2
-rw-r--r--sys/netinet/tcp_offload.c2
-rw-r--r--sys/netinet/tcp_subr.c3
-rw-r--r--sys/netinet/tcp_syncache.c13
-rw-r--r--sys/netinet/tcp_timewait.c1
-rw-r--r--sys/netinet/tcp_usrreq.c1
-rw-r--r--sys/netinet/tcp_var.h4
-rw-r--r--usr.bin/systat/netstat.c2
8 files changed, 24 insertions, 4 deletions
diff --git a/sys/dev/cxgbe/tom/t4_cpl_io.c b/sys/dev/cxgbe/tom/t4_cpl_io.c
index f18f115..43e4d611 100644
--- a/sys/dev/cxgbe/tom/t4_cpl_io.c
+++ b/sys/dev/cxgbe/tom/t4_cpl_io.c
@@ -45,10 +45,10 @@ __FBSDID("$FreeBSD$");
#include <netinet/in_pcb.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
-#include <netinet/tcp_var.h>
#define TCPSTATES
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_seq.h>
+#include <netinet/tcp_var.h>
#include <netinet/toecore.h>
#include "common/common.h"
diff --git a/sys/netinet/tcp_offload.c b/sys/netinet/tcp_offload.c
index 683e212..60fd7e9 100644
--- a/sys/netinet/tcp_offload.c
+++ b/sys/netinet/tcp_offload.c
@@ -42,10 +42,10 @@ __FBSDID("$FreeBSD$");
#include <netinet/in.h>
#include <netinet/in_pcb.h>
#include <netinet/tcp.h>
-#include <netinet/tcp_var.h>
#include <netinet/tcp_offload.h>
#define TCPOUTFLAGS
#include <netinet/tcp_fsm.h>
+#include <netinet/tcp_var.h>
#include <netinet/toecore.h>
int registered_toedevs;
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 6358e81..b16f540 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -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 newstate)
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);
}
diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c
index 940d3de..45e00e9 100644
--- a/sys/netinet/tcp_syncache.c
+++ b/sys/netinet/tcp_syncache.c
@@ -351,6 +351,7 @@ syncache_insert(struct syncache *sc, struct syncache_head *sch)
SCH_UNLOCK(sch);
+ TCPSTAT_INC(tcps_states[TCPS_SYN_RECEIVED]);
TCPSTAT_INC(tcps_sc_added);
}
@@ -364,6 +365,7 @@ syncache_drop(struct syncache *sc, struct syncache_head *sch)
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, struct tcpopt *to, struct tcphdr *th,
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
diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c
index 4685fe7..c98de24 100644
--- a/sys/netinet/tcp_timewait.c
+++ b/sys/netinet/tcp_timewait.c
@@ -660,6 +660,7 @@ tcp_tw_2msl_stop(struct tcptw *tw, int reuse)
if (!reuse)
uma_zfree(V_tcptw_zone, tw);
+ TCPSTAT_DEC(tcps_states[TCPS_TIME_WAIT]);
}
struct tcptw *
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 4b3150b..0a87a62 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -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);
}
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 4712c6b..32aa0bb 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -34,6 +34,7 @@
#define _NETINET_TCP_VAR_H_
#include <netinet/tcp.h>
+#include <netinet/tcp_fsm.h>
#ifdef _KERNEL
#include <net/vnet.h>
@@ -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 */
};
diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c
index 3f994e8..56bc34e 100644
--- a/usr.bin/systat/netstat.c
+++ b/usr.bin/systat/netstat.c
@@ -59,10 +59,10 @@ static const char sccsid[] = "@(#)netstat.c 8.1 (Berkeley) 6/6/93";
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include <netinet/tcp_seq.h>
-#include <netinet/tcp_var.h>
#define TCPSTATES
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
#include <netinet/tcp_debug.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
OpenPOWER on IntegriCloud