Skip to contentSkip to conversation

netpoll: Fix carrier_timeout for msleep()

PATCH In review Yajun Deng 2 participants 2 messages Oct 11, 2021 – Oct 12, 2021

Subsystems (2)
lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH 1/1 netpoll: Fix carrier_timeout for msleep()

It should be sleep carrier_timeout seconds rather than 4 seconds if carrier_timeout has been modified.
Add start variable, hence atleast and atmost use the same jiffies, and use msecs_to_jiffies() and MSEC_PER_SEC match with jiffies. At the same time, msleep() is not for 1ms - 20ms, use usleep_range() instead, see Documentation/timers/timers-howto.rst.

Fixes bff38771e106 ("netpoll: Introduce netpoll_carrier_timeout kernel option")
---
 net/core/netpoll.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
net/core/netpoll.c +8 -6
index edfc0f8011f8..88e4ff3b9e95 100644
@@ -682,7 +682,7 @@ int netpoll_setup(struct netpoll *np)
 	}
 
 	if (!netif_running(ndev)) {
-		unsigned long atmost, atleast;
+		unsigned long atmost, atleast, start;
 
 		np_info(np, "device %s not up yet, forcing it\n", np->dev_name);
 
@@ -694,14 +694,15 @@ int netpoll_setup(struct netpoll *np)
 		}
 
 		rtnl_unlock();
-		atleast = jiffies + HZ/10;
-		atmost = jiffies + carrier_timeout * HZ;
+		start = jiffies;
+		atleast = start + msecs_to_jiffies(MSEC_PER_SEC / 10);
+		atmost = start + msecs_to_jiffies(carrier_timeout * MSEC_PER_SEC);
 		while (!netif_carrier_ok(ndev)) {
 			if (time_after(jiffies, atmost)) {
 				np_notice(np, "timeout waiting for carrier\n");
 				break;
 			}
-			msleep(1);
+			usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC);
 		}
 
 		/* If carrier appears to come up instantly, we don't
@@ -710,8 +711,9 @@ int netpoll_setup(struct netpoll *np)
 		 */
 
 		if (time_before(jiffies, atleast)) {
-			np_notice(np, "carrier detect appears untrustworthy, waiting 4 seconds\n");
-			msleep(4000);
+			np_notice(np, "carrier detect appears untrustworthy, waiting %d seconds\n",
+				  carrier_timeout);
+			msleep(carrier_timeout * MSEC_PER_SEC);
 		}
 		rtnl_lock();
 	}
Signature · 1 line
2.32.0
maintainer
#1 lore raw
Quoted 2 lines · On Mon, 11 Oct 2021 16:57:53 +0800 Yajun Deng wrote:

It should be sleep carrier_timeout seconds rather than 4 seconds if carrier_timeout has been modified.

carrier_timeout is for changing the upper bound of the wait, not for controlling how long to wait if carrier is untrustworthy.

Quoted 7 lines

Add start variable, hence atleast and atmost use the same jiffies, and use msecs_to_jiffies() and MSEC_PER_SEC match with jiffies. At the same time, msleep() is not for 1ms - 20ms, use usleep_range() instead, see Documentation/timers/timers-howto.rst.

Fixes bff38771e106 ("netpoll: Introduce netpoll_carrier_timeout kernel option")