AF_XDP not transmitting frames immediately
Hi Magnus and Bjørn,
I'm coding on an AF_XDP program[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).
My observations are that AF_XDP doesn't send the frames immediately. And yes, I do call sendto() to trigger a TX kick.
In zero-copy mode this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving host.
Is the a known property of AF_XDP?
How can I get AF_XDP to "flush" TX packets when calling sendto()? Should we add another flag than the current MSG_DONTWAIT?
--Jesper
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j adapter_unsynced
--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42
Notice[1] on specific branch:
[1]
https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_example/AF_XDP-interaction
Quoted 18 lines
-----Original Message-----
From: Jesper Dangaard Brouer <[email protected]>
Sent: Monday, December 13, 2021 10:04 PM
To: Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]>
Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject:AF_XDPnot transmitting frames immediatelyHi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).
Quoted 7 lines
My observations are that
AF_XDPdoesn't send the frames immediately. And yes, I do callsendto()to trigger a TX kick.
In zero-copy mode this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving host.Is the a known property of
AF_XDP?
Nope! It is supposed to be able to send one packet at a time, though I have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in the core code. There is even a test these days for just sending a single packet, since we have had issues with this in the past. That test does pass in bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What driver are you using in zero-copy mode and what kernel version are you on?
Quoted 2 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?
In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the xsk_wakeup ndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.
/Magnus
Quoted 11 lines
--Jesper
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano
-w af_xdp_tx_cyclic.dump42Notice[1] on specific branch:
[1]
https://github.com/xdp-project/bpf-
examples/tree/vestas03_AF_XDP_example/AF_XDP-interaction
Quoted 22 lines · Magnus
Quoted 22 lines
-----Original Message----- From: Jesper Dangaard Brouer
<[email protected]> Sent: Monday, December 13, 2021 10:04 PM To:
Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]> Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong
<[email protected]>; Joao Pedro Barros Silva
<[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]> Subject:AF_XDPnot transmitting frames immediatelyHi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).My observations are that
AF_XDPdoesn't send the frames immediately. And yes, I do callsendto()to trigger a TX kick. In zero-copy mode this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving host.
Quoted 6 lines
Quoted 1 line
Is the a known property of
AF_XDP?Nope! It is supposed to be able to send one packet at a time, though I have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in the core code. There is even a test these days for just sending a single packet,
Where is that test in the kernel tree?
Quoted 4 lines
since we have had issues with this in the past. That test does pass in bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What driver are you using in zero-copy mode and what kernel version are you on?
Driver: igc with Intel chip i225
Kernel version: 5.15.0-net-next+ #618 SMP PREEMPT
- Devel branch at commit 6d3b1b069946 (v5.15-12802-g6d3b1b069946)
Quoted 8 lines
Quoted 1 line
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.
I will investigate driver level issues.
I have other (100G) NICs in my testlab, but I'm using these 1G NICs because they support hardware timestamping, which allows me to investigate these timing issues. I'll find a way to see of other drivers behave differently.
Quoted 7 lines
Quoted 6 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch: [1] https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_example/AF_XDP-interaction
Thanks for your feedback,
--Jesper
Adding Ederson and Maciej.
Quoted 36 lines
-----Original Message-----
From: Jesper Dangaard Brouer <[email protected]>
Sent: Tuesday, December 14, 2021 11:32 AM
To: Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]>
Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject: Re:AF_XDPnot transmitting frames immediatelyQuoted 22 lines · Magnus
Quoted 22 lines
-----Original Message----- From: Jesper Dangaard Brouer <[email protected]> Sent: Monday, December 13, 2021 10:04 PM To:
Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]> Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject:AF_XDPnot transmitting frames immediatelyHi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).My observations are that
AF_XDPdoesn't send the frames immediately. And yes, I do callsendto()to trigger a TX kick. In zero-copy mode this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving host.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Is the a known property of
AF_XDP?Nope! It is supposed to be able to send one packet at a time, though I have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in the core code. There is even a test these days for just sending a single packet,
Where is that test in the kernel tree?
In tools/testing/selftests/bpf/xdpxceiver.c. It is the RUN_TO_COMPLETION_SINGLE_PKT test. But the framework only operates on veth currently.
Quoted 6 lines
Quoted 4 lines
since we have had issues with this in the past. That test does pass in bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What driver are you using in zero-copy mode and what kernel version are you on?
Driver: igc with Intel chip i225
Have never tried this one personally. Do not know if I have one in the lab but let me check.
Ederson, do you have any experience with this card and if so, have you seen something similar?
Quoted 12 lines
Kernel version: 5.15.0-net-next+ #618 SMP PREEMPT
- Devel branch at commit6d3b1b069946(v5.15-12802-g6d3b1b069946)Quoted 8 lines
Quoted 2 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.
Quoted 6 lines
I will investigate driver level issues.
I have other (100G) NICs in my testlab, but I'm using these 1G NICs because they support hardware timestamping, which allows me to investigate these timing issues.
I'll find a way to see of other drivers behave differently.
Would be great if you could check if the problem also exists on e.g. ice.
Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch: [1]
https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_exam
Quoted 2 lines
Quoted 1 line
ple/AF_XDP-interaction
Thanks for your feedback,
--Jesper
Quoted 27 lines · Magnus
Adding Ederson and Maciej.
Quoted 25 lines · Magnus
Quoted 24 lines
Quoted 23 lines
-----Original Message----- From: Jesper Dangaard Brouer <[email protected]> Sent: Monday, December 13, 2021 10:04 PM To:
Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]> Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject:AF_XDPnot transmitting frames immediatelyHi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).My observations are that
AF_XDPdoesn't send the frames immediately. And yes, I do callsendto()to trigger a TX kick. In zero-copy mode this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving host.Is the a known property of
AF_XDP?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Nope! It is supposed to be able to send one packet at a time, though I have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in the core code. There is even a test these days for just sending a single packet,
Where is that test in the kernel tree?
In
tools/testing/selftests/bpf/xdpxceiver.c. It is theRUN_TO_COMPLETION_SINGLE_PKTtest. But the framework only operates on veth currently.
I'd say it's driver's fault. Magnus fixed something similar for i40e:
https://lore.kernel.org/netdev/[email protected]/
We don't have currently igc HW on our side to dig this :<
Quoted 48 lines
Quoted 7 lines
Quoted 5 lines
since we have had issues with this in the past. That test does pass in bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What driver are you using in zero-copy mode and what kernel version are you on?
Driver: igc with Intel chip i225
Have never tried this one personally. Do not know if I have one in the lab but let me check.
Ederson, do you have any experience with this card and if so, have you seen something similar?
Quoted 12 lines
Kernel version: 5.15.0-net-next+ #618 SMP PREEMPT
- Devel branch at commit6d3b1b069946(v5.15-12802-g6d3b1b069946)Quoted 8 lines
Quoted 2 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.Quoted 6 lines
I will investigate driver level issues.
I have other (100G) NICs in my testlab, but I'm using these 1G NICs because they support hardware timestamping, which allows me to investigate these timing issues.
I'll find a way to see of other drivers behave differently.Would be great if you could check if the problem also exists on e.g. ice.
Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch: [1]
https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_exam
Quoted 2 lines
Quoted 1 line
ple/AF_XDP-interaction
Thanks for your feedback,
--Jesper
Quoted 33 lines · Maciej Fijalkowski
Quoted 32 lines · Magnus
Adding Ederson and Maciej.
Quoted 30 lines · Magnus
Quoted 28 lines
Quoted 16 lines
-----Original Message----- From: Jesper Dangaard Brouer <[email protected]> Sent: Monday, December 13, 2021 10:04 PM To:
Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]> Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject:AF_XDPnot transmitting frames immediatelyHi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).Quoted 7 lines
My observations are that
AF_XDPdoesn't send the frames immediately. And yes, I do callsendto()to trigger a TX kick. In zero-copy mode this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving host.Is the a known property of
AF_XDP?Nope! It is supposed to be able to send one packet at a time, though I have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in the core code. There is even a test these days for just sending a single packet,
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Where is that test in the kernel tree?
In
tools/testing/selftests/bpf/xdpxceiver.c. It is theRUN_TO_COMPLETION_SINGLE_PKTtest. But the framework only operates on veth currently.I'd say it's driver's fault. Magnus fixed something similar for i40e:
https://lore.kernel.org/netdev/[email protected]/
Thanks for that hint.
Quoted 2 lines
We don't have currently igc HW on our side to dig this :<
I suspected Boon Leong (cc) would have this hardware.
Quoted 26 lines
Quoted 26 lines
Quoted 7 lines
Quoted 5 lines
since we have had issues with this in the past. That test does pass in bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What driver are you using in zero-copy mode and what kernel version are you on?
Driver: igc with Intel chip i225
Have never tried this one personally. Do not know if I have one in the lab but let me check.
Ederson, do you have any experience with this card and if so, have you seen something similar?
Quoted 14 lines
Kernel version: 5.15.0-net-next+ #618 SMP PREEMPT
- Devel branch at commit6d3b1b069946(v5.15-12802-g6d3b1b069946)Quoted 8 lines
Quoted 2 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.I will investigate driver level issues.
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
I have other (100G) NICs in my testlab, but I'm using these 1G NICs because they support hardware timestamping, which allows me to investigate these timing issues.
I'll find a way to see of other drivers behave differently.Would be great if you could check if the problem also exists on e.g. ice.
Having issues getting my ICE hardware to link up.
I tested that driver i40e works as expected. Thus, this is likely an issue with the driver. I will digg some more.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch:
[1] https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_example/AF_XDP-interaction
In [1] I tried to play with SO_PREFER_BUSY_POLL, but it didn't make a difference.
[2] https://github.com/xdp-project/bpf-examples/commit/3685d5ea93fced
--Jesper
Quoted 42 lines · Maciej Fijalkowski
Quoted 28 lines · Magnus
Quoted 27 lines
Adding Ederson and Maciej.
Quoted 25 lines · Magnus
Quoted 24 lines
Quoted 23 lines
-----Original Message----- From: Jesper Dangaard Brouer <[email protected]> Sent: Monday, December 13, 2021 10:04 PM To:
Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]> Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject:AF_XDPnot transmitting frames immediatelyHi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).My observations are that
AF_XDPdoesn't send the frames immediately. And yes, I do callsendto()to trigger a TX kick. In zero-copy mode this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving host.Is the a known property of
AF_XDP?Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Nope! It is supposed to be able to send one packet at a time, though I have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in the core code. There is even a test these days for just sending a single packet,
Where is that test in the kernel tree?
In
tools/testing/selftests/bpf/xdpxceiver.c. It is the
RUN_TO_COMPLETION_SINGLE_PKTtest. But the framework only operates on veth currently.Quoted 3 lines
I'd say it's driver's fault. Magnus fixed something similar for i40e:
https://lore.kernel.org/netdev/20210401172107.1191618-3-
Quoted 8 lines
Thanks for that hint.
Quoted 2 lines
We don't have currently igc HW on our side to dig this :<
I suspected Boon Leong (cc) would have this hardware.
Unfortunately, my current setup in lab does not have I225 hooked-up and I am working remotely due to control access to intel facility. Perhaps, Ederson may have ready system to test?
For ZC mode, the igc driver (also true to stmmac) depends on the XSK wakeup to trigger the NAPI poll (igc_poll) to first clean-up Tx ring and eventually call igc_xdp_xmit_zc() to start submitting Tx frame into DMA engine. We have used busy-poll to ensure in smaller Tx frame latency/jitter.
There was another issue in stmmac that was patched [1] recently to ensure the driver does not perform MAC reset whenever XDP program is added so that between XDP socket creation, the Tx transmit does not take extra 2-3s due to link down/up. Jesper, are you seeing something similar in your app?
If yes, then it is likely because of the implementation of igc driver in mainline that is doing igc_down(), a little bit too aggressive in reseting MAC completely.
[1] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 62 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
since we have had issues with this in the past. That test does pass in bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What driver are you using in zero-copy mode and what kernel version are you on?
Driver: igc with Intel chip i225
Have never tried this one personally. Do not know if I have one in the lab
but let me check.
Quoted 2 lines
Quoted 2 lines
Ederson, do you have any experience with this card and if so, have you seen
something similar?
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Kernel version: 5.15.0-net-next+ #618 SMP PREEMPT
- Devel branch at commit6d3b1b069946(v5.15-12802-g6d3b1b069946)Quoted 8 lines
Quoted 2 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
I will investigate driver level issues.
I have other (100G) NICs in my testlab, but I'm using these 1G NICs because they support hardware timestamping, which allows me to investigate
these
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
timing issues.
I'll find a way to see of other drivers behave differently.Would be great if you could check if the problem also exists on e.g. ice.
Having issues getting my ICE hardware to link up.
I tested that driver i40e works as expected. Thus, this is likely an issue with the driver. I will digg some more.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch:
[1]
https://github.com/xdp-project/bpf-
examples/tree/vestas03_AF_XDP_example/AF_XDP-interactionIn [1] I tried to play with
SO_PREFER_BUSY_POLL, but it didn't make a difference.[2] https://github.com/xdp-project/bpf-examples/commit/3685d5ea93fced
--Jesper
Quoted 11 lines · Boon Leong
Quoted 1 line
I suspected Boon Leong (cc) would have this hardware.
Unfortunately, my current setup in lab does not have I225 hooked-up and I am working remotely due to control access to intel facility. Perhaps, Ederson may have ready system to test?
For ZC mode, the igc driver (also true to stmmac) depends on the XSK wakeup to trigger the NAPI poll (
igc_poll) to first clean-up Tx ring and eventually calligc_xdp_xmit_zc()to start submitting Tx frame into DMA engine. We have used busy-poll to ensure in smaller Tx frame latency/jitter.
Quoted 5 lines
There was another issue in stmmac that was patched [1] recently to ensure the driver does not perform MAC reset whenever XDP program is added so that between XDP socket creation, the Tx transmit does not take extra 2-3s due to link down/up. Jesper, are you seeing something similar in your app?
Yes, and it is quite annoying.
In my setup, if I AF_XDP transmit packets too early they are simply lost... that confused me a bit.
I wanted to ask AF_XDP maintainers:
- What is the best way to know when AF_XDP is ready to Tx packets?
E.g. what API should I call, e.g. that blocks, until XSK socket is ready to transmit on?
Quoted 3 lines
If yes, then it is likely because of the implementation of igc driver in mainline that is doing
igc_down(), a little bit too aggressive in reseting MAC completely.
It would be good to fix igc too, like[1].
BUT afaik it will only make the window smaller when XSK is not ready for TX packets.
Thanks for the link
--Jesper
Quoted 21 lines · Jesper Dangaard Brouer
Quoted 11 lines · Boon Leong
Quoted 1 line
I suspected Boon Leong (cc) would have this hardware.
Unfortunately, my current setup in lab does not have I225 hooked-up and I am working remotely due to control access to intel facility. Perhaps, Ederson may have ready system to test?
For ZC mode, the igc driver (also true to stmmac) depends on the XSK wakeup to trigger the NAPI poll (
igc_poll) to first clean-up Tx ring and eventually calligc_xdp_xmit_zc()to start submitting Tx frame into DMA engine. We have used busy-poll to ensure in smaller Tx frame latency/jitter.Quoted 5 lines
There was another issue in stmmac that was patched [1] recently to ensure the driver does not perform MAC reset whenever XDP program is added so that between XDP socket creation, the Tx transmit does not take extra 2-3s due to link down/up. Jesper, are you seeing something similar in your app?
Yes, and it is quite annoying.
Quoted 8 lines
In my setup, if I
AF_XDPtransmit packets too early they are simply lost... that confused me a bit.I wanted to ask
AF_XDPmaintainers:
- What is the best way to know whenAF_XDPis ready to Tx packets?E.g. what API should I call, e.g. that blocks, until XSK socket is ready to transmit on?
Not a maintainer, but anyway.
From a driver POV xsk_tx_peek_desc() (or batching variant) is used to make sure that user space produced entries in the XSK Tx ring so that driver can consume it and place it onto HW descriptors.
From the top of my head I'm not aware of any blocking calls, maybe you could spin on xsk_tx_peek_desc.
For igc maybe it would be worth returning some status from igc_xdp_xmit_zc(). Like, imagine that you consumed all the budget but there are still descriptors in the XSK Tx ring. You'd like to signal to NAPI that there is still work to be done.
Quoted 17 lines
Quoted 5 lines
If yes, then it is likely because of the implementation of igc driver in mainline that is doing
igc_down(), a little bit too aggressive in reseting MAC completely.It would be good to fix igc too, like[1].
BUT afaik it will only make the window smaller when XSK is not ready for TX packets.Thanks for the link
--Jesper
+Vinicius
Quoted 67 lines · Magnus
Adding Ederson and Maciej.
Quoted 46 lines
-----Original Message-----
From: Jesper Dangaard Brouer <[email protected]>
Sent: Tuesday, December 14, 2021 11:32 AM
To: Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]>
Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>;
Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima
<[email protected]>
Subject: Re:AF_XDPnot transmitting frames immediatelyQuoted 30 lines · Magnus
Quoted 29 lines
-----Original Message----- From: Jesper Dangaard Brouer <[email protected]> Sent: Monday, December 13, 2021 10:04 PM To:
Karlsson, Magnus <[email protected]>; Björn Töpel <[email protected]> Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject:AF_XDPnot transmitting frames immediatelyHi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).My observations are that
AF_XDPdoesn't send the frames immediately.
And yes, I do callsendto()to trigger a TX kick. In zero-copy mode
this is particular bad. My program want to send 4 packets in a burst, but I'm observing 8 packets grouped together on the receiving
host.Is the a known property of
AF_XDP?Quoted 8 lines
Quoted 6 lines
Nope! It is supposed to be able to send one packet at a time, though I
have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in the core code.
There is even a test these days for just sending a single packet,Where is that test in the kernel tree?
In
tools/testing/selftests/bpf/xdpxceiver.c. It is theRUN_TO_COMPLETION_SINGLE_PKTtest. But the framework only operates on veth currently.Quoted 6 lines
Quoted 5 lines
since we have had issues with this in the past. That test does pass in
bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What driver are you using in zero-copy mode and what kernel version are you on?
Quoted 7 lines
Quoted 1 line
Driver: igc with Intel chip i225
Have never tried this one personally. Do not know if I have one in the lab but let me check.
Ederson, do you have any experience with this card and if so, have you seen something similar?
Not sure. I wonder how small is the interval Jesper is using. I imagine that if it's too small, the interrupt generated to trigger the tx could end up serving more than one packet.
Vinicius should have more prompt access to i225 - could you please help on this?
Quoted 48 lines
Quoted 20 lines
Kernel version: 5.15.0-net-next+ #618 SMP PREEMPT
- Devel branch at commit6d3b1b069946(v5.15-12802- g6d3b1b069946)Quoted 4 lines
Quoted 3 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()?
Should we add another flag than the currentMSG_DONTWAIT?Quoted 10 lines
In zero-copy mode with softirq driver processing (not busy poll), a
sendto will just trigger thexsk_wakeupndo that schedules napi unless
it is already executing. It is up to the driver to then get packets
from the Tx ring and put them on the HW and make sure they are sent.
Barring any HW quirks, sending one packets should be perfectly fine.Quoted 8 lines
I will investigate driver level issues.
I have other (100G) NICs in my testlab, but I'm using these 1G NICs because
they support hardware timestamping, which allows me to investigate these
timing issues.
I'll find a way to see of other drivers behave differently.Would be great if you could check if the problem also exists on e.g. ice.
Quoted 15 lines
Quoted 9 lines
Quoted 9 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via
cmdline:tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch: [1]
https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_exam
Quoted 2 lines
Quoted 1 line
ple/AF_XDP-interaction
Thanks for your feedback,
--Jesper
Quoted 40 lines · Ederson
+Vinicius
Quoted 37 lines · Magnus
Adding Ederson and Maciej.
Quoted 16 lines · Magnus
Quoted 15 lines
Quoted 15 lines
From: Jesper Dangaard Brouer
Hi Magnus and Bjørn,
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).My observations are that
AF_XDPdoesn't send the frames immediately. And yes, I do callsendto()to trigger a TX kick. In zero-copy mode this is particular bad. My program
want to send 4 packets in a burst, but I'm observing 8
packets grouped together on the receiving host.Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Is the a known property of
AF_XDP?Nope! It is supposed to be able to send one packet at a time, though I have several times seen bugs in the drivers where the batching behavior shines through like this, and once a bug in
the core code. There is even a test these days for just sending
a single packet,Where is that test in the kernel tree?
In
tools/testing/selftests/bpf/xdpxceiver.c. It is theRUN_TO_COMPLETION_SINGLE_PKTtest. But the framework only operates on veth currently.Quoted 6 lines
Quoted 4 lines
since we have had issues with this in the past. That test does pass in bpf-next, but it is only run with the veth driver that does not support zero-copy so could still be an issue. What
driver are you using in zero-copy mode and what kernel version
are you on?Driver: igc with Intel chip i225
Quoted 7 lines
Quoted 3 lines
Have never tried this one personally. Do not know if I have one in the lab but let me check.
Ederson, do you have any experience with this card and if so, have you seen something similar?
Not sure. I wonder how small is the interval Jesper is using. I imagine that if it's too small, the interrupt generated to trigger the tx could end up serving more than one packet.
The interval is currently 1 second (code here[0]), thus the TX interrupt should have plenty of time to trigger.
Quoted 2 lines
Vinicius should have more prompt access to i225 - could you please help on this?
My reproducer[1] need option --zero-copy to enable the error case, as it defaults to 'copy-mode'.
It is only in zero-copy mode for igc/i225 that I see the behavior of 8 packet bulking, when expecting/sending bulks of 4 packets ever second.
[1] https://github.com/xdp-project/bpf-example/tree/vestas03_AF_XDP_example/AF_XDP-interaction
--Jesper
Quoted 6 lines · Magnus
Quoted 6 lines
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).
[...]
Quoted 9 lines
Quoted 2 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.
This actually doesn't sound so good from my customers use-case PoV. That we only trigger a ndo_xsk_wakeup that schedules napi.
We want to trigger HW transmission immediately.
Can we achieve this via using busy-poll mode?
Quoted 6 lines
Quoted 6 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch: [1] https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_example/AF_XDP-interaction
Quoted 32 lines
-----Original Message-----
From: Jesper Dangaard Brouer <[email protected]>
Sent: Wednesday, December 15, 2021 11:18 AM
To: Karlsson, Magnus <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Björn Töpel <[email protected]>
Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject: Re:AF_XDPnot transmitting frames immediatelyQuoted 5 lines · Magnus
Quoted 5 lines
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).[...]
Quoted 9 lines
Quoted 3 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.
Quoted 5 lines
This actually doesn't sound so good from my customers use-case PoV. That we only trigger a
ndo_xsk_wakeupthat schedules napi.We want to trigger HW transmission immediately.
Can we achieve this via using busy-poll mode?
Yes, but not without napi. The napi context will in this case be executed in process context right away, unless it is already running somewhere else but that should not be the case. Will this be good enough?
Quoted 11 lines
Quoted 9 lines
Quoted 9 lines
Hint, I'm using tcpdump hardware timestamping on receiving hist via cmdline:
tcpdump -vv -s0 -ni eth1 -j
adapter_unsynced--time-stamp-precision=nano -w af_xdp_tx_cyclic.dump42Notice[1] on specific branch: [1]
https://github.com/xdp-project/bpf-examples/tree/vestas03_AF_XDP_exam
Quoted 1 line
Quoted 1 line
ple/AF_XDP-interaction
Quoted 25 lines · Magnus
Quoted 25 lines
From: Jesper Dangaard Brouer <[email protected]> On 14/12/2021
Quoted 6 lines · Magnus
Quoted 6 lines
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).[...]
Quoted 11 lines
Quoted 4 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.This actually doesn't sound so good from my customers use-case PoV. That we only trigger a
ndo_xsk_wakeupthat schedules napi.
Quoted 7 lines
Quoted 2 lines
We want to trigger HW transmission immediately. Can we achieve this via using busy-poll mode?
Yes, but not without napi. The napi context will in this case be executed in process context right away, unless it is already running somewhere else but that should not be the case. Will this be good enough?
"Time" will tell if it is good enough (pun intended). Meaning I will implement and measure it.
The busy-poll mode does sound like a way forward.
Looking at kernel code, I can see that drivers TX NAPI usually does DMA-TX completion *before* transmitting new frames. This usually makes sense, but for our use-case of hitting a narrow time-slot, I worry about the jitter this introduces. I would like to see a mode/flag that would allow transmitting new frames (and afterwards invoking/scheduling TX-completion, e.g. via raising the softirq/NAPI). Well this is future work, first I will measure current implementation.
--Jesper
Quoted 52 lines
-----Original Message-----
From: Jesper Dangaard Brouer <[email protected]>
Sent: Wednesday, December 15, 2021 6:11 PM
To: Karlsson, Magnus <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Björn Töpel <[email protected]>
Cc: Brouer, Jesper <[email protected]>; Xdp <xdp- [email protected]>; Ong, Boon Leong <[email protected]>; Joao Pedro Barros Silva <[email protected]>; Diogo Alexandre Da Silva Lima <[email protected]>
Subject: Re:AF_XDPnot transmitting frames immediatelyQuoted 24 lines · Magnus
Quoted 24 lines
From: Jesper Dangaard Brouer <[email protected]> On 14/12/2021
Quoted 6 lines · Magnus
Quoted 6 lines
I'm coding on an
AF_XDPprogram[1] that need to send (a bulk of packets) in a short time-window (related to Time-Triggered Ethernet).[...]
Quoted 10 lines
Quoted 3 lines
How can I get
AF_XDPto "flush" TX packets when callingsendto()? Should we add another flag than the currentMSG_DONTWAIT?In zero-copy mode with softirq driver processing (not busy poll), a sendto will just trigger the
xsk_wakeupndo that schedules napi unless it is already executing. It is up to the driver to then get packets from the Tx ring and put them on the HW and make sure they are sent. Barring any HW quirks, sending one packets should be perfectly fine.This actually doesn't sound so good from my customers use-case PoV. That we only trigger a
ndo_xsk_wakeupthat schedules napi.Quoted 7 lines
Quoted 2 lines
We want to trigger HW transmission immediately. Can we achieve this via using busy-poll mode?
Yes, but not without napi. The napi context will in this case be executed in process context right away, unless it is already running somewhere else but that should not be the case. Will this be good enough?
"Time" will tell if it is good enough (pun intended). Meaning I will implement and measure it.
The busy-poll mode does sound like a way forward.
Quoted 7 lines
Looking at kernel code, I can see that drivers TX NAPI usually does DMA-TX completion *before* transmitting new frames. This usually makes sense, but for our use-case of hitting a narrow time-slot, I worry about the jitter this introduces. I would like to see a mode/flag that would allow transmitting new frames (and afterwards invoking/scheduling TX-completion, e.g. via raising the softirq/NAPI).
Well this is future work, first I will measure current implementation.
Maciej has been experimenting with the ice driver to do sending first. Completions are only done lazily when needed to make sure that there are always a number of descriptors available for sending. This yields much better throughput and is the style that DPDK uses for its drivers. Hopefully, this will also improve latency, though we have not measured that. Could be adopted for the igc driver too if that is the case.
Quoted 1 line
--Jesper
Quoted 12 lines · Magnus
Quoted 11 lines
"Time" will tell if it is good enough (pun intended). Meaning I will implement and measure it.
The busy-poll mode does sound like a way forward.Looking at kernel code, I can see that drivers TX NAPI usually does DMA-TX completion *before* transmitting new frames. This usually makes sense, but for our use-case of hitting a narrow time-slot, I worry about the jitter this introduces. I would like to see a mode/flag that would allow transmitting new frames (and afterwards invoking/scheduling TX-completion, e.g. via raising the softirq/NAPI).
Well this is future work, first I will measure current implementation.
Quoted 7 lines
Maciej has been experimenting with the ice driver to do sending first. Completions are only done lazily when needed to make sure that there are always a number of descriptors available for sending. This yields much better throughput and is the style that DPDK uses for its drivers. Hopefully, this will also improve latency, though we have not measured that. Could be adopted for the igc driver too if that is the case.
I think this came up before, there was a concern that some applications may forgo retransmiting data until they see a completions (like skb_still_in_host_queue()). Make sure you call out that it's a change in behavior in the commit message and/or docs.