Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Use callouts for TCP timers, rather than travers...



details:   https://anonhg.NetBSD.org/src/rev/510f2aad42a3
branches:  trunk
changeset: 514805:510f2aad42a3
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Sep 10 22:14:26 2001 +0000

description:
Use callouts for TCP timers, rather than traversing the list of
all open TCP connections in tcp_slowtimo() (which is called 2x
per second).  It's fairly rare for TCP timers to actually fire,
so saving this list traversal is good, especially if you want
to scale to thousands of open connections.

diffstat:

 sys/netinet/tcp_input.c  |   3 +-
 sys/netinet/tcp_output.c |   3 +-
 sys/netinet/tcp_subr.c   |   3 +-
 sys/netinet/tcp_timer.c  |  82 +++++------------------------------------------
 sys/netinet/tcp_timer.h  |  22 +++++-------
 sys/netinet/tcp_var.h    |   4 +-
 6 files changed, 28 insertions(+), 89 deletions(-)

diffs (242 lines):

diff -r 3f6bd62b8b33 -r 510f2aad42a3 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c   Mon Sep 10 21:25:23 2001 +0000
+++ b/sys/netinet/tcp_input.c   Mon Sep 10 22:14:26 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_input.c,v 1.128 2001/09/10 15:23:09 thorpej Exp $  */
+/*     $NetBSD: tcp_input.c,v 1.129 2001/09/10 22:14:26 thorpej Exp $  */
 
 /*
 %%% portions-copyright-nrl-95
@@ -140,6 +140,7 @@
 #include <sys/syslog.h>
 #include <sys/pool.h>
 #include <sys/domain.h>
+#include <sys/kernel.h>
 
 #include <net/if.h>
 #include <net/route.h>
diff -r 3f6bd62b8b33 -r 510f2aad42a3 sys/netinet/tcp_output.c
--- a/sys/netinet/tcp_output.c  Mon Sep 10 21:25:23 2001 +0000
+++ b/sys/netinet/tcp_output.c  Mon Sep 10 22:14:26 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_output.c,v 1.73 2001/09/10 15:23:10 thorpej Exp $  */
+/*     $NetBSD: tcp_output.c,v 1.74 2001/09/10 22:14:27 thorpej Exp $  */
 
 /*
 %%% portions-copyright-nrl-95
@@ -127,6 +127,7 @@
 #include <sys/socketvar.h>
 #include <sys/errno.h>
 #include <sys/domain.h>
+#include <sys/kernel.h>
 
 #include <net/if.h>
 #include <net/route.h>
diff -r 3f6bd62b8b33 -r 510f2aad42a3 sys/netinet/tcp_subr.c
--- a/sys/netinet/tcp_subr.c    Mon Sep 10 21:25:23 2001 +0000
+++ b/sys/netinet/tcp_subr.c    Mon Sep 10 22:14:26 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_subr.c,v 1.117 2001/09/10 20:36:43 thorpej Exp $   */
+/*     $NetBSD: tcp_subr.c,v 1.118 2001/09/10 22:14:27 thorpej Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -1021,6 +1021,7 @@
        (void) tcp_freeq(tp);
        TCP_REASS_UNLOCK(tp);
 
+       tcp_canceltimers(tp);
        TCP_CLEAR_DELACK(tp);
        syn_cache_cleanup(tp);
 
diff -r 3f6bd62b8b33 -r 510f2aad42a3 sys/netinet/tcp_timer.c
--- a/sys/netinet/tcp_timer.c   Mon Sep 10 21:25:23 2001 +0000
+++ b/sys/netinet/tcp_timer.c   Mon Sep 10 22:14:26 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_timer.c,v 1.52 2001/09/10 20:36:43 thorpej Exp $   */
+/*     $NetBSD: tcp_timer.c,v 1.53 2001/09/10 22:14:28 thorpej Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -221,87 +221,17 @@
 void
 tcp_slowtimo()
 {
-       struct inpcb *inp, *ninp;
-       struct tcpcb *tp;
-#ifdef INET6
-       struct in6pcb *in6p, *nin6p;
-#endif
+       static int syn_cache_last = 0;
        int s;
-       long i;
-       static int syn_cache_last = 0;
-       int skip, mask;
-
-       skip = mask = 0;
 
        s = splsoftnet();
        tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
-       /*
-        * Search through tcb's and update active timers.
-        */
-       mask |= 1;
-       inp = tcbtable.inpt_queue.cqh_first;
-       if (inp == (struct inpcb *)0) {                         /* XXX */
-               skip |= 1;
-               goto dotcb6;
-       }
-       for (; inp != (struct inpcb *)&tcbtable.inpt_queue; inp = ninp) {
-               ninp = inp->inp_queue.cqe_next;
-               tp = intotcpcb(inp);
-               if (tp == 0 || tp->t_state == TCPS_LISTEN)
-                       continue;
-               for (i = 0; i < TCPT_NTIMERS; i++) {
-                       if (TCP_TIMER_ISEXPIRED(tp, i)) {
-                               TCP_TIMER_DISARM(tp, i);
-                               (*(tcp_timer_funcs[i]))(tp);
-                               /* XXX NOT MP SAFE */
-                               if ((ninp == (void *)&tcbtable.inpt_queue &&
-                                   tcbtable.inpt_queue.cqh_last != inp) ||
-                                   ninp->inp_queue.cqe_prev != inp)
-                                       goto tpgone;
-                       }
-               }
-tpgone:
-               ;
-       }
-dotcb6:
-#ifdef INET6
-       mask |= 2;
-       in6p = tcb6.in6p_next;
-       if (in6p == (struct in6pcb *)0) {                       /* XXX */
-               skip |= 2;
-               goto doiss;
-       }
-       for (; in6p != (struct in6pcb *)&tcb6; in6p = nin6p) {
-               nin6p = in6p->in6p_next;
-               tp = in6totcpcb(in6p);
-               if (tp == 0 || tp->t_state == TCPS_LISTEN)
-                       continue;
-               for (i = 0; i < TCPT_NTIMERS; i++) {
-                       if (TCP_TIMER_ISEXPIRED(tp, i)) {
-                               TCP_TIMER_DISARM(tp, i);
-                               (*(tcp_timer_funcs[i]))(tp);
-                               /* XXX NOT MP SAFE */
-                               if ((nin6p == (void *)&tcb6 &&
-                                   tcb6.in6p_prev != in6p) ||
-                                   nin6p->in6p_prev != in6p)
-                                       goto tp6gone;
-                       }
-               }
-tp6gone:
-               ;
-       }
-
-doiss:
-#endif
-       if (mask == skip)
-               goto done;
        tcp_iss_seq += TCP_ISSINCR;                     /* increment iss */
        tcp_now++;                                      /* for timestamps */
        if (++syn_cache_last >= tcp_syn_cache_interval) {
                syn_cache_timer();
                syn_cache_last = 0;
        }
-done:
        splx(s);
 }
 
@@ -340,6 +270,8 @@
 
        s = splsoftnet();
 
+       callout_deactivate(&tp->t_timer[TCPT_REXMT]);
+
 #ifdef TCP_DEBUG
 #ifdef INET
        if (tp->t_inpcb)
@@ -485,6 +417,8 @@
 
        s = splsoftnet();
 
+       callout_deactivate(&tp->t_timer[TCPT_PERSIST]);
+
 #ifdef INET
        if (tp->t_inpcb)
                so = tp->t_inpcb->inp_socket;
@@ -547,6 +481,8 @@
 
        s = splsoftnet();
 
+       callout_deactivate(&tp->t_timer[TCPT_KEEP]);
+
 #ifdef TCP_DEBUG
        ostate = tp->t_state;
 #endif /* TCP_DEBUG */
@@ -629,6 +565,8 @@
 
        s = splsoftnet();
 
+       callout_deactivate(&tp->t_timer[TCPT_2MSL]);
+
 #ifdef INET
        if (tp->t_inpcb)
                so = tp->t_inpcb->inp_socket;
diff -r 3f6bd62b8b33 -r 510f2aad42a3 sys/netinet/tcp_timer.h
--- a/sys/netinet/tcp_timer.h   Mon Sep 10 21:25:23 2001 +0000
+++ b/sys/netinet/tcp_timer.h   Mon Sep 10 22:14:26 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_timer.h,v 1.14 2001/09/10 20:36:43 thorpej Exp $   */
+/*     $NetBSD: tcp_timer.h,v 1.15 2001/09/10 22:14:28 thorpej Exp $   */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -118,20 +118,18 @@
 /*
  * Init, arm, disarm, and test TCP timers.
  */
-#define        TCP_TIMER_INIT(tp, timer) \
-       /* Nothing. */
-
-#define        TCP_TIMER_ARM(tp, timer, nticks) \
-       PRT_SLOW_ARM((tp)->t_timer[(timer)], (nticks))
+#define        TCP_TIMER_INIT(tp, timer)                                       \
+       callout_init(&(tp)->t_timer[(timer)])
 
-#define        TCP_TIMER_DISARM(tp, timer) \
-       PRT_SLOW_DISARM((tp)->t_timer[(timer)])
+#define        TCP_TIMER_ARM(tp, timer, nticks)                                \
+       callout_reset(&(tp)->t_timer[(timer)],                          \
+           (nticks) * (hz / PR_SLOWHZ), tcp_timer_funcs[(timer)], tp)
 
-#define        TCP_TIMER_ISARMED(tp, timer) \
-       PRT_SLOW_ISARMED((tp)->t_timer[(timer)])
+#define        TCP_TIMER_DISARM(tp, timer)                                     \
+       callout_stop(&(tp)->t_timer[(timer)])
 
-#define        TCP_TIMER_ISEXPIRED(tp, timer) \
-       PRT_SLOW_ISEXPIRED((tp)->t_timer[(timer)])
+#define        TCP_TIMER_ISARMED(tp, timer)                                    \
+       callout_active(&(tp)->t_timer[(timer)])
 
 /*
  * Force a time value to be in a certain range.
diff -r 3f6bd62b8b33 -r 510f2aad42a3 sys/netinet/tcp_var.h
--- a/sys/netinet/tcp_var.h     Mon Sep 10 21:25:23 2001 +0000
+++ b/sys/netinet/tcp_var.h     Mon Sep 10 22:14:26 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_var.h,v 1.85 2001/09/10 20:15:15 thorpej Exp $     */
+/*     $NetBSD: tcp_var.h,v 1.86 2001/09/10 22:14:28 thorpej Exp $     */
 
 /*
 %%% portions-copyright-nrl-98
@@ -133,7 +133,7 @@
 struct tcpcb {
        int     t_family;               /* address family on the wire */
        struct ipqehead segq;           /* sequencing queue */
-       u_int   t_timer[TCPT_NTIMERS];  /* tcp timers */
+       struct callout t_timer[TCPT_NTIMERS];/* tcp timers */
        short   t_state;                /* state of this connection */
        short   t_rxtshift;             /* log(2) of rexmt exp. backoff */
        uint32_t t_rxtcur;              /* current retransmit value */



Home | Main Index | Thread Index | Old Index