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: 13939791 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 C7D6DC02180 for ; Wed, 15 Jan 2025 03:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lRq1k9DQ7dcpFSRaoKAokYKGtHAonMVK3g5kkcieDXA=; b=qYBv6JPppmcafLxudsqCzW2Z0R yY7Uy+cCv/ZqwKd3/ZbeLJdnZQnMiK8fXYv67cYJaimuTnt1/3H5NwAtXaKl9tK+6W9Ndn7byHWMJ M5uE6lg4Wh7VOqIXOe3AamABaqAe6Zf4TpxSu+xVdX+QFgGVgsLPPeZvgCrWpXXKYQD25qAerMgxy kQAqcTg1L/qCgTtSgADAzfJ92xvKI19JwMcSseNn8HrVCq2yT6ZXgJOWz9cD34wvUDY77ed7ql/IL R7OLSeoKP1RQzGEuKMx+njgEd8bQA/HIVNW+AtLEiaUiAWOlDMsHux8eVsZxAc/R9uVLXVV9ovP7c XJx5M/nQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXu6W-0000000AVip-1h6L; Wed, 15 Jan 2025 03:30:04 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXu44-0000000AVFN-28A3 for linux-arm-kernel@lists.infradead.org; Wed, 15 Jan 2025 03:27:33 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-21634338cfdso104953005ad.2 for ; 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=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=lRq1k9DQ7dcpFSRaoKAokYKGtHAonMVK3g5kkcieDXA=; b=mqrYUyVjzUmIoBzFXuMvrtAaIk4qP2n9NIIMN2HcXyuvQWSIFIjepvr0pU/mVDRqh2 7ERUHp5vaDNuBANNheFQk0c6kjhBNE5gNKevmSmQI8TpkRVEtVGh2M8SPAYcooJCp5VB MpwAFO9gCmgwy1xDSsIGGhrpqHYDc80C/ptwmwhglz2+PeQ4dY1QXz+7LPgdu0iIb+ru vzwxfSMd3JjyXLxMjRcTF90o3CgRzXke4yOk4Osfcyy1fOG/6y6ZdpmW8jG3ZPsgQAsr 8/LaoV54p+G5CW/0DU6WGjC5tltiOkhh3YytgtCehfCYEgmxvwkf1Ikf7uR/FlD0Tig4 51IQ== 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=rc43JKeyNk58GIkkumA7z9cPMAiZtJ+AKzWR8nmCXTdbqPjTZretykbxXyM8ZU36kQ KvkwiHbbVI1k85tVf5WDEpcioxYJfRpncdKzhrOfpj8l0kjkLSnM3gOgYYdgJ0fohTO5 90F19pPElpuzMWG8+oVb03gvNgxYGuLqdyMyrViiaUg0gBjPmBYBquXOX5h9XOWFdaf9 l4VJW1rSE6UbLh0rEJf7k2G374qKLOhv19Wprr5efC8Ftzl08C7I6iAslicUhdGEkqpF p4A77o4FgtYGx9EM0MMEwDVbWXqfoxIG3bcmRSSSj8Ca+/3D5bQSAb4QMGAOw3FcbeYW +Bsg== X-Forwarded-Encrypted: i=1; AJvYcCVgcdPg44Sp+I+eMWEW35J9+KEyqkJvB5sFP2+LTGKf8xke2WxdW+8CiIsle2VqL7n+FJ/0X8HLx4o/KX9RFEBk@lists.infradead.org X-Gm-Message-State: AOJu0YxQtbe7rSbMldxsnBJQ9qUFGvfiOYihiUUGkT1425wMxa43I1qE 0a/GBFiDk4hYdllQUAa4M6beJF/eR/flUNk6t8SA1eutmua9/ROd X-Gm-Gg: ASbGncuS/v7TP6QWAAyrpceJbbhhgaCc4MBqKtlxvlyFl6xjykX69MC/MG+OCLKbHqk RTCb3F6+ytl14PJvVBeocYXhExa/Y2LoG3v1dtZZPB+GhnyPOA1duoJjuTLncDU9V/tPuJ5uycL M5D2AHYOiypNmlasj1VzODK0+IJazjbiRMzBkSn7Bx0vHaX464SoW+GJlLsfycMuEPc/imgCKjJ YFb4Jh1gBmh9cofi0c4TfLwwBiypN1RsQ/bhDMvgrg2tie4ZMZpZ7VNx+PcBwh6nEhjZg== 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250114_192732_545232_EEB24A99 X-CRM114-Status: GOOD ( 16.07 ) 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 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: 13939792 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 B3DD9C02180 for ; Wed, 15 Jan 2025 03:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8UUplh7fAcpeM7Q5zE9FRPEWMTlb68cB4RMo0G5W1ro=; b=DtS/5qwlN8kTBZU5iwwlUH6V1i Xm2lWZXaBB5VlADOA/RiKNXO78pHqHurY8t3zh1nThYyYXNiNQZ8qCO4gdAkvJh/bp9hzT6EMtsmp 1Hk5iDiz6T+qtjb4OojHFaQLZG2AkXJwhdnotnZWQRjtqLhftSLm18WvZEyRJws0XZP6296cxK4yE nGxJIiYqDoyIoVpLdijM2Eyi2OZK8DL5Uv63y0Im0NCWIZNC1kOqjpPkrfSmhgGeTDOXiBfSHDBs9 aoPRn7Vd5teXrjyzTigFoQwp+fR2oKspD0+Ccaj3ZDhodFGIrFGqXdpsLqDvYVFLcCA42fa5vfLU5 +0fYBQYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXu7l-0000000AVsf-0E4V; Wed, 15 Jan 2025 03:31:21 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXu49-0000000AVFs-0l6O for linux-arm-kernel@lists.infradead.org; Wed, 15 Jan 2025 03:27:38 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-21670dce0a7so135234615ad.1 for ; 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=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=8UUplh7fAcpeM7Q5zE9FRPEWMTlb68cB4RMo0G5W1ro=; b=AyA0vTO05rWdhJevl8Cd6fGLLe7B9bkWUheYTqWeuiFWb/c0v6CYuv8atMqgc8CUv9 oQvOc3QDBvURqWYzr27YYXn90g4ykSBldWfsTO2vqVZ5s8s5sC6YZNR0/giYvY2Jba9D 1cRyFZr1K7yLplAoTNU7ZU8Wq0dSRJUmfOVw7aeGynlYOJP/DposEus8Z4ucnH+EY3wr Lbchda+MvjMAS7WaDuWt9lx+aXDYRXVt5Xi27mpr64TSh6J3Imux1yQkapE2EE3qU371 XztODV9xl7fwC47iKADA4DwDPRT+j8wM5TFJJZuMmAL7Ofa5+L6fx74EMcznMj16aeEo hZ2g== 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=mDae969dhMulWbYUw7V6S8jG9yS3cR8QUbZG/JJa/R6iFgYiRF1ULGC7TVWgPOXMQf m34CqwP1wuj7CvP0Q/uihjdB49hggIAJuQzZ5nYLvPna4tzWssu1xqiKmdmmOneasUi/ T1MaJglae0WyTzRmgrBCEzAiAp0S8TAkJxYYAHCq6qVmyIwTdJthyr1DU4xX/yvAKOJ0 OB2lw+jBH5dDTao5tAUeRK54VFzX0O2HQ7U7qa+KDASBWPnOFQTQvV4A5S4UhFZBsw6i 5VK9sGhqUCePjOSsCnN0LyWkK1Ap77co00gGI/QCH628WrfsWz9O5wRlxRJHLKXEL/Ms +JWw== X-Forwarded-Encrypted: i=1; AJvYcCVqw4yILF9XpJrv4Y//ycsJOrX/6yT7sPheAnmitN6aY7PlqrvhVwm1uEn4hbpVF5JKp2sVwRC2rFfMZ7gdLSLf@lists.infradead.org X-Gm-Message-State: AOJu0YwGj03P8Zzsr/MRNmDaEqSohtwxYvSmU5n+5lZvspF7sjLz7d+q k50aeYJIN18Z5NM1uPL0du9L2zG+7NnGdQi985EDdDzgh/b5EwznhJg/Rw== X-Gm-Gg: ASbGncssePv1zBZguzDoeQlxkvAReNr6gkovlY5bPVx9cJJf6F9jxurG+uz4Yrs8BWh RamwIAZBKJqSWm6FKUtObDJbRM/RFtnhVRMfcGZLA1GT4sUkNfeGKr97c2DMzz4V0rjM84EExmv 6E012rOYeXefAFGd/0ouI2HfQTw9GlID1lXrVxO7En1Oe0WjMlJ/3jbgg2wkpBfeI19/VCefDyX ERw+70gptnP30809sLIHK1ymyZ6wOPVet99hw51v3wJg1URMRWGUR1Y6xu2YvPRdTqi4w== 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250114_192737_218323_14BFC32C X-CRM114-Status: GOOD ( 14.15 ) 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 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: 13939793 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 2B410C02180 for ; Wed, 15 Jan 2025 03:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=F8jofsVUx8ZDCJ6z8E8sSP3dj56gjS3NJDcAVJdYxeo=; b=oLLR5SLJcLHMGwBe+kqDSQNyq4 kgPkpjmUOWSwkIGgHGpTUOEwe2zSSroKW63z8vffnRPcJ+NME+6QyIINSd9vVhwngzSkPCRs8a+Gb r8w34J2aBp304ZQBz/WKRH8e5mbkv4aWsyjUz+6xVzSLTighgaUcQJkW64+Uu/0Q0zVos+1ScdHZD 681pzc4UwmJw6h7pGNdY+XPB/gnkoSszYm6sh+hPJk7xhi/639hGGmimksTLymrZbX2Iy8qPIhRUT t2iDrf4/MwCwJHbe0Ah/0E8/zZOh/pTfnieb3qamCEr+KIvhA1RZcdcPTqkKsGuzwNpTA08Jx8oPX 7dSet0mg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXu92-0000000AW1K-2o3d; Wed, 15 Jan 2025 03:32:41 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXu4D-0000000AVGw-3rbv for linux-arm-kernel@lists.infradead.org; Wed, 15 Jan 2025 03:27:42 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-21636268e43so146462855ad.2 for ; Tue, 14 Jan 2025 19:27:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736911661; x=1737516461; 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=F8jofsVUx8ZDCJ6z8E8sSP3dj56gjS3NJDcAVJdYxeo=; b=NXZBRpH8nSepMEPcbzKp2iENmxTCM1lq+letP8p6GBE+KVsRBXi27suWbUPruJ0WwV j6ALJ9jc6TaCvjGJbANNZYsTYRxz7p9Z3dhlHeyxCIyQ1vZ5qZfnpwstTxjwGp+h9Vah 94cCD0f2yXgqyEKFSiLxg8Zs3TbV9H6oz9jOZIWq7v56GynJWfNEP0OQdCmRx3u2Hy1N iHQXjmf7Ibi39BH3PRnWMuAmiN0iUmpcj50fWwr0Sr7d7w2uM2s5CaDhwC4s/tZVFidd BYymJtbnhIeUu2hj0YIM/Q38SoMsZW3gWj6NNDTHhQdxhyaL0HfyZE4ZF8KUik73J05C FIEQ== 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=GN2QFM1kk7GCUhpotEs/LieUD4a55rY0DLvK7KYnU4hBAmFJqU71XrvxzlTs5MAiU/ 5NCHj/rtB2SY4f/aiiNbKrcu81SxkPiiDnz5lFyKB2gXexg3gCyOcn3+ZtTDTNJVFv4l ry/xkX8FwKz5wgGnE0IefaHUrWMBVr0MYE3gnM99ZSdSbX2b7FrjMakfpFmc6nnwGMgp YVrxxnD3tWrzXIKgKAfKe9UlEkZtEatd0RPhNchMR1BGy+DYEVbaGowPfwipD8CJj1fo 6SVhRogw9akf56PpLFElljW5T12JesRvkNr8g6hondwCvaZl60n2Bd3SLhEwGsJCKOQZ se0Q== X-Forwarded-Encrypted: i=1; AJvYcCUruA78vymXYSICBDvgsYoPvt/U11I9q933JXY5geo6R6tLNDq75lDWuZWOP5BprXpCsZrXm7fGb/u633kBCwwz@lists.infradead.org X-Gm-Message-State: AOJu0YxWxcSs1DA4q+q8Vw6j3Q9OzkLBRLEl8Sh0rJ8j54WhPahveLYv nJfJKQzhuFasiZO0a0ho0sEHC/e8ghnpsJKb5UKYP34injk4XuR8 X-Gm-Gg: ASbGncvKgFs306QrDwepHpsjfMun5aNIkvUsVDECNi8DIBGHXTzhEeM2bCGea8NSMne yxiDnYbVZqGWs6l17xhJ+8OmG4g019KH2Z3XSGpfUktr3eTUmQ1ice1WhVVihQ2qtb44IoaEXkR WnNZZ830MhKrCIb//zrC+Sllq/VE0mHhNbi66vpwQeUpV4wDHx4SelEl1qYdGJtE5uqPimO3xRH 52P4c6wT9QQLS7p3FEXBIObaOYmntjlgfGughJfkni+keX2gy/KVpM6uGAg0knRVSrx2w== 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250114_192741_955443_4979E7C2 X-CRM114-Status: GOOD ( 11.51 ) 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 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: 13939794 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 BED67C02180 for ; Wed, 15 Jan 2025 03:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vrnZOWuzbTsFJQSfUdSJAVwNu1OpPEJIPOluJRIjDnY=; b=GlH2h1y3aBcDQM8hF5N1REAJUx RFoCY0toV8w64p/Xd+EBIl8mytEsi5whZOEci+eyAAECiFQmSdEW7suOtDWf82tR7AAKMjzLLbnfH ofG1JD2BiX+UJmoyY6YecfeYA8KZjxpk/aaTCi++7WS1F/TH3otOKXC53d3oFZiPnsMq/NjmpYRZo e02DJ8u82sgtANkxRFnxS0l6kpjuVkbm+9j0LFmL5w8kzYiRUshI7jy8EiS1/VRMB6vMxqGiPzG4B DEtKEC7d9VAJF0v9gYOSOe/mSHzb/dQTRdCPuIhGyTYMuxzLaxq19kgc6I63inxUPJhYBTmwoPwEj t/qWPzSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXuAK-0000000AW9r-0NNM; Wed, 15 Jan 2025 03:34:00 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXu4K-0000000AVJD-058x for linux-arm-kernel@lists.infradead.org; Wed, 15 Jan 2025 03:27:49 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-21669fd5c7cso113757055ad.3 for ; Tue, 14 Jan 2025 19:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736911667; x=1737516467; 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=vrnZOWuzbTsFJQSfUdSJAVwNu1OpPEJIPOluJRIjDnY=; b=jm+qjlKIgBGAU8sztcqN3EEnN3n9K+qS2aYCEaT4rSdg6pQR/xW6k3dtTKiccMdHUX EJfRlCI9JbLMGeP+J54W9vFPGDaof1sKSVgBkSuoqvw8fgZ6YUfgY8fn/rG+vQ2F+Cxc 4Lsa0JQSYkIWbGI8cvdvehFCHSsC8YKmrI8irN7zuRCAI1alrEjWhstsdTNZPXUscPkx ovOJALcoGyMMSbye+cgPhHNfmwGLB019lRKQn6iel7QzIhvfR5AyD20ZldpFcTkK438k HkWwvvOAmWy5bVNE0og88idSDvMzK759/cSExBuQHe4j71or2Ek9J3yWhcF4MJGy0JP5 yqVQ== 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=hw9iXqaJXqNpSUtxwuRBAWoqtsKdvmeBDqu/i/Ab84l+YjOib6AQXgTM+ukijUDY3V rakDvraF//HgFPCVhtxcfewSyfmSHstAZ960Je1kBmIqRiCuZTumkMunBrNvaLu+kM0i hEyDruR5g98Qo9ABMS5EJ1HuO68/VQvdZi4sNSN3yypnTg7GQD1fYsjiUVjKk9c9ffN/ erVsn1szwp+9JOapQ5koLx2udT+7Yz/FQ51MJOdZ6XJjOkChw+uqm12to+M2CTFSI7+o NYoW3v9DOCMGqek10mzK34MqRarzM2E+CWrUupHS///ZifAf9AgTbKfAFXpxQvnCiB0Z zBvw== X-Forwarded-Encrypted: i=1; AJvYcCVe5lxXIHrikD0igkITLUcK+u43MhVPZ1WpOqIUWtltPP4TAxVVv4H4jBbqkWKYyPI1NiFqT1EKNbHFdYaqx2Un@lists.infradead.org X-Gm-Message-State: AOJu0YyzebWGaqeZnL7Qg3YiTeVyd8xkWq1suMnKCl76izBKOaE5qxgX PIgfRvBZ5+DUyiGWJTA+npwAGI7Ri/ZWa6mEvkvfsk48foAb60bb X-Gm-Gg: ASbGncs+FQ70o80UuOUALCWaB9iTu5FpeWcU+jb5VmcUjceVr3fpFrUDtlN83GyoNW7 UlLSlpNdA6TwKPZ3DQlgSzYN62uajHgtMxsbx2yd87ZNm+8c5d0RrZyTpZEnOuBQtK1j+/PQNDv noSGxS7VYjhQWweoHIfud6j3KE8zbbAIGfDnypKAxfYCeTymu1cE342aMjEeGR7ItO6APQBM3dx sYlsrCtqFVnLpgoReQ3IbB3F349LN4Yu6qzS/qX6DQzDohTQBfpcmDAjcPyFtcBRdRsiQ== 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: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250114_192748_062110_47B3EA41 X-CRM114-Status: GOOD ( 11.60 ) 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 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),