Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1454654pxb; Mon, 11 Oct 2021 06:26:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZYFSBH6CbzH/lUa4HnJqSwiF29hOSqoaCLu802CtRI0Cxords0VeEsAyRPZ8NMqGS+xET X-Received: by 2002:a17:906:1755:: with SMTP id d21mr26306285eje.257.1633958773837; Mon, 11 Oct 2021 06:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633958773; cv=none; d=google.com; s=arc-20160816; b=t6vIcMkMJPIHU9yUru+U6UoWaAj6ZRdTlghaAUoeYA6PJAKvPAYdRjDX9QT+QeEENV t4KV25Ui9OP1WEoL2w7ZV1Lu76sOcgJ8izAJ6Xqw5vLDT6NBSfE9u4kNyXmmMzT2ChIG 8Maa022URZXVOixZRk9/OyuZf8TbVlibfQ8+Bq/dBzDiBbH/YpW3SAWb69rxZePRiYxf DFuFk1kDGiKw9NqGQwoRs/wuEQVuFdOzBI8JSRiB+Vq5lRM8VrHkA6+wosQjJPc3DgMQ yqcpHtoe9caCXuLIRdteVxxGZ9kssthGibjfe5WcI3gjJshV22/AshUOaKQbIcase2su lMeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=NLXZ7qe2WI7jiN6OL9JMvA8o04nmr0kltNqfWaB2bOM=; b=gABuUo0ssMvKs4rD84K27UjamURMY8uLEDPfpKhTsli7g/uXczKspizlNtlUB0pUnc XA+c3d2sWYsFRQTfQa1oht5gYfpPWSQG3lvF5SNsqCOjGY8cuj6uceRsO0rVeWyEXET4 rA/pHueYMNUF4OH3LjxnoObSB7i6CGrpmfBpL0cLfpB7RfxHmx+RyCOsxP90MkPbx0xt o4FYW+QbG12WXsIV68H8DVBvbGXPPVgQMdEQs1Q9jf4F2fzOYyDqMYbDxAM5zM4a4C3s bUvKIwS5zMIe70I7OsubIg0aDMWYzx4q06I6moewFixsURxGjJhLlK+EPCWtMp85I9Bb U2ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QbGMZ8sF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l21si12733312edw.448.2021.10.11.06.25.50; Mon, 11 Oct 2021 06:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QbGMZ8sF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235321AbhJKJAL (ORCPT + 99 others); Mon, 11 Oct 2021 05:00:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235241AbhJKJAL (ORCPT ); Mon, 11 Oct 2021 05:00:11 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B5DC061570 for ; Mon, 11 Oct 2021 01:58:10 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1633942689; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=NLXZ7qe2WI7jiN6OL9JMvA8o04nmr0kltNqfWaB2bOM=; b=QbGMZ8sF2pnEozrhe6cnvISmp2a9lssITo8OIczbEKFpTFn8D9Og8UYNxrzXA0hBORq8t2 guTeDVdHA/Wt6+XcjcozyHnjZV8Z8dxVlXvImXXl9YJ+BZpwnrrLdasPXulajPDFAclglP YPhFzsma2ot5bGp7TZptZ5ZYrtMf8w0= From: Yajun Deng To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH net-next] netpoll: Fix carrier_timeout for msleep() Date: Mon, 11 Oct 2021 16:57:53 +0800 Message-Id: <20211011085753.20706-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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