All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] netpoll: Fix carrier_timeout for msleep()
@ 2021-10-11  8:57 Yajun Deng
  2021-10-12  0:11 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Yajun Deng @ 2021-10-11  8:57 UTC (permalink / raw)
  To: davem, kuba; +Cc: netdev, linux-kernel, Yajun Deng

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")
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 net/core/netpoll.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index edfc0f8011f8..88e4ff3b9e95 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -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();
 	}
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] netpoll: Fix carrier_timeout for msleep()
  2021-10-11  8:57 [PATCH net-next] netpoll: Fix carrier_timeout for msleep() Yajun Deng
@ 2021-10-12  0:11 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2021-10-12  0:11 UTC (permalink / raw)
  To: Yajun Deng; +Cc: davem, netdev, linux-kernel

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.

> 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")
> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-12  0:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-11  8:57 [PATCH net-next] netpoll: Fix carrier_timeout for msleep() Yajun Deng
2021-10-12  0:11 ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.