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: 13426993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 376F4CDB482 for ; Wed, 18 Oct 2023 12:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=d9vV/w9Fz+9jaquDjdA7tyyEX4ns/k1zxyzdj4nbPc8=; b=4WjvLMISHqf8KG Pm0mv6YLcWX9jCNTOiWLzmyWa/jkBqBbUfC70Rspgok2i2Tis8Hfbnr2crGBtIFYzB1RV34vrdpBw yKuCLdDL0UJUNzwGoJ5Kt9zB24OjYf017/2+BJ0UHA5oHBja7Y3x9JiHC1BrKxDErknT36Ko3QmiA uvM8RtcPmyc6hDakJtU3ifxeM0AydSiNX4x2rlIVS6NHzH4+So3qSw1WyL3Y5f3Fbi2q1ItY7xwiQ acivcV+ZmZYQODs3MQrImNRhiECmaFBuLuGGWYlwmKkuoBj8dyzLrtW+dupDujO9yeUfE+90zc3HN XJ6qa4UpuEhnRs79461A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qt5mW-00Efjy-0z; Wed, 18 Oct 2023 12:36:12 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qt5mP-00Efe5-2h for linux-arm-kernel@lists.infradead.org; Wed, 18 Oct 2023 12:36:07 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40790b0a224so14960585e9.0 for ; Wed, 18 Oct 2023 05:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697632563; x=1698237363; darn=lists.infradead.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=COjzchPNOEQXcpN5RLvYRdoxR5DgBivjvS1e+yodUQ6cfjSoXGk+vkOnpWCnU8tKRN AkqtK7i6DWkgXoQyVh1B/1cseBPBuV8WSgib4YsVYjD3FM6zkHWwAlwyapoGMo1n2G+m 7GK3BNxfnn/47EdyDROWf2IfFSfEv88QLXaYqiROCBkdtEjM4u6QnziHLf42WY8SIWpU g7i79zIEHh9Zo26D4hUnZM6wKe66PMGmoeEEGRJg9lFLNZm7gvYBlUs/T+XwWZ8WkzdA sPgQ0MySNIqGVBbGuWjVc3I7sZouIKVwoN3YAB11TtrA9MxgqjB2hZsGG33Rw3Kl8BLh hzQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697632563; x=1698237363; 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=OS13DGP2qubcnSwL8BUSEh2xFZq/JrEdWk+4f9dfOa6ZypianYiP75vqT4PIT9+Ps4 j5//a855mXyhXPZlYZ6SYCyG7yggSo0pdeepKAyhz0/fFGwDxCcjZODKehWSjfBx2xzo iZioArRHqL9BMGYNkYDvFbpsVwSkZ6E35iVF9CyY3jhAVEMtikV7yFrsIxXPpzFC1eh5 X6/PtdCB1b7sB3sulU9XJR1+snZvVWhe9IPFM6giCmgDBUfQhGr9PhPhD32hVodMp0KV 88M/CXIL73IufyT+wJl+Ie6CXtaLX360thhn13uubD9CqD3PIZIeebVZzI+hLA5i7F+1 sSKQ== X-Gm-Message-State: AOJu0Yw6UEnftGVWsYKNnLL6A1OLgzlN7tHkMchcn7fvyT0c6NVmNhY/ 3U3FHGouYsbPqvMInc+wJbY= X-Google-Smtp-Source: AGHT+IHYxeHjCIR/FT2JDqNfUwmEd2G8A/49wx/hETYLT6M/03g9TnduO1+10bkcfRpmv5Wp7ErFMw== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231018_053605_874810_05D0F656 X-CRM114-Status: GOOD ( 19.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); }