Skip to content

Commit eff9415

Browse files
netoptimizerAlexei Starovoitov
authored andcommitted
samples/bpf: xdp_redirect_cpu_user: Cpumap qsize set larger default
Experience from production shows queue size of 192 is too small, as this caused packet drops during cpumap-enqueue on RX-CPU. This can be diagnosed with xdp_monitor sample program. This bpftrace program was used to diagnose the problem in more detail: bpftrace -e ' tracepoint:xdp:xdp_cpumap_kthread { @deq_bulk = lhist(args->processed,0,10,1); @drop_net = lhist(args->drops,0,10,1) } tracepoint:xdp:xdp_cpumap_enqueue { @enq_bulk = lhist(args->processed,0,10,1); @enq_drops = lhist(args->drops,0,10,1); }' Watch out for the @enq_drops counter. The @drop_net counter can happen when netstack gets invalid packets, so don't despair it can be natural, and that counter will likely disappear in newer kernels as it was a source of confusion (look at netstat info for reason of the netstack @drop_net counters). The production system was configured with CPU power-saving C6 state. Learn more in this blogpost[1]. And wakeup latency in usec for the states are: # grep -H . /sys/devices/system/cpu/cpu0/cpuidle/*/latency /sys/devices/system/cpu/cpu0/cpuidle/state0/latency:0 /sys/devices/system/cpu/cpu0/cpuidle/state1/latency:2 /sys/devices/system/cpu/cpu0/cpuidle/state2/latency:10 /sys/devices/system/cpu/cpu0/cpuidle/state3/latency:133 Deepest state take 133 usec to wakeup from (133/10^6). The link speed is 25Gbit/s ((25*10^9/8) in bytes/sec). How many bytes can arrive with in 133 usec at this speed: (25*10^9/8)*(133/10^6) = 415625 bytes. With MTU size packets this is 275 packets, and with minimum Ethernet (incl intergap overhead) 84 bytes it is 4948 packets. Clearly default queue size is too small. Setting default cpumap queue to 2048 as worst-case (small packet) at 10Gbit/s is 1979 packets with 133 usec wakeup time, +64 packet before kthread wakeup call (due to xdp_do_flush) worst-case 2043 packets. Thus, if a packet burst on RX-CPU will enqueue packets to a remote cpumap CPU that is in deep-sleep state it can overrun the cpumap queue. The production system was also configured to avoid deep-sleep via: tuned-adm profile network-latency [1] https://jeremyeder.com/2013/08/30/oh-did-you-expect-the-cpu/ Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/162523477604.786243.13372630844944530891.stgit@firesoul
1 parent e0bc892 commit eff9415

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎samples/bpf/xdp_redirect_cpu_user.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,23 @@ int main(int argc, char **argv)
792792

793793
n_cpus = get_nprocs_conf();
794794

795-
/* Notice: choosing he queue size is very important with the
796-
* ixgbe driver, because it's driver page recycling trick is
797-
* dependend on pages being returned quickly. The number of
798-
* out-standing packets in the system must be less-than 2x
799-
* RX-ring size.
795+
/* Notice: Choosing the queue size is very important when CPU is
796+
* configured with power-saving states.
797+
*
798+
* If deepest state take 133 usec to wakeup from (133/10^6). When link
799+
* speed is 10Gbit/s ((10*10^9/8) in bytes/sec). How many bytes can
800+
* arrive with in 133 usec at this speed: (10*10^9/8)*(133/10^6) =
801+
* 166250 bytes. With MTU size packets this is 110 packets, and with
802+
* minimum Ethernet (MAC-preamble + intergap) 84 bytes is 1979 packets.
803+
*
804+
* Setting default cpumap queue to 2048 as worst-case (small packet)
805+
* should be +64 packet due kthread wakeup call (due to xdp_do_flush)
806+
* worst-case is 2043 packets.
807+
*
808+
* Sysadm can configured system to avoid deep-sleep via:
809+
* tuned-adm profile network-latency
800810
*/
801-
qsize = 128+64;
811+
qsize = 2048;
802812

803813
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
804814
prog_load_attr.file = filename;

0 commit comments

Comments
 (0)