From: Yajun Deng <yajun.deng@linux.dev>
To: davem@davemloft.net, kuba@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Yajun Deng <yajun.deng@linux.dev>
Subject: [PATCH net-next] netpoll: Fix carrier_timeout for msleep()
Date: Mon, 11 Oct 2021 16:57:53 +0800 [thread overview]
Message-ID: <20211011085753.20706-1-yajun.deng@linux.dev> (raw)
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
next reply other threads:[~2021-10-11 8:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-11 8:57 Yajun Deng [this message]
2021-10-12 0:11 ` [PATCH net-next] netpoll: Fix carrier_timeout for msleep() Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211011085753.20706-1-yajun.deng@linux.dev \
--to=yajun.deng@linux.dev \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).