The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netiso/tp_timer.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: tp_timer.c,v 1.13 2003/08/07 16:33:42 agc Exp $        */
    2 
    3 /*-
    4  * Copyright (c) 1991, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)tp_timer.c  8.1 (Berkeley) 6/10/93
   32  */
   33 
   34 /***********************************************************
   35                 Copyright IBM Corporation 1987
   36 
   37                       All Rights Reserved
   38 
   39 Permission to use, copy, modify, and distribute this software and its
   40 documentation for any purpose and without fee is hereby granted,
   41 provided that the above copyright notice appear in all copies and that
   42 both that copyright notice and this permission notice appear in
   43 supporting documentation, and that the name of IBM not be
   44 used in advertising or publicity pertaining to distribution of the
   45 software without specific, written prior permission.
   46 
   47 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
   48 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
   49 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
   50 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
   51 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
   52 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
   53 SOFTWARE.
   54 
   55 ******************************************************************/
   56 
   57 /*
   58  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
   59  */
   60 
   61 #include <sys/cdefs.h>
   62 __KERNEL_RCSID(0, "$NetBSD: tp_timer.c,v 1.13 2003/08/07 16:33:42 agc Exp $");
   63 
   64 #include <sys/param.h>
   65 #include <sys/systm.h>
   66 #include <sys/time.h>
   67 #include <sys/malloc.h>
   68 #include <sys/protosw.h>
   69 #include <sys/socket.h>
   70 #include <sys/kernel.h>
   71 
   72 #include <netiso/argo_debug.h>
   73 #include <netiso/tp_param.h>
   74 #include <netiso/tp_timer.h>
   75 #include <netiso/tp_stat.h>
   76 #include <netiso/tp_pcb.h>
   77 #include <netiso/tp_tpdu.h>
   78 #include <netiso/tp_trace.h>
   79 #include <netiso/tp_seq.h>
   80 #include <netiso/tp_var.h>
   81 
   82 struct tp_ref  *tp_ref;
   83 int             tp_rttdiv, tp_rttadd, N_TPREF = 127;
   84 struct tp_refinfo tp_refinfo;
   85 struct tp_pcb  *tp_ftimeolist = (struct tp_pcb *) & tp_ftimeolist;
   86 
   87 /*
   88  * CALLED FROM:
   89  *  at autoconfig time from tp_init()
   90  *      a combo of event, state, predicate
   91  * FUNCTION and ARGUMENTS:
   92  *  initialize data structures for the timers
   93  */
   94 void
   95 tp_timerinit()
   96 {
   97         int    s;
   98         /*
   99          * Initialize storage
  100          */
  101         if (tp_refinfo.tpr_base)
  102                 return;
  103         tp_refinfo.tpr_size = N_TPREF + 1;      /* Need to start somewhere */
  104         s = sizeof(*tp_ref) * tp_refinfo.tpr_size;
  105         if ((tp_ref = (struct tp_ref *) malloc(s, M_PCB, M_NOWAIT)) == 0)
  106                 panic("tp_timerinit");
  107         bzero((caddr_t) tp_ref, (unsigned) s);
  108         tp_refinfo.tpr_base = tp_ref;
  109         tp_rttdiv = hz / PR_SLOWHZ;
  110         tp_rttadd = (2 * tp_rttdiv) - 1;
  111 }
  112 #ifdef TP_DEBUG_TIMERS
  113 /**********************  e timers *************************/
  114 
  115 /*
  116  * CALLED FROM:
  117  *  tp.trans all over
  118  * FUNCTION and ARGUMENTS:
  119  * Set an E type timer.
  120  */
  121 void
  122 tp_etimeout(tpcb, fun, ticks)
  123         struct tp_pcb *tpcb;
  124         int             fun;    /* function to be called */
  125         int             ticks;
  126 {
  127 
  128         u_int *callp;
  129 #ifdef ARGO_DEBUG
  130         if (argo_debug[D_TIMER]) {
  131                 printf("etimeout pcb %p state 0x%x\n", tpcb, tpcb->tp_state);
  132         }
  133 #endif
  134 #ifdef TPPT
  135         if (tp_traceflags[D_TIMER]) {
  136                 tptrace(TPPTmisc, "tp_etimeout ref refstate tks Etick", tpcb->tp_lref,
  137                         tpcb->tp_state, ticks, tp_stat.ts_Eticks);
  138         }
  139 #endif
  140         if (tpcb == 0)
  141                 return;
  142         IncStat(ts_Eset);
  143         if (ticks == 0)
  144                 ticks = 1;
  145         callp = tpcb->tp_timer + fun;
  146         if (*callp == 0 || *callp > ticks)
  147                 *callp = ticks;
  148 }
  149 
  150 /*
  151  * CALLED FROM:
  152  *  tp.trans all over
  153  * FUNCTION and ARGUMENTS:
  154  *  Cancel all occurrences of E-timer function (fun) for reference (refp)
  155  */
  156 void
  157 tp_euntimeout(tpcb, fun)
  158         struct tp_pcb *tpcb;
  159         int             fun;
  160 {
  161 #ifdef TPPT
  162         if (tp_traceflags[D_TIMER]) {
  163                 tptrace(TPPTmisc, "tp_euntimeout ref", tpcb->tp_lref, 0, 0, 0);
  164         }
  165 #endif
  166 
  167         if (tpcb)
  168                 tpcb->tp_timer[fun] = 0;
  169 }
  170 
  171 /****************  c timers **********************
  172  *
  173  * These are not chained together; they sit
  174  * in the tp_ref structure. they are the kind that
  175  * are typically cancelled so it's faster not to
  176  * mess with the chains
  177  */
  178 #endif
  179 /*
  180  * CALLED FROM:
  181  *  the clock, every 500 ms
  182  * FUNCTION and ARGUMENTS:
  183  *  Look for open references with active timers.
  184  *  If they exist, call the appropriate timer routines to update
  185  *  the timers and possibly generate events.
  186  */
  187 void
  188 tp_slowtimo()
  189 {
  190         u_int *cp;
  191         struct tp_ref *rp;
  192         struct tp_pcb  *tpcb;
  193         struct tp_event E;
  194         int             s = splsoftnet(), t;
  195 
  196         /* check only open reference structures */
  197         IncStat(ts_Cticks);
  198         /* tp_ref[0] is never used */
  199         for (rp = tp_ref + tp_refinfo.tpr_maxopen; rp > tp_ref; rp--) {
  200                 if ((tpcb = rp->tpr_pcb) == 0 || tpcb->tp_refstate < REF_OPEN)
  201                         continue;
  202                 /* check the timers */
  203                 for (t = 0; t < TM_NTIMERS; t++) {
  204                         cp = tpcb->tp_timer + t;
  205                         if (*cp && --(*cp) <= 0) {
  206                                 *cp = 0;
  207                                 E.ev_number = t;
  208 #ifdef ARGO_DEBUG
  209                                 if (argo_debug[D_TIMER]) {
  210                                         printf("tp_slowtimo: pcb %p t %d\n",
  211                                                tpcb, t);
  212                                 }
  213 #endif
  214                                 IncStat(ts_Cexpired);
  215                                 tp_driver(tpcb, &E);
  216                                 if (t == TM_reference && tpcb->tp_state == TP_CLOSED) {
  217                                         if (tpcb->tp_notdetached) {
  218 #ifdef ARGO_DEBUG
  219                                                 if (argo_debug[D_CONN]) {
  220                                                         printf("PRU_DETACH: not detached\n");
  221                                                 }
  222 #endif
  223                                                 tp_detach(tpcb);
  224                                         }
  225                                         /* XXX wart; where else to do it? */
  226                                         free((caddr_t) tpcb, M_PCB);
  227                                 }
  228                         }
  229                 }
  230         }
  231         splx(s);
  232 }
  233 
  234 /*
  235  * Called From: tp.trans from tp_slowtimo() -- retransmission timer went off.
  236  */
  237 void
  238 tp_data_retrans(tpcb)
  239         struct tp_pcb *tpcb;
  240 {
  241         int             rexmt, win;
  242         tpcb->tp_rttemit = 0;   /* cancel current round trip time */
  243         tpcb->tp_dupacks = 0;
  244         tpcb->tp_sndnxt = tpcb->tp_snduna;
  245         if (tpcb->tp_fcredit == 0) {
  246                 /*
  247                  * We transmitted new data, started timing it and the window
  248                  * got shrunk under us.  This can only happen if all data
  249                  * that they wanted us to send got acked, so don't
  250                  * bother shrinking the congestion windows, et. al.
  251                  * The retransmission timer should have been reset in goodack()
  252                  */
  253 #ifdef ARGO_DEBUG
  254                 if (argo_debug[D_ACKRECV]) {
  255                         printf("tp_data_retrans: 0 window tpcb %p una 0x%x\n",
  256                                tpcb, tpcb->tp_snduna);
  257                 }
  258 #endif
  259                 tpcb->tp_rxtshift = 0;
  260                 tpcb->tp_timer[TM_data_retrans] = 0;
  261                 tpcb->tp_timer[TM_sendack] = tpcb->tp_dt_ticks;
  262                 return;
  263         }
  264         rexmt = tpcb->tp_dt_ticks << min(tpcb->tp_rxtshift, TP_MAXRXTSHIFT);
  265         win = min(tpcb->tp_fcredit, (tpcb->tp_cong_win / tpcb->tp_l_tpdusize / 2));
  266         win = max(win, 2);
  267         tpcb->tp_cong_win = tpcb->tp_l_tpdusize;        /* slow start again. */
  268         tpcb->tp_ssthresh = win * tpcb->tp_l_tpdusize;
  269         /*
  270          * We're losing; our srtt estimate is probably bogus. Clobber it so
  271          * we'll take the next rtt measurement as our srtt; Maintain current
  272          * rxt times until then.
  273          */
  274         if (++tpcb->tp_rxtshift > TP_NRETRANS / 4) {
  275                 /* tpcb->tp_nlprotosw->nlp_losing(tpcb->tp_npcb) someday */
  276                 tpcb->tp_rtt = 0;
  277         }
  278         TP_RANGESET(tpcb->tp_rxtcur, rexmt, tpcb->tp_peer_acktime, 128);
  279         tpcb->tp_timer[TM_data_retrans] = tpcb->tp_rxtcur;
  280         tp_send(tpcb);
  281 }
  282 
  283 void
  284 tp_fasttimo()
  285 {
  286         struct tp_pcb *t;
  287         int             s = splsoftnet();
  288         struct tp_event E;
  289 
  290         E.ev_number = TM_sendack;
  291         while ((t = tp_ftimeolist) != (struct tp_pcb *) & tp_ftimeolist) {
  292                 if (t == 0) {
  293                         printf("tp_fasttimeo: should panic");
  294                         tp_ftimeolist = (struct tp_pcb *) & tp_ftimeolist;
  295                 } else {
  296                         if (t->tp_flags & TPF_DELACK) {
  297                                 IncStat(ts_Fdelack);
  298                                 tp_driver(t, &E);
  299                                 t->tp_flags &= ~TPF_DELACK;
  300                         } else
  301                                 IncStat(ts_Fpruned);
  302                         tp_ftimeolist = t->tp_fasttimeo;
  303                         t->tp_fasttimeo = 0;
  304                 }
  305         }
  306         splx(s);
  307 }
  308 
  309 #ifdef TP_DEBUG_TIMERS
  310 /*
  311  * CALLED FROM:
  312  *  tp.trans, tp_emit()
  313  * FUNCTION and ARGUMENTS:
  314  *      Set a C type timer of type (which) to go off after (ticks) time.
  315  */
  316 void
  317 tp_ctimeout(tpcb, which, ticks)
  318         struct tp_pcb *tpcb;
  319         int             which, ticks;
  320 {
  321 
  322 #ifdef TPPT
  323         if (tp_traceflags[D_TIMER]) {
  324                 tptrace(TPPTmisc, "tp_ctimeout ref which tpcb active",
  325                         tpcb->tp_lref, which, tpcb, tpcb->tp_timer[which]);
  326         }
  327 #endif
  328         if (tpcb->tp_timer[which])
  329                 IncStat(ts_Ccan_act);
  330         IncStat(ts_Cset);
  331         if (ticks <= 0)
  332                 ticks = 1;
  333         tpcb->tp_timer[which] = ticks;
  334 }
  335 
  336 /*
  337  * CALLED FROM:
  338  *  tp.trans
  339  * FUNCTION and ARGUMENTS:
  340  *      Version of tp_ctimeout that resets the C-type time if the
  341  *      parameter (ticks) is > the current value of the timer.
  342  */
  343 void
  344 tp_ctimeout_MIN(tpcb, which, ticks)
  345         struct tp_pcb *tpcb;
  346         int             which, ticks;
  347 {
  348 #ifdef TPPT
  349         if (tp_traceflags[D_TIMER]) {
  350                 tptrace(TPPTmisc, "tp_ctimeout_MIN ref which tpcb active",
  351                         tpcb->tp_lref, which, tpcb, tpcb->tp_timer[which]);
  352         }
  353 #endif
  354                 IncStat(ts_Cset);
  355         if (tpcb->tp_timer[which]) {
  356                 tpcb->tp_timer[which] = min(ticks, tpcb->tp_timer[which]);
  357                 IncStat(ts_Ccan_act);
  358         } else
  359                 tpcb->tp_timer[which] = ticks;
  360 }
  361 
  362 /*
  363  * CALLED FROM:
  364  *  tp.trans
  365  * FUNCTION and ARGUMENTS:
  366  *  Cancel the (which) timer in the ref structure indicated by (refp).
  367  */
  368 void
  369 tp_cuntimeout(tpcb, which)
  370         struct tp_pcb *tpcb;
  371         int             which;
  372 {
  373 #ifdef ARGO_DEBUG
  374         if (argo_debug[D_TIMER]) {
  375                 printf("tp_cuntimeout(%p, %d) active %d\n",
  376                        tpcb, which, tpcb->tp_timer[which]);
  377         }
  378 #endif
  379 
  380 #ifdef TPPT
  381         if (tp_traceflags[D_TIMER]) {
  382                 tptrace(TPPTmisc, "tp_cuntimeout ref which, active", refp - tp_ref,
  383                         which, tpcb->tp_timer[which], 0);
  384         }
  385 #endif
  386 
  387         if (tpcb->tp_timer[which])
  388                 IncStat(ts_Ccan_act);
  389         else
  390                 IncStat(ts_Ccan_inact);
  391         tpcb->tp_timer[which] = 0;
  392 }
  393 #endif

Cache object: 010fe81582cb8e9f79d9cf2b6766de15


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.