ソースを参照

[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年前
コミット
ff2b6a512d
4個のファイルの変更37行の追加13行の削除
  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 ファイルの表示

@@ -466,6 +466,10 @@ struct dhcphdr {
466 466
 /** Maximum time that we will wait for ProxyDHCP responses */
467 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 473
 /** Settings block name used for DHCP responses */
470 474
 #define DHCP_SETTINGS_NAME "dhcp"
471 475
 

+ 16
- 0
src/include/gpxe/retry.h ファイルの表示

@@ -9,12 +9,28 @@
9 9
 
10 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 18
 /** A retry timer */
13 19
 struct retry_timer {
14 20
 	/** List of active timers */
15 21
 	struct list_head list;
16 22
 	/** Timeout value (in ticks) */
17 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 34
 	/** Start time (in ticks)
19 35
 	 *
20 36
 	 * A start time of zero indicates a stopped timer.

+ 15
- 13
src/net/retry.c ファイルの表示

@@ -36,20 +36,11 @@
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 39
 /* The theoretical minimum that the algorithm in stop_timer() can
46 40
  * adjust the timeout back down to is seven ticks, so set the minimum
47 41
  * timeout to at least that value for the sake of consistency.
48 42
  */
49
-#if MIN_TIMEOUT < 7
50
-#undef MIN_TIMEOUT
51 43
 #define MIN_TIMEOUT 7
52
-#endif
53 44
 
54 45
 /** List of running timers */
55 46
 static LIST_HEAD ( timers );
@@ -67,8 +58,17 @@ void start_timer ( struct retry_timer *timer ) {
67 58
 	if ( ! timer_running ( timer ) )
68 59
 		list_add ( &timer->list, &timers );
69 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 72
 	DBG2 ( "Timer %p started at time %ld (expires at %ld)\n",
73 73
 	       timer, timer->start, ( timer->start + timer->timeout ) );
74 74
 }
@@ -150,8 +150,10 @@ static void timer_expired ( struct retry_timer *timer ) {
150 150
 
151 151
 	/* Back off the timeout value */
152 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 157
 	DBG ( "Timer %p timeout backed off to %ld\n",
156 158
 	      timer, timer->timeout );
157 159
 

+ 2
- 0
src/net/udp/dhcp.c ファイルの表示

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

読み込み中…
キャンセル
保存