Browse Source

[retry] Added configurable timeouts to retry timer

New min_timeout and max_timeout fields in struct retry_timer allow
users of this timer to set their own desired minimum and maximum
timeouts, without being constrained to a single global minimum and
maximum. Users of the timer can still elect to use the default global
values by leaving the min_timeout and max_timeout fields as 0.
tags/v0.9.4
Andrew Schran 16 years ago
parent
commit
ff2b6a512d
4 changed files with 37 additions and 13 deletions
  1. 4
    0
      src/include/gpxe/dhcp.h
  2. 16
    0
      src/include/gpxe/retry.h
  3. 15
    13
      src/net/retry.c
  4. 2
    0
      src/net/udp/dhcp.c

+ 4
- 0
src/include/gpxe/dhcp.h View File

466
 /** Maximum time that we will wait for ProxyDHCP responses */
466
 /** Maximum time that we will wait for ProxyDHCP responses */
467
 #define PROXYDHCP_WAIT_TIME ( TICKS_PER_SEC * 1 )
467
 #define PROXYDHCP_WAIT_TIME ( TICKS_PER_SEC * 1 )
468
 
468
 
469
+/** Timeouts for sending DHCP packets */
470
+#define DHCP_MIN_TIMEOUT ( 1 * TICKS_PER_SEC )
471
+#define DHCP_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
472
+
469
 /** Settings block name used for DHCP responses */
473
 /** Settings block name used for DHCP responses */
470
 #define DHCP_SETTINGS_NAME "dhcp"
474
 #define DHCP_SETTINGS_NAME "dhcp"
471
 
475
 

+ 16
- 0
src/include/gpxe/retry.h View File

9
 
9
 
10
 #include <gpxe/list.h>
10
 #include <gpxe/list.h>
11
 
11
 
12
+/** Default timeout value */
13
+#define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
14
+
15
+/** Limit after which the timeout will be deemed permanent */
16
+#define DEFAULT_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
17
+
12
 /** A retry timer */
18
 /** A retry timer */
13
 struct retry_timer {
19
 struct retry_timer {
14
 	/** List of active timers */
20
 	/** List of active timers */
15
 	struct list_head list;
21
 	struct list_head list;
16
 	/** Timeout value (in ticks) */
22
 	/** Timeout value (in ticks) */
17
 	unsigned long timeout;
23
 	unsigned long timeout;
24
+	/** Minimum timeout value (in ticks)
25
+	 *
26
+	 * A value of zero means "use default timeout."
27
+	 */
28
+	unsigned long min_timeout;
29
+	/** Maximum timeout value before failure (in ticks)
30
+	 *
31
+	 * A value of zero means "use default timeout."
32
+	 */
33
+	unsigned long max_timeout;
18
 	/** Start time (in ticks)
34
 	/** Start time (in ticks)
19
 	 *
35
 	 *
20
 	 * A start time of zero indicates a stopped timer.
36
 	 * A start time of zero indicates a stopped timer.

+ 15
- 13
src/net/retry.c View File

36
  * 
36
  * 
37
  */
37
  */
38
 
38
 
39
-/** Default timeout value */
40
-#define MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
41
-
42
-/** Limit after which the timeout will be deemed permanent */
43
-#define MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
44
-
45
 /* The theoretical minimum that the algorithm in stop_timer() can
39
 /* The theoretical minimum that the algorithm in stop_timer() can
46
  * adjust the timeout back down to is seven ticks, so set the minimum
40
  * adjust the timeout back down to is seven ticks, so set the minimum
47
  * timeout to at least that value for the sake of consistency.
41
  * timeout to at least that value for the sake of consistency.
48
  */
42
  */
49
-#if MIN_TIMEOUT < 7
50
-#undef MIN_TIMEOUT
51
 #define MIN_TIMEOUT 7
43
 #define MIN_TIMEOUT 7
52
-#endif
53
 
44
 
54
 /** List of running timers */
45
 /** List of running timers */
55
 static LIST_HEAD ( timers );
46
 static LIST_HEAD ( timers );
67
 	if ( ! timer_running ( timer ) )
58
 	if ( ! timer_running ( timer ) )
68
 		list_add ( &timer->list, &timers );
59
 		list_add ( &timer->list, &timers );
69
 	timer->start = currticks();
60
 	timer->start = currticks();
70
-	if ( timer->timeout < MIN_TIMEOUT )
71
-		timer->timeout = MIN_TIMEOUT;
61
+
62
+	/* 0 means "use default timeout" */
63
+	if ( timer->min_timeout == 0 )
64
+		timer->min_timeout = DEFAULT_MIN_TIMEOUT;
65
+	/* We must never be less than MIN_TIMEOUT under any circumstances */
66
+	if ( timer->min_timeout < MIN_TIMEOUT )
67
+		timer->min_timeout = MIN_TIMEOUT;
68
+	/* Honor user-specified minimum timeout */
69
+	if ( timer->timeout < timer->min_timeout )
70
+		timer->timeout = timer->min_timeout;
71
+
72
 	DBG2 ( "Timer %p started at time %ld (expires at %ld)\n",
72
 	DBG2 ( "Timer %p started at time %ld (expires at %ld)\n",
73
 	       timer, timer->start, ( timer->start + timer->timeout ) );
73
 	       timer, timer->start, ( timer->start + timer->timeout ) );
74
 }
74
 }
150
 
150
 
151
 	/* Back off the timeout value */
151
 	/* Back off the timeout value */
152
 	timer->timeout <<= 1;
152
 	timer->timeout <<= 1;
153
-	if ( ( fail = ( timer->timeout > MAX_TIMEOUT ) ) )
154
-		timer->timeout = MAX_TIMEOUT;
153
+	if ( timer->max_timeout == 0 ) /* 0 means "use default timeout" */
154
+		timer->max_timeout = DEFAULT_MAX_TIMEOUT;
155
+	if ( ( fail = ( timer->timeout > timer->max_timeout ) ) )
156
+		timer->timeout = timer->max_timeout;
155
 	DBG ( "Timer %p timeout backed off to %ld\n",
157
 	DBG ( "Timer %p timeout backed off to %ld\n",
156
 	      timer, timer->timeout );
158
 	      timer, timer->timeout );
157
 
159
 

+ 2
- 0
src/net/udp/dhcp.c View File

1059
 	xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
1059
 	xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
1060
 	dhcp->netdev = netdev_get ( netdev );
1060
 	dhcp->netdev = netdev_get ( netdev );
1061
 	dhcp->timer.expired = dhcp_timer_expired;
1061
 	dhcp->timer.expired = dhcp_timer_expired;
1062
+	dhcp->timer.min_timeout = DHCP_MIN_TIMEOUT;
1063
+	dhcp->timer.max_timeout = DHCP_MAX_TIMEOUT;
1062
 	dhcp->start = currticks();
1064
 	dhcp->start = currticks();
1063
 
1065
 
1064
 	/* Instantiate child objects and attach to our interfaces */
1066
 	/* Instantiate child objects and attach to our interfaces */

Loading…
Cancel
Save