mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] net: lan966x: extract IFH fields with word loads
@ 2026-11-17 12:49 Daniel Machon
  2026-11-19 22:30 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Machon @ 2026-11-17 12:49 UTC (permalink / raw)
  To: Horatiu Vultur, UNGLinuxDriver, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Daniel Machon

Every frame the CPU receives goes through lan966x_ifh_get() for its
source port and timestamp. lan966x_ifh_get() builds each field one bit
at a time, with a 64 bit shift for each bit.

On a lan9668, this bit loop takes about an eighth of the CPU time spent
on receiving a small frame, which limits the RX frame rate.

To improve the RX performance, read the fields with word loads instead.
The IFH is a big endian bit field, so a field spans at most two 32 bit
words. Load the word, or the two words, the field lives in, then shift
and mask. On a lan9668, this saves about 1 us of CPU time per received
frame.

Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 .../net/ethernet/microchip/lan966x/lan966x_main.c  | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
index b8696fc7e9b93..6aa53e5208a02 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
@@ -11,6 +11,7 @@
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
 #include <linux/reset.h>
+#include <linux/unaligned.h>
 #include <net/addrconf.h>
 
 #include "lan966x_main.h"
@@ -633,21 +634,18 @@ static int lan966x_rx_frame_word(struct lan966x *lan966x, u8 grp, u32 *rval)
 
 static u64 lan966x_ifh_get(u8 *ifh, size_t pos, size_t length)
 {
-	u64 val = 0;
-	u8 v;
+	size_t w = pos / 32;
+	u64 val;
 
-	for (int i = 0; i < length ; i++) {
-		int j = pos + i;
-		int k = j % 8;
+	/* Load the 32 bit word that holds bit pos */
+	val = get_unaligned_be32(ifh + IFH_LEN_BYTES - 4 * (w + 1));
 
-		if (i == 0 || k == 0)
-			v = ifh[IFH_LEN_BYTES - (j / 8) - 1];
+	/* If the field continues into the next word, load that word too */
+	if (pos % 32 + length > 32)
+		val |= (u64)get_unaligned_be32(ifh + IFH_LEN_BYTES - 4 * (w + 2)) << 32;
 
-		if (v & (1 << k))
-			val |= (1ULL << i);
-	}
-
-	return val;
+	/* Shift the field down to bit 0 and mask off the bits above it */
+	return (val >> (pos % 32)) & GENMASK_ULL(length - 1, 0);
 }
 
 void lan966x_ifh_get_src_port(void *ifh, u64 *src_port)

---
base-commit: 994089a3fa3882f27f4bed9fc5815ee7df502e88
change-id: 20261116-lan966x-ifh-word-loads-3e9734db3d4c

Best regards,
-- 
Daniel Machon <daniel.machon@microchip.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: lan966x: extract IFH fields with word loads
  2026-11-17 12:49 [PATCH net-next] net: lan966x: extract IFH fields with word loads Daniel Machon
@ 2026-11-19 22:30 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-19 22:30 UTC (permalink / raw)
  To: Daniel Machon
  Cc: horatiu.vultur, UNGLinuxDriver, andrew+netdev, davem, edumazet,
	kuba, pabeni, netdev, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 17 Nov 2026 13:49:34 +0100 you wrote:
> Every frame the CPU receives goes through lan966x_ifh_get() for its
> source port and timestamp. lan966x_ifh_get() builds each field one bit
> at a time, with a 64 bit shift for each bit.
> 
> On a lan9668, this bit loop takes about an eighth of the CPU time spent
> on receiving a small frame, which limits the RX frame rate.
> 
> [...]

Here is the summary with links:
  - [net-next] net: lan966x: extract IFH fields with word loads
    https://git.kernel.org/netdev/net-next/c/6d53e01dd9bb

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 22:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 12:49 [PATCH net-next] net: lan966x: extract IFH fields with word loads Daniel Machon
2026-11-19 22:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®