Data Structures | Defines | Functions | Variables
retry.h File Reference

Retry timers. More...

#include <ipxe/list.h>

Go to the source code of this file.

Data Structures

struct  retry_timer
 A retry timer. More...


 Default minimum timeout value (in ticks)
 Default maximum timeout value (in ticks)
#define TIMER_INIT(expired_fn)


static __attribute__ ((always_inline)) void timer_init(struct retry_timer *timer
 Initialise a timer.
void start_timer_fixed (struct retry_timer *timer, unsigned long timeout)
 Start timer with a specified timeout.
void stop_timer (struct retry_timer *timer)
 Stop timer.
void retry_poll (void)
 Poll the retry timer list.
static void start_timer_nodelay (struct retry_timer *timer)
 Start timer with no delay.


static void(* expired )(struct retry_timer *timer, int over)
static unsigned long min

Detailed Description

Retry timers.

Definition in file retry.h.

Define Documentation


Default minimum timeout value (in ticks)

Definition at line 15 of file retry.h.

Referenced by start_timer().


Default maximum timeout value (in ticks)

Definition at line 18 of file retry.h.

Referenced by timer_expired().

#define TIMER_INIT (   expired_fn)
{                       \
                .expired = (expired_fn),                \

Function Documentation

static __attribute__ ( (always_inline)  ) [inline, static]

Initialise a timer.

Set minimum and maximum timeouts.

Test to see if timer is currently running.

timerRetry timer
expiredTimer expired callback
refcntReference counter, or NULL
timerRetry timer
Return values:
runningNon-zero if timer is running
timerRetry timer
minMinimum timeout (in ticks), or zero to use default
maxMaximum timeout (in ticks), or zero to use default
void start_timer_fixed ( struct retry_timer timer,
unsigned long  timeout 
) [read]

Start timer with a specified timeout.

timerRetry timer
timeoutTimeout, in ticks

This starts the timer running with the specified timeout value. If stop_timer() is not called before the timer expires, the timer will be stopped and the timer's callback function will be called.

Definition at line 64 of file retry.c.

References currticks(), DBGC2, retry_timer::list, list_add, ref_get, retry_timer::refcnt, retry_timer::running, retry_timer::start, retry_timer::timeout, and timeout().

Referenced by dhcp_discovery_expired(), efi_watchdog_expired(), exanic_expired(), exanic_open(), fc_link_err(), fc_link_expired(), fc_xchg_rx(), fc_xchg_tx(), fcoe_expired(), fragment_reassemble(), http_transfer_complete(), netdev_link_block(), peerblk_open(), peerblk_raw_open(), peerblk_raw_rx(), peerblk_retrieval_open(), peerblk_retrieval_rx(), peerdisc_expired(), pinger_expired(), pool_add(), sandev_command(), slam_mc_socket_deliver(), slam_open(), start_timer(), start_timer_nodelay(), tcp_keepalive_expired(), tcp_rx(), tcp_rx_ack(), xcm_keepalive(), xcm_reopen(), xsigo_discover(), xsigo_ib_open(), and xsigo_xcm_complete().


        /* Add to list of running timers (if applicable) */
        if ( ! timer->running ) {
                list_add ( &timer->list, &timers );
                ref_get ( timer->refcnt );
                timer->running = 1;

        /* Record start time */
        timer->start = currticks();

        /* Record timeout */
        timer->timeout = timeout;

        DBGC2 ( timer, "Timer %p started at time %ld (expires at %ld)\n",
                timer, timer->start, ( timer->start + timer->timeout ) );
void stop_timer ( struct retry_timer timer)

Stop timer.

timerRetry timer

This stops the timer and updates the timer's timeout value.

Definition at line 117 of file retry.c.

References retry_timer::count, currticks(), DBGC, DBGC2, retry_timer::list, list_del, ref_put, retry_timer::refcnt, retry_timer::running, retry_timer::start, and retry_timer::timeout.

Referenced by aoecmd_close(), dhcp_finished(), dhcp_set_state(), dhcpv6_finished(), dns_done(), dns_xfer_deliver(), efi_watchdog_stop(), exanic_close(), fc_link_stop(), fc_link_up(), fc_xchg_close(), fcoe_close(), fcoe_expired(), fcoe_reset(), fragment_reassemble(), free_netdev(), http_close(), ib_destroy_madx(), ipv6conf_done(), ipv6conf_rx_router_advertisement(), neighbour_destroy(), neighbour_discovered(), netdev_link_err(), netdev_link_unblock(), ntp_close(), peerblk_reset(), peerblk_retrieval_close(), peerdisc_destroy(), pinger_close(), pool_del(), sandev_command_close(), slam_finished(), slam_mc_socket_deliver(), slam_socket_deliver(), tcp_close(), tcp_rx(), tcp_rx_ack(), tftp_done(), tftp_send_packet(), xcm_close(), xcm_destroy(), xcm_reopen(), xsigo_ib_notify(), and xsigo_ib_remove().

        unsigned long old_timeout = timer->timeout;
        unsigned long now = currticks();
        unsigned long runtime;

        /* If timer was already stopped, do nothing */
        if ( ! timer->running )

        list_del ( &timer->list );
        runtime = ( now - timer->start );
        timer->running = 0;
        DBGC2 ( timer, "Timer %p stopped at time %ld (ran for %ld)\n",
                timer, now, runtime );

        /* Update timer.  Variables are:
         *   r = round-trip time estimate (i.e. runtime)
         *   t = timeout value (i.e. timer->timeout)
         *   s = smoothed round-trip time
         * By choice, we set t = 4s, i.e. allow for four times the
         * normal round-trip time to pass before retransmitting.
         * We want to smooth according to s := ( 7 s + r ) / 8
         * Since we don't actually store s, this reduces to
         * t := ( 7 t / 8 ) + ( r / 2 )
        if ( timer->count ) {
        } else {
                timer->timeout -= ( timer->timeout >> 3 );
                timer->timeout += ( runtime >> 1 );
                if ( timer->timeout != old_timeout ) {
                        DBGC ( timer, "Timer %p timeout updated to %ld\n",
                               timer, timer->timeout );

        ref_put ( timer->refcnt );
void retry_poll ( void  )

Poll the retry timer list.

Definition at line 197 of file retry.c.

References currticks(), retry_timer::list, list_for_each_entry, retry_timer::start, retry_timer::timeout, timer, and timer_expired().

Referenced by eoib_poll(), ipoib_poll(), and retry_step().

        struct retry_timer *timer;
        unsigned long now = currticks();
        unsigned long used;

        /* Process at most one timer expiry.  We cannot process
         * multiple expiries in one pass, because one timer expiring
         * may end up triggering another timer's deletion from the
         * list.
        list_for_each_entry ( timer, &timers, list ) {
                used = ( now - timer->start );
                if ( used >= timer->timeout ) {
                        timer_expired ( timer );
static void start_timer_nodelay ( struct retry_timer timer) [inline, static]

Variable Documentation

void( * expired)(struct retry_timer *timer, int over)

Definition at line 71 of file retry.h.

unsigned long min

Definition at line 122 of file retry.h.