From patchwork Wed Jan 15 03:27:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Furong Xu <0x1207@gmail.com> X-Patchwork-Id: 13939786 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 369CB22F146; Wed, 15 Jan 2025 03:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911654; cv=none; b=J4zvbhxoX5BUdsYkQZd3+VVIrMp4qwY3M3JkKH/sblkxIaUBR0KlMkiBiHCG62trcnVC0pR69YL2oB6ZWem3xj4ixsFlf+EiskbDxMVuCM1zapAWl1E2PBUTZTFWPehoeVNNeNUgod1lYc0CCiLR0+9QStlHwXLXxoHG3wDG5Bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911654; c=relaxed/simple; bh=dCcIgnHXNICdJy+lWeTRtb9bU/MYBis3hGx1McIK2ms=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jjkTJeU50SIFWHHWbddIcjqjzVv9clniZOlUmNHnxkOubw6EB368R7BhasUEzdUYVCgrMLy+faRBZJqC0F57gnxyO16sSvFwKoB7nIe9Gk+rIgeBw5UJzxhgqRu5wQkRiUsGmQ6tLAsHJZ8ec4vneadz96MBLkt7tyyu3qAONzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j2PRtBKz; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j2PRtBKz" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-21634338cfdso104953145ad.2; Tue, 14 Jan 2025 19:27:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736911652; x=1737516452; 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=lRq1k9DQ7dcpFSRaoKAokYKGtHAonMVK3g5kkcieDXA=; b=j2PRtBKzQZWNgwIXsV62VvziCGXP0EW1uVr6pIn1dghPSrJxtudgqfvudq9NzihvZv 0e8HexD/DVOJ0I0lt4o+6tqEpYNb7Gcm9NEWKiWJ5XABSArcAMss198sE9DOGoesAS+x knbSz9nFn/p79JIX8KfQQn6gJy77T2KmZcq9VVBJpgv3C2wEbKn9qz9ixMaj31irEaBF i2/Ou6F3/8WsWuee8fIYyie11eBnmYspbGTlQcFRXjaTyexEc52FDOSH7M9NpZkhkLf+ zlO+PJz3TUiwjyJowmZk+jhh+RX0vUbfwoJCUI6UTnp2gqrhOAX4YCMDAmuOlx+jkaA8 G3Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736911652; x=1737516452; 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=lRq1k9DQ7dcpFSRaoKAokYKGtHAonMVK3g5kkcieDXA=; b=FaYx0Ge4ob1yBt3mjgbFzxY3KFvrMUj4inB9DOnVQX/TUXBrHCBUYE+40lXCb8tbVY Oxl4peFOdtYATYnwFLfTu3IJtgqHet9SRuI2RYgfXOnvSydmTwj4SCHrfoCwXkRsOvDD OjjA3bwiFf6oCaEDJIV5velquL8/S4BAv74vkcVkc6UQoBv+jt/EZT+WUF3dHEinlURg GUNIvyEc23dxme/oNsTCQSHNznrge8jmlcTp9zUdCdsoxnRXhYhJ+vZd9RtYO6g0Ws/p 8zVmf9QPowr0OH7TxNXOiwbnpyxtnWNXR/Xon/9OBPkU5uS3nmS6o38C0R6URMvKN6V5 eh4A== X-Forwarded-Encrypted: i=1; AJvYcCVqcAykcYYeWRFnZr1mYVe0ZRI6Wo5FsPCspxGsxyS7+lxGQPAiCAHBkCp23v+BDHjfYNut3E0kHWUT0Kk=@vger.kernel.org X-Gm-Message-State: AOJu0YzhqPO1oU/GwOpCLMXYbOLxCHBkLBZ6StBSzQQlsPGl7csw1DVL CYKe9oFh7rQRJDwWCAW12JTU76uSFEOJSW3B8ianED5svKjAuswdgnWp5g== X-Gm-Gg: ASbGncuQqAQzGNnAsQvGbGYDdjZhbrSFIiViOwEc5zNhAU2oDcxNy0a3DxZLPN4ycLy FprA2wVKR0Ndep+cd5z+Tm9becEiK97oKC+NnzH3lgYgAp9MF2vRxqktAKCY4zCbZQ6Z8UgU+/n MK8gd6oxiIeIuV0e6thYnHn4y+rBGhfTvX/PTmhBDa89cO+de/Ce6gLo9sqqd+TQyiqgPmTX2Gq tdTBdghS7gXTC+NHcaIURImrZy1Zy5see/O3SaDabrhF+1Ie4pRSegJljxVtRqtrjUK5g== X-Google-Smtp-Source: AGHT+IG7F3H2v0kSliTabXyeox9qkdn3NF3T6JxmOyvChSMJeeHU3yFa4THc3jIhecOqrdwKMRxkVA== X-Received: by 2002:a05:6a00:35c7:b0:725:ef4d:c1bd with SMTP id d2e1a72fcca58-72d21fcec0fmr43073016b3a.19.1736911651509; Tue, 14 Jan 2025 19:27:31 -0800 (PST) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72d405493basm8166452b3a.27.2025.01.14.19.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 19:27:31 -0800 (PST) From: Furong Xu <0x1207@gmail.com> To: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexander Lobakin , Joe Damato , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , xfr@outlook.com, Furong Xu <0x1207@gmail.com> Subject: [PATCH net-next v3 1/4] net: stmmac: Switch to zero-copy in non-XDP RX path Date: Wed, 15 Jan 2025 11:27:02 +0800 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Avoid memcpy in non-XDP RX path by marking all allocated SKBs to be recycled in the upper network stack. This patch brings ~11.5% driver performance improvement in a TCP RX throughput test with iPerf tool on a single isolated Cortex-A65 CPU core, from 2.18 Gbits/sec increased to 2.43 Gbits/sec. Signed-off-by: Furong Xu <0x1207@gmail.com> Reviewed-by: Alexander Lobakin --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index e8dbce20129c..f05cae103d83 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -126,6 +126,7 @@ struct stmmac_rx_queue { unsigned int cur_rx; unsigned int dirty_rx; unsigned int buf_alloc_num; + unsigned int napi_skb_frag_size; dma_addr_t dma_rx_phy; u32 rx_tail_addr; unsigned int state_saved; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index acd6994c1764..1d98a5e8c98c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1341,7 +1341,7 @@ static unsigned int stmmac_rx_offset(struct stmmac_priv *priv) if (stmmac_xdp_is_enabled(priv)) return XDP_PACKET_HEADROOM; - return 0; + return NET_SKB_PAD; } static int stmmac_set_bfsize(int mtu, int bufsize) @@ -2040,17 +2040,21 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, struct stmmac_channel *ch = &priv->channel[queue]; bool xdp_prog = stmmac_xdp_is_enabled(priv); struct page_pool_params pp_params = { 0 }; - unsigned int num_pages; + unsigned int dma_buf_sz_pad, num_pages; unsigned int napi_id; int ret; + dma_buf_sz_pad = stmmac_rx_offset(priv) + dma_conf->dma_buf_sz + + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + num_pages = DIV_ROUND_UP(dma_buf_sz_pad, PAGE_SIZE); + rx_q->queue_index = queue; rx_q->priv_data = priv; + rx_q->napi_skb_frag_size = num_pages * PAGE_SIZE; pp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV; pp_params.pool_size = dma_conf->dma_rx_size; - num_pages = DIV_ROUND_UP(dma_conf->dma_buf_sz, PAGE_SIZE); - pp_params.order = ilog2(num_pages); + pp_params.order = order_base_2(num_pages); pp_params.nid = dev_to_node(priv->device); pp_params.dev = priv->device; pp_params.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE; @@ -5582,22 +5586,26 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) } if (!skb) { + unsigned int head_pad_len; + /* XDP program may expand or reduce tail */ buf1_len = ctx.xdp.data_end - ctx.xdp.data; - skb = napi_alloc_skb(&ch->rx_napi, buf1_len); + skb = napi_build_skb(page_address(buf->page), + rx_q->napi_skb_frag_size); if (!skb) { + page_pool_recycle_direct(rx_q->page_pool, + buf->page); rx_dropped++; count++; goto drain_data; } /* XDP program may adjust header */ - skb_copy_to_linear_data(skb, ctx.xdp.data, buf1_len); + head_pad_len = ctx.xdp.data - ctx.xdp.data_hard_start; + skb_reserve(skb, head_pad_len); skb_put(skb, buf1_len); - - /* Data payload copied into SKB, page ready for recycle */ - page_pool_recycle_direct(rx_q->page_pool, buf->page); + skb_mark_for_recycle(skb); buf->page = NULL; } else if (buf1_len) { dma_sync_single_for_cpu(priv->device, buf->addr, From patchwork Wed Jan 15 03:27:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Furong Xu <0x1207@gmail.com> X-Patchwork-Id: 13939787 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 079D422F394; Wed, 15 Jan 2025 03:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911659; cv=none; b=VkMDCH3wtmgtAF3GBwxbAlO8e0iOuJW8CLGhij3vUNpR9/q9a232nZ+u/ldjllnb6q/64uJ8Syqnxe+j0bHxOkYhEgnjhKZtEFjheL6KftozgDCWoq7YX/tnjSmE+sw/q7jrMJEjhuEGaw57xSl2+xT74bYS6I/NFh+DrnWojKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911659; c=relaxed/simple; bh=uMwbCf7sFcsA9X+hAd0RGlXwIc3DrBZUKSKTBT/eyVI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TnSjupKrvSeU+tBT9iw/5jJ/+F9/CDc5HCy2yvrf/Qe3mGkbu/2CC2SXFmMJApY+49clIN10spcbXUOxgyUM9hoFz0LEqrPwE/zxTKkmAU05Pgu1gzdtn1F8GeHZyrFJxBvVWT5q+r8nF1gZNYscoI+/9B9J47iHJ3SYQBLy3g8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j9B0ecly; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j9B0ecly" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2163bd70069so113495845ad.0; Tue, 14 Jan 2025 19:27:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736911656; x=1737516456; 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=8UUplh7fAcpeM7Q5zE9FRPEWMTlb68cB4RMo0G5W1ro=; b=j9B0eclyP5w0qZbwI+em+Pqt9W2B5qf30fyAHSFkZHpvF7Xu4sx5//eCTGyxUK49l+ AJSNEiq6m46F/kK5DpNcRkHTnm9Or+AnsJ+kzoQIyD7W0c26UteBC9n9ECnjnbPbKPvV Ywu8mv1gcEpMOyh7k9r7JDu6JCcC0+hJlQy6q/9ud2SRZnN0Erh2RhvuL338GM3T29vO dtIW6pELewKneAxaj2QwnIjmdVXgA86tA9NuTDiL5I8IAkeFIn5vIaakpInJUrX5UjcO Ali9SGR22/Ah40fMIrhn0683qpkLwKvgYV15i6RHTi156xGunGCmm4/jSR9V3HS03ozC jpgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736911656; x=1737516456; 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=8UUplh7fAcpeM7Q5zE9FRPEWMTlb68cB4RMo0G5W1ro=; b=d8FbkNoWe8KIQYWyVY64G6+IllH9cP8Z0QfDYpDJsq4Pje4Dc7XUX+KKkqAnQQT01y vX8FxHj5FTrkppVaE9w6zrTq3R2eUw48QrDQF0eVVsFSkTHutgOMV1hs39Qx41HPKLSn mkqfwS3oMYJScsc50FTptd8poxya8m73UaHVGNeQmZPwtvdbwgZuUNY1yW5JUbWi2w4b CcHuFwRxLIeN+FF1IqR9M78bURVnQHNyVqbYePa47l4AFew5fWRALrAvUosKjgZirYqy Meu87/TSnkoi+qYX9mYgvwCl3CBrgyRZPYlHK8acahWPdQB6hHFQe2os4cP1EQf/e16G zs+g== X-Forwarded-Encrypted: i=1; AJvYcCV2x+Tjo5iDjl47NPe/HOtH4HeygcPmypLJhnIbOZyi51TAO21Ypv+GQ6S+9eHvUf2mjZnhqcBjMMYH/b4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0ydx9r+KHPV8Q8lWtPpdplkdX+ayD9ROfvpfGfoPd+LZMKFSV TWfBrcqZ1f8Xd4ytiFZE37MZLuveXIA1TqDPTafHFg/+FfYI9oKRNOnOCA== X-Gm-Gg: ASbGncuGywbx4s4rwzm/zpsJaKRJXnEZhYeFIRLgjfZP+b0Z8n/z63U84hzSKEHyRcb vo7KtDlmfI7PwF6vHNzqZNqOEFeANg8dse3FUzryyJZLZHOf/+vikRGlRXY8VOabAUYwBRL0YAd EQfN9hjOl8JHy5/2QUMT5gGI/GW9c/rGqs5cTTp9Y9P/8D2Za/icV/WVx266GRw0NlNWWt9HQA+ oCWqMF9kW3cQaEYXwOBcDJqojpLzfY6Lo5nUyKao6YAzphrjIU+S/tzlc7eLfJM5uPbKw== X-Google-Smtp-Source: AGHT+IFNvLpuNXbqq/IV5KYaf3Nik/z1qK9SvaIPNMSsFV2O8gjEl3T3nKlKoNCJXm0ou755RaN0PQ== X-Received: by 2002:a05:6a00:340c:b0:725:e015:908d with SMTP id d2e1a72fcca58-72d21f459b9mr35478358b3a.1.1736911656332; Tue, 14 Jan 2025 19:27:36 -0800 (PST) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72d405493basm8166452b3a.27.2025.01.14.19.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 19:27:35 -0800 (PST) From: Furong Xu <0x1207@gmail.com> To: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexander Lobakin , Joe Damato , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , xfr@outlook.com, Furong Xu <0x1207@gmail.com> Subject: [PATCH net-next v3 2/4] net: stmmac: Set page_pool_params.max_len to a precise size Date: Wed, 15 Jan 2025 11:27:03 +0800 Message-Id: <538f87c8bdd0ba9e2b9cb5cd0e2964511c001890.1736910454.git.0x1207@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org DMA engine will always write no more than dma_buf_sz bytes of a received frame into a page buffer, the remaining spaces are unused or used by CPU exclusively. Setting page_pool_params.max_len to almost the full size of page(s) helps nothing more, but wastes more CPU cycles on cache maintenance. For a standard MTU of 1500, then dma_buf_sz is assigned to 1536, and this patch brings ~16.9% driver performance improvement in a TCP RX throughput test with iPerf tool on a single isolated Cortex-A65 CPU core, from 2.43 Gbits/sec increased to 2.84 Gbits/sec. Signed-off-by: Furong Xu <0x1207@gmail.com> Reviewed-by: Alexander Lobakin Reviewed-by: Yanteng Si --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 1d98a5e8c98c..811e2d372abf 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2059,7 +2059,7 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv, pp_params.dev = priv->device; pp_params.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE; pp_params.offset = stmmac_rx_offset(priv); - pp_params.max_len = STMMAC_MAX_RX_BUF_SIZE(num_pages); + pp_params.max_len = dma_conf->dma_buf_sz; rx_q->page_pool = page_pool_create(&pp_params); if (IS_ERR(rx_q->page_pool)) { diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h index 896dc987d4ef..77ce8cfbe976 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_xdp.h @@ -4,7 +4,6 @@ #ifndef _STMMAC_XDP_H_ #define _STMMAC_XDP_H_ -#define STMMAC_MAX_RX_BUF_SIZE(num) (((num) * PAGE_SIZE) - XDP_PACKET_HEADROOM) #define STMMAC_RX_DMA_ATTR (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING) int stmmac_xdp_setup_pool(struct stmmac_priv *priv, struct xsk_buff_pool *pool, From patchwork Wed Jan 15 03:27:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Furong Xu <0x1207@gmail.com> X-Patchwork-Id: 13939788 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0D40155303; Wed, 15 Jan 2025 03:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911664; cv=none; b=CMfQ+OLzPXnjWWBROBZrGkzuS1F8fFmayo8Ef3HTtdo/FMfaOoNRbc3a4ujlmW6DiLHu289wKG0tNHw64zytQDpSlOUXknZY6gOUFZz5exdgdVimmi9LaJMFhGT+fI7F8/ETIliOkqYVKiz386saPnz1Fd+16LUwzVuCNUFjYig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911664; c=relaxed/simple; bh=h95hPWBFG1aitrl/HabWmrPaBlEQI2s8HlYWGMIB7CM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F4KQscxHiUPubgoE/ev5E2HxJtkaRf42NzU1QgBg4UcA8CgyeunVg9qaZEbUCMsPgsFTKpKfM6+Bmleq2mb4+fxXqS6Vix5pVwfkhzdo7T5vy+gE921rf/pB4BEnY6o7+kUvhl/P9Eeo9L7rGmlcDoekulXE9s1+XEeQGuhFG2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NnyK9GOT; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NnyK9GOT" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-21644aca3a0so137136565ad.3; Tue, 14 Jan 2025 19:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736911661; x=1737516461; 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=F8jofsVUx8ZDCJ6z8E8sSP3dj56gjS3NJDcAVJdYxeo=; b=NnyK9GOTZSvkXnW17Rvk84x+BfnV8xuBmM3RkpLgO9SiKrCHChyEHrl+NO8NKR9IKq tgChWglc//wg11swdwUrmaOA2VcjaSoLUyxBcmvy7PWP4ZQ9wA8foieGOClnldaG3zPw EkS8Qs0o/1U5rdZhAESPVJaiUUcCsWAhxGR3BoDIyOd0VX9OxHBzvm9vpwwMTgfOGNhd 2AJjRGorr3C8QtNY+8Z2ZjstVklNifod6pAjx00eYAn1VeILbOh0dW7wwSzyayFFpi86 coipYkYZU1qVrOU582l0pZoYOIq0fD8/JLO5Qe/SP8U3WQOCJyhjwKvW5aHeCeKmgUuV Fgtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736911661; x=1737516461; 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=F8jofsVUx8ZDCJ6z8E8sSP3dj56gjS3NJDcAVJdYxeo=; b=bY54g+5UgQNkrtiB7DzgvzID5sI5Y5zUgFKBm4Xf80ePJSz0kRZhokKvFNUveB0GlI l6nD5/r97Z9MF+5VOYGK2ss4X0iSESHfgP4GIyIdZ+VdSb3HzDY5EwzPHR50Dxd9jXAU 6oxxL9iI+o5oQLndEmOwdVmVhxflyc0TymehmfHSkVD5bfJes2RJFJLCDEBflkPAKG4l o0opzR+9wiAy+/IoSgE6PKL+TJGrVDXdlvIu07CBGFA6aXZZdmvq+nOuCEIoO6m0HwUD PvckXCNBOS6hy4RvA0NFQXq5aaquTKJ71qAw1sOJ3xDdj27pwT01y9x9OkLNkvmGkIDz OYiw== X-Forwarded-Encrypted: i=1; AJvYcCVCGTpQ55MnGhNsMoLNVI+IBLs/atPLywbaWTO+BGTK2KsDqrdicxzn7W9JeHeRYZ3JvSh0bKEUYua8JCw=@vger.kernel.org X-Gm-Message-State: AOJu0YyiqteE9rw9YAP2/rCZRBD7ta7jdHcaBF+/XcZ2mgiXeKI0Rhkn n5KMyqhNv5h68Ez5PYg79/4LF5P2jurHVEAPQp7o/JoUcZBH2AjlsdS5Dw== X-Gm-Gg: ASbGncveiXkHV/3xlQFjT9nR1+LfzDXWiuazjhoCgAQy2EMLNlus9eCROz+8VPT2oO7 q026hn7yCusyv8+NM1o8fH2/JqejTtbmbI9JyXDtnxB0mNsakcJ+FgoXq2COWlcTcZ86cthrdzq PfoFN4JrmkMdOUTCzojhOFsZNSWT8l/C0/oDBZsCeJBUJ5taINRGOIYo3U8pavqkKNOgpFLd4NS ZSYP3oD1RQKAiL4K6tYTK5C6cY2waLNkPXroXtfVaQQ2D3Pqa6j/zbcO9s+bDMLc7EVXA== X-Google-Smtp-Source: AGHT+IH3vKpIs9HEB7OG2AlV/K4DtSeYgzdkPcn7TCEV2c0jCWcevtA7LwBwelnqC2AKojzBKBFAxQ== X-Received: by 2002:a05:6a00:3c93:b0:72a:8461:d172 with SMTP id d2e1a72fcca58-72d21f4537emr43075844b3a.3.1736911661159; Tue, 14 Jan 2025 19:27:41 -0800 (PST) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72d405493basm8166452b3a.27.2025.01.14.19.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 19:27:40 -0800 (PST) From: Furong Xu <0x1207@gmail.com> To: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexander Lobakin , Joe Damato , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , xfr@outlook.com, Furong Xu <0x1207@gmail.com> Subject: [PATCH net-next v3 3/4] net: stmmac: Optimize cache prefetch in RX path Date: Wed, 15 Jan 2025 11:27:04 +0800 Message-Id: <2574b35be4a9ccf6c4b1788c854fe8c13951f9d5.1736910454.git.0x1207@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Current code prefetches cache lines for the received frame first, and then dma_sync_single_for_cpu() against this frame, this is wrong. Cache prefetch should be triggered after dma_sync_single_for_cpu(). This patch brings ~2.8% driver performance improvement in a TCP RX throughput test with iPerf tool on a single isolated Cortex-A65 CPU core, 2.84 Gbits/sec increased to 2.92 Gbits/sec. Signed-off-by: Furong Xu <0x1207@gmail.com> Reviewed-by: Alexander Lobakin --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 811e2d372abf..ad928e8e21a9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5508,10 +5508,6 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) /* Buffer is good. Go on. */ - prefetch(page_address(buf->page) + buf->page_offset); - if (buf->sec_page) - prefetch(page_address(buf->sec_page)); - buf1_len = stmmac_rx_buf1_len(priv, p, status, len); len += buf1_len; buf2_len = stmmac_rx_buf2_len(priv, p, status, len); @@ -5533,6 +5529,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) dma_sync_single_for_cpu(priv->device, buf->addr, buf1_len, dma_dir); + prefetch(page_address(buf->page) + buf->page_offset); xdp_init_buff(&ctx.xdp, buf_sz, &rx_q->xdp_rxq); xdp_prepare_buff(&ctx.xdp, page_address(buf->page), From patchwork Wed Jan 15 03:27:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Furong Xu <0x1207@gmail.com> X-Patchwork-Id: 13939789 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3139B22F152; Wed, 15 Jan 2025 03:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911669; cv=none; b=tPKGrfJAC/deesjvr306ugZFqRFvB09VjoUBaG8oETDOE8eP/ZBAj37rhVqCRmB3s5+MHRCadd595rfdIg3/JAHFTIMd0R2c6NLj8T/loPGRYLs4e6NRSAxdlqdm4B/4BkCbza66ZMnRoUleYWEYwWZVLMGXO40T/QPAdSM773Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736911669; c=relaxed/simple; bh=ELqzb7GOkkxhmiH++knkIhUE2YwbBBJ9bPiY6iO6wrQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PCGjAhYnphbkbWz4TffCo/IL2Q+vPrhcZiuCV9XMZvoTop8yBpo7GWe8XTeIqM81w2mi7PZJsTSWZrNJLBBAu1VbABOVzIv81928p70AYeT+FMHNtUC42PvBvdECfq3b5wl3agrKyp2iQwm1HMDpfQa3ii6xH/aeb7Ll34H6LYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jOugD/YN; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jOugD/YN" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-21669fd5c7cso113757105ad.3; Tue, 14 Jan 2025 19:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736911667; x=1737516467; 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=vrnZOWuzbTsFJQSfUdSJAVwNu1OpPEJIPOluJRIjDnY=; b=jOugD/YNA4Gm8aXCfSyMZNMds8icosDlcijNlpHFbi/tKpdG9jYScups+2NRPertoG JZeay0eRQ0mbfYni4MwXLwCzJ2SEVVhkkUGFpuLmWqIINmsKMgb3myOsVgZE1ruOp9xY PgJTEwHiUe5H63nt1lB4RyrysjGdu72a9jgwnaQTygASei2fp8XPH46ySzAV40njOuK8 jYh3F7ZHXBHZCwOkMouU1xAcxG6eK8tZCJD1MTqiSWd+yMBpDHc6VvlxmbC154OfCoeW q5MXBDtJndt9EDDSkeJr+003bXzLqxVEjZYNdWBBApMXJplDuMLo0mq15oVdPIz9rFz8 r6ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736911667; x=1737516467; 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=vrnZOWuzbTsFJQSfUdSJAVwNu1OpPEJIPOluJRIjDnY=; b=JwbtGsnkP1A78KLWCZD7TW1+USlBK6ZcE0tb9zYmGAzZlFXcGfgot58UOQpUvZFCVC Mrt4PNMJQsfpjce9quWL3BBtOnidd+FgAtmlffKixw9M6t4CJTvOvtoZSrgLkbhOOAMs FCsl4YX5wA1K5GZHKxdFcuFzSWrT7EadWcpCN/wYh3Yabth5w51e7GptW3MieOt9LuH7 tM/MpGX4cPDl3Yt7e28jpX5jLnVu16J8y4W2OY74WlzaAVHGZ44AFjGxfBwA8Plsop+m XqS/02QsoUcqHiWxWv6ZQrh+EVSDZEVbmeimJxZCHsrA+tXHQcbWtnU3K3s8D0BhCd7g Y6jg== X-Forwarded-Encrypted: i=1; AJvYcCXkzQ4WVxkqo7/TPnHF0EqBhUUeYJVmZSWNudVe1uoZ0tA7fzPPpYExiOg/YUZMGpjCO+v06ozlhM0gMgE=@vger.kernel.org X-Gm-Message-State: AOJu0YwTaRwl0nPkbjDZPySyfWm+udHbLlaeE2aaawKiaQdT5E7RM/rQ P+dr3lJZgz5lgCeBIp0aP3B/J6BHDsuDAY7Guy682zB38G0asDRcS4lXCA== X-Gm-Gg: ASbGnctXAWfTLLO2XezSU9iba3gg6HKcDlwX3obSu6cJUAKZSQdrSo5WOGoVQOOrEzI YcOVIKeYNPmjqaesksvuVv3qUCQvqTVzkt5Kzr1ODcAiT8DYbjivHajskVpZNiOIxsPt11YaRgl iAsmGdsL4FEKt07JdqXnDg1bbetsUHBBJGZCq2GQ2aAN4uf5OltwforY0NrBdBrllZeBrM0rWJx JXtDEzdN43/KMjQ8u2YIj31fh0cKqNd4kpi2GREs4TY4Lacz4LehdAHflg5Ct5i1ySiZQ== X-Google-Smtp-Source: AGHT+IEgvbbedPhMmlQrROuWhBJEvCl3rJhkcO1ll2KbOYDFwCkOh7dbSjQ3/MMG4kA76MxUXWGidA== X-Received: by 2002:a05:6a00:39a7:b0:728:e382:5f14 with SMTP id d2e1a72fcca58-72d21f314e9mr32614582b3a.9.1736911665971; Tue, 14 Jan 2025 19:27:45 -0800 (PST) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72d405493basm8166452b3a.27.2025.01.14.19.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 19:27:45 -0800 (PST) From: Furong Xu <0x1207@gmail.com> To: netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexander Lobakin , Joe Damato , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , xfr@outlook.com, Furong Xu <0x1207@gmail.com> Subject: [PATCH net-next v3 4/4] net: stmmac: Convert prefetch() to net_prefetch() for received frames Date: Wed, 15 Jan 2025 11:27:05 +0800 Message-Id: <909631f38edfac07244ea62d94dc76953d52035e.1736910454.git.0x1207@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The size of DMA descriptors is 32 bytes at most. net_prefetch() for received frames, and keep prefetch() for descriptors. This patch brings ~4.8% driver performance improvement in a TCP RX throughput test with iPerf tool on a single isolated Cortex-A65 CPU core, 2.92 Gbits/sec increased to 3.06 Gbits/sec. Suggested-by: Joe Damato Signed-off-by: Furong Xu <0x1207@gmail.com> --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index ad928e8e21a9..49b41148d594 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5529,7 +5529,8 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) dma_sync_single_for_cpu(priv->device, buf->addr, buf1_len, dma_dir); - prefetch(page_address(buf->page) + buf->page_offset); + net_prefetch(page_address(buf->page) + + buf->page_offset); xdp_init_buff(&ctx.xdp, buf_sz, &rx_q->xdp_rxq); xdp_prepare_buff(&ctx.xdp, page_address(buf->page),