* Copyright (c) 1991 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)tp_timer.c 7.5 (Berkeley) 5/6/91
/***********************************************************
Copyright IBM Corporation 1987
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
******************************************************************/
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
* $Header: tp_timer.c,v 5.2 88/11/18 17:29:07 nhall Exp $
* $Source: /usr/argo/sys/netiso/RCS/tp_timer.c,v $
* Contains all the timer code.
* There are two sources of calls to these routines:
* the clock, and tp.trans. (ok, and tp_pcb.c calls it at init time)
* Timers come in two flavors - those that generally get
* cancelled (tp_ctimeout, tp_cuntimeout)
* and those that either usually expire (tp_etimeout,
* tp_euntimeout, tp_slowtimo) or may require more than one instance
* of the timer active at a time.
* The C timers are stored in the tp_ref structure. Their "going off"
* is manifested by a driver event of the TM_xxx form.
* The E timers are handled like the generic kernel callouts.
* Their "going off" is manifested by a function call w/ 3 arguments.
struct Ecallout
*TP_callfree
;
struct Ecallout
*TP_callout
;
extern int tp_maxrefopen
; /* highest ref # of an open tp connection */
* at autoconfig time from tp_init()
* a combo of event, state, predicate
* FUNCTION and ARGUMENTS:
* initialize data structures for the timers
register struct Ecallout
*e
;
#define GETME(x, t, n) {s = (n)*sizeof(*x); x = (t) malloc(s, M_PCB, M_NOWAIT);\
if (x == 0) panic("tp_timerinit"); bzero((caddr_t)x, s);}
GETME(TP_callout
, struct Ecallout
*, 2 * N_TPREF
);
GETME(tp_ref
, struct tp_ref
*, 1 + N_TPREF
);
TP_callfree
= TP_callout
+ ((2 * N_TPREF
) - 1);
for (e
= TP_callfree
; e
> TP_callout
; e
--)
/* hate to do this but we really don't want zero to be a legit ref */
tp_ref
[0].tpr_state
= REF_FROZEN
; /* white lie -- no ref timer, don't
* want this one to be allocated- ever
* unless, of course, you make refs and address instead of an
* index - then 0 can be allocated
/********************** e timers *************************/
* tp_slowtimo() every 1/2 second, for each open reference
* FUNCTION and ARGUMENTS:
* (refp) indicates a reference structure that is in use.
* This ref structure may contain active E-type timers.
* Update the timers and if any expire, create an event and
struct tp_ref
*refp
; /* the reference structure */
register struct Ecallout
*p1
; /* to drift through the list of callouts */
struct tp_event E
; /* event to pass to tp_driver() */
int tp_driver(); /* drives the FSM */
* Update real-time timeout queue.
* At front of queue are some number of events which are ``due''.
* The time to these is <= 0 and if negative represents the
* number of ticks which have passed since it was supposed to happen.
* The rest of the q elements (times > 0) are events yet to happen,
* where the time for each is given as a delta from the previous.
* Decrementing just the first of these serves to decrement the time
* This version, which calls the driver directly, doesn't pass
* along the ticks - may want to add the ticks if there's any use
p1
= refp
->tpr_calltodo
.c_next
;
if ((p1
= refp
->tpr_calltodo
.c_next
) == 0 || p1
->c_time
> 0) {
refp
->tpr_calltodo
.c_next
= p1
->c_next
;
p1
->c_next
= TP_callfree
;
E
.ev_number
= p1
->c_func
;
E
.ATTR(TM_data_retrans
).e_low
= (SeqNum
) p1
->c_arg1
;
E
.ATTR(TM_data_retrans
).e_high
= (SeqNum
) p1
->c_arg2
;
E
.ATTR(TM_data_retrans
).e_retrans
= p1
->c_arg3
;
printf("E expired! event 0x%x (0x%x,0x%x), pcb 0x%x ref %d\n",
p1
->c_func
, p1
->c_arg1
, p1
->c_arg2
, refp
->tpr_pcb
,
(void) tp_driver( tpcb
= refp
->tpr_pcb
, &E
);
if (p1
->c_func
== TM_reference
&& tpcb
->tp_state
== TP_CLOSED
)
free((caddr_t
)tpcb
, M_PCB
); /* XXX wart; where else to do it? */
* FUNCTION and ARGUMENTS:
* Set an E type timer. (refp) is the ref structure.
* Causes fun(arg1,arg2,arg3) to be called after time t.
tp_etimeout(refp
, fun
, arg1
, arg2
, arg3
, ticks
)
int fun
; /* function to be called */
register struct Ecallout
*p1
, *p2
, *pnew
;
/* p1 and p2 drift through the list of timeout callout structures,
* pnew points to the newly created callout structure
printf("etimeout pcb 0x%x state 0x%x\n", refp
->tpr_pcb
,
refp
->tpr_pcb
->tp_state
);
tptrace(TPPTmisc
, "tp_etimeout ref refstate tks Etick", refp
-tp_ref
,
refp
->tpr_state
, ticks
, tp_stat
.ts_Eticks
);
if (pnew
== (struct Ecallout
*)0)
panic("tp timeout table overflow");
TP_callfree
= pnew
->c_next
;
for (p1
= &(refp
->tpr_calltodo
);
(p2
= p1
->c_next
) && p2
->c_time
< ticks
; p1
= p2
)
* FUNCTION and ARGUMENTS:
* Cancel all occurrences of E-timer function (fun) for reference (refp)
register struct Ecallout
*p1
, *p2
; /* ptrs to drift through the list */
tptrace(TPPTmisc
, "tp_euntimeout ref", refp
-tp_ref
, 0, 0, 0);
p1
= &refp
->tpr_calltodo
;
while ( (p2
= p1
->c_next
) != 0) {
if (p2
->c_next
&& p2
->c_time
> 0)
p2
->c_next
->c_time
+= p2
->c_time
;
p2
->c_next
= TP_callfree
;
* tp.trans, when an incoming ACK causes things to be dropped
* from the retransmission queue, and we want their associated
* timers to be cancelled.
* FUNCTION and ARGUMENTS:
* cancel all occurrences of function (fun) where (arg2) < (seq)
tp_euntimeout_lss(refp
, fun
, seq
)
register struct Ecallout
*p1
, *p2
;
tptrace(TPPTmisc
, "tp_euntimeoutLSS ref", refp
-tp_ref
, seq
, 0, 0);
p1
= &refp
->tpr_calltodo
;
while ( (p2
= p1
->c_next
) != 0) {
if ((p2
->c_func
== fun
) && SEQ_LT(refp
->tpr_pcb
, p2
->c_arg2
, seq
)) {
if (p2
->c_next
&& p2
->c_time
> 0)
p2
->c_next
->c_time
+= p2
->c_time
;
p2
->c_next
= TP_callfree
;
/**************** c timers **********************
* These are not chained together; they sit
* in the tp_ref structure. they are the kind that
* are typically cancelled so it's faster not to
* the clock, every 500 ms
* FUNCTION and ARGUMENTS:
* Look for open references with active timers.
* If they exist, call the appropriate timer routines to update
* the timers and possibly generate events.
* (The E timers are done in other procedures; the C timers are
* updated here, and events for them are generated here.)
struct tp_ref
*rp
= tp_ref
;
/* check only open reference structures */
rp
++; /* tp_ref[0] is never used */
for( r
=1 ; (r
<= tp_maxrefopen
) ; r
++,rp
++ ) {
if (rp
->tpr_state
< REF_OPEN
)
/* check the C-type timers */
for (t
=0 ; t
< N_CTIMERS
; t
++,cp
++) {
if( --cp
->c_time
<= 0 ) {
printf("C expired! type 0x%x\n", t
);
tp_driver( rp
->tpr_pcb
, &E
);
/* now update the list */
* FUNCTION and ARGUMENTS:
* Set a C type timer of type (which) to go off after (ticks) time.
tp_ctimeout(refp
, which
, ticks
)
register struct tp_ref
*refp
;
register struct Ccallout
*cp
= &(refp
->tpr_callout
[which
]);
tptrace(TPPTmisc
, "tp_ctimeout ref which tpcb active",
(int)(refp
- tp_ref
), which
, refp
->tpr_pcb
, cp
->c_active
);
* FUNCTION and ARGUMENTS:
* Version of tp_ctimeout that resets the C-type time if the
* parameter (ticks) is > the current value of the timer.
tp_ctimeout_MIN(refp
, which
, ticks
)
register struct tp_ref
*refp
;
register struct Ccallout
*cp
= &(refp
->tpr_callout
[which
]);
tptrace(TPPTmisc
, "tp_ctimeout_MIN ref which tpcb active",
(int)(refp
- tp_ref
), which
, refp
->tpr_pcb
, cp
->c_active
);
cp
->c_time
= MIN(ticks
, cp
->c_time
);
* FUNCTION and ARGUMENTS:
* Cancel the (which) timer in the ref structure indicated by (refp).
tp_cuntimeout(refp
, which
)
register struct tp_ref
*refp
;
register struct Ccallout
*cp
;
cp
= &(refp
->tpr_callout
[which
]);
printf("tp_cuntimeout(0x%x, %d) active %d\n", refp
, which
, cp
->c_active
);
tptrace(TPPTmisc
, "tp_cuntimeout ref which, active", refp
-tp_ref
,