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); } /**