Skip to contentSkip to conversation

pcnet32: switch to napi_alloc_skb() and napi_gro_receive()

PATCH In review Oscar Maes 3 participants 13 messages May 25 – Jun 2

Subsystems (3)
lore
Share & tools
lore

Oscar Maes

author
#0 lore raw

v2 cover pcnet32: switch to napi_alloc_skb() and napi_gro_receive()

Use the newer and more efficient napi_alloc_skb() and napi_gro_receive() APIs to improve RX throughput.

In my testing this resulted in up to a 25% RX throughput increase in iperf3 tests in both directions.

Changes in v2:
- Clarified why releasing the spinlock during napi_complete_done is legal

Previous version:
https://lore.kernel.org/netdev/[email protected]/

Oscar Maes (2):
pcnet32: stop holding device spin lock during napi_complete_done
pcnet32: switch to napi_alloc_skb() and napi_gro_receive()

 drivers/net/ethernet/amd/pcnet32.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.39.5
author
#1 lore raw

PATCH v2 1/2 pcnet32: stop holding device spin lock during napi_complete_done

napi_complete_done may call gro_flush_normal (though not currently, as GRO is unsupported at the moment), which may result in packet TX. This will eventually result in calling pcnet32_start_xmit - resulting in a deadlock while trying to re-acquire the already locked spin lock.

It is safe to split the spinlock block into two, because the hardware registers are still protected from concurrent access, and the two blocks perform unrelated operations that don't need to happen atomically. The call to napi_complete_done does not require external locking.

---
 drivers/net/ethernet/amd/pcnet32.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/amd/pcnet32.c +3 -1
index 911808ab13a7..4f3076d4ea34 100644
@@ -1407,8 +1407,10 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
 		pcnet32_restart(dev, CSR0_START);
 		netif_wake_queue(dev);
 	}
+	spin_unlock_irqrestore(&lp->lock, flags);
 
 	if (work_done < budget && napi_complete_done(napi, work_done)) {
+		spin_lock_irqsave(&lp->lock, flags);
 		/* clear interrupt masks */
 		val = lp->a->read_csr(ioaddr, CSR3);
 		val &= 0x00ff;
@@ -1416,9 +1418,9 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
 
 		/* Set interrupt enable. */
 		lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
+		spin_unlock_irqrestore(&lp->lock, flags);
 	}
 
-	spin_unlock_irqrestore(&lp->lock, flags);
 	return work_done;
 }
 
Signature · 1 line
2.39.5
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH net-next v2 1/2] pcnet32: stop holding device spin lock during napi_complete_done

Quoted 11 lines · Oscar Maes

napi_complete_done may call gro_flush_normal (though not currently, as GRO is unsupported at the moment), which may result in packet TX. This will eventually result in calling pcnet32_start_xmit - resulting in a deadlock while trying to re-acquire the already locked spin lock.

It is safe to split the spinlock block into two, because the hardware registers are still protected from concurrent access, and the two blocks perform unrelated operations that don't need to happen atomically. The call to napi_complete_done does not require external locking.

Andrew

maintainer
#3 lore raw

Re: [PATCH net-next v2 1/2] pcnet32: stop holding device spin lock during napi_complete_done

In reply to Oscar Maes
Quoted 4 lines · On Mon, 25 May 2026 14:54:36 +0200 Oscar Maes wrote:

napi_complete_done may call gro_flush_normal (though not currently, as GRO is unsupported at the moment), which may result in packet TX. This will eventually result in calling pcnet32_start_xmit - resulting in a deadlock while trying to re-acquire the already locked spin lock.

Looks like a legit bug fix, please add a Fixes tag and repost for net (rather than net-next)

author
#4 lore raw

PATCH v2 2/2 pcnet32: switch to napi_alloc_skb() and napi_gro_receive()

In reply to Oscar Maes

Use the newer and more efficient napi_alloc_skb() and napi_gro_receive() APIs to improve RX throughput.

Also removes the manual calls to skb_reserve(NET_IP_ALIGN), since napi_alloc_skb() already does this internally.

In my testing this resulted in up to a 25% RX throughput increase in iperf3 tests in both directions.

---
 drivers/net/ethernet/amd/pcnet32.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/amd/pcnet32.c +3 -5
index 4f3076d4ea34..06d5432bb464 100644
@@ -1220,13 +1220,12 @@ static void pcnet32_rx_entry(struct net_device *dev,
 		struct sk_buff *newskb;
 		dma_addr_t new_dma_addr;
 
-		newskb = netdev_alloc_skb(dev, PKT_BUF_SKB);
+		newskb = napi_alloc_skb(&lp->napi, PKT_BUF_SIZE);
 		/*
 		 * map the new buffer, if mapping fails, drop the packet and
 		 * reuse the old buffer
 		 */
 		if (newskb) {
-			skb_reserve(newskb, NET_IP_ALIGN);
 			new_dma_addr = dma_map_single(&lp->pci_dev->dev,
 						      newskb->data,
 						      PKT_BUF_SIZE,
@@ -1251,14 +1250,13 @@ static void pcnet32_rx_entry(struct net_device *dev,
 		} else
 			skb = NULL;
 	} else
-		skb = netdev_alloc_skb(dev, pkt_len + NET_IP_ALIGN);
+		skb = napi_alloc_skb(&lp->napi, pkt_len);
 
 	if (!skb) {
 		dev->stats.rx_dropped++;
 		return;
 	}
 	if (!rx_in_place) {
-		skb_reserve(skb, NET_IP_ALIGN);
 		skb_put(skb, pkt_len);	/* Make room */
 		dma_sync_single_for_cpu(&lp->pci_dev->dev,
 					lp->rx_dma_addr[entry], pkt_len,
@@ -1272,7 +1270,7 @@ static void pcnet32_rx_entry(struct net_device *dev,
 	}
 	dev->stats.rx_bytes += skb->len;
 	skb->protocol = eth_type_trans(skb, dev);
-	netif_receive_skb(skb);
+	napi_gro_receive(&lp->napi, skb);
 	dev->stats.rx_packets++;
 }
 
Signature · 1 line
2.39.5
maintainer
#5 lore raw
Quoted 2 lines · On Mon, 25 May 2026 14:54:37 +0200 Oscar Maes wrote:

In my testing this resulted in up to a 25% RX throughput increase in iperf3 tests in both directions.

On which platform?

author
#6 lore raw
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 25 May 2026 14:54:37 +0200 Oscar Maes wrote:

In my testing this resulted in up to a 25% RX throughput increase in iperf3 tests in both directions.

On which platform?

Intel x86

maintainer
#7 lore raw
Quoted 8 lines · On Thu, 28 May 2026 16:28:51 +0200 Oscar Maes wrote:
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 25 May 2026 14:54:37 +0200 Oscar Maes wrote:

In my testing this resulted in up to a 25% RX throughput increase in iperf3 tests in both directions.

On which platform?

Intel x86

LOL. Please. Which _hardware_ platform.
Or to ask more directly - is it QEMU.

author
#8 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 28 May 2026 16:28:51 +0200 Oscar Maes wrote:
Quoted 4 lines · Jakub Kicinski
Quoted 2 lines · On Mon, 25 May 2026 14:54:37 +0200 Oscar Maes wrote:

In my testing this resulted in up to a 25% RX throughput increase in iperf3 tests in both directions.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

On which platform?

Intel x86

LOL. Please. Which _hardware_ platform.
Or to ask more directly - is it QEMU.

It was indeed tested on QEMU.
Either way, the performance measurements were just a sanity check. Changing the code to use the modern API is just better.

maintainer
#9 lore raw
Quoted 11 lines · On Thu, 28 May 2026 19:05:10 +0200 Oscar Maes wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 28 May 2026 16:28:51 +0200 Oscar Maes wrote:

On Mon, May 25, 2026 at 08:45:28AM -0700, Jakub Kicinski wrote:
Intel x86

LOL. Please. Which _hardware_ platform.
Or to ask more directly - is it QEMU.

It was indeed tested on QEMU.
Either way, the performance measurements were just a sanity check. Changing the code to use the modern API is just better.

Please don't waste our time with optimizations to unused code.

author
#10 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 28 May 2026 19:05:10 +0200 Oscar Maes wrote:
Quoted 4 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 28 May 2026 16:28:51 +0200 Oscar Maes wrote:

On Mon, May 25, 2026 at 08:45:28AM -0700, Jakub Kicinski wrote:
Intel x86

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

LOL. Please. Which _hardware_ platform.
Or to ask more directly - is it QEMU.

It was indeed tested on QEMU.
Either way, the performance measurements were just a sanity check. Changing the code to use the modern API is just better.

Please don't waste our time with optimizations to unused code.

It's not unused code. VMware emulates this device by default in some cases. I've encountered it when installing QubesOS in vmware which is based on relatively modern Linux.

#11 lore raw
Quoted 14 lines · Oscar Maes
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Thu, 28 May 2026 19:05:10 +0200 Oscar Maes wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 28 May 2026 16:28:51 +0200 Oscar Maes wrote:

On Mon, May 25, 2026 at 08:45:28AM -0700, Jakub Kicinski wrote:
Intel x86

LOL. Please. Which _hardware_ platform.
Or to ask more directly - is it QEMU.

It was indeed tested on QEMU.
Either way, the performance measurements were just a sanity check. Changing the code to use the modern API is just better.

Quoted 5 lines
Quoted 1 line

Please don't waste our time with optimizations to unused code.

It's not unused code. VMware emulates this device by default in some cases. I've encountered it when installing QubesOS in vmware which is based on relatively modern Linux.

There is a saying: If it is not broken, don't fix it.

"Changing the code to use the modern API is just better" if not a good enough reason on its own. Using older APIs does not mean it is broken. It does not need fixing. Some percentage of changes like this break stuff. We Reviewers/Maintainers need to look closely at such changes and decide if it does actually break stuff. And we want to know what the return on investment is? I would much rather spend my time reviewing new drivers for hardware which currently does not have a driver.

So, if you say something like: I'm using this driver daily for X. I've spent some time optimising it, and with this change, my use case gets a 10% increase in performance. Here are my numbers....

That gives us a better feeling that you have extensively tested this, so it is less likely you have broken something. You can also show there is a real improvement. So the change is actually worth while.

Andrew

author
#12 lore raw
Quoted 36 lines · Andrew Lunn
Quoted 14 lines · Oscar Maes
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Thu, 28 May 2026 19:05:10 +0200 Oscar Maes wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 28 May 2026 16:28:51 +0200 Oscar Maes wrote:

On Mon, May 25, 2026 at 08:45:28AM -0700, Jakub Kicinski wrote:
Intel x86

LOL. Please. Which _hardware_ platform.
Or to ask more directly - is it QEMU.

It was indeed tested on QEMU.
Either way, the performance measurements were just a sanity check. Changing the code to use the modern API is just better.

Quoted 5 lines
Quoted 1 line

Please don't waste our time with optimizations to unused code.

It's not unused code. VMware emulates this device by default in some cases. I've encountered it when installing QubesOS in vmware which is based on relatively modern Linux.

There is a saying: If it is not broken, don't fix it.

"Changing the code to use the modern API is just better" if not a good enough reason on its own. Using older APIs does not mean it is broken. It does not need fixing. Some percentage of changes like this break stuff. We Reviewers/Maintainers need to look closely at such changes and decide if it does actually break stuff. And we want to know what the return on investment is? I would much rather spend my time reviewing new drivers for hardware which currently does not have a driver.

So, if you say something like: I'm using this driver daily for X. I've spent some time optimising it, and with this change, my use case gets a 10% increase in performance. Here are my numbers....

Quoted 10 lines

That gives us a better feeling that you have extensively tested this, so it is less likely you have broken something. You can also show there is a real improvement. So the change is actually worth while.

Andrew

Fair enough, I appreciate the input.
This change isn't a big deal to me, so I guess we can drop it. I'll make sure to keep your advice in mind for future patches.