From mboxrd@z Thu Jan 1 00:00:00 1970 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 22F65CD4F57 for ; Fri, 22 Sep 2023 11:13:46 +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=DMcCNHSSKL3I2VjDLZEQaocHEulX5AJrCZmxJyl47NI=; b=UEhs6kEO5TPa4C Ri8bk4xRzUEaBnMk5ADjYk0QbWQbptnuurHpJIFmy4T29vjLJ2qELNazYk/xPhb7mxCrK3LBkm88J dISYvJ3I9imEco8h3TvwJAtkiLul6ipYrULb6SY+aIHE+c5fL6xPsybXgxd+jDe4WHVGSNuNM3zTB 5x50nKnb1rjiSPIh9AoX859EZPG9D+zQ3uol/rj9//m6SuQI5U/ZAfbnsmL2JbYoU0teYl2je7LHt oiC7TYVr42mM6Oq3B5fIAbZ7RJVG+3sP4g5EVvxHxWsDPin92sNqxOAQQ3iO75KzyXYZ8vrKhsqoq PqnHdZ49cF7Q1bMD2WDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qje62-008vUu-1G; Fri, 22 Sep 2023 11:13:18 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qje5u-008vSQ-0S for linux-arm-kernel@lists.infradead.org; Fri, 22 Sep 2023 11:13:11 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-32172a50356so1935018f8f.0 for ; Fri, 22 Sep 2023 04:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695381187; x=1695985987; 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=NO4PPCAYeBqa8N3X8iNMzO62NO9a8Aa1IWA9xi7rYvw=; b=Ow01nf2B2T1vDQSeX0Zc284H16polOafdDjnddefShFpdceNPoFPxwWx8KchKD/jKM FSjbH+LqnN1xa8uXCeZRE70uUYeIuWcNdJqzzuJM+rneVNG3y5PzBQ9IBGrs1oZI5diw ttz4Q/sEfKJhK3F2lfpHhKC2Bx7olCUxSnUWq+QDHejJZxBiB9wDn+/IlbpEDitiaIZv uU7iQBNBY7JGI+liBeADmjOSWA9wpIvVW5XdczwZ0urg6YLEKxqEsNCNwCdrR28aFfBG IN+HoF6JMdJv67h3zJP/z7s+ekiXjWoJja58DWkKeUbgKidbuy8zzIfUSvcVgqXucWOv 89dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695381187; x=1695985987; 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=NO4PPCAYeBqa8N3X8iNMzO62NO9a8Aa1IWA9xi7rYvw=; b=JUtonMJPIKUlNCYdGr+G/vHXSDx5ESAelUAtnfLxHRYNKh+kLjIj6iRvRdk57LHiqh EcbCyguJsqfJXhk+zTxUJjzv7v02FiD2qY6jgSuxkW3RW47wWopo8hq3tPLZspRjaWVz O8LkfCJ/kL0KEQX2Kx2q0nEeziu8kSJJt+AVpF2Bj+aTod4WSlDpRu7NJBqmQgQAMFyh /N1Z5z03KAhmGxvyZOawvRyAxh7MrG/0jmx+1HED8eppevdAQRJewaQjVZ43u9tqiS/7 qCOCkvZTqFIOhLfxXGPgKGyb+qelW3VBBXUFcl2YL1UlxlQBCOtpUWueIMOSTlQvjl0J mcBg== X-Gm-Message-State: AOJu0Yw80K/v0IhvlaOphyVB7GI0sBKCpKWMeiaCv27ijDsXjYR9z7z6 9TxMUHF7sYYFH7VIG0Of54Y= X-Google-Smtp-Source: AGHT+IGt2zxWyI/cHaEIM9YNy0bqvfBVCcm7j3twnx0VeOiWaEz6/6Yr9n/oPYq1bGBQ0w34CKjfgA== X-Received: by 2002:adf:fbcf:0:b0:31f:d8b3:e9f5 with SMTP id d15-20020adffbcf000000b0031fd8b3e9f5mr6831681wrs.34.1695381186972; Fri, 22 Sep 2023 04:13:06 -0700 (PDT) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id g10-20020adffc8a000000b003176c6e87b1sm4191765wrr.81.2023.09.22.04.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 04:13:06 -0700 (PDT) From: Christian Marangi To: Vincent Whitchurch , 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 2/3] net: stmmac: improve TX timer arm logic Date: Fri, 22 Sep 2023 13:12:46 +0200 Message-Id: <20230922111247.497-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230922111247.497-1-ansuelsmth@gmail.com> References: <20230922111247.497-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230922_041310_177949_63748B32 X-CRM114-Status: GOOD ( 21.56 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 9201ed778ebc..14bf6fae6662 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2994,13 +2994,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); } /** -- 2.40.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel