diff mbox series

[net-next] netpoll: Fix carrier_timeout for msleep()

Message ID 20211011085753.20706-1-yajun.deng@linux.dev (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series [net-next] netpoll: Fix carrier_timeout for msleep() | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers fail 1 blamed authors not CCed: avorontsov@ru.mvista.com; 5 maintainers not CCed: arnd@arndb.de avorontsov@ru.mvista.com wander@redhat.com f.fainelli@gmail.com vladimir.oltean@nxp.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Fixes tag looks correct
netdev/checkpatch warning WARNING: 'atleast' may be misspelled - perhaps 'at least'? WARNING: line length of 82 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Yajun Deng Oct. 11, 2021, 8:57 a.m. UTC
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(-)

Comments

Jakub Kicinski Oct. 12, 2021, 12:11 a.m. UTC | #1
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>
diff mbox series

Patch

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();
 	}