From patchwork Thu Oct 12 10:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13418797 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 6F822CDB46E for ; Thu, 12 Oct 2023 10:09:17 +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=mFLR8KyVyiqHWIqwJPAZzm6LKe0uyP1BEzZ1USgWofU=; b=ZThNAbPGfqOokB aNt7DUnQ/7KNK5LvfvbuU9bygKa+Ghh6Gf79wEEIRT2DXgEM8AuxGD+RSzhNqe5N0lCxyz+6mWF8V pnIUmU94Xzxjhaf4/eTnfBqwsnjnURVEY151rryz5NFd7lFoDIxUCsjAZ+LZszgKjqproWConOyfq BErQCavgEF9OOn89JsoXuKwz/0WnWDc255xmuLfwNIKzHvJz2KhADfyDqpg1962NuBlaT7h3mPEAF c1OY2iRRtM9od81r5UFgwzJsVhxCcZtHCKH9QPSQzNqrwS6VvJ7bL7ZHq19vJvfSrUaFeWqXvhnY7 ZGnEonVBDkB3uo4FVqMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqscY-000X62-1I; Thu, 12 Oct 2023 10:08:46 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqscR-000Wyp-09 for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2023 10:08:40 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-32483535e51so761557f8f.0 for ; Thu, 12 Oct 2023 03:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697105317; x=1697710117; 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=uMV6knP2vLu/vHdHEBOSBg5/6andL2RYQDxRoSzD5RA=; b=Ab19EA7sve7d/j9raHxoyqUdSlUFEdQRu7b4q0w6KRW1ry9dpz7wXvcwR84bhCCwqn 48nAHfqlJFuuiE7fFqXyFXKZ/Xr/ERu/WvAU2qfs3cZ8w8+bUVr9ODWlb8t3igZCMFVl cMh8ckTeWSPdztVZbNWB6c85DrQYCprqCSoz4/Y+X2hgNjO4pwBncTiLCmATZ+EXBhgK xEclz7hn8oKqJKuglaxiZ1f6aZWU89Z3Bv+WcwsgGR8aAisYbwaK0ZV7CtW4r/Ai1mWQ ct1eIVcuDtziZwiq1bjuy5h2yCatGE2gFeqVH62zJgQTNzZknRpQOUOifAxhCqKUzAad XDKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697105317; x=1697710117; 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=uMV6knP2vLu/vHdHEBOSBg5/6andL2RYQDxRoSzD5RA=; b=SWBDcX2W+301seYEoPJJPTwAUFnr71jBKuwuqAwERBs9CrYc7pLH/2A20EiiFUZ4e5 3zKXUG1bqKuEnGt/w+rAd95Id9sWYXZ+oCg425hiju4AJDzd26f6rQTCtbDVNFlvFlaA UNJ1snMrN9AFdgmAaUJ9DIubbEAzlGs/FZ4N9hfS5bStOx9YP2uDe2ME/IeksOVS+ZgI 9IgxG2P8fdFc6ugYKynVIyNPj1uKsmBskKwq2NRAGRIsi4UhMXIRgo8VUJRZW6mdkJYv XdIJr+smNsdr/6QQRJBwtmGvoeqa3DD73JIjpHhcUJD/oj+TVhC4/RDdd0+JZgsipDuo tFqQ== X-Gm-Message-State: AOJu0YxxSohPaa4vvHJ6MzrRi0ULHzwQzI8V1AaDqy3OPzQeIK1KARZ/ 5IVTs+NlKUKKsMSFZj6Q/Hs= X-Google-Smtp-Source: AGHT+IFjKjcTaHf2NJ6N29120b+8wBoJ+W6K+tl9kn9/Z768BH9cEbvLUKjARc7MjgjfPGjGv95C4A== X-Received: by 2002:adf:e8ca:0:b0:324:7a6b:d504 with SMTP id k10-20020adfe8ca000000b003247a6bd504mr23080121wrn.4.1697105316670; Thu, 12 Oct 2023 03:08:36 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id dj16-20020a0560000b1000b003198a9d758dsm922737wrb.78.2023.10.12.03.08.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 03:08:36 -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 v2 1/4] net: introduce napi_is_scheduled helper Date: Thu, 12 Oct 2023 12:04:56 +0200 Message-Id: <20231012100459.6158-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231012100459.6158-1-ansuelsmth@gmail.com> References: <20231012100459.6158-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231012_030839_082690_31734CF5 X-CRM114-Status: GOOD ( 19.44 ) 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 ae553f886796..ad75875a854d 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 02949a929e7f..c2ec535bc9b4 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6523,7 +6523,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); } From patchwork Thu Oct 12 10:04:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13418798 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 2AB4ACDB483 for ; Thu, 12 Oct 2023 10:09:18 +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=3xRVVi68y+GNNSBzQLzVelki3ki1lYmnNmGkMDBbgds=; b=lJ2IWqHubXr48R 4O/CjL8fG1ZzAhZMb41dNgIe2zVUsdlY8UH4bbD7tAyvYUINvsmJqU2l4uOCjmLoQXhL6y33hrcwu pBtdasetb+muIDywhvh+yrzVmlxSX5Fum7t+xRPmstZ4f1WEt7poUTrtdlCKGvD/Zv7FXyHvOjcdx pCvxIjRFMBQcCNSlXh+lBuhDfu4d6kHZAfZIxBO11xFF2ZQgS+1nudxrUjp6fZhoRSTGWXqntUEGL V5EkMpQduPkWXoc6cuFNhTwoeOwCjMJGWxkhR9kKnMig9wFGRG+iMRcaQ3JeGiaNKqsI9Ng3u8Uoc VlP/3PbENrpyPP1Y4uZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqscZ-000X6l-0H; Thu, 12 Oct 2023 10:08:47 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqscS-000Wzi-0p for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2023 10:08:41 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-32d569e73acso748535f8f.1 for ; Thu, 12 Oct 2023 03:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697105318; x=1697710118; 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=zIsjeim7XUbQUze6bD56uxG9gvOx0giE5m3S+sNf+CI=; b=KtB2s+tv0/EuIJ6oQ+Lb3/J4/33KZPaWoY5OYPpnxL+drOfXLCeoVTrBLLSEY/JBGt UKZcHP0uDi0aqwuqK75gjpSujsKa/NR0ihqquzc2zETma1MEueEAv5z9GD2nA6EtenWe yq029DiVPdIn5aykbhFoj4H1gAbOz8dWoqrmiAq5+/P4UNGYbyEMXNuhFNHmec5VmxHl mcCxjhlOjRbgPe5KTgYz+OHGNGn3zQg1Y7er7V8pyYddTzOl1xIrKfLHovlo8LJhh0ta FvH+RiX6HCW/mBHT7/zCHBGuRYg9l1PGxbzYADCv/Ib1K+gFogkwKCcmRIJgRHiAu7+a oCSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697105318; x=1697710118; 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=zIsjeim7XUbQUze6bD56uxG9gvOx0giE5m3S+sNf+CI=; b=lVxsT5hvFf4k/07XNfjZQHWvBBf/8mJO4WncGz+1QiPE01jAEWAPxbCIHANi9oMqt5 q8MZAazHk86Iy4+60PLXbqihA4oXJDIwhDn4ClOG6TzHQzH7WKkrzOb0KcYULyIkf4GQ sCM6uDnt3a6DKhhot3mlA1ZSSoLbw1lzQzxPj6hZzp4KbCJiuMUMB8Kkiei3yn90mdTU efYyVO30PqZIJcr+1BFpw+4fR/JD+GIuUllf1E+57ghEkpI/C3oVeI5KOxZO3ML1yfND vwqVtKM5PS9zh9fhrmQVKCYB5D1FuiUlrylVZFWR8F0ErO/6ipV07L3lg4z+AGOJmhvd kncw== X-Gm-Message-State: AOJu0YzSCpevu8+nHHBxr5fkDV+O/3ctCkV2O2YCXV3zVSZ2wR/KHt6t vQfqZpYy14C8nHMh/0lPKAo= X-Google-Smtp-Source: AGHT+IHpdKVnN91CglYdASUt5zwHQXrdDBnHHb+85IX/ZvGINItZUurXQ7kVAD8loaEYbKmTZ81veA== X-Received: by 2002:a05:6000:4e1:b0:31f:ea18:6f6b with SMTP id cr1-20020a05600004e100b0031fea186f6bmr20124897wrb.19.1697105317932; Thu, 12 Oct 2023 03:08:37 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id dj16-20020a0560000b1000b003198a9d758dsm922737wrb.78.2023.10.12.03.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 03:08:37 -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 v2 2/4] net: stmmac: improve TX timer arm logic Date: Thu, 12 Oct 2023 12:04:57 +0200 Message-Id: <20231012100459.6158-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231012100459.6158-1-ansuelsmth@gmail.com> References: <20231012100459.6158-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231012_030840_294835_AC5C7297 X-CRM114-Status: GOOD ( 21.32 ) 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 There is currently a problem with the TX timer getting armed multiple unnecessary times causing big performance regression on some device that suffer from heavy handling of hrtimer rearm. The use of the TX timer is an old implementation that predates the napi implementation and the interrupt enable/disable handling. Due to stmmac being a very old code, the TX timer was never evaluated again with this new implementation and was kept there causing performance regression. The performance regression started to appear with kernel version 4.19 with 8fce33317023 ("net: stmmac: Rework coalesce timer and fix multi-queue races") where the timer was reduced to 1ms causing it to be armed 40 times more than before. Decreasing the timer made the problem more present and caused the regression in the other of 600-700mbps on some device (regression where this was notice is ipq806x). The problem is in the fact that handling the hrtimer on some target is expensive and recent kernel made the timer armed much more times. A solution that was proposed was reverting the hrtimer change and use mod_timer but such solution would still hide the real problem in the current implementation. To fix the regression, apply some additional logic and skip arming the timer when not needed. Arm the timer ONLY if a napi is not already scheduled. Running the timer is redundant since the same function (stmmac_tx_clean) will run in the napi TX poll. Also try to cancel any timer if a napi is scheduled to prevent redundant run of TX call. With the following new logic the original performance are restored while keeping using the hrtimer. Signed-off-by: Christian Marangi --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index bb1dbf4c9f6c..5124ee87286c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2996,13 +2996,25 @@ static void stmmac_tx_timer_arm(struct stmmac_priv *priv, u32 queue) { struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue]; u32 tx_coal_timer = priv->tx_coal_timer[queue]; + struct stmmac_channel *ch; + struct napi_struct *napi; if (!tx_coal_timer) return; - hrtimer_start(&tx_q->txtimer, - STMMAC_COAL_TIMER(tx_coal_timer), - HRTIMER_MODE_REL); + ch = &priv->channel[tx_q->queue_index]; + napi = tx_q->xsk_pool ? &ch->rxtx_napi : &ch->tx_napi; + + /* Arm timer only if napi is not already scheduled. + * Try to cancel any timer if napi is scheduled, timer will be armed + * again in the next scheduled napi. + */ + if (unlikely(!napi_is_scheduled(napi))) + hrtimer_start(&tx_q->txtimer, + STMMAC_COAL_TIMER(tx_coal_timer), + HRTIMER_MODE_REL); + else + hrtimer_try_to_cancel(&tx_q->txtimer); } /** From patchwork Thu Oct 12 10:04:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13418796 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 1F082CDB482 for ; Thu, 12 Oct 2023 10:09:15 +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=szc2n1ig7oAgNRLvpJA3l7tE51FtrilIjhltjTy00hU=; b=ITIH16BzJwriT6 VVvyFyH9FB+t1RXAUhl7Bjq5YM0VaF/2z2/S6dCQzAMSWOflnNqYHBYBjYe0N1/h30pQ8oe+eD46A C/GeeK7jfRRw3fX+RVvDAzIahoVTBFYpTdUC+pTCuewDEbip0XecktqrvbGww5n87+7XuTWqO8hAG 8xWU5GZh5ZSr1IZPIlK5h3z7wTi8NUcdV4rApaow2Sc9o7TekfkVubiE/TtJdi0xoZ3yaHHjriR1E BiRE5N5tnMAHQbcLIjg5EUsEX8VvvDc+Ex5EE3MfmjDPVmAlL1/+Hlp3EpUNQf6bUDg1rogW3HUhT 9VPp4e7sZLbh+RFsGwJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqscZ-000X7P-2E; Thu, 12 Oct 2023 10:08:47 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqscT-000X0f-1w for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2023 10:08:43 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40566f8a093so8133965e9.3 for ; Thu, 12 Oct 2023 03:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697105319; x=1697710119; 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=u+fXPfuQFbOLDaAm3isa5Mto3s8GQTNxK9ZpHoavLmQ=; b=a28FuraKdpS/4MYc0OBelULk6zX6KfLSlfAhDSIwwxop/MT+Ydk1ZZ/IAlDJBktW1A 2GVxlXRmGlWYlHVRZ+ZrZKoyTP5QPzijNNJIQSY+6sjSys1nApcvzm1vOYe8sbCizqH5 bBJOP/x1Mqj835I7bxNzjGddrDxroofssKedt3Hw66QJo1m8aW5X2E2QEzXmEbi2KgJ7 S9ZVVTujT6Upn6qLJzB9iv573MrsXzc76d/BgOcqaOwqvN5VHGo8qsp2i8En1G1PHTZV a3dDmC44zPw7Muw8T3YM49EY3d4dA2JXgD0of+ifIAc6wmtZZk+3ewNHO17vxmdUEps2 S4aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697105319; x=1697710119; 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=u+fXPfuQFbOLDaAm3isa5Mto3s8GQTNxK9ZpHoavLmQ=; b=emb9HM6hJ8cauVjIWH5e2e//BZV99A4FIi/ntKNDRRXxw5SfNfXXBNJcGozP4AGcPq iqAB5y1/pzmemETc9FtsgVyqvG/L2KLBNA1fxrjccHimNpYV1IN8bAhSH8Pm2MRNCnmw WgRA5Lx2gf2CZPKSem3rM2vSzb6RLoU1J1EsLv0rBdjVAfMh6b5XkyV8i2vScnj4/LUc BKbGRkvVfVr17xmFpt/vdFzw86NrJ98YZtwi9Mr0sjA+7jN3Z+4ApW4VTPjK1dAQDHzg xl8Sjqx8Wa5HmZRBTC9PzNyBm97GOiY0d9C3KvOvYrfPOMsWdCU9P9wu49lU0NmyUaGq qGuA== X-Gm-Message-State: AOJu0Yzg8WWGbfwrD/GRvyZMEFcAVFVlsdFOUEqV09igfz8qAQN07uO7 YYm2udIJLHJz3TtUaNdnoq4= X-Google-Smtp-Source: AGHT+IHltHLJC8hhVtlccIc/Xfw4D1hVrWKY3835qupMDM2NnVVGZetkTqBYcRWK9c3pUY4nLHFDAQ== X-Received: by 2002:a5d:6e85:0:b0:323:10b8:543e with SMTP id k5-20020a5d6e85000000b0032310b8543emr19294869wrz.49.1697105319104; Thu, 12 Oct 2023 03:08:39 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id dj16-20020a0560000b1000b003198a9d758dsm922737wrb.78.2023.10.12.03.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 03:08:38 -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 v2 3/4] net: stmmac: move TX timer arm after DMA enable Date: Thu, 12 Oct 2023 12:04:58 +0200 Message-Id: <20231012100459.6158-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231012100459.6158-1-ansuelsmth@gmail.com> References: <20231012100459.6158-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231012_030841_653141_D5961ED3 X-CRM114-Status: GOOD ( 15.74 ) 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 Move TX timer arm call after DMA interrupt is enabled again. The TX timer arm function changed logic and now is skipped if a napi is already scheduled. By moving the TX timer arm call after DMA is enabled, we permit to correctly skip if a DMA interrupt has been fired and a napi has been scheduled again. Signed-off-by: Christian Marangi --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 5124ee87286c..b2f63f12aee5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2545,7 +2545,8 @@ static void stmmac_bump_dma_threshold(struct stmmac_priv *priv, u32 chan) * @queue: TX queue index * Description: it reclaims the transmit resources after transmission completes. */ -static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue) +static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue + bool *pending_packets) { struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue]; struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[queue]; @@ -2706,7 +2707,7 @@ static int stmmac_tx_clean(struct stmmac_priv *priv, int budget, u32 queue) /* We still have pending packets, let's call for a new scheduling */ if (tx_q->dirty_tx != tx_q->cur_tx) - stmmac_tx_timer_arm(priv, queue); + *pending_packets = true; flags = u64_stats_update_begin_irqsave(&txq_stats->syncp); txq_stats->tx_packets += tx_packets; @@ -5572,6 +5573,7 @@ static int stmmac_napi_poll_tx(struct napi_struct *napi, int budget) container_of(napi, struct stmmac_channel, tx_napi); struct stmmac_priv *priv = ch->priv_data; struct stmmac_txq_stats *txq_stats; + bool pending_packets = false; u32 chan = ch->index; unsigned long flags; int work_done; @@ -5581,7 +5583,7 @@ static int stmmac_napi_poll_tx(struct napi_struct *napi, int budget) txq_stats->napi_poll++; u64_stats_update_end_irqrestore(&txq_stats->syncp, flags); - work_done = stmmac_tx_clean(priv, budget, chan); + work_done = stmmac_tx_clean(priv, budget, chan, &pending_packets); work_done = min(work_done, budget); if (work_done < budget && napi_complete_done(napi, work_done)) { @@ -5592,6 +5594,10 @@ static int stmmac_napi_poll_tx(struct napi_struct *napi, int budget) spin_unlock_irqrestore(&ch->lock, flags); } + /* TX still have packet to handle, check if we need to arm tx timer */ + if (pending_packets) + stmmac_tx_timer_arm(priv, chan); + return work_done; } @@ -5600,6 +5606,7 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *napi, int budget) struct stmmac_channel *ch = container_of(napi, struct stmmac_channel, rxtx_napi); struct stmmac_priv *priv = ch->priv_data; + bool tx_pending_packets = false; int rx_done, tx_done, rxtx_done; struct stmmac_rxq_stats *rxq_stats; struct stmmac_txq_stats *txq_stats; @@ -5616,7 +5623,7 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *napi, int budget) txq_stats->napi_poll++; u64_stats_update_end_irqrestore(&txq_stats->syncp, flags); - tx_done = stmmac_tx_clean(priv, budget, chan); + tx_done = stmmac_tx_clean(priv, budget, chan, &tx_pending_packets); tx_done = min(tx_done, budget); rx_done = stmmac_rx_zc(priv, budget, chan); @@ -5641,6 +5648,10 @@ static int stmmac_napi_poll_rxtx(struct napi_struct *napi, int budget) spin_unlock_irqrestore(&ch->lock, flags); } + /* TX still have packet to handle, check if we need to arm tx timer */ + if (tx_pending_packets) + stmmac_tx_timer_arm(priv, chan); + return min(rxtx_done, budget - 1); } From patchwork Thu Oct 12 10:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13418799 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 C1AFACDB47E for ; Thu, 12 Oct 2023 10:09:19 +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=P4kRgfyq9lsa+pHJsbqHRsTJzyNHHQSUdvhaftYD/hc=; b=MiZpTLa5x+nr/+ PTP0t6Ct0LwQJm7nBQflnj4uo+Hb9dwro5kIoJ4gR0rYrHcw7xklYgxPjXTOgULh02UR1vI51Pkh4 NxkRceilDoPsxhF84PC6FHPfwbqKg78d/QdJVLtgJA/htZLxh3X7nzbFB8RMf9ROEEGMxyBf8k7E/ aMFLkj6mkOLDyOYMDFOIzm1bGbq253hwqWY3n8ZXV8TT3pNp6IBt1NNV/XO0oS8wxc1+IBMCL5Jc/ wGH/4zUegyQc+eRM7Go91kXcN2aIesmUWLD68rLPL6tMR0dGxuH8fGoI00ioH2C9Id+02vnivLZ3p olEy640OpjmB0EfOAg2w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qqsca-000X8C-1Q; Thu, 12 Oct 2023 10:08:48 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qqscV-000X1w-07 for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2023 10:08:44 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-50573e85ee0so1056866e87.3 for ; Thu, 12 Oct 2023 03:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697105320; x=1697710120; 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=SSAhxNCccBDPfEaHOYwSm94ZHYVqbuNn4mUPNvHQg0g=; b=SAqRa+XUA5fkc5ByzUPIFoW62D6fE7eR40H5ozsfgHJ3mPm9H8DJQU5GiScK40h/kn 6/hI/Y1MMNOUsPWUdectpZsu10apiIu8wUlDls8xoDQG328Kp+V0bIWfVUj+wf7E0Mvy NsyptTJMiv8A1Ar6TIpzTlw/O9+Pt+YEJJ3o+1BSTqO/C8YTJZzGyQUCEAM0I4I9kQX9 DjZ8bnY1aqDukqazpbUr+nNnOcwgK0UYFU7xbVQWRWdDb4PCA8MtalfTY5pRLMAXemym gLkZd2JWFfjl40m5asoLMvKkNZJjell7LhQ+VLj98aPqP580bf46KoGby98b/6hAjeUF 7jTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697105320; x=1697710120; 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=SSAhxNCccBDPfEaHOYwSm94ZHYVqbuNn4mUPNvHQg0g=; b=lopuZfd4yyGB2NZpY1g8haIf1OP+jY2zg6Csw78ffpW/GfHU1SAg7IXI5GtIFEKo0V FPHv9FROMykFSaNgdI1hIzyU0Cr15iwqcaQyc9ySSwpCz7/gDat9O9dlPLap2bq7Y4FF 1JcfnPAEYL913RhEBcOBMXuWFhgvY3A2W4ix9oTUXhNVZGeBr73i8TSSomDWqSBCx9L6 74Ca7WorSRpEgAxkDsT75+ETdNY0O3Eaj91v8eQS2N6gUlfEGgltPah06r8nvTY7WFa9 /+luPgm+r9HRY59JvFL9mLSSPA3zOboD99pdqjzECvhRvEi1Zh/L7L4mLb1xA0JLLqfU 2fOw== X-Gm-Message-State: AOJu0YzYfVEjgDUKTZ0b/K1/B6fnY5MJVL6yJqp65egHXfWtBbwJdJ6+ fVGnCmF6kIUDOtLEUexUkgY= X-Google-Smtp-Source: AGHT+IFS5wYVsErszFbLHXbccvljCxec7tsdB2hdb2nVZS6k8/mqAnVjAi0sisagLq6W9E03Rccilg== X-Received: by 2002:a05:6512:210c:b0:503:36cb:5436 with SMTP id q12-20020a056512210c00b0050336cb5436mr18333699lfr.9.1697105320566; Thu, 12 Oct 2023 03:08:40 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id dj16-20020a0560000b1000b003198a9d758dsm922737wrb.78.2023.10.12.03.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 03:08:40 -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 v2 4/4] net: stmmac: increase TX coalesce timer to 5ms Date: Thu, 12 Oct 2023 12:04:59 +0200 Message-Id: <20231012100459.6158-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231012100459.6158-1-ansuelsmth@gmail.com> References: <20231012100459.6158-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231012_030843_087171_5C5E905B X-CRM114-Status: GOOD ( 14.84 ) 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 Commit 8fce33317023 ("net: stmmac: Rework coalesce timer and fix multi-queue races") decreased the TX coalesce timer from 40ms to 1ms. This caused some performance regression on some target (regression was reported at least on ipq806x) in the order of 600mbps dropping from gigabit handling to only 200mbps. The problem was identified in the TX timer getting armed too much time. While this was fixed and improved in another commit, performance can be improved even further by increasing the timer delay a bit moving from 1ms to 5ms. The value is a good balance between battery saving by prevending too much interrupt to be generated and permitting good performance for internet oriented devices. Signed-off-by: Christian Marangi --- drivers/net/ethernet/stmicro/stmmac/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 1e996c29043d..e3f650e88f82 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -293,7 +293,7 @@ struct stmmac_safety_stats { #define MIN_DMA_RIWT 0x10 #define DEF_DMA_RIWT 0xa0 /* Tx coalesce parameters */ -#define STMMAC_COAL_TX_TIMER 1000 +#define STMMAC_COAL_TX_TIMER 5000 #define STMMAC_MAX_COAL_TX_TICK 100000 #define STMMAC_TX_MAX_FRAMES 256 #define STMMAC_TX_FRAMES 25