tsnep: XDP socket zero-copy support
Subsystems (3)
v3 cover tsnep: XDP socket zero-copy support
Implement XDP socket zero-copy support for tsnep driver. I tried to follow existing drivers like igc as far as possible. But one main difference is that tsnep does not need any reconfiguration for XDP BPF program setup. So I decided to keep this behavior no matter if a XSK pool is used or not. As a result, tsnep starts using the XSK pool even if no XDP BPF program is available.
Another difference is that I tried to prevent potentially failing allocations during XSK pool setup. E.g. both memory models for page pool and XSK pool are registered all the time. Thus, XSK pool setup cannot end up with not working queues.
Some prework is done to reduce the last two XSK commits to actual XSK changes.
v3:
- use __netif_tx_lock_bh() (Paolo Abeni)
- comment that rx->page_buffer is always zero terminated (Paolo Abeni)
v2:
- eliminate modulo op in TX/RX path (Maciej Fijalkowski)
- eliminate retval variable in tsnep_rx_alloc_zc() (Maciej Fijalkowski)
- scope variable entry within loop (Maciej Fijalkowski)
- use DMA_ATTR_SKIP_CPU_SYNC directly (Maciej Fijalkowski)
- union for page/xdp in tsnep_rx_entry (Maciej Fijalkowski)
- provide performance numbers (Maciej Fijalkowski)
- use xsk_buff_alloc_batch() (Maciej Fijalkowski)
- use xsk_tx_peek_release_desc_batch() (Maciej Fijalkowski)
- don't call tsnep_rx_reopen() if netdev is down
- init adapter pointer of queue only once
Gerhard Engleder (6):
tsnep: Replace modulo operation with mask
tsnep: Rework TX/RX queue initialization
tsnep: Add functions for queue enable/disable
tsnep: Move skb receive action to separate function
tsnep: Add XDP socket zero-copy RX support
tsnep: Add XDP socket zero-copy TX support
drivers/net/ethernet/engleder/tsnep.h | 16 +- drivers/net/ethernet/engleder/tsnep_main.c | 863 ++++++++++++++++++--- drivers/net/ethernet/engleder/tsnep_xdp.c | 66 ++ 3 files changed, 822 insertions(+), 123 deletions(-)
Signature · 1 line
2.30.2
PATCH v3 1/6 tsnep: Replace modulo operation with mask
TX/RX ring size is static and power of 2 to enable compiler to optimize modulo operation to mask operation. Make this optimization already in the code and don't rely on the compiler.
--- drivers/net/ethernet/engleder/tsnep.h | 1 + drivers/net/ethernet/engleder/tsnep_main.c | 28 +++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +1 -0
@@ -18,6 +18,7 @@#define TSNEP "tsnep"#define TSNEP_RING_SIZE 256 +#define TSNEP_RING_MASK (TSNEP_RING_SIZE - 1)#define TSNEP_RING_RX_REFILL 16#define TSNEP_RING_RX_REUSE (TSNEP_RING_SIZE - TSNEP_RING_SIZE / 4)#define TSNEP_RING_ENTRIES_PER_PAGE (PAGE_SIZE / TSNEP_DESC_SIZE)
drivers/net/ethernet/engleder/tsnep_main.c +14 -14
@@ -292,7 +292,7 @@ static int tsnep_tx_ring_init(struct tsnep_tx *tx) }for (i =0 ; i <TSNEP_RING_SIZE ; i++) { entry = &tx->entry[i]; - next_entry = &tx->entry[(i +1 ) %TSNEP_RING_SIZE ]; + next_entry = &tx->entry[(i +1 ) &TSNEP_RING_MASK ]; entry->desc->next =__cpu_to_le64 (next_entry->desc_dma); }
@@ -381,7 +381,7 @@ static int tsnep_tx_map(struct sk_buff *skb, struct tsnep_tx *tx, int count)int i;for (i =0 ; i < count; i++) { - entry = &tx->entry[(tx->write + i) %TSNEP_RING_SIZE ]; + entry = &tx->entry[(tx->write + i) &TSNEP_RING_MASK ];if (!i) { len =skb_headlen (skb);
@@ -419,7 +419,7 @@ static int tsnep_tx_unmap(struct tsnep_tx *tx, int index, int count)int i;for (i =0 ; i < count; i++) { - entry = &tx->entry[(index + i) %TSNEP_RING_SIZE ]; + entry = &tx->entry[(index + i) &TSNEP_RING_MASK ];if (entry->len) {if (entry->type &TSNEP_TX_TYPE_SKB )
@@ -481,9 +481,9 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ;for (i =0 ; i < count; i++) -tsnep_tx_activate (tx, (tx->write + i) %TSNEP_RING_SIZE , length, +tsnep_tx_activate (tx, (tx->write + i) &TSNEP_RING_MASK , length, i == count -1 ); - tx->write = (tx->write + count) %TSNEP_RING_SIZE ; + tx->write = (tx->write + count) &TSNEP_RING_MASK ;skb_tx_timestamp (skb);
@@ -516,7 +516,7 @@ static int tsnep_xdp_tx_map(struct xdp_frame *xdpf, struct tsnep_tx *tx, frag =NULL ; len = xdpf->len;for (i =0 ; i < count; i++) { - entry = &tx->entry[(tx->write + i) %TSNEP_RING_SIZE ]; + entry = &tx->entry[(tx->write + i) &TSNEP_RING_MASK ];if (type &TSNEP_TX_TYPE_XDP_NDO ) { data =unlikely (frag) ?skb_frag_address (frag) : xdpf->data;
@@ -589,9 +589,9 @@ static bool tsnep_xdp_xmit_frame_ring(struct xdp_frame *xdpf, length = retval;for (i =0 ; i < count; i++) -tsnep_tx_activate (tx, (tx->write + i) %TSNEP_RING_SIZE , length, +tsnep_tx_activate (tx, (tx->write + i) &TSNEP_RING_MASK , length, i == count -1 ); - tx->write = (tx->write + count) %TSNEP_RING_SIZE ; + tx->write = (tx->write + count) &TSNEP_RING_MASK ;/* descriptor properties shall be valid before hardware is notified */ dma_wmb ();
@@ -691,7 +691,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)/* xdpf is union with skb */ entry->skb =NULL ; - tx->read = (tx->read + count) %TSNEP_RING_SIZE ; + tx->read = (tx->read + count) &TSNEP_RING_MASK ; tx->packets++; tx->bytes += length +ETH_FCS_LEN ;
@@ -839,7 +839,7 @@ static int tsnep_rx_ring_init(struct tsnep_rx *rx)for (i =0 ; i <TSNEP_RING_SIZE ; i++) { entry = &rx->entry[i]; - next_entry = &rx->entry[(i +1 ) %TSNEP_RING_SIZE ]; + next_entry = &rx->entry[(i +1 ) &TSNEP_RING_MASK ]; entry->desc->next =__cpu_to_le64 (next_entry->desc_dma); }
@@ -925,7 +925,7 @@ static int tsnep_rx_refill(struct tsnep_rx *rx, int count, bool reuse)int retval;for (i =0 ; i < count && !alloc_failed; i++) { - index = (rx->write + i) %TSNEP_RING_SIZE ; + index = (rx->write + i) &TSNEP_RING_MASK ; retval =tsnep_rx_alloc_buffer (rx, index);if (unlikely (retval)) {
@@ -945,7 +945,7 @@ static int tsnep_rx_refill(struct tsnep_rx *rx, int count, bool reuse) }if (enable) { - rx->write = (rx->write + i) %TSNEP_RING_SIZE ; + rx->write = (rx->write + i) &TSNEP_RING_MASK ;/* descriptor properties shall be valid before hardware is * notified
@@ -1090,7 +1090,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,* empty RX ring, thus buffer cannot be used for * RX processing */ - rx->read = (rx->read +1 ) %TSNEP_RING_SIZE ; + rx->read = (rx->read +1 ) &TSNEP_RING_MASK ; desc_available++; rx->dropped++;
@@ -1117,7 +1117,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,*/ length -=TSNEP_RX_INLINE_METADATA_SIZE ; - rx->read = (rx->read +1 ) %TSNEP_RING_SIZE ; + rx->read = (rx->read +1 ) &TSNEP_RING_MASK ; desc_available++;if (prog) {
Signature · 1 line
2.30.2
Re: [PATCH net-next v3 1/6] tsnep: Replace modulo operation with mask
Quoted 3 lines · Gerhard Engleder
TX/RX ring size is static and power of 2 to enable compiler to optimize modulo operation to mask operation. Make this optimization already in the code and don't rely on the compiler.
I think this came out of my review, so:
Does this give you a minor perf boost?
Quoted 140 lines
Signed-off-by Gerhard Engleder <[email protected]>--- drivers/net/ethernet/engleder/tsnep.h | 1 + drivers/net/ethernet/engleder/tsnep_main.c | 28 +++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-)drivers/net/ethernet/engleder/tsnep.h +1
-0@@ -18,6 +18,7 @@#define TSNEP "tsnep"#define TSNEP_RING_SIZE 256 +#define TSNEP_RING_MASK (TSNEP_RING_SIZE - 1)#define TSNEP_RING_RX_REFILL 16#define TSNEP_RING_RX_REUSE (TSNEP_RING_SIZE - TSNEP_RING_SIZE / 4)#define TSNEP_RING_ENTRIES_PER_PAGE (PAGE_SIZE / TSNEP_DESC_SIZE)drivers/net/ethernet/engleder/tsnep_main.c +14
-14@@ -292,7 +292,7 @@ static int tsnep_tx_ring_init(struct tsnep_tx *tx) }for (i =0 ; i <TSNEP_RING_SIZE ; i++) { entry = &tx->entry[i]; - next_entry = &tx->entry[(i +1 ) %TSNEP_RING_SIZE ]; + next_entry = &tx->entry[(i +1 ) &TSNEP_RING_MASK ]; entry->desc->next =__cpu_to_le64 (next_entry->desc_dma); }@@ -381,7 +381,7 @@ static int tsnep_tx_map(struct sk_buff *skb, struct tsnep_tx *tx, int count)int i;for (i =0 ; i < count; i++) { - entry = &tx->entry[(tx->write + i) %TSNEP_RING_SIZE ]; + entry = &tx->entry[(tx->write + i) &TSNEP_RING_MASK ];if (!i) { len =skb_headlen (skb);@@ -419,7 +419,7 @@ static int tsnep_tx_unmap(struct tsnep_tx *tx, int index, int count)int i;for (i =0 ; i < count; i++) { - entry = &tx->entry[(index + i) %TSNEP_RING_SIZE ]; + entry = &tx->entry[(index + i) &TSNEP_RING_MASK ];if (entry->len) {if (entry->type &TSNEP_TX_TYPE_SKB )@@ -481,9 +481,9 @@ static netdev_tx_t tsnep_xmit_frame_ring(struct sk_buff *skb,skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ;for (i =0 ; i < count; i++) -tsnep_tx_activate (tx, (tx->write + i) %TSNEP_RING_SIZE , length, +tsnep_tx_activate (tx, (tx->write + i) &TSNEP_RING_MASK , length, i == count -1 ); - tx->write = (tx->write + count) %TSNEP_RING_SIZE ; + tx->write = (tx->write + count) &TSNEP_RING_MASK ;skb_tx_timestamp (skb);@@ -516,7 +516,7 @@ static int tsnep_xdp_tx_map(struct xdp_frame *xdpf, struct tsnep_tx *tx, frag =NULL ; len = xdpf->len;for (i =0 ; i < count; i++) { - entry = &tx->entry[(tx->write + i) %TSNEP_RING_SIZE ]; + entry = &tx->entry[(tx->write + i) &TSNEP_RING_MASK ];if (type &TSNEP_TX_TYPE_XDP_NDO ) { data =unlikely (frag) ?skb_frag_address (frag) : xdpf->data;@@ -589,9 +589,9 @@ static bool tsnep_xdp_xmit_frame_ring(struct xdp_frame *xdpf, length = retval;for (i =0 ; i < count; i++) -tsnep_tx_activate (tx, (tx->write + i) %TSNEP_RING_SIZE , length, +tsnep_tx_activate (tx, (tx->write + i) &TSNEP_RING_MASK , length, i == count -1 ); - tx->write = (tx->write + count) %TSNEP_RING_SIZE ; + tx->write = (tx->write + count) &TSNEP_RING_MASK ;/* descriptor properties shall be valid before hardware is notified */ dma_wmb ();@@ -691,7 +691,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)/* xdpf is union with skb */ entry->skb =NULL ; - tx->read = (tx->read + count) %TSNEP_RING_SIZE ; + tx->read = (tx->read + count) &TSNEP_RING_MASK ; tx->packets++; tx->bytes += length +ETH_FCS_LEN ;@@ -839,7 +839,7 @@ static int tsnep_rx_ring_init(struct tsnep_rx *rx)for (i =0 ; i <TSNEP_RING_SIZE ; i++) { entry = &rx->entry[i]; - next_entry = &rx->entry[(i +1 ) %TSNEP_RING_SIZE ]; + next_entry = &rx->entry[(i +1 ) &TSNEP_RING_MASK ]; entry->desc->next =__cpu_to_le64 (next_entry->desc_dma); }@@ -925,7 +925,7 @@ static int tsnep_rx_refill(struct tsnep_rx *rx, int count, bool reuse)int retval;for (i =0 ; i < count && !alloc_failed; i++) { - index = (rx->write + i) %TSNEP_RING_SIZE ; + index = (rx->write + i) &TSNEP_RING_MASK ; retval =tsnep_rx_alloc_buffer (rx, index);if (unlikely (retval)) {@@ -945,7 +945,7 @@ static int tsnep_rx_refill(struct tsnep_rx *rx, int count, bool reuse) }if (enable) { - rx->write = (rx->write + i) %TSNEP_RING_SIZE ; + rx->write = (rx->write + i) &TSNEP_RING_MASK ;/* descriptor properties shall be valid before hardware is * notified @@ -1090,7 +1090,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,* empty RX ring, thus buffer cannot be used for * RX processing */ - rx->read = (rx->read +1 ) %TSNEP_RING_SIZE ; + rx->read = (rx->read +1 ) &TSNEP_RING_MASK ; desc_available++; rx->dropped++;@@ -1117,7 +1117,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,*/ length -=TSNEP_RX_INLINE_METADATA_SIZE ; - rx->read = (rx->read +1 ) %TSNEP_RING_SIZE ; + rx->read = (rx->read +1 ) &TSNEP_RING_MASK ; desc_available++;if (prog) {Signature · 1 line
2.30.2
Re: [PATCH net-next v3 1/6] tsnep: Replace modulo operation with mask
Quoted 9 lines · On Thu, 20 Apr 2023 16:23:10 +0200 Maciej Fijalkowski…
Quoted 3 lines · Gerhard Engleder
TX/RX ring size is static and power of 2 to enable compiler to optimize modulo operation to mask operation. Make this optimization already in the code and don't rely on the compiler.
I think this came out of my review, so:
Suggested-by Maciej Fijalkowski <[email protected]>Does this give you a minor perf boost?
If you change the loop counter to be unsigned, then Gcc (and Clang) will optimize this into a mask operation. That is a better simpler fix.
If loop counter (i) is an integer, then compiler has keep the potential for wrap around.
Re: [PATCH net-next v3 1/6] tsnep: Replace modulo operation with mask
Quoted 11 lines · Stephen Hemminger
Quoted 8 lines · On Thu, 20 Apr 2023 16:23:10 +0200 Maciej Fijalkowski…
Quoted 3 lines · Gerhard Engleder
TX/RX ring size is static and power of 2 to enable compiler to optimize modulo operation to mask operation. Make this optimization already in the code and don't rely on the compiler.
I think this came out of my review, so:
Suggested-by Maciej Fijalkowski <[email protected]>
Quoted 7 lines
Quoted 1 line
Does this give you a minor perf boost?
If you change the loop counter to be unsigned, then Gcc (and Clang) will optimize this into a mask operation. That is a better simpler fix.
If loop counter (i) is an integer, then compiler has keep the potential for wrap around.
I'm unsure which solution should be preferred. But I could change to unsigned anyway.
Re: [PATCH net-next v3 1/6] tsnep: Replace modulo operation with mask
In reply to Maciej FijalkowskiQuoted 7 lines · Maciej Fijalkowski
Quoted 3 lines · Gerhard Engleder
TX/RX ring size is static and power of 2 to enable compiler to optimize modulo operation to mask operation. Make this optimization already in the code and don't rely on the compiler.
I think this came out of my review, so:
Suggested-by Maciej Fijalkowski <[email protected]>
Sorry, I forgot to add it.
Quoted 1 line
Does this give you a minor perf boost?
I will try to measure some difference.
PATCH v3 2/6 tsnep: Rework TX/RX queue initialization
In reply to Gerhard EnglederMake initialization of TX and RX queues less dynamic by moving some initialization from netdev open/close to device probing.
Additionally, move some initialization code to separate functions to enable future use in other execution paths.
This is done as preparation for queue reconfigure at runtime, which is necessary for XSK zero-copy support.
--- drivers/net/ethernet/engleder/tsnep_main.c | 94 ++++++++++++---------- 1 file changed, 51 insertions(+), 43 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +51 -43
@@ -265,7 +265,7 @@ static void tsnep_tx_ring_cleanup(struct tsnep_tx *tx) } } -static int tsnep_tx_ring_init (struct tsnep_tx *tx) +static int tsnep_tx_ring_create (struct tsnep_tx *tx) {struct device *dmadev = tx->adapter->dmadev;struct tsnep_tx_entry *entry;
@@ -288,6 +288,7 @@ static int tsnep_tx_ring_init(struct tsnep_tx *tx) entry->desc = (struct tsnep_tx_desc *) (((u8 *)entry->desc_wb) +TSNEP_DESC_OFFSET ); entry->desc_dma = tx->page_dma[i] +TSNEP_DESC_SIZE * j; + entry->owner_user_flag = false; } }for (i =0 ; i <TSNEP_RING_SIZE ; i++) {
@@ -303,6 +304,19 @@ static int tsnep_tx_ring_init(struct tsnep_tx *tx)return retval; } +static void tsnep_tx_init (struct tsnep_tx *tx) +{ +dma_addr_t dma; + + dma = tx->entry[0 ].desc_dma |TSNEP_RESET_OWNER_COUNTER ; +iowrite32 (DMA_ADDR_LOW (dma), tx->addr +TSNEP_TX_DESC_ADDR_LOW ); +iowrite32 (DMA_ADDR_HIGH (dma), tx->addr +TSNEP_TX_DESC_ADDR_HIGH ); + tx->write =0 ; + tx->read =0 ; + tx->owner_counter =1 ; + tx->increment_owner_counter =TSNEP_RING_SIZE -1 ; +} +static void tsnep_tx_activate (struct tsnep_tx *tx,int index,int length,bool last) {
@@ -731,26 +745,15 @@ static bool tsnep_tx_pending(struct tsnep_tx *tx)return pending; } -static int tsnep_tx_open (struct tsnep_adapter *adapter,void __iomem *addr, -int queue_index,struct tsnep_tx *tx) +static int tsnep_tx_open (struct tsnep_tx *tx) { -dma_addr_t dma;int retval; -memset (tx,0 ,sizeof (*tx)); - tx->adapter = adapter; - tx->addr = addr; - tx->queue_index = queue_index; - - retval =tsnep_tx_ring_init (tx); + retval =tsnep_tx_ring_create (tx);if (retval)return retval; - dma = tx->entry[0 ].desc_dma |TSNEP_RESET_OWNER_COUNTER ; -iowrite32 (DMA_ADDR_LOW (dma), tx->addr +TSNEP_TX_DESC_ADDR_LOW ); -iowrite32 (DMA_ADDR_HIGH (dma), tx->addr +TSNEP_TX_DESC_ADDR_HIGH ); - tx->owner_counter =1 ; - tx->increment_owner_counter =TSNEP_RING_SIZE -1 ; +tsnep_tx_init (tx);return 0 ; }
@@ -795,7 +798,7 @@ static void tsnep_rx_ring_cleanup(struct tsnep_rx *rx) } } -static int tsnep_rx_ring_init (struct tsnep_rx *rx) +static int tsnep_rx_ring_create (struct tsnep_rx *rx) {struct device *dmadev = rx->adapter->dmadev;struct tsnep_rx_entry *entry;
@@ -850,6 +853,19 @@ static int tsnep_rx_ring_init(struct tsnep_rx *rx)return retval; } +static void tsnep_rx_init (struct tsnep_rx *rx) +{ +dma_addr_t dma; + + dma = rx->entry[0 ].desc_dma |TSNEP_RESET_OWNER_COUNTER ; +iowrite32 (DMA_ADDR_LOW (dma), rx->addr +TSNEP_RX_DESC_ADDR_LOW ); +iowrite32 (DMA_ADDR_HIGH (dma), rx->addr +TSNEP_RX_DESC_ADDR_HIGH ); + rx->write =0 ; + rx->read =0 ; + rx->owner_counter =1 ; + rx->increment_owner_counter =TSNEP_RING_SIZE -1 ; +} +static int tsnep_rx_desc_available (struct tsnep_rx *rx) {if (rx->read <= rx->write)
@@ -1181,26 +1197,15 @@ static bool tsnep_rx_pending(struct tsnep_rx *rx)return false; } -static int tsnep_rx_open (struct tsnep_adapter *adapter,void __iomem *addr, -int queue_index,struct tsnep_rx *rx) +static int tsnep_rx_open (struct tsnep_rx *rx) { -dma_addr_t dma;int retval; -memset (rx,0 ,sizeof (*rx)); - rx->adapter = adapter; - rx->addr = addr; - rx->queue_index = queue_index; - - retval =tsnep_rx_ring_init (rx); + retval =tsnep_rx_ring_create (rx);if (retval)return retval; - dma = rx->entry[0 ].desc_dma |TSNEP_RESET_OWNER_COUNTER ; -iowrite32 (DMA_ADDR_LOW (dma), rx->addr +TSNEP_RX_DESC_ADDR_LOW ); -iowrite32 (DMA_ADDR_HIGH (dma), rx->addr +TSNEP_RX_DESC_ADDR_HIGH ); - rx->owner_counter =1 ; - rx->increment_owner_counter =TSNEP_RING_SIZE -1 ; +tsnep_rx_init (rx);tsnep_rx_refill (rx,tsnep_rx_desc_available (rx), false);
@@ -1335,8 +1340,6 @@ static int tsnep_queue_open(struct tsnep_adapter *adapter,struct tsnep_tx *tx = queue->tx;int retval; - queue->adapter = adapter; -netif_napi_add (adapter->netdev, &queue->napi, tsnep_poll);if (rx) {
@@ -1377,27 +1380,18 @@ static int tsnep_queue_open(struct tsnep_adapter *adapter,static int tsnep_netdev_open (struct net_device *netdev) {struct tsnep_adapter *adapter =netdev_priv (netdev); -int tx_queue_index =0 ; -int rx_queue_index =0 ; -void __iomem *addr;int i, retval;for (i =0 ; i < adapter->num_queues; i++) {if (adapter->queue[i].tx) { - addr = adapter->addr +TSNEP_QUEUE (tx_queue_index); - retval =tsnep_tx_open (adapter, addr, tx_queue_index, - adapter->queue[i].tx); + retval =tsnep_tx_open (adapter->queue[i].tx);if (retval) goto failed; - tx_queue_index++; }if (adapter->queue[i].rx) { - addr = adapter->addr +TSNEP_QUEUE (rx_queue_index); - retval =tsnep_rx_open (adapter, addr, rx_queue_index, - adapter->queue[i].rx); + retval =tsnep_rx_open (adapter->queue[i].rx);if (retval) goto failed; - rx_queue_index++; } retval =tsnep_queue_open (adapter, &adapter->queue[i], i ==0 );
@@ -1796,9 +1790,16 @@ static int tsnep_queue_init(struct tsnep_adapter *adapter, int queue_count) adapter->num_tx_queues =1 ; adapter->num_rx_queues =1 ; adapter->num_queues =1 ; + adapter->queue[0 ].adapter = adapter; adapter->queue[0 ].irq = retval; adapter->queue[0 ].tx = &adapter->tx[0 ]; + adapter->queue[0 ].tx->adapter = adapter; + adapter->queue[0 ].tx->addr = adapter->addr +TSNEP_QUEUE (0 ); + adapter->queue[0 ].tx->queue_index =0 ; adapter->queue[0 ].rx = &adapter->rx[0 ]; + adapter->queue[0 ].rx->adapter = adapter; + adapter->queue[0 ].rx->addr = adapter->addr +TSNEP_QUEUE (0 ); + adapter->queue[0 ].rx->queue_index =0 ; adapter->queue[0 ].irq_mask = irq_mask; adapter->queue[0 ].irq_delay_addr = adapter->addr +ECM_INT_DELAY ; retval = tsnep_set_irq_coalesce(&adapter->queue[0],
@@ -1820,9 +1821,16 @@ static int tsnep_queue_init(struct tsnep_adapter *adapter, int queue_count) adapter->num_tx_queues++; adapter->num_rx_queues++; adapter->num_queues++; + adapter->queue[i].adapter = adapter; adapter->queue[i].irq = retval; adapter->queue[i].tx = &adapter->tx[i]; + adapter->queue[i].tx->adapter = adapter; + adapter->queue[i].tx->addr = adapter->addr +TSNEP_QUEUE (i); + adapter->queue[i].tx->queue_index = i; adapter->queue[i].rx = &adapter->rx[i]; + adapter->queue[i].rx->adapter = adapter; + adapter->queue[i].rx->addr = adapter->addr +TSNEP_QUEUE (i); + adapter->queue[i].rx->queue_index = i; adapter->queue[i].irq_mask = irq_mask << (ECM_INT_TXRX_SHIFT * i); adapter->queue[i].irq_delay_addr =
Signature · 1 line
2.30.2
PATCH v3 3/6 tsnep: Add functions for queue enable/disable
In reply to Gerhard EnglederMove queue enable and disable code to separate functions. This way the activation and deactivation of the queues are defined actions, which can be used in future execution paths.
This functions will be used for the queue reconfiguration at runtime, which is necessary for XSK zero-copy support.
--- drivers/net/ethernet/engleder/tsnep_main.c | 97 ++++++++++++++-------- 1 file changed, 64 insertions(+), 33 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +64 -33
@@ -866,6 +866,24 @@ static void tsnep_rx_init(struct tsnep_rx *rx) rx->increment_owner_counter =TSNEP_RING_SIZE -1 ; } +static void tsnep_rx_enable (struct tsnep_rx *rx) +{ +/* descriptor properties shall be valid before hardware is notified */ +dma_wmb (); + +iowrite32 (TSNEP_CONTROL_RX_ENABLE , rx->addr +TSNEP_CONTROL ); +} + +static void tsnep_rx_disable (struct tsnep_rx *rx) +{ +u32 val; + +iowrite32 (TSNEP_CONTROL_RX_DISABLE , rx->addr +TSNEP_CONTROL ); +readx_poll_timeout (ioread32, rx->addr +TSNEP_CONTROL , val, + ((val &TSNEP_CONTROL_RX_ENABLE ) ==0 ),10000 , +1000000 ); +} +static int tsnep_rx_desc_available (struct tsnep_rx *rx) {if (rx->read <= rx->write)
@@ -932,19 +950,15 @@ static void tsnep_rx_activate(struct tsnep_rx *rx, int index) entry->desc->properties =__cpu_to_le32 (entry->properties); } -static int tsnep_rx_refill (struct tsnep_rx *rx,int count,bool reuse) +static int tsnep_rx_alloc (struct tsnep_rx *rx,int count,bool reuse) { -int index;bool alloc_failed = false; -bool enable = false; -int i; -int retval; +int i, index;for (i =0 ; i < count && !alloc_failed; i++) { index = (rx->write + i) &TSNEP_RING_MASK ; - retval =tsnep_rx_alloc_buffer (rx, index); -if (unlikely (retval)) { +if (unlikely (tsnep_rx_alloc_buffer (rx, index))) { rx->alloc_failed++; alloc_failed = true;
@@ -956,22 +970,23 @@ static int tsnep_rx_refill(struct tsnep_rx *rx, int count, bool reuse) }tsnep_rx_activate (rx, index); - - enable = true; } -if (enable) { +if (i) rx->write = (rx->write + i) &TSNEP_RING_MASK ; -/* descriptor properties shall be valid before hardware is -* notified -*/ -dma_wmb (); +return i; +} -iowrite32 (TSNEP_CONTROL_RX_ENABLE , rx->addr +TSNEP_CONTROL ); - } +static int tsnep_rx_refill (struct tsnep_rx *rx,int count,bool reuse) +{ +int desc_refilled; -return i; + desc_refilled =tsnep_rx_alloc (rx, count, reuse); +if (desc_refilled) +tsnep_rx_enable (rx); + +return desc_refilled; } static bool tsnep_xdp_run_prog(struct tsnep_rx *rx, struct bpf_prog *prog,
@@ -1199,6 +1214,7 @@ static bool tsnep_rx_pending(struct tsnep_rx *rx)static int tsnep_rx_open (struct tsnep_rx *rx) { +int desc_available;int retval; retval =tsnep_rx_ring_create (rx);
@@ -1207,20 +1223,19 @@ static int tsnep_rx_open(struct tsnep_rx *rx)tsnep_rx_init (rx); -tsnep_rx_refill (rx,tsnep_rx_desc_available (rx), false); + desc_available =tsnep_rx_desc_available (rx); + retval =tsnep_rx_alloc (rx, desc_available, false); +if (retval != desc_available) { +tsnep_rx_ring_cleanup (rx); + +return -ENOMEM ; + }return 0 ; }static void tsnep_rx_close (struct tsnep_rx *rx) { -u32 val; - -iowrite32 (TSNEP_CONTROL_RX_DISABLE , rx->addr +TSNEP_CONTROL ); -readx_poll_timeout (ioread32, rx->addr +TSNEP_CONTROL , val, - ((val &TSNEP_CONTROL_RX_ENABLE ) ==0 ),10000 , -1000000 ); -tsnep_rx_ring_cleanup (rx); }
@@ -1377,6 +1392,27 @@ static int tsnep_queue_open(struct tsnep_adapter *adapter,return retval; } +static void tsnep_queue_enable (struct tsnep_queue *queue) +{ +napi_enable (&queue->napi); +tsnep_enable_irq (queue->adapter, queue->irq_mask); + +if (queue->rx) +tsnep_rx_enable (queue->rx); +} + +static void tsnep_queue_disable (struct tsnep_queue *queue) +{ +napi_disable (&queue->napi); +tsnep_disable_irq (queue->adapter, queue->irq_mask); + +/* disable RX after NAPI polling has been disabled, because RX can be +* enabled during NAPI polling +*/ +if (queue->rx) +tsnep_rx_disable (queue->rx); +} +static int tsnep_netdev_open (struct net_device *netdev) {struct tsnep_adapter *adapter =netdev_priv (netdev);
@@ -1413,11 +1449,8 @@ static int tsnep_netdev_open(struct net_device *netdev)if (retval) goto phy_failed; -for (i =0 ; i < adapter->num_queues; i++) { -napi_enable (&adapter->queue[i].napi); - -tsnep_enable_irq (adapter, adapter->queue[i].irq_mask); - } +for (i =0 ; i < adapter->num_queues; i++) +tsnep_queue_enable (&adapter->queue[i]);return 0 ;
@@ -1444,9 +1477,7 @@ static int tsnep_netdev_close(struct net_device *netdev)tsnep_phy_close (adapter);for (i =0 ; i < adapter->num_queues; i++) { -tsnep_disable_irq (adapter, adapter->queue[i].irq_mask); - -napi_disable (&adapter->queue[i].napi); +tsnep_queue_disable (&adapter->queue[i]);tsnep_queue_close (&adapter->queue[i], i ==0 );
Signature · 1 line
2.30.2
PATCH v3 4/6 tsnep: Move skb receive action to separate function
In reply to Gerhard EnglederThe function tsnep_rx_poll() is already pretty long and the skb receive action can be reused for XSK zero-copy support. Move page based skb receive to separate function.
--- drivers/net/ethernet/engleder/tsnep_main.c | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-)
drivers/net/ethernet/engleder/tsnep_main.c +23 -16
@@ -1076,6 +1076,28 @@ static struct sk_buff *tsnep_build_skb(struct tsnep_rx *rx, struct page *page,return skb; } +static void tsnep_rx_page (struct tsnep_rx *rx,struct napi_struct *napi, +struct page *page,int length) +{ +struct sk_buff *skb; + + skb =tsnep_build_skb (rx, page, length); +if (skb) { +page_pool_release_page (rx->page_pool, page); + + rx->packets++; + rx->bytes += length; +if (skb->pkt_type ==PACKET_MULTICAST ) + rx->multicast++; + +napi_gro_receive (napi, skb); + }else { +page_pool_recycle_direct (rx->page_pool, page); + + rx->dropped++; + } +} +static int tsnep_rx_poll (struct tsnep_rx *rx,struct napi_struct *napi,int budget) {
@@ -1085,7 +1107,6 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi,struct netdev_queue *tx_nq;struct bpf_prog *prog;struct xdp_buff xdp; -struct sk_buff *skb;struct tsnep_tx *tx;int desc_available;int xdp_status =0 ;
@@ -1170,21 +1191,7 @@ static int tsnep_rx_poll(struct tsnep_rx *rx, struct napi_struct *napi, } } - skb =tsnep_build_skb (rx, entry->page, length); -if (skb) { -page_pool_release_page (rx->page_pool, entry->page); - - rx->packets++; - rx->bytes += length; -if (skb->pkt_type ==PACKET_MULTICAST ) - rx->multicast++; - -napi_gro_receive (napi, skb); - }else { -page_pool_recycle_direct (rx->page_pool, entry->page); - - rx->dropped++; - } +tsnep_rx_page (rx, napi, entry->page, length); entry->page =NULL ; }
Signature · 1 line
2.30.2
PATCH v3 5/6 tsnep: Add XDP socket zero-copy RX support
In reply to Gerhard EnglederAdd support for XSK zero-copy to RX path. The setup of the XSK pool can be done at runtime. If the netdev is running, then the queue must be disabled and enabled during reconfiguration. This can be done easily with functions introduced in previous commits.
A more important property is that, if the netdev is running, then the setup of the XSK pool shall not stop the netdev in case of errors. A broken netdev after a failed XSK pool setup is bad behavior. Therefore, the allocation and setup of resources during XSK pool setup is done only before any queue is disabled. Additionally, freeing and later allocation of resources is eliminated in some cases. Page pool entries are kept for later use. Two memory models are registered in parallel. As a result, the XSK pool setup cannot fail during queue reconfiguration.
In contrast to other drivers, XSK pool setup and XDP BPF program setup are separate actions. XSK pool setup can be done without any XDP BPF program. The XDP BPF program can be added, removed or changed without any reconfiguration of the XSK pool.
Test results with A53 1.2GHz:
xdpsock rxdrop copy mode:
pps pkts 1.00
rx 856,054 10,625,775
Two CPUs with both 100% utilization.
xdpsock rxdrop zero-copy mode:
pps pkts 1.00
rx 889,388 4,615,284
Two CPUs with 100% and 20% utilization.
xdpsock l2fwd copy mode:
pps pkts 1.00 rx 248,985 7,315,885 tx 248,921 7,315,885
Two CPUs with 100% and 10% utilization.
xdpsock l2fwd zero-copy mode:
pps pkts 1.00 rx 254,735 3,039,456 tx 254,735 3,039,456
Two CPUs with 100% and 4% utilization.
Packet rate increases and CPU utilization is reduced in both cases. 100% CPU load seems to the base load. This load is consumed by ksoftirqd just for dropping the generated packets without xdpsock running.
Using batch API reduced CPU utilization slightly, but measurements are not stable enough to provide meaningful numbers.
--- drivers/net/ethernet/engleder/tsnep.h | 13 +- drivers/net/ethernet/engleder/tsnep_main.c | 494 ++++++++++++++++++++- drivers/net/ethernet/engleder/tsnep_xdp.c | 66 +++ 3 files changed, 558 insertions(+), 15 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +12 -1
@@ -101,7 +101,10 @@ struct tsnep_rx_entry {u32 properties; -struct page *page; +union { +struct page *page; +struct xdp_buff *xdp; + };size_t len;dma_addr_t dma; };
@@ -121,6 +124,9 @@ struct tsnep_rx {u32 owner_counter;int increment_owner_counter;struct page_pool *page_pool; +struct page **page_buffer; +struct xsk_buff_pool *xsk_pool; +struct xdp_buff **xdp_batch;u32 packets;u32 bytes;
@@ -129,6 +135,7 @@ struct tsnep_rx {u32 alloc_failed;struct xdp_rxq_info xdp_rxq; +struct xdp_rxq_info xdp_rxq_zc; };struct tsnep_queue {
@@ -214,6 +221,8 @@ int tsnep_rxnfc_del_rule(struct tsnep_adapter *adapter,int tsnep_xdp_setup_prog (struct tsnep_adapter *adapter,struct bpf_prog *prog,struct netlink_ext_ack *extack); +int tsnep_xdp_setup_pool (struct tsnep_adapter *adapter, +struct xsk_buff_pool *pool,u16 queue_id);#if IS_ENABLED (CONFIG_TSNEP_SELFTESTS )int tsnep_ethtool_get_test_count (void );
@@ -242,5 +251,7 @@ static inline void tsnep_ethtool_self_test(struct net_device *dev,void tsnep_get_system_time (struct tsnep_adapter *adapter,u64 *time);int tsnep_set_irq_coalesce (struct tsnep_queue *queue,u32 usecs);u32 tsnep_get_irq_coalesce (struct tsnep_queue *queue); +int tsnep_enable_xsk (struct tsnep_queue *queue,struct xsk_buff_pool *pool); +void tsnep_disable_xsk (struct tsnep_queue *queue);#endif /* _TSNEP_H */
drivers/net/ethernet/engleder/tsnep_main.c +480 -14
627 lines not on this page · raw message
drivers/net/ethernet/engleder/tsnep_xdp.c +66 -0
69 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH net-next v3 5/6] tsnep: Add XDP socket zero-copy RX support
Quoted 35 lines · Gerhard Engleder
Add support for XSK zero-copy to RX path. The setup of the XSK pool can be done at runtime. If the netdev is running, then the queue must be disabled and enabled during reconfiguration. This can be done easily with functions introduced in previous commits.
A more important property is that, if the netdev is running, then the setup of the XSK pool shall not stop the netdev in case of errors. A broken netdev after a failed XSK pool setup is bad behavior. Therefore, the allocation and setup of resources during XSK pool setup is done only before any queue is disabled. Additionally, freeing and later allocation of resources is eliminated in some cases. Page pool entries are kept for later use. Two memory models are registered in parallel. As a result, the XSK pool setup cannot fail during queue reconfiguration.
In contrast to other drivers, XSK pool setup and XDP BPF program setup are separate actions. XSK pool setup can be done without any XDP BPF program. The XDP BPF program can be added, removed or changed without any reconfiguration of the XSK pool.
Test results with A53 1.2GHz:
xdpsock rxdrop copy mode:
pps pkts 1.00
rx 856,054 10,625,775
Two CPUs with both 100% utilization.xdpsock rxdrop zero-copy mode:
pps pkts 1.00
rx 889,388 4,615,284
Two CPUs with 100% and 20% utilization.xdpsock l2fwd copy mode:
pps pkts 1.00 rx 248,985 7,315,885 tx 248,921 7,315,885
Quoted 7 lines
Two CPUs with 100% and 10% utilization.
xdpsock l2fwd zero-copy mode:
pps pkts 1.00 rx 254,735 3,039,456 tx 254,735 3,039,456Two CPUs with 100% and 4% utilization.
Thanks for sharing the numbers. This is for 64 byte frames?
Quoted 15 lines
Packet rate increases and CPU utilization is reduced in both cases. 100% CPU load seems to the base load. This load is consumed by ksoftirqd just for dropping the generated packets without xdpsock running.
Using batch API reduced CPU utilization slightly, but measurements are not stable enough to provide meaningful numbers.
Signed-off-by Gerhard Engleder <[email protected]>--- drivers/net/ethernet/engleder/tsnep.h | 13 +- drivers/net/ethernet/engleder/tsnep_main.c | 494 ++++++++++++++++++++- drivers/net/ethernet/engleder/tsnep_xdp.c | 66 +++ 3 files changed, 558 insertions(+), 15 deletions(-)
(...)
Quoted 12 lines
static const struct
net_device_opstsnep_netdev_ops= {drivers/net/ethernet/engleder/tsnep_main.c +1
-0.ndo_open = tsnep_netdev_open, .ndo_stop = tsnep_netdev_close,@@ -1713,6 +2177,7 @@ static const struct net_device_ops tsnep_netdev_ops = { .ndo_setup_tc = tsnep_tc_setup, .ndo_bpf = tsnep_netdev_bpf, .ndo_xdp_xmit = tsnep_netdev_xdp_xmit, + .ndo_xsk_wakeup = tsnep_netdev_xsk_wakeup, };static int tsnep_mac_init (struct tsnep_adapter *adapter)
drivers/net/ethernet/engleder/tsnep_main.c static int tsnep_probe(struct platform_device *pdev) · line 2442
Quoted 6 lines
drivers/net/ethernet/engleder/tsnep_main.c +2
-1@@ -1973,7 +2438,8 @@ static int tsnep_probe(struct platform_device *pdev) netdev->xdp_features =NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT |NETDEV_XDP_ACT_NDO_XMIT | -NETDEV_XDP_ACT_NDO_XMIT_SG ; +NETDEV_XDP_ACT_NDO_XMIT_SG | +NETDEV_XDP_ACT_XSK_ZEROCOPY ;
In theory enabling this feature here before implementing Tx ZC can expose you to some broken behavior, so just for the sake of completeness, i would move this to Tx ZC patch.
Quoted 1 line
Re: [PATCH net-next v3 5/6] tsnep: Add XDP socket zero-copy RX support
Quoted 38 lines · Maciej Fijalkowski
Quoted 37 lines · Gerhard Engleder
Add support for XSK zero-copy to RX path. The setup of the XSK pool can be done at runtime. If the netdev is running, then the queue must be disabled and enabled during reconfiguration. This can be done easily with functions introduced in previous commits.
A more important property is that, if the netdev is running, then the setup of the XSK pool shall not stop the netdev in case of errors. A broken netdev after a failed XSK pool setup is bad behavior. Therefore, the allocation and setup of resources during XSK pool setup is done only before any queue is disabled. Additionally, freeing and later allocation of resources is eliminated in some cases. Page pool entries are kept for later use. Two memory models are registered in parallel. As a result, the XSK pool setup cannot fail during queue reconfiguration.
In contrast to other drivers, XSK pool setup and XDP BPF program setup are separate actions. XSK pool setup can be done without any XDP BPF program. The XDP BPF program can be added, removed or changed without any reconfiguration of the XSK pool.
Test results with A53 1.2GHz:
xdpsock rxdrop copy mode:
pps pkts 1.00
rx 856,054 10,625,775
Two CPUs with both 100% utilization.xdpsock rxdrop zero-copy mode:
pps pkts 1.00
rx 889,388 4,615,284
Two CPUs with 100% and 20% utilization.xdpsock l2fwd copy mode:
pps pkts 1.00rx 248,985 7,315,885 tx 248,921 7,315,885Two CPUs with 100% and 10% utilization.
Quoted 7 lines
Quoted 5 lines
xdpsock l2fwd zero-copy mode:
pps pkts 1.00rx 254,735 3,039,456 tx 254,735 3,039,456Two CPUs with 100% and 4% utilization.
Thanks for sharing the numbers. This is for 64 byte frames?
Yes. I will add that information.
Quoted 31 lines
Quoted 15 lines
Packet rate increases and CPU utilization is reduced in both cases. 100% CPU load seems to the base load. This load is consumed by ksoftirqd just for dropping the generated packets without xdpsock running.
Using batch API reduced CPU utilization slightly, but measurements are not stable enough to provide meaningful numbers.
Signed-off-by Gerhard Engleder <[email protected]>--- drivers/net/ethernet/engleder/tsnep.h | 13 +- drivers/net/ethernet/engleder/tsnep_main.c | 494 ++++++++++++++++++++- drivers/net/ethernet/engleder/tsnep_xdp.c | 66 +++ 3 files changed, 558 insertions(+), 15 deletions(-)(...)
Quoted 13 lines
static const struct net_device_ops tsnep_netdev_ops = { .ndo_open = tsnep_netdev_open, .ndo_stop = tsnep_netdev_close,drivers/net/ethernet/engleder/tsnep_main.c +1
-0@@ -1713,6 +2177,7 @@ static const struct net_device_ops tsnep_netdev_ops = { .ndo_setup_tc = tsnep_tc_setup, .ndo_bpf = tsnep_netdev_bpf, .ndo_xdp_xmit = tsnep_netdev_xdp_xmit, + .ndo_xsk_wakeup = tsnep_netdev_xsk_wakeup, };static int tsnep_mac_init (struct tsnep_adapter *adapter)@@ -1973,7 +2438,8 @@ static int tsnep_probe(struct platform_device *pdev)
Quoted 9 lines
drivers/net/ethernet/engleder/tsnep_main.c static int tsnep_probe(struct platform_device *pdev) · line 2442
Quoted 5 lines
drivers/net/ethernet/engleder/tsnep_main.c +2
-1netdev->xdp_features =NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT |NETDEV_XDP_ACT_NDO_XMIT | -NETDEV_XDP_ACT_NDO_XMIT_SG ; +NETDEV_XDP_ACT_NDO_XMIT_SG | +NETDEV_XDP_ACT_XSK_ZEROCOPY ;In theory enabling this feature here before implementing Tx ZC can expose you to some broken behavior, so just for the sake of completeness, i would move this to Tx ZC patch.
Will be done.
PATCH v3 6/6 tsnep: Add XDP socket zero-copy TX support
In reply to Gerhard EnglederSend and complete XSK pool frames within TX NAPI context. NAPI context is triggered by ndo_xsk_wakeup.
Test results with A53 1.2GHz:
xdpsock txonly copy mode:
pps pkts 1.00
tx 284,409 11,398,144
Two CPUs with 100% and 10% utilization.
xdpsock txonly zero-copy mode:
pps pkts 1.00
tx 511,929 5,890,368
Two CPUs with 100% and 1% utilization.
Packet rate increases and CPU utilization is reduced.
--- drivers/net/ethernet/engleder/tsnep.h | 2 + drivers/net/ethernet/engleder/tsnep_main.c | 127 +++++++++++++++++++-- 2 files changed, 119 insertions(+), 10 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +2 -0
@@ -70,6 +70,7 @@ struct tsnep_tx_entry {union {struct sk_buff *skb;struct xdp_frame *xdpf; +bool zc; };size_t len;DEFINE_DMA_UNMAP_ADDR (dma);
@@ -88,6 +89,7 @@ struct tsnep_tx {int read;u32 owner_counter;int increment_owner_counter; +struct xsk_buff_pool *xsk_pool;u32 packets;u32 bytes;
drivers/net/ethernet/engleder/tsnep_main.c +117 -10
204 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH net-next v3 6/6] tsnep: Add XDP socket zero-copy TX support
Quoted 10 lines · Gerhard Engleder
Send and complete XSK pool frames within TX NAPI context. NAPI context is triggered by
ndo_xsk_wakeup.Test results with A53 1.2GHz:
xdpsock txonly copy mode:
pps pkts 1.00
tx 284,409 11,398,144
Two CPUs with 100% and 10% utilization.
Quoted 4 lines
xdpsock txonly zero-copy mode:
pps pkts 1.00
tx 511,929 5,890,368
Two CPUs with 100% and 1% utilization.
Hmm, I think l2fwd ZC numbers should be included here not in the previous patch?
Quoted 9 lines
Packet rate increases and CPU utilization is reduced.
Signed-off-by Gerhard Engleder <[email protected]>--- drivers/net/ethernet/engleder/tsnep.h | 2 + drivers/net/ethernet/engleder/tsnep_main.c | 127 +++++++++++++++++++-- 2 files changed, 119 insertions(+), 10 deletions(-)
(...)
Quoted 90 lines
drivers/net/ethernet/engleder/tsnep_main.c +64
-3+static int tsnep_xdp_tx_map_zc (struct xdp_desc *xdpd,struct tsnep_tx *tx) +{ +struct tsnep_tx_entry *entry; +dma_addr_t dma; + + entry = &tx->entry[tx->write]; + entry->zc = true; + + dma =xsk_buff_raw_get_dma (tx->xsk_pool, xdpd->addr); +xsk_buff_raw_dma_sync_for_device (tx->xsk_pool, dma, xdpd->len); + + entry->type =TSNEP_TX_TYPE_XSK ; + entry->len = xdpd->len; + + entry->desc->tx =__cpu_to_le64 (dma); + +return xdpd->len; +} + +static void tsnep_xdp_xmit_frame_ring_zc (struct xdp_desc *xdpd, +struct tsnep_tx *tx) +{ +int length; + + length =tsnep_xdp_tx_map_zc (xdpd, tx); + +tsnep_tx_activate (tx, tx->write, length, true); + tx->write = (tx->write +1 ) &TSNEP_RING_MASK ; +} + +static void tsnep_xdp_xmit_zc (struct tsnep_tx *tx) +{ +int desc_available =tsnep_tx_desc_available (tx); +struct xdp_desc *descs = tx->xsk_pool->tx_descs; +int batch, i; + +/* ensure that TX ring is not filled up by XDP, always MAX_SKB_FRAGS +* will be available for normal TX path and queue is stopped there if +* necessary +*/ +if (desc_available <= (MAX_SKB_FRAGS +1 )) +return ; + desc_available -=MAX_SKB_FRAGS +1 ; + + batch =xsk_tx_peek_release_desc_batch (tx->xsk_pool, desc_available); +for (i =0 ; i < batch; i++) +tsnep_xdp_xmit_frame_ring_zc (&descs[i], tx); + +if (batch) { +/* descriptor properties shall be valid before hardware is +* notified +*/ +dma_wmb (); + +tsnep_xdp_xmit_flush (tx); + } +} +static bool tsnep_tx_poll (struct tsnep_tx *tx,int napi_budget) {struct tsnep_tx_entry *entry;struct netdev_queue *nq; +int xsk_frames =0 ;int budget =128 ;int length;int count;@@ -676,7 +771,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if ((entry->type &TSNEP_TX_TYPE_SKB ) &&skb_shinfo (entry->skb)->nr_frags >0 ) count +=skb_shinfo (entry->skb)->nr_frags; -else if (!(entry->type &TSNEP_TX_TYPE_SKB ) && +else if ((entry->type &TSNEP_TX_TYPE_XDP ) &&xdp_frame_has_frags (entry->xdpf)) count +=xdp_get_shared_info_from_frame (entry->xdpf)->nr_frags;@@ -705,9 +800,11 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if (entry->type &TSNEP_TX_TYPE_SKB )napi_consume_skb (entry->skb, napi_budget); -else +else if (entry->type &TSNEP_TX_TYPE_XDP )xdp_return_frame_rx_napi (entry->xdpf); -/* xdpf is union with skb */ +else + xsk_frames++; +/* xdpf and zc are union with skb */ entry->skb =NULL ; tx->read = (tx->read + count) &TSNEP_RING_MASK ;
drivers/net/ethernet/engleder/tsnep_main.c static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) · line 823
Quoted 9 lines
drivers/net/ethernet/engleder/tsnep_main.c +6
-0@@ -718,6 +815,14 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) budget--; }while (likely (budget)); +if (tx->xsk_pool) { +if (xsk_frames) +xsk_tx_completed (tx->xsk_pool, xsk_frames); +if (xsk_uses_need_wakeup (tx->xsk_pool)) +xsk_set_tx_need_wakeup (tx->xsk_pool); +tsnep_xdp_xmit_zc (tx);
would be good to signal to NAPI if we are done with the work or is there a need to be rescheduled (when you didn't manage to consume all of the descs from XSK Tx ring).
Quoted 56 lines
drivers/net/ethernet/engleder/tsnep_main.c +10
-6+ } +if ((tsnep_tx_desc_available (tx) >= ((MAX_SKB_FRAGS +1 ) *2 )) &&netif_tx_queue_stopped (nq)) {netif_tx_wake_queue (nq);@@ -765,12 +870,6 @@ static int tsnep_tx_open(struct tsnep_tx *tx)static void tsnep_tx_close (struct tsnep_tx *tx) { -u32 val; - -readx_poll_timeout (ioread32, tx->addr +TSNEP_CONTROL , val, - ((val &TSNEP_CONTROL_TX_ENABLE ) ==0 ),10000 , -1000000 ); -tsnep_tx_ring_cleanup (tx); }@@ -1786,12 +1885,18 @@ static void tsnep_queue_enable(struct tsnep_queue *queue)napi_enable (&queue->napi);tsnep_enable_irq (queue->adapter, queue->irq_mask); +if (queue->tx) +tsnep_tx_enable (queue->tx); +if (queue->rx)tsnep_rx_enable (queue->rx); }static void tsnep_queue_disable (struct tsnep_queue *queue) { +if (queue->tx) +tsnep_tx_disable (queue->tx, &queue->napi); +napi_disable (&queue->napi);tsnep_disable_irq (queue->adapter, queue->irq_mask);@@ -1908,6 +2013,7 @@ int tsnep_enable_xsk(struct tsnep_queue *queue, struct xsk_buff_pool *pool)if (running)tsnep_queue_disable (queue); + queue->tx->xsk_pool = pool; queue->rx->xsk_pool = pool;if (running) {@@ -1928,6 +2034,7 @@ void tsnep_disable_xsk(struct tsnep_queue *queue)tsnep_rx_free_zc (queue->rx); queue->rx->xsk_pool =NULL ; + queue->tx->xsk_pool =NULL ;if (running) {tsnep_rx_reopen (queue->rx);Signature · 1 line
2.30.2
Re: [PATCH net-next v3 6/6] tsnep: Add XDP socket zero-copy TX support
Quoted 11 lines · Maciej Fijalkowski
Quoted 10 lines · Gerhard Engleder
Send and complete XSK pool frames within TX NAPI context. NAPI context is triggered by
ndo_xsk_wakeup.Test results with A53 1.2GHz:
xdpsock txonly copy mode:
pps pkts 1.00
tx 284,409 11,398,144
Two CPUs with 100% and 10% utilization.
Quoted 7 lines
Quoted 4 lines
xdpsock txonly zero-copy mode:
pps pkts 1.00
tx 511,929 5,890,368
Two CPUs with 100% and 1% utilization.Hmm, I think l2fwd ZC numbers should be included here not in the previous patch?
Will be done.
Quoted 9 lines
Quoted 9 lines
Packet rate increases and CPU utilization is reduced.
Signed-off-by Gerhard Engleder <[email protected]>--- drivers/net/ethernet/engleder/tsnep.h | 2 + drivers/net/ethernet/engleder/tsnep_main.c | 127 +++++++++++++++++++-- 2 files changed, 119 insertions(+), 10 deletions(-)
(...)
Quoted 35 lines
Quoted 35 lines
static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) { struct tsnep_tx_entry *entry; struct netdev_queue *nq;drivers/net/ethernet/engleder/tsnep_main.c +6
-3+int xsk_frames =0 ;int budget =128 ;int length;int count;@@ -676,7 +771,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if ((entry->type &TSNEP_TX_TYPE_SKB ) &&skb_shinfo (entry->skb)->nr_frags >0 ) count +=skb_shinfo (entry->skb)->nr_frags; -else if (!(entry->type &TSNEP_TX_TYPE_SKB ) && +else if ((entry->type &TSNEP_TX_TYPE_XDP ) &&xdp_frame_has_frags (entry->xdpf)) count +=xdp_get_shared_info_from_frame (entry->xdpf)->nr_frags;@@ -705,9 +800,11 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if (entry->type &TSNEP_TX_TYPE_SKB )napi_consume_skb (entry->skb, napi_budget); -else +else if (entry->type &TSNEP_TX_TYPE_XDP )xdp_return_frame_rx_napi (entry->xdpf); -/* xdpf is union with skb */ +else + xsk_frames++; +/* xdpf and zc are union with skb */ entry->skb =NULL ; tx->read = (tx->read + count) &TSNEP_RING_MASK ;@@ -718,6 +815,14 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) budget--; }while (likely (budget));
Quoted 10 lines
drivers/net/ethernet/engleder/tsnep_main.c static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) · line 823
Quoted 6 lines
drivers/net/ethernet/engleder/tsnep_main.c +6
-0+if (tx->xsk_pool) { +if (xsk_frames) +xsk_tx_completed (tx->xsk_pool, xsk_frames); +if (xsk_uses_need_wakeup (tx->xsk_pool)) +xsk_set_tx_need_wakeup (tx->xsk_pool); +tsnep_xdp_xmit_zc (tx);would be good to signal to NAPI if we are done with the work or is there a need to be rescheduled (when you didn't manage to consume all of the descs from XSK Tx ring).
In my opinion this is already done. If some budget is left, then we are done and tsnep_tx_poll() returns true to signal work is complete. If buget gets zero, then tsnep_tx_poll() returns false to signal work is not complete. This return value is considered for the NAPI signaling by tsnep_poll().
Re: [PATCH net-next v3 6/6] tsnep: Add XDP socket zero-copy TX support
Quoted 76 lines · Gerhard Engleder
Quoted 11 lines · Maciej Fijalkowski
Quoted 10 lines · Gerhard Engleder
Send and complete XSK pool frames within TX NAPI context. NAPI context is triggered by
ndo_xsk_wakeup.Test results with A53 1.2GHz:
xdpsock txonly copy mode:
pps pkts 1.00
tx 284,409 11,398,144
Two CPUs with 100% and 10% utilization.Quoted 7 lines
Quoted 4 lines
xdpsock txonly zero-copy mode:
pps pkts 1.00
tx 511,929 5,890,368
Two CPUs with 100% and 1% utilization.Hmm, I think l2fwd ZC numbers should be included here not in the previous patch?
Will be done.
Quoted 9 lines
Quoted 9 lines
Packet rate increases and CPU utilization is reduced.
Signed-off-by Gerhard Engleder <[email protected]>--- drivers/net/ethernet/engleder/tsnep.h | 2 + drivers/net/ethernet/engleder/tsnep_main.c | 127 +++++++++++++++++++-- 2 files changed, 119 insertions(+), 10 deletions(-)(...)
Quoted 33 lines
Quoted 33 lines
static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) { struct tsnep_tx_entry *entry; struct netdev_queue *nq;drivers/net/ethernet/engleder/tsnep_main.c +8
-3+int xsk_frames =0 ;int budget =128 ;int length;int count;@@ -676,7 +771,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if ((entry->type &TSNEP_TX_TYPE_SKB ) &&skb_shinfo (entry->skb)->nr_frags >0 ) count +=skb_shinfo (entry->skb)->nr_frags; -else if (!(entry->type &TSNEP_TX_TYPE_SKB ) && +else if ((entry->type &TSNEP_TX_TYPE_XDP ) &&xdp_frame_has_frags (entry->xdpf)) count +=xdp_get_shared_info_from_frame (entry->xdpf)->nr_frags;@@ -705,9 +800,11 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if (entry->type &TSNEP_TX_TYPE_SKB )napi_consume_skb (entry->skb, napi_budget); -else +else if (entry->type &TSNEP_TX_TYPE_XDP )xdp_return_frame_rx_napi (entry->xdpf); -/* xdpf is union with skb */ +else + xsk_frames++; +/* xdpf and zc are union with skb */ entry->skb =NULL ; tx->read = (tx->read + count) &TSNEP_RING_MASK ;@@ -718,6 +815,14 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) budget--; }while (likely (budget)); +if (tx->xsk_pool) { +if (xsk_frames)Quoted 8 lines
drivers/net/ethernet/engleder/tsnep_main.c static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) · line 823
Quoted 4 lines
drivers/net/ethernet/engleder/tsnep_main.c +4
-0+xsk_tx_completed (tx->xsk_pool, xsk_frames); +if (xsk_uses_need_wakeup (tx->xsk_pool)) +xsk_set_tx_need_wakeup (tx->xsk_pool); +tsnep_xdp_xmit_zc (tx);would be good to signal to NAPI if we are done with the work or is there a need to be rescheduled (when you didn't manage to consume all of the descs from XSK Tx ring).
Quoted 5 lines
In my opinion this is already done. If some budget is left, then we are done and
tsnep_tx_poll()returns true to signal work is complete. If buget gets zero, thentsnep_tx_poll()returns false to signal work is not complete. This return value is considered for the NAPI signaling bytsnep_poll().
i was only referring to tsnep_xdp_xmit_zc() being void on return. Thing is that there is currently no way you would tell to napi there is more work to be done. you should do so if desc_available == batch. That would mean there might be still descriptors on XSK Tx ring ready to be consumed. NAPI budget is out of the picture here.
Re: [PATCH net-next v3 6/6] tsnep: Add XDP socket zero-copy TX support
Quoted 83 lines · Maciej Fijalkowski
Quoted 76 lines · Gerhard Engleder
Quoted 11 lines · Maciej Fijalkowski
Quoted 10 lines · Gerhard Engleder
Send and complete XSK pool frames within TX NAPI context. NAPI context is triggered by
ndo_xsk_wakeup.Test results with A53 1.2GHz:
xdpsock txonly copy mode:
pps pkts 1.00
tx 284,409 11,398,144
Two CPUs with 100% and 10% utilization.Quoted 7 lines
Quoted 4 lines
xdpsock txonly zero-copy mode:
pps pkts 1.00
tx 511,929 5,890,368
Two CPUs with 100% and 1% utilization.Hmm, I think l2fwd ZC numbers should be included here not in the previous patch?
Will be done.
Quoted 9 lines
Quoted 9 lines
Packet rate increases and CPU utilization is reduced.
Signed-off-by Gerhard Engleder <[email protected]>--- drivers/net/ethernet/engleder/tsnep.h | 2 + drivers/net/ethernet/engleder/tsnep_main.c | 127 +++++++++++++++++++-- 2 files changed, 119 insertions(+), 10 deletions(-)(...)
Quoted 33 lines
Quoted 33 lines
static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) { struct tsnep_tx_entry *entry; struct netdev_queue *nq;drivers/net/ethernet/engleder/tsnep_main.c +8
-3+int xsk_frames =0 ;int budget =128 ;int length;int count;@@ -676,7 +771,7 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if ((entry->type &TSNEP_TX_TYPE_SKB ) &&skb_shinfo (entry->skb)->nr_frags >0 ) count +=skb_shinfo (entry->skb)->nr_frags; -else if (!(entry->type &TSNEP_TX_TYPE_SKB ) && +else if ((entry->type &TSNEP_TX_TYPE_XDP ) &&xdp_frame_has_frags (entry->xdpf)) count +=xdp_get_shared_info_from_frame (entry->xdpf)->nr_frags;@@ -705,9 +800,11 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget)if (entry->type &TSNEP_TX_TYPE_SKB )napi_consume_skb (entry->skb, napi_budget); -else +else if (entry->type &TSNEP_TX_TYPE_XDP )xdp_return_frame_rx_napi (entry->xdpf); -/* xdpf is union with skb */ +else + xsk_frames++; +/* xdpf and zc are union with skb */ entry->skb =NULL ; tx->read = (tx->read + count) &TSNEP_RING_MASK ;@@ -718,6 +815,14 @@ static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) budget--; }while (likely (budget)); +if (tx->xsk_pool) { +if (xsk_frames)Quoted 8 lines
drivers/net/ethernet/engleder/tsnep_main.c static bool tsnep_tx_poll(struct tsnep_tx *tx, int napi_budget) · line 823
Quoted 4 lines
drivers/net/ethernet/engleder/tsnep_main.c +4
-0+xsk_tx_completed (tx->xsk_pool, xsk_frames); +if (xsk_uses_need_wakeup (tx->xsk_pool)) +xsk_set_tx_need_wakeup (tx->xsk_pool); +tsnep_xdp_xmit_zc (tx);would be good to signal to NAPI if we are done with the work or is there a need to be rescheduled (when you didn't manage to consume all of the descs from XSK Tx ring).
Quoted 5 lines
In my opinion this is already done. If some budget is left, then we are done and
tsnep_tx_poll()returns true to signal work is complete. If buget gets zero, thentsnep_tx_poll()returns false to signal work is not complete. This return value is considered for the NAPI signaling bytsnep_poll().
Quoted 5 lines
i was only referring to
tsnep_xdp_xmit_zc()being void on return. Thing is that there is currently no way you would tell to napi there is more work to be done. you should do so ifdesc_available== batch. That would mean there might be still descriptors on XSK Tx ring ready to be consumed. NAPI budget is out of the picture here.
Now I got it. Pending zero-copy work shall be signaled to napi directly. In current implementation it would be processed if TX interrupt signals completed descriptors. By signaling napi directly, the TX interrupt could be prevented. In my opinion both options are possible, but the performance may differ. I will check if telling napi that there is more work to be done would improve performance.
Quoted 7 lines · Gerhard Engleder
Implement XDP socket zero-copy support for tsnep driver. I tried to follow existing drivers like igc as far as possible. But one main difference is that tsnep does not need any reconfiguration for XDP BPF program setup. So I decided to keep this behavior no matter if a XSK pool is used or not. As a result, tsnep starts using the XSK pool even if no XDP BPF program is available.
Quoted 7 lines
Another difference is that I tried to prevent potentially failing allocations during XSK pool setup. E.g. both memory models for page pool and XSK pool are registered all the time. Thus, XSK pool setup cannot end up with not working queues.
Some prework is done to reduce the last two XSK commits to actual XSK changes.
I had minor comments on two last patches, besides:
Quoted 33 lines
v3:
- use__netif_tx_lock_bh()(Paolo Abeni)
- comment thatrx->page_bufferis always zero terminated (Paolo Abeni)v2:
- eliminate modulo op in TX/RX path (Maciej Fijalkowski)
- eliminate retval variable intsnep_rx_alloc_zc()(Maciej Fijalkowski)
- scope variable entry within loop (Maciej Fijalkowski)
- useDMA_ATTR_SKIP_CPU_SYNCdirectly (Maciej Fijalkowski)
- union for page/xdp intsnep_rx_entry(Maciej Fijalkowski)
- provide performance numbers (Maciej Fijalkowski)
- usexsk_buff_alloc_batch()(Maciej Fijalkowski)
- usexsk_tx_peek_release_desc_batch()(Maciej Fijalkowski)
- don't calltsnep_rx_reopen()if netdev is down
- init adapter pointer of queue only onceGerhard Engleder (6):
tsnep: Replace modulo operation with mask
tsnep: Rework TX/RX queue initialization
tsnep: Add functions for queue enable/disable
tsnep: Move skb receive action to separate function
tsnep: Add XDP socket zero-copy RX support
tsnep: Add XDP socket zero-copy TX supportdrivers/net/ethernet/engleder/tsnep.h | 16 +- drivers/net/ethernet/engleder/tsnep_main.c | 863 ++++++++++++++++++--- drivers/net/ethernet/engleder/tsnep_xdp.c | 66 ++ 3 files changed, 822 insertions(+), 123 deletions(-)Signature · 1 line
2.30.2
Quoted 13 lines · Maciej Fijalkowski
Quoted 12 lines · Gerhard Engleder
Implement XDP socket zero-copy support for tsnep driver. I tried to follow existing drivers like igc as far as possible. But one main difference is that tsnep does not need any reconfiguration for XDP BPF program setup. So I decided to keep this behavior no matter if a XSK pool is used or not. As a result, tsnep starts using the XSK pool even if no XDP BPF program is available.
Another difference is that I tried to prevent potentially failing allocations during XSK pool setup. E.g. both memory models for page pool and XSK pool are registered all the time. Thus, XSK pool setup cannot end up with not working queues.
Quoted 5 lines
Quoted 2 lines
Some prework is done to reduce the last two XSK commits to actual XSK changes.
I had minor comments on two last patches, besides:
Reviewed-by Maciej Fijalkowski <[email protected]>
I will add that tag to all commits.
Thank you for the review!
Gerhard