Skip to content

Commit df54228

Browse files
committed
Merge branch 'xdp-preferred-busy-polling'
Björn Töpel says: ==================== This series introduces three new features: 1. A new "heavy traffic" busy-polling variant that works in concert with the existing napi_defer_hard_irqs and gro_flush_timeout knobs. 2. A new socket option that let a user change the busy-polling NAPI budget. 3. Allow busy-polling to be performed on XDP sockets. The existing busy-polling mode, enabled by the SO_BUSY_POLL socket option or system-wide using the /proc/sys/net/core/busy_read knob, is an opportunistic. That means that if the NAPI context is not scheduled, it will poll it. If, after busy-polling, the budget is exceeded the busy-polling logic will schedule the NAPI onto the regular softirq handling. One implication of the behavior above is that a busy/heavy loaded NAPI context will never enter/allow for busy-polling. Some applications prefer that most NAPI processing would be done by busy-polling. This series adds a new socket option, SO_PREFER_BUSY_POLL, that works in concert with the napi_defer_hard_irqs and gro_flush_timeout knobs. The napi_defer_hard_irqs and gro_flush_timeout knobs were introduced in commit 6f8b12d ("net: napi: add hard irqs deferral feature"), and allows for a user to defer interrupts to be enabled and instead schedule the NAPI context from a watchdog timer. When a user enables the SO_PREFER_BUSY_POLL, again with the other knobs enabled, and the NAPI context is being processed by a softirq, the softirq NAPI processing will exit early to allow the busy-polling to be performed. If the application stops performing busy-polling via a system call, the watchdog timer defined by gro_flush_timeout will timeout, and regular softirq handling will resume. In summary; Heavy traffic applications that prefer busy-polling over softirq processing should use this option. Patch 6 touches a lot of drivers, so the Cc: list is grossly long. Example usage: $ echo 2 | sudo tee /sys/class/net/ens785f1/napi_defer_hard_irqs $ echo 200000 | sudo tee /sys/class/net/ens785f1/gro_flush_timeout Note that the timeout should be larger than the userspace processing window, otherwise the watchdog will timeout and fall back to regular softirq processing. Enable the SO_BUSY_POLL/SO_PREFER_BUSY_POLL options on your socket. Performance simple UDP ping-pong: A packet generator blasts UDP packets from a packet generator to a certain {src,dst}IP/port, so a dedicated ksoftirq will be busy handling the packets at a certain core. A simple UDP test program that simply does recvfrom/sendto is running at the host end. Throughput in pps and RTT latency is measured at the packet generator. /proc/sys/net/core/busy_read is set (20). Min Max Avg (usec) 1. Blocking 2-cores: 490Kpps 1218.192 1335.427 1271.083 2. Blocking, 1-core: 155Kpps 1327.195 17294.855 4761.367 3. Non-blocking, 2-cores: 475Kpps 1221.197 1330.465 1270.740 4. Non-blocking, 1-core: 3Kpps 29006.482 37260.465 33128.367 5. Non-blocking, prefer busy-poll, 1-core: 420Kpps 1202.535 5494.052 4885.443 Scenario 2 and 5 shows when the new option should be used. Throughput go from 155 to 420Kpps, average latency are similar, but the tail latencies are much better for the latter. Performance XDP sockets: Again, a packet generator blasts UDP packets from a packet generator to a certain {src,dst}IP/port. Today, running XDP sockets sample on the same core as the softirq handling, performance tanks mainly because we do not yield to user-space when the XDP socket Rx queue is full. # taskset -c 5 ./xdpsock -i ens785f1 -q 5 -n 1 -r Rx: 64Kpps # # preferred busy-polling, budget 8 # taskset -c 5 ./xdpsock -i ens785f1 -q 5 -n 1 -r -B -b 8 Rx 9.9Mpps # # preferred busy-polling, budget 64 # taskset -c 5 ./xdpsock -i ens785f1 -q 5 -n 1 -r -B -b 64 Rx: 19.3Mpps # # preferred busy-polling, budget 256 # taskset -c 5 ./xdpsock -i ens785f1 -q 5 -n 1 -r -B -b 256 Rx: 21.4Mpps # # preferred busy-polling, budget 512 # taskset -c 5 ./xdpsock -i ens785f1 -q 5 -n 1 -r -B -b 512 Rx: 21.7Mpps Compared to the two-core case: # taskset -c 4 ./xdpsock -i ens785f1 -q 20 -n 1 -r Rx: 20.7Mpps We're getting better single-core performance than two, for this naïve drop scenario. Performance netperf UDP_RR: Note that netperf UDP_RR is not a heavy traffic tests, and preferred busy-polling is not typically something we want to use here. $ echo 20 | sudo tee /proc/sys/net/core/busy_read $ netperf -H 192.168.1.1 -l 30 -t UDP_RR -v 2 -- \ -o min_latency,mean_latency,max_latency,stddev_latency,transaction_rate busy-polling blocking sockets: 12,13.33,224,0.63,74731.177 I hacked netperf to use non-blocking sockets and re-ran: busy-polling non-blocking sockets: 12,13.46,218,0.72,73991.172 prefer busy-polling non-blocking sockets: 12,13.62,221,0.59,73138.448 Using the preferred busy-polling mode does not impact performance. The above tests was done for the 'ice' driver. Thanks to Jakub for suggesting this busy-polling addition [1], and Eric for all input/review! Changes: rfc-v1 [2] -> rfc-v2: * Changed name from bias to prefer. * Base the work on Eric's/Luigi's defer irq/gro timeout work. * Proper GRO flushing. * Build issues for some XDP drivers. rfc-v2 [3] -> v1: * Fixed broken qlogic build. * Do not trigger an IPI (XDP socket wakeup) when busy-polling is enabled. v1 [4] -> v2: * Added napi_id to socionext driver, and added Ilias Acked-by:. (Ilias) * Added a samples patch to improve busy-polling for xdpsock/l2fwd. * Correctly mark atomic operations with {WRITE,READ}_ONCE, to make KCSAN and the code readers happy. (Eric) * Check NAPI budget not to exceed U16_MAX. (Eric) * Added kdoc. v2 [5] -> v3: * Collected Acked-by. * Check NAPI disable prior prefer busy-polling. (Jakub) * Added napi_id registration for virtio-net. (Michael) * Added napi_id registration for veth. v3 [6] -> v4: * Collected Acked-by/Reviewed-by. [1] https://lore.kernel.org/netdev/20200925120652.10b8d7c5@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com/ [2] https://lore.kernel.org/bpf/20201028133437.212503-1-bjorn.topel@gmail.com/ [3] https://lore.kernel.org/bpf/20201105102812.152836-1-bjorn.topel@gmail.com/ [4] https://lore.kernel.org/bpf/20201112114041.131998-1-bjorn.topel@gmail.com/ [5] https://lore.kernel.org/bpf/20201116110416.10719-1-bjorn.topel@gmail.com/ [6] https://lore.kernel.org/bpf/20201119083024.119566-1-bjorn.topel@gmail.com/ ==================== Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2 parents 854055c + 41bf900 commit df54228

File tree

40 files changed

+300
-107
lines changed

40 files changed

+300
-107
lines changed

arch/alpha/include/uapi/asm/socket.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124

125125
#define SO_DETACH_REUSEPORT_BPF 68
126126

127+
#define SO_PREFER_BUSY_POLL 69
128+
#define SO_BUSY_POLL_BUDGET 70
129+
127130
#if !defined(__KERNEL__)
128131

129132
#if __BITS_PER_LONG == 64

arch/mips/include/uapi/asm/socket.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135

136136
#define SO_DETACH_REUSEPORT_BPF 68
137137

138+
#define SO_PREFER_BUSY_POLL 69
139+
#define SO_BUSY_POLL_BUDGET 70
140+
138141
#if !defined(__KERNEL__)
139142

140143
#if __BITS_PER_LONG == 64

arch/parisc/include/uapi/asm/socket.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116

117117
#define SO_DETACH_REUSEPORT_BPF 0x4042
118118

119+
#define SO_PREFER_BUSY_POLL 0x4043
120+
#define SO_BUSY_POLL_BUDGET 0x4044
121+
119122
#if !defined(__KERNEL__)
120123

121124
#if __BITS_PER_LONG == 64

arch/sparc/include/uapi/asm/socket.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117

118118
#define SO_DETACH_REUSEPORT_BPF 0x0047
119119

120+
#define SO_PREFER_BUSY_POLL 0x0048
121+
#define SO_BUSY_POLL_BUDGET 0x0049
122+
120123
#if !defined(__KERNEL__)
121124

122125

drivers/net/ethernet/amazon/ena/ena_netdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ static int ena_xdp_register_rxq_info(struct ena_ring *rx_ring)
416416
{
417417
int rc;
418418

419-
rc = xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev, rx_ring->qid);
419+
rc = xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev, rx_ring->qid, 0);
420420

421421
if (rc) {
422422
netif_err(rx_ring->adapter, ifup, rx_ring->netdev,

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2884,7 +2884,7 @@ static int bnxt_alloc_rx_rings(struct bnxt *bp)
28842884
if (rc)
28852885
return rc;
28862886

2887-
rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i);
2887+
rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i, 0);
28882888
if (rc < 0)
28892889
return rc;
28902890

drivers/net/ethernet/cavium/thunder/nicvf_queues.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static void nicvf_rcv_queue_config(struct nicvf *nic, struct queue_set *qs,
770770
rq->caching = 1;
771771

772772
/* Driver have no proper error path for failed XDP RX-queue info reg */
773-
WARN_ON(xdp_rxq_info_reg(&rq->xdp_rxq, nic->netdev, qidx) < 0);
773+
WARN_ON(xdp_rxq_info_reg(&rq->xdp_rxq, nic->netdev, qidx, 0) < 0);
774774

775775
/* Send a mailbox msg to PF to config RQ */
776776
mbx.rq.msg = NIC_MBOX_MSG_RQ_CFG;

drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3334,7 +3334,7 @@ static int dpaa2_eth_setup_rx_flow(struct dpaa2_eth_priv *priv,
33343334
return 0;
33353335

33363336
err = xdp_rxq_info_reg(&fq->channel->xdp_rxq, priv->net_dev,
3337-
fq->flowid);
3337+
fq->flowid, 0);
33383338
if (err) {
33393339
dev_err(dev, "xdp_rxq_info_reg failed\n");
33403340
return err;

drivers/net/ethernet/intel/i40e/i40e_txrx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ int i40e_setup_rx_descriptors(struct i40e_ring *rx_ring)
14471447
/* XDP RX-queue info only needed for RX rings exposed to XDP */
14481448
if (rx_ring->vsi->type == I40E_VSI_MAIN) {
14491449
err = xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev,
1450-
rx_ring->queue_index);
1450+
rx_ring->queue_index, rx_ring->q_vector->napi.napi_id);
14511451
if (err < 0)
14521452
return err;
14531453
}

drivers/net/ethernet/intel/ice/ice_base.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ int ice_setup_rx_ctx(struct ice_ring *ring)
306306
if (!xdp_rxq_info_is_reg(&ring->xdp_rxq))
307307
/* coverity[check_return] */
308308
xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev,
309-
ring->q_index);
309+
ring->q_index, ring->q_vector->napi.napi_id);
310310

311311
ring->xsk_pool = ice_xsk_pool(ring);
312312
if (ring->xsk_pool) {
@@ -333,7 +333,7 @@ int ice_setup_rx_ctx(struct ice_ring *ring)
333333
/* coverity[check_return] */
334334
xdp_rxq_info_reg(&ring->xdp_rxq,
335335
ring->netdev,
336-
ring->q_index);
336+
ring->q_index, ring->q_vector->napi.napi_id);
337337

338338
err = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
339339
MEM_TYPE_PAGE_SHARED,

0 commit comments

Comments
 (0)