From patchwork Mon Jan 13 14:20:29 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: 13937436 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 987B71CAA80; Mon, 13 Jan 2025 14:20:57 +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=1736778059; cv=none; b=EDSR16AeXe9pEr1q0odcibcsXE474Bnss0MdDcabc6Gjfn75Hyp1eBevmLkgK83oMwC+GjfNyeBCePwOr9ZdhmlZiEuwC4c85gudnl3I4499R+y/pIXRkXIbM9ufRZ/APYQzz4pfOz4msOntm0E+5gX6GK8j/jgVRasy8Or1ik4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778059; c=relaxed/simple; bh=1PVh8C2yjnUHnMVEp1XjPPO2t1Qz//HqdwDj2GiJ0PQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JgXDtnBlbWbMgOUaI1+7fSLUdmelCmMNuhdf+GdSdMcZQmmo3fV61W2cAOsdV/krQf+9NMETotUDBzRsykDNxlcpo4/W9gEj2LbpSXCvr5uAI2F8gsYKNku7qgU5K7Ig806mtLdsWvmFRRZZhgcFbxXt2P8p07Nxt6Dx8nBLM1c= 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=aJkyLbWd; 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="aJkyLbWd" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2163bd70069so78103685ad.0; Mon, 13 Jan 2025 06:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736778056; x=1737382856; 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=ccKpY1leYRtGPw2tEgtgVTc2GSp/SOKDOJPp9BmSe4Y=; b=aJkyLbWdeiaXipoA1CURQJ0xadX9/+3nL8d9MvUIABM+ZMq7RoHZhCKblUCPkimfNr xjrVcTxR8ozGZYVzjfcjbje2J0yjknf2etjiUGG+9dgbxXHZDeBBu5ZPtMh+4meBmR5H F68ZwzEuq5vKipSQuhoBeQd0eAkm787AWv3kzRLowLTzlWHW8lEOttC0lpfTannZXZbA E/lX0Sd6Rj6QUq85RRvrS16u7TreriFINbHpuAVtTA5i1QMhFYGebhmo9R4XZKFexzfx DZCayTpBXsFkgSdCiZIH4W+1DgDZKqqOOdCJZhdhqdA4j+dx+JTnrZfoLlqawj5XcX2d wohQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736778056; x=1737382856; 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=ccKpY1leYRtGPw2tEgtgVTc2GSp/SOKDOJPp9BmSe4Y=; b=aKBxNRD/aaqfGZF9Rn/a0UPKvbP30KEtHDQebdHDLjmO7KOEO68aFWry/xJs3/ULvP Ko22oYcS6jyOyilnn3A5qyUL2mAhbclDmDXs++EMQlXkEp/fJwPJIAq7/Vx2ji+9JGBE d7Owf1wVAZ3pQNpkD1c7hS09JVMWadCfXF4stS7J72J8RsMfl69a3Pc15dP7+pPNFMQk lGvmHIRpdulW1//AUsLBp3mR/LCuNJ3gDxz2sTOR7MCUwObbyxRTqtAYmTKROyXO3TeJ g1Qi/OoC46WJpQRwKTjDiOFAbEE6Ok27Em0MHRTbeqiuVBeI9yJ2jlBJaFfRXakqPGaa rQ1Q== X-Forwarded-Encrypted: i=1; AJvYcCXQSEwkhY12yunj3z5NHgn548Z+Z5+AtMEUzS2Gy3DA6myuHLFiGmTunmBb4pAhLh5G26YResxL2cEMJyA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8FY6NZiuKxfQM+ye/vQsGuuAQZltZwPXOjCXW1BG0Fxl03uxC mEPp7q3MeQGvRtyGy5mng7QU/JAOv9+xeXODIlHTMl9AgkauR0SbAPQzUw== X-Gm-Gg: ASbGncslrk5OYNaCv8yjzFEMsQrtn855bqHxj4MV/9Y6GzcMowpk+K7KVB4WtTjNQpp DhdFe6/INg7jc3kWvs8hfrAiIXPorLXzj3wyz1dDHIlpCuxX//Fp4/zCrI+q627htXC44olv8RT 13BebtfevtbSSrT0qDPCoWS+4naa4yubWoAoBYjTtdWDrd4ULpGSif6oA5Nq9gUMVMl0RusYZC1 S+KzBrfE1gnSYkRHnIzB/4MC1eKdaJW6ZHNyxsxsU5/jPEvNtzXoRAp2OyBu/OJAsNiTw== X-Google-Smtp-Source: AGHT+IGKv3lMSzF+D1LHruGGkM9/Rgx0EUTXEe4+mf7NCbt27F7Ct+oQGMUGSmcsLeFCk+WT+xqn0A== X-Received: by 2002:a05:6a21:4a41:b0:1e3:e836:8ad8 with SMTP id adf61e73a8af0-1e88d0ef9f6mr36157231637.38.1736778056233; Mon, 13 Jan 2025 06:20:56 -0800 (PST) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72d4067f0d1sm6089222b3a.136.2025.01.13.06.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:20:55 -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 , 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 v2 1/3] net: stmmac: Switch to zero-copy in non-XDP RX path Date: Mon, 13 Jan 2025 22:20:29 +0800 Message-Id: <7e7c594913b003b3eb7a836042fe00515421218e.1736777576.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 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> --- 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 58b013528dea..6ec7bc61df9b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1330,7 +1330,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) @@ -2029,17 +2029,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; @@ -5574,22 +5578,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 Mon Jan 13 14:20:30 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: 13937437 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 E75731CAA80; Mon, 13 Jan 2025 14:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778064; cv=none; b=on4UP9Dmlz0uZqIFHixlCWCqIfVUYQnxwnAw4FepAWc1DG7dB9IcgRWYjeMkpmWt0VFLH8UVuzh0YHInFj2OFexTYrHZYVkpC+ii7lB8xpt83N6rKQZUOt9PV/8AnRMwSDRpCVg2o8IjR6XAZu9hFBjxxi0t4dj3i5PC4qSa9mI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778064; c=relaxed/simple; bh=/b1oafs5v3Q21RTlmWKOsnPyCGjsECPHxzk/z9aCqsI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SL/uq6zjYO43hqe+JGlp64tMPjMMdaKZbQBiusxpqLN2b95O6xur0W2Wai44R0Rmn5AlX/bUPZt1nUfxnVNoUFKD7WKPbNcYXObWoKmHz2N1zqR8jrpAb6L69lUlhcXDQM7OaZMU73I8iyX35BUUtoQ3tY5xQKXzn5d4UgT9QiM= 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=exrPIoy5; arc=none smtp.client-ip=209.85.214.176 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="exrPIoy5" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21636268e43so101022245ad.2; Mon, 13 Jan 2025 06:21:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736778061; x=1737382861; 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=YMPRQoz16EyCK3xxuYYjiNmaFFaTgtlHtG3fh6pk8TQ=; b=exrPIoy5KwB0pv9wvAtslZz748DclA9Vy50jo925ybnOOWCVYIdAynt93tuigpd9Fr yRMCkA5+X/yqtL5NULoXWMMukjcy1rNYURBZMzAS+7jhDME+tcNo9/OdMbyoFfFTNi+H LE/9z+yS0EPAodUn+OVq17Th8P5OGQWlrI3OnO51cicQySMV1IHIcgz40F4WYfM6TwFl U9b/7WZROGfouPaq4Yrp6iABplzPk0EDXsPnkZIwzNZUhMGEn3AJ94vsHgd5L0ZCDApB d+hHkSQcErgRxM9gLJ68c771+9e+rwG/7/BSQqhldA7u75+/2rdr6Gtcsp60nVJyUwsa UCGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736778061; x=1737382861; 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=YMPRQoz16EyCK3xxuYYjiNmaFFaTgtlHtG3fh6pk8TQ=; b=krI6KuoJYVTEwwdBBQILbi1/TLKqDe+N+T354Iyslm3ifKDqClZa2/CYo7rnTyE5z2 WXfp8hz1q49zkHHukQAiyV5+zGdrcH8q0DRLK2EU2UEwbdowOIergd4XKP82X3Mt3yEi SQEwCpmy6cWJvkGEfHzCLmk1Y5YiAAR1pU/THqGbh0uq4rvrRjhLaHOwsBVW2f8oO3Ic cYJxp12XXQ9EX2KWDpLKJya4TKRcZhQ3bwi+Q0ywojgOCHlJVFezFCnnJVDzO1oE7mw9 oHwf9VxBypw8Xj344o4rbj6MEDw63l2qwbNQRFMQPvO5v/AwUfx5o9JkdkhZUzxOnEl/ QpVw== X-Forwarded-Encrypted: i=1; AJvYcCU3u84s+voShpExgPL1/ZlboF8liVrEROkMc7y4JjMmlZk6Ge9MMvTfDJZ+3iz+2P7NYbkg1La7vf0Xi3U=@vger.kernel.org X-Gm-Message-State: AOJu0YyA4iyL50R3d49V9dfqY0vJJk1rqou/nkLQoeU5AMt7CsFYKHuN YfNfsoSC9zDjxshSoezfCSo77TvGpDmkdJMxzSIXGpp3zefAt05t1m0JjQ== X-Gm-Gg: ASbGncvPZQKJm5OEwJdcnRjviceLY2jSEC5vKK5bGjqu1kThUi5SmqkXdsqR7p6GQNS V/g86/1q7L73Ari706o5avKANfrZJpdXSKTxkJXVzCuygAUj5/sbzUEE2YEFhm1/BvL0ai7Y4/e SVVcvIiwbgvr1JgZIcRUaQBaWzuJ4/zpxhv2+RrmYGA5Yf6SdWizUOB/xBge3/mLm1oIA/oq19o uC6czALs2HF6HBoGex5mzKrSRdQ6wHtCBEKl5ekm/cBmlu2lcb3WrXaVxDpNpsgDVCRgw== X-Google-Smtp-Source: AGHT+IEzC0EK5taqL22BOdLKvphG994lgupCqXrHRE6t3LRIiNlReqX+BVov6VJfmVVXuiJkjK9M/A== X-Received: by 2002:a05:6a20:7491:b0:1e1:a06b:375a with SMTP id adf61e73a8af0-1e88d0ddc82mr38181731637.35.1736778061055; Mon, 13 Jan 2025 06:21:01 -0800 (PST) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72d4067f0d1sm6089222b3a.136.2025.01.13.06.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:21:00 -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 , 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 v2 2/3] net: stmmac: Set page_pool_params.max_len to a precise size Date: Mon, 13 Jan 2025 22:20:30 +0800 Message-Id: <3f0cad344d45bb15957e20059f9cda44d6369419.1736777576.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> --- 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 6ec7bc61df9b..ca340fd8c937 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -2048,7 +2048,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 Mon Jan 13 14:20:31 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: 13937438 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 52AEF1CAA80; Mon, 13 Jan 2025 14:21:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778069; cv=none; b=qh959P3JEHLR+cx57MNQFSgRED0yQRxftUMqu83sWOKT68jR8gQn6Vj4o6Mb6ATZRqETJxaaWklqdaK4HTMHKH3ZMumJ9UoKQS+K7Rvv9H89ANIqYF9XGI6hQQy15Fldp+plUUr3jkfllvE/TAIlPU9NuH5LI5TPOSyNch4giLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778069; c=relaxed/simple; bh=MKWAKejBR93uTWtWIK4+DOobUQNzCP/ozdxmNfH+pkA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tjM6cA/Uvw1z/+CNJhzUgoMtFeK9IItmlFChLXUPR5O3T9q+6ONoRcHT8DYHUuRCAE0T+aYUFTAfm5sPEcmWVacOqpTID0B8VFSh5llQ7P7jLh5a2f97rB/dG2f0gjyb32Ob9UpgXrIxX1x1aTqa81osOsi3ly+wcrSm5sB71bk= 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=KPu75jIu; arc=none smtp.client-ip=209.85.214.171 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="KPu75jIu" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2163b0c09afso78197155ad.0; Mon, 13 Jan 2025 06:21:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736778067; x=1737382867; 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=0Y3BfZz7MekY1Z7yjTuQ+MWMRBeT+ElDKi7mbMigxYQ=; b=KPu75jIuz6D2Q0kjnPqE5fImfBGRzGkmix77AzM5BKdAxyt2mvcUCXKtcBNFO6sdaa gmXJXTKeKTUFShaS7QFtDGN2UKE2aiKmC6VEYiifpwxdvnH6cwzdm2RqJxcmFl5QrkwS utQPzEWkJ+m+TAS9ONLFvPQlAGoZCIoeY5yoSLJZ4wDSSDxc/poVSElqwisvwIYw5M1k 1biqwty/Ms8NikY1FDSHHzowMHXjUugjC7wEMD7ogR9hZY3cZzosfUX4DedDWKrsSdNH MnFbrXuzcRhRbyI0SYcpq90TuD2P2J6BXFLT4VlefxcaUi1WMaRYyqeh0Y45X56dpaa9 iq5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736778067; x=1737382867; 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=0Y3BfZz7MekY1Z7yjTuQ+MWMRBeT+ElDKi7mbMigxYQ=; b=rYYU5OefXU3DXhiwchGYCgMlfj6w/cuiP8VSuIul1tn24/WrmgMo0cuN0xGlheMb9m P+k8b+5K4jb6CAWzuQ3c0LouG9s0rZALJ9Sm1mX6Z8PlN8e9igMKV5Jhn/yQg9Jg92gm KvbBpijPILV1pyLnqiO7oeHJdIGOgwcGTzAMIC1Dh6+MWOs5lI+xFN76dR6a/S7M5/cT fr2KE736Qxvb7gPNy+ZC2o/5upk/g4rA3zHlyWkBMbqtnJDSzxlhQVqF/BoFi7BDfDuk 1GPy/c8eWWaliSLrdzpV45ui4SeL4JD7rf2/eGqNnJd/4Z6QU+t1B89YVNEeZGB0+Eao 6XCQ== X-Forwarded-Encrypted: i=1; AJvYcCWZGo6nSNku1P6A9Qg8nmQiMbda6E+AeiOd4OOtp7FycMHcKwcqE5jIaiauNTZq7lVf8AN+uetUxgns+nI=@vger.kernel.org X-Gm-Message-State: AOJu0YwdVKpCEavBhYh9d/Jp6M64G8qbn/Ys+F/Sp+W+M6eqmYE/lJXv /2Nv4x9O/fdEF7+7B8nxrBxiFVXwS7mrp7jOvESmqerLjVM61grlQBBvkA== X-Gm-Gg: ASbGncswHnKLV9K/QjmysSt3KHI/v0bp0rdLgaAknyjMMlDi/6k+1+hHtl4U8alhmRe GyyvUEe7Kn1yMP8o+l/c3sXIdM9wGjUkU8RW8Bz8ujdi0gZygcwgSHy907IeODdk3HYQkvyN6uC QMKZdO7K29j6cNGvWaH7iJ5vhbmX0k2Fh2I56RTpIYUGH8qmftu8Zbr753osWddsIfVl9xvAUl3 EJiatBcPoPR1MgIfYbiEi8M4CG+FzhpWhxT63Yoswt6H84omH6CM7aWqYP06EIcSu4JBA== X-Google-Smtp-Source: AGHT+IFg3sXPhg66pW+bXzniVJ+GWukBtXItLNm4Jyw30Z7qC0CWxK5D402KdXwOTZ+TRgV9PNNiUg== X-Received: by 2002:a05:6a00:4603:b0:728:e745:23cd with SMTP id d2e1a72fcca58-72d21f113a1mr32141933b3a.3.1736778066667; Mon, 13 Jan 2025 06:21:06 -0800 (PST) Received: from localhost.localdomain ([129.146.253.192]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72d4067f0d1sm6089222b3a.136.2025.01.13.06.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 06:21:06 -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 , 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 v2 3/3] net: stmmac: Optimize cache prefetch in RX path Date: Mon, 13 Jan 2025 22:20:31 +0800 Message-Id: <668cfa117e41a0f1325593c94f6bb739c3bb38da.1736777576.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> --- 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 ca340fd8c937..b60f2f27140c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5500,10 +5500,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); @@ -5525,6 +5521,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),