From patchwork Wed Oct 18 12:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 154862 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4756892vqb; Wed, 18 Oct 2023 05:36:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBZQ7brs0D7A3/TxEey4nvm2DMAubfrAqQGOy94aioZVzcfScEBb1CIVHzzLEOAZ6WJdQC X-Received: by 2002:a9d:6853:0:b0:6c4:7516:f2cf with SMTP id c19-20020a9d6853000000b006c47516f2cfmr5175074oto.2.1697632580866; Wed, 18 Oct 2023 05:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697632580; cv=none; d=google.com; s=arc-20160816; b=GiHur62vL+bwHf0Ifvn81pZGBsObiWF3QX4T6PSYDtQlxNU1usK3hy8JaV6LZ7dKvE jODCaov41fvz9BYiXCxKZsayt9VQRxBrsNf+MysPDEXzwFOP4rMl2WJD1xYhYLIjKQDn 8UpeZTDKsqD0gQHw2G5bhRxFk9oyqjjLQgoR+RvOigRPjuYCzH5x1IGgNDhRBdluQdDI A5p8+Xcauwi1/1Yq5UHJSsWpCJgB9kuVYLqFKhDJkem11Ch66DnNlAC1lpqz/pOugfq0 E99LYp7bGW6anE7ik4v8mIpQwymUrsJfy5FOia9elN1LF62xzrAgg885/isoQSFzerAN m1YA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0v0ZmldTmEHElH0nzfPoImpxhHxc/jfxnYXGlHkEaSw=; fh=jvZ7yAidasmFREPdFLzcn6X72yjJtrVlKHskOtM6Gso=; b=GF7QRRO0MfJTCduohTjE98yu8H9wTVy6K3gRn//Tvm06ZYy7rN4iF7WHNWbP4hN3k5 KBfX2LebZ6P7kpKAx8cQmBx5ZKquuiYjHpRLmdqCCUSsaK0DDMxAclaAz8PYBc/s2Qfx cI3CcXQMg6Ln67aYV7UfF3WmKkJ0yjnQky8aOOa0y+FS5CGQmM2DY5kVMlKq1s5WCoUd 1sjMRhvBENDg/wlHjVO0CdJPL1N8CxOqLkZllR/EUKIE6vCwB/J5K/KdWekjLHQW9nok U85TwwUhZPZQL4S6F5CB/KLIhNaGHPLwkrblbxvoY7tM5z6F3bDI6/y9MorxPzMbPjlf EGgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="P/FnAP9A"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d189-20020a6336c6000000b005b5c68e2c92si2085666pga.371.2023.10.18.05.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 05:36:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="P/FnAP9A"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 65CCF80D5856; Wed, 18 Oct 2023 05:36:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235146AbjJRMgH (ORCPT + 23 others); Wed, 18 Oct 2023 08:36:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234927AbjJRMgC (ORCPT ); Wed, 18 Oct 2023 08:36:02 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AC35114; Wed, 18 Oct 2023 05:36:00 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4083cd39188so4660215e9.2; Wed, 18 Oct 2023 05:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697632558; x=1698237358; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0v0ZmldTmEHElH0nzfPoImpxhHxc/jfxnYXGlHkEaSw=; b=P/FnAP9ANfmDDxex6pXE8sdpnuIA4RjlogwtL6Ul37mnpF5bcN8VE6D1bXHGPoU/OC XPpRFIMlnIOzYWN9j2OU0uqXtjcRwG7gNyQqdIkstfJs2yS77OGXs1gJlPfSwdQ61o24 JUGwhY8GK9AtKTosNTe5c2gD0y5wTekNzzRLKQjEgsLEd0dKBgRlN0Szp9tyV4IXTqHG bdtJwW+YKtP4YeEoA7v5khVhlS12LQG0ELO+kLVXCANJyWW44L8dMHL6uZbM7nLYVLvR ZL+kwYh8I84WS9ed2GWAlAZFr782nQrj5p9WlP7rRa99+1Is/0ptvQqyOao4PrQyt0Ne PrzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697632558; x=1698237358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0v0ZmldTmEHElH0nzfPoImpxhHxc/jfxnYXGlHkEaSw=; b=Ls/g2JXAAXVTqVAt3lnqRZZMMjtBZ7MXNOq59r+ZUbnaRlsnCF4tsyLqJxQYOo8Gkt E5BaZDV4/Iye9ss41ZVqLpwJEBKwoV8JbKqY1oRXn9M9EZRPGjE6E3sDfpxKSAjR/Sbp Qab6QlRUcTTxaOASJDygBW6OEanyNqzPMvJ+40s7fM0XZA4LSFBdhhlTwneoyhj4xR8m 15eramOofmJouBpxd/yyyBJXykAH/2pPvI3X1l/2Ucbc6DCb2AS6MVabUV1Srasot1st iP+fQDCNiXF8OE/lOvJNrC9BbCLeR84yvO/iOLfdebbvgS9E5vBlGdKzk5DFUgyF4O47 QvtQ== X-Gm-Message-State: AOJu0Yy12u167d84IWg6WHdqe6wX6KbJqb+KqzEuLhG4mdvKaPP4mstq /SmkREEnguTtCv5DZBrjoy3qQzEcwrU= X-Received: by 2002:a05:600c:3511:b0:404:72fe:ed5c with SMTP id h17-20020a05600c351100b0040472feed5cmr4380670wmq.29.1697632558280; Wed, 18 Oct 2023 05:35:58 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id q28-20020adfab1c000000b003248a490e3asm2048211wrc.39.2023.10.18.05.35.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 05:35:57 -0700 (PDT) From: Christian Marangi To: Raju Rangoju , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Ping-Ke Shih , Kalle Valo , Simon Horman , Daniel Borkmann , Jiri Pirko , Hangbin Liu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-wireless@vger.kernel.org Cc: Christian Marangi Subject: [net-next PATCH v4 1/4] net: introduce napi_is_scheduled helper Date: Wed, 18 Oct 2023 14:35:47 +0200 Message-Id: <20231018123550.27110-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231018123550.27110-1-ansuelsmth@gmail.com> References: <20231018123550.27110-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 18 Oct 2023 05:36:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780096780991606110 X-GMAIL-MSGID: 1780096780991606110 We currently have napi_if_scheduled_mark_missed that can be used to check if napi is scheduled but that does more thing than simply checking it and return a bool. Some driver already implement custom function to check if napi is scheduled. Drop these custom function and introduce napi_is_scheduled that simply check if napi is scheduled atomically. Update any driver and code that implement a similar check and instead use this new helper. Signed-off-by: Christian Marangi --- drivers/net/ethernet/chelsio/cxgb3/sge.c | 8 -------- drivers/net/wireless/realtek/rtw89/core.c | 2 +- include/linux/netdevice.h | 23 +++++++++++++++++++++++ net/core/dev.c | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c index 2e9a74fe0970..71fa2dc19034 100644 --- a/drivers/net/ethernet/chelsio/cxgb3/sge.c +++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c @@ -2501,14 +2501,6 @@ static int napi_rx_handler(struct napi_struct *napi, int budget) return work_done; } -/* - * Returns true if the device is already scheduled for polling. - */ -static inline int napi_is_scheduled(struct napi_struct *napi) -{ - return test_bit(NAPI_STATE_SCHED, &napi->state); -} - /** * process_pure_responses - process pure responses from a response queue * @adap: the adapter diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c index cca18d7ea1dd..6faf4dcf007c 100644 --- a/drivers/net/wireless/realtek/rtw89/core.c +++ b/drivers/net/wireless/realtek/rtw89/core.c @@ -1919,7 +1919,7 @@ static void rtw89_core_rx_to_mac80211(struct rtw89_dev *rtwdev, struct napi_struct *napi = &rtwdev->napi; /* In low power mode, napi isn't scheduled. Receive it to netif. */ - if (unlikely(!test_bit(NAPI_STATE_SCHED, &napi->state))) + if (unlikely(!napi_is_scheduled(napi))) napi = NULL; rtw89_core_hw_to_sband_rate(rx_status); diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 1c7681263d30..b8bf669212cc 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -482,6 +482,29 @@ static inline bool napi_prefer_busy_poll(struct napi_struct *n) return test_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state); } +/** + * napi_is_scheduled - test if NAPI is scheduled + * @n: NAPI context + * + * This check is "best-effort". With no locking implemented, + * a NAPI can be scheduled or terminate right after this check + * and produce not precise results. + * + * NAPI_STATE_SCHED is an internal state, napi_is_scheduled + * should not be used normally and napi_schedule should be + * used instead. + * + * Use only if the driver really needs to check if a NAPI + * is scheduled for example in the context of delayed timer + * that can be skipped if a NAPI is already scheduled. + * + * Return True if NAPI is scheduled, False otherwise. + */ +static inline bool napi_is_scheduled(struct napi_struct *n) +{ + return test_bit(NAPI_STATE_SCHED, &n->state); +} + bool napi_schedule_prep(struct napi_struct *n); /** diff --git a/net/core/dev.c b/net/core/dev.c index 3ca746a5f0ad..8d267fc0b988 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6527,7 +6527,7 @@ static int __napi_poll(struct napi_struct *n, bool *repoll) * accidentally calling ->poll() when NAPI is not scheduled. */ work = 0; - if (test_bit(NAPI_STATE_SCHED, &n->state)) { + if (napi_is_scheduled(n)) { work = n->poll(n, weight); trace_napi_poll(n, work, weight); }