igc: Add Tx hardware timestamp request for AF_XDP zero-copy packet
Subsystems (4)
PATCH v4 1/1 igc: Add Tx hardware timestamp request for AF_XDP zero-copy packet
This patch adds support to per-packet Tx hardware timestamp request to AF_XDP zero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability via igc_ioctl() with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.
Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and *xsk_tx_buffer pointers are used to indicate whether the timestamping register is already occupied.
Furthermore, a boolean variable named xsk_pending_ts is used to hold the transmit completion until the tx hardware timestamp is ready. This is because, for i225/i226, the timestamp notification event comes some time after the transmit completion event. The driver will retrigger hardware irq to clean the packet after retrieve the tx hardware timestamp.
Besides, xsk_meta is added into struct igc_tx_timestamp_request as a hook to the metadata location of the transmit packet. When the Tx timestamp interrupt is fired, the interrupt handler will copy the value of Tx hwts into metadata location via xsk_tx_metadata_complete().
This patch is tested with tools/testing/selftests/bpf/xdp_hw_metadata on Intel ADL-S platform. Below are the test steps and results.
Test Step 1: Run xdp_hw_metadata app
./xdp_hw_metadata <iface> > /dev/shm/result.log
Test Step 2: Enable Tx hardware timestamp
hwstamp_ctl -i <iface> -t 1 -r 1
Test Step 3: Run ptp4l and phc2sys for time synchronization
Test Step 4: Generate UDP packets with 1ms interval for 10s
trafgen --dev <iface> '{eth(da=<addr>), udp(dp=9091)}' -t 1ms -n 10000
Test Step 5: Rerun Step 1-3 with 10s iperf3 as background traffic
Test Step 6: Rerun Step 1-4 with 10s iperf3 as background traffic
Based on iperf3 results below, the impact of holding tx completion to throughput is not observable.
Result of last UDP packet (no. 10000) in Step 4:
poll: 1 (0) skip=99 fail=0 redir=10000xsk_ring_cons__peek: 10x5640a37972d0: rx_desc[9999]->addr=f2110 addr=f2110 comp_addr=f2110 EoP
rx_hash: 0x2049BE1D with RSS type:0x1 HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to User RX-time sec:0.0000 (14.990 usec) XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User RX-time sec:0.0000 (4.271 usec) No rx_vlan_tci or rx_vlan_proto, err=-95 0x5640a37972d0: ping-pong with csum=ab19 (want 315b) csum_start=34 csum_offset=6 0x5640a37972d0: complete tx idx=9999 addr=f010 HW TX-complete-time: 1679819246793036971 (sec:1679819246.7930) delta to User TX-complete-time sec:0.0001 (77.656 usec) XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User TX-complete-time sec:0.0001 (132.640 usec) HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to HW TX-complete-time sec:0.0001 (65.703 usec)
0x5640a37972d0: complete rx idx=10127 addr=f2110
Result of iperf3 without tx hwts request in step 5:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.05 sec 2.74 GBytes 2.34 Gbits/sec receiver
Result of iperf3 running parallel with trafgen command in step 6:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.04 sec 2.74 GBytes 2.34 Gbits/sec receiver
---
V1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
V2: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
V3: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
changelog:
V1 -> V2
- In struct igc_tx_timestamp_request, keep a pointer to igc_tx_buffer, instead of pointing xsk_pending_ts (Vinicius).
- In struct igc_tx_timestamp_request, introduce buffer_type to indicate whether skb or igc_tx_buffer pointer should be use (Vinicius).
- In struct igc_metadata_request, remove igc_adapter pointer (Vinicius).
- When request tx hwts, copy the value of cmd_type, instead of using pointer (Vinicius).
- For boolean variable, use true and false, instead of 1 and 0 (Vinicius).
- In igc_xsk_request_timestamp(), make an early return if none of the 4 ts registers is available (Vinicius).
- Create helper functions to clear tx buffer and skb for tstamp (John).
- Perform throughput test with mix traffic (Vinicius & John). V2 -> V3
- Improve tstamp reg searching loop for better readability (John).
- In igc_ptp_free_tx_buffer(), add comment to inform user that tstamp->xsk_tx_buffer and tstamp->skb are in union (John).
V3 -> V4
- Add protection with xp_tx_metadata_enabled (Kurt & Maciej).
---
--- drivers/net/ethernet/intel/igc/igc.h | 71 ++++++++------ drivers/net/ethernet/intel/igc/igc_main.c | 113 ++++++++++++++++++++-- drivers/net/ethernet/intel/igc/igc_ptp.c | 51 ++++++++-- 3 files changed, 195 insertions(+), 40 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +44 -27
@@ -72,13 +72,46 @@ struct igc_rx_packet_stats {u64 other_packets; }; +enum igc_tx_buffer_type { +IGC_TX_BUFFER_TYPE_SKB , +IGC_TX_BUFFER_TYPE_XDP , +IGC_TX_BUFFER_TYPE_XSK , +}; + +/* wrapper around a pointer to a socket buffer, +* so a DMA handle can be stored along with the buffer +*/ +struct igc_tx_buffer { +union igc_adv_tx_desc *next_to_watch; +unsigned long time_stamp; +enum igc_tx_buffer_type type; +union { +struct sk_buff *skb; +struct xdp_frame *xdpf; + }; +unsigned int bytecount; +u16 gso_segs; +__be16 protocol; + +DEFINE_DMA_UNMAP_ADDR (dma); +DEFINE_DMA_UNMAP_LEN (len); +u32 tx_flags; +bool xsk_pending_ts; +}; +struct igc_tx_timestamp_request { -struct sk_buff *skb;/* reference to the packet being timestamped */ +union {/* reference to the packet being timestamped */ +struct sk_buff *skb; +struct igc_tx_buffer *xsk_tx_buffer; + }; +enum igc_tx_buffer_type buffer_type;unsigned long start;/* when the tstamp request started (jiffies) */ u32 mask;/* _TSYNCTXCTL_TXTT_{X} bit for this request */ u32 regl;/* which TXSTMPL_{X} register should be used */ u32 regh;/* which TXSTMPH_{X} register should be used */ u32 flags;/* flags that should be added to the tx_buffer */ +u8 xsk_queue_index;/* Tx queue which requesting timestamp */ +struct xsk_tx_metadata_compl xsk_meta;/* ref to xsk Tx metadata */ };struct igc_inline_rx_tstamps {
@@ -322,6 +355,9 @@ void igc_disable_tx_ring(struct igc_ring *ring);void igc_enable_tx_ring (struct igc_ring *ring);int igc_xsk_wakeup (struct net_device *dev,u32 queue_id,u32 flags); +/* AF_XDP TX metadata operations */ +extern const struct xsk_tx_metadata_ops igc_xsk_tx_metadata_ops; +/* igc_dump declarations */ void igc_rings_dump (struct igc_adapter *adapter);void igc_regs_dump (struct igc_adapter *adapter);
@@ -507,32 +543,6 @@ enum igc_boards {#define TXD_USE_COUNT (S ) DIV_ROUND_UP((S), IGC_MAX_DATA_PER_TXD)#define DESC_NEEDED (MAX_SKB_FRAGS + 4) -enum igc_tx_buffer_type { -IGC_TX_BUFFER_TYPE_SKB , -IGC_TX_BUFFER_TYPE_XDP , -IGC_TX_BUFFER_TYPE_XSK , -}; - -/* wrapper around a pointer to a socket buffer, -* so a DMA handle can be stored along with the buffer -*/ -struct igc_tx_buffer { -union igc_adv_tx_desc *next_to_watch; -unsigned long time_stamp; -enum igc_tx_buffer_type type; -union { -struct sk_buff *skb; -struct xdp_frame *xdpf; - }; -unsigned int bytecount; -u16 gso_segs; -__be16 protocol; - -DEFINE_DMA_UNMAP_ADDR (dma); -DEFINE_DMA_UNMAP_LEN (len); -u32 tx_flags; -}; - struct igc_rx_buffer { union { struct {
@@ -556,6 +566,13 @@ struct igc_xdp_buff {struct igc_inline_rx_tstamps *rx_ts;/* data indication bit IGC_RXDADV_STAT_TSIP */ }; +struct igc_metadata_request { +struct igc_tx_buffer *tx_buffer; +struct xsk_tx_metadata *meta; +struct igc_ring *tx_ring; +u32 cmd_type; +}; +struct igc_q_vector {struct igc_adapter *adapter;/* backlink */ void __iomem *itr_register;
drivers/net/ethernet/intel/igc/igc_main.c +107 -6
149 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_ptp.c +44 -7
82 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 103 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.Furthermore, a boolean variable named
xsk_pending_tsis used to hold the transmit completion until the tx hardware timestamp is ready. This is because, for i225/i226, the timestamp notification event comes some time after the transmit completion event. The driver will retrigger hardware irq to clean the packet after retrieve the tx hardware timestamp.Besides,
xsk_metais added into structigc_tx_timestamp_requestas a hook to the metadata location of the transmit packet. When the Tx timestamp interrupt is fired, the interrupt handler will copy the value of Tx hwts into metadata location viaxsk_tx_metadata_complete().This patch is tested with
tools/testing/selftests/bpf/xdp_hw_metadataon Intel ADL-S platform. Below are the test steps and results.Test Step 1: Run
xdp_hw_metadataapp
./xdp_hw_metadata <iface> >/dev/shm/result.logTest Step 2: Enable Tx hardware timestamp
hwstamp_ctl-i <iface> -t 1 -r 1Test Step 3: Run ptp4l and phc2sys for time synchronization
Test Step 4: Generate UDP packets with 1ms interval for 10s
trafgen --dev <iface> '{eth(da=<addr>), udp(dp=9091)}' -t 1ms -n 10000Test Step 5: Rerun Step 1-3 with 10s iperf3 as background traffic
Test Step 6: Rerun Step 1-4 with 10s iperf3 as background traffic
Based on iperf3 results below, the impact of holding tx completion to throughput is not observable.
Result of last UDP packet (no. 10000) in Step 4:
poll: 1 (0) skip=99 fail=0 redir=10000xsk_ring_cons__peek: 10x5640a37972d0: rx_desc[9999]->addr=f2110 addr=f2110 comp_addr=f2110 EoPrx_hash: 0x2049BE1D with RSS type:0x1 HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to User RX-time sec:0.0000 (14.990 usec) XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User RX-time sec:0.0000 (4.271 usec) No rx_vlan_tci or rx_vlan_proto, err=-95 0x5640a37972d0: ping-pong with csum=ab19 (want 315b) csum_start=34 csum_offset=6 0x5640a37972d0: complete tx idx=9999 addr=f010 HW TX-complete-time: 1679819246793036971 (sec:1679819246.7930) delta to User TX-complete-time sec:0.0001 (77.656 usec) XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User TX-complete-time sec:0.0001 (132.640 usec) HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to HW TX-complete-time sec:0.0001 (65.703 usec)
0x5640a37972d0: complete rx idx=10127 addr=f2110Result of iperf3 without tx hwts request in step 5:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.05 sec 2.74 GBytes 2.34 Gbits/sec receiverResult of iperf3 running parallel with trafgen command in step 6:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.04 sec 2.74 GBytes 2.34 Gbits/sec receiverCo-developed-by Lai Peter Jun Ann <[email protected]>Signed-off-by Lai Peter Jun Ann <[email protected]>Signed-off-by Song Yoong Siang <[email protected]>Acked-by John Fastabend <[email protected]>---
V1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
V2: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
V3: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/changelog:
V1 -> V2
- In structigc_tx_timestamp_request, keep a pointer toigc_tx_buffer, instead of pointingxsk_pending_ts(Vinicius).
- In structigc_tx_timestamp_request, introducebuffer_typeto indicate whether skb origc_tx_bufferpointer should be use (Vinicius).
- In structigc_metadata_request, removeigc_adapterpointer (Vinicius).
- When request tx hwts, copy the value ofcmd_type, instead of using pointer (Vinicius).
- For boolean variable, use true and false, instead of 1 and 0 (Vinicius).
- Inigc_xsk_request_timestamp(), make an early return if none of the 4 ts registers is available (Vinicius).
- Create helper functions to clear tx buffer and skb for tstamp (John).
- Perform throughput test with mix traffic (Vinicius & John). V2 -> V3
- Improve tstamp reg searching loop for better readability (John).
- Inigc_ptp_free_tx_buffer(), add comment to inform user thattstamp->xsk_tx_bufferandtstamp->skbare in union (John).
V3 -> V4
- Add protection withxp_tx_metadata_enabled(Kurt & Maciej).
------ drivers/net/ethernet/intel/igc/igc.h | 71 ++++++++------ drivers/net/ethernet/intel/igc/igc_main.c | 113 ++++++++++++++++++++-- drivers/net/ethernet/intel/igc/igc_ptp.c | 51 ++++++++-- 3 files changed, 195 insertions(+), 40 deletions(-)
[...]
Quoted 44 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +25
-0@@ -11,6 +11,7 @@#include <linux/ktime.h> #include <linux/delay.h> #include <linux/iopoll.h> +#include <net/xdp_sock_drv.h> #define INCVALUE_MASK 0x7fffffff#define ISGN 0x80000000@@ -545,6 +546,30 @@ static void igc_ptp_enable_rx_timestamp(struct igc_adapter *adapter)wr32 (IGC_TSYNCRXCTL , val); } +static void igc_ptp_free_tx_buffer (struct igc_adapter *adapter, +struct igc_tx_timestamp_request *tstamp) +{ +if (tstamp->buffer_type ==IGC_TX_BUFFER_TYPE_XSK ) { +/* Release the transmit completion */ + tstamp->xsk_tx_buffer->xsk_pending_ts = false; + +/* Note: tstamp->skb and tstamp->xsk_tx_buffer are in union. +* By setting tstamp->xsk_tx_buffer to NULL, tstamp->skb will +* become NULL as well. +*/ + tstamp->xsk_tx_buffer =NULL ; + tstamp->buffer_type =0 ; + +/* Trigger txrx interrupt for transmit completion */ +igc_xsk_wakeup (adapter->netdev, tstamp->xsk_queue_index,0 ); + +return ; + } + +dev_kfree_skb_any (tstamp->skb); + tstamp->skb =NULL ; +} +static void igc_ptp_clear_tx_tstamp (struct igc_adapter *adapter) {unsigned long flags;
drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_clear_tx_tstamp(struct igc_adapter *adapter) · line 586
Quoted 9 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +2
-2@@ -555,8 +580,8 @@ static void igc_ptp_clear_tx_tstamp(struct igc_adapter *adapter)for (i =0 ; i <IGC_MAX_TX_TSTAMP_REGS ; i++) {struct igc_tx_timestamp_request *tstamp = &adapter->tx_tstamp[i]; -dev_kfree_skb_any (tstamp->skb); - tstamp->skb =NULL ; +if (tstamp->skb) +igc_ptp_free_tx_buffer (adapter, tstamp); }
More a question: you are potentially triggering an interrupt from igc_ptp_clear_tx_tstamp() (igc_xsk_wakeup()) which can be called from igc_down(). So, how does it work when there's a pending timestamp and you remove the igc module? (example of a situation that it might be problematic).
Cheers,
Signature · 1 line
Vinicius
Quoted 170 lines · Vinicius
Quoted 42 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.Furthermore, a boolean variable named
xsk_pending_tsis used to hold the transmit completion until the tx hardware timestamp is ready. This is because, for i225/i226, the timestamp notification event comes some time after the transmit completion event. The driver will retrigger hardware irq to clean the packet after retrieve the tx hardware timestamp.Besides,
xsk_metais added into structigc_tx_timestamp_requestas a hook to the metadata location of the transmit packet. When the Tx timestamp interrupt is fired, the interrupt handler will copy the value of Tx hwts into metadata location viaxsk_tx_metadata_complete().This patch is tested with
tools/testing/selftests/bpf/xdp_hw_metadataon Intel ADL-S platform. Below are the test steps and results.Test Step 1: Run
xdp_hw_metadataapp
./xdp_hw_metadata <iface> >/dev/shm/result.logTest Step 2: Enable Tx hardware timestamp
hwstamp_ctl-i <iface> -t 1 -r 1Test Step 3: Run ptp4l and phc2sys for time synchronization
Test Step 4: Generate UDP packets with 1ms interval for 10s
trafgen --dev <iface> '{eth(da=<addr>), udp(dp=9091)}' -t 1ms -n 10000Test Step 5: Rerun Step 1-3 with 10s iperf3 as background traffic
Test Step 6: Rerun Step 1-4 with 10s iperf3 as background traffic
Based on iperf3 results below, the impact of holding tx completion to throughput is not observable.
Quoted 6 lines
Result of last UDP packet (no. 10000) in Step 4:
poll: 1 (0) skip=99 fail=0 redir=10000xsk_ring_cons__peek: 10x5640a37972d0: rx_desc[9999]->addr=f2110 addr=f2110 comp_addr=f2110 EoPrx_hash:0x2049BE1Dwith RSS type:0x1
HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to User RX-timesec:0.0000 (14.990 usec)
Quoted 1 line
XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User RX-time
sec:0.0000 (4.271 usec)
Quoted 2 lines
No
rx_vlan_tciorrx_vlan_proto, err=-950x5640a37972d0: ping-pong with csum=ab19 (want 315b) csum_start=34csum_offset=6
Quoted 2 lines
0x5640a37972d0: complete tx idx=9999 addr=f010
HW TX-complete-time: 1679819246793036971 (sec:1679819246.7930) delta toUser TX-complete-time sec:0.0001 (77.656 usec)
Quoted 1 line
XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User TX-
complete-time sec:0.0001 (132.640 usec)
Quoted 1 line
HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to HW TX-
complete-time sec:0.0001 (65.703 usec)
Quoted 12 lines
0x5640a37972d0: complete rx idx=10127 addr=f2110Result of iperf3 without tx hwts request in step 5:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.05 sec 2.74 GBytes 2.34 Gbits/sec receiverResult of iperf3 running parallel with trafgen command in step 6:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.04 sec 2.74 GBytes 2.34 Gbits/sec receiverQuoted 6 lines
Co-developed-by Lai Peter Jun Ann <[email protected]>Signed-off-by Lai Peter Jun Ann <[email protected]>Signed-off-by Song Yoong Siang <[email protected]>Acked-by John Fastabend <[email protected]>---
V1:https://patchwork.kernel.org/project/netdevbpf/patch/20231215162158.951925-1-
[email protected]/Quoted 1 line
V2:
https://patchwork.kernel.org/project/netdevbpf/cover/20240301162348.898619-1-
[email protected]/Quoted 1 line
V3:
https://patchwork.kernel.org/project/netdevbpf/cover/20240303083225.1184165-1-
[email protected]/Quoted 28 lines
changelog:
V1 -> V2
- In structigc_tx_timestamp_request, keep a pointer toigc_tx_buffer, instead of pointingxsk_pending_ts(Vinicius).
- In structigc_tx_timestamp_request, introducebuffer_typeto indicate whether skb origc_tx_bufferpointer should be use (Vinicius).
- In structigc_metadata_request, removeigc_adapterpointer (Vinicius).
- When request tx hwts, copy the value ofcmd_type, instead of using pointer (Vinicius).
- For boolean variable, use true and false, instead of 1 and 0 (Vinicius).
- Inigc_xsk_request_timestamp(), make an early return if none of the 4 ts registers is available (Vinicius).
- Create helper functions to clear tx buffer and skb for tstamp (John).
- Perform throughput test with mix traffic (Vinicius & John). V2 -> V3
- Improve tstamp reg searching loop for better readability (John).
- Inigc_ptp_free_tx_buffer(), add comment to inform user thattstamp->xsk_tx_bufferandtstamp->skbare in union (John).
V3 -> V4
- Add protection withxp_tx_metadata_enabled(Kurt & Maciej).
------ drivers/net/ethernet/intel/igc/igc.h | 71 ++++++++------ drivers/net/ethernet/intel/igc/igc_main.c | 113 ++++++++++++++++++++-- drivers/net/ethernet/intel/igc/igc_ptp.c | 51 ++++++++-- 3 files changed, 195 insertions(+), 40 deletions(-)[...]
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/net/ethernet/intel/igc/igc_ptp.cdrivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_enable_rx_timestamp(struct
Quoted 12 lines
index
885faaa7b9de..1bb026232efc100644drivers/net/ethernet/intel/igc/igc_ptp.c +1
-0@@ -11,6 +11,7 @@#include <linux/ktime.h> #include <linux/delay.h> #include <linux/iopoll.h> +#include <net/xdp_sock_drv.h> #define INCVALUE_MASK 0x7fffffff#define ISGN 0x80000000@@ -545,6 +546,30 @@ static void igc_ptp_enable_rx_timestamp(struct
igc_adapter*adapter)drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_clear_tx_tstamp(struct igc_adapter
Quoted 31 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +24
-0wr32 (IGC_TSYNCRXCTL , val); } +static void igc_ptp_free_tx_buffer (struct igc_adapter *adapter, +struct igc_tx_timestamp_request *tstamp) +{ +if (tstamp->buffer_type ==IGC_TX_BUFFER_TYPE_XSK ) { +/* Release the transmit completion */ + tstamp->xsk_tx_buffer->xsk_pending_ts = false; + +/* Note: tstamp->skb and tstamp->xsk_tx_buffer are in union. +* By setting tstamp->xsk_tx_buffer to NULL, tstamp->skb will +* become NULL as well. +*/ + tstamp->xsk_tx_buffer =NULL ; + tstamp->buffer_type =0 ; + +/* Trigger txrx interrupt for transmit completion */ +igc_xsk_wakeup (adapter->netdev, tstamp->xsk_queue_index,0 ); + +return ; + } + +dev_kfree_skb_any (tstamp->skb); + tstamp->skb =NULL ; +} +static void igc_ptp_clear_tx_tstamp (struct igc_adapter *adapter) {unsigned long flags;@@ -555,8 +580,8 @@ static void igc_ptp_clear_tx_tstamp(struct igc_adapter*adapter)
Quoted 3 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +0
-0for (i =0 ; i <IGC_MAX_TX_TSTAMP_REGS ; i++) {struct igc_tx_timestamp_request *tstamp = &adapter->tx_tstamp[i];
Quoted 12 lines
drivers/net/ethernet/intel/igc/igc_ptp.c static void igc_ptp_clear_tx_tstamp(struct igc_adapter *adapter) · line 586
Quoted 6 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +2
-2-dev_kfree_skb_any (tstamp->skb); - tstamp->skb =NULL ; +if (tstamp->skb) +igc_ptp_free_tx_buffer (adapter, tstamp); }More a question: you are potentially triggering an interrupt from
igc_ptp_clear_tx_tstamp()(igc_xsk_wakeup()) which can be called fromigc_down(). So, how does it work when there's a pending timestamp and you remove the igc module? (example of a situation that it might be problematic).
Hi Vinicius,
Thanks for reviewing the patch.
There is test_bit(__IGC_DOWN, &adapter->state) checking in igc_sxk_wakeup(). Since igc_down() will set __IGC_DOWN before call into igc_ptp_suspend(), so I believe the checking in igc_sxk_wakeup() should be enough to prevent the situation that you mentioned.
Quoted 5 lines
Cheers,
--
Vinicius
Thanks & Regards
Siang
Vinicius Costa Gomes
Acked-byQuoted 7 lines · Yoong Siang
Quoted 6 lines
More a question: you are potentially triggering an interrupt from
igc_ptp_clear_tx_tstamp()(igc_xsk_wakeup()) which can be called fromigc_down(). So, how does it work when there's a pending timestamp and you remove the igc module? (example of a situation that it might be problematic).
Quoted 9 lines
Hi Vinicius,
Thanks for reviewing the patch.
There is
test_bit(__IGC_DOWN, &adapter->state)checking inigc_sxk_wakeup(). Sinceigc_down()will set__IGC_DOWNbefore call intoigc_ptp_suspend(), so I believe the checking inigc_sxk_wakeup()should be enough to prevent the situation that you mentioned.
Oh, I missed that one, sorry. Then:
Cheers,
Signature · 1 line
Vinicius
Quoted 9 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.
Let me make sure that I fully understand that: In my own words:
With that applied I'm able to get the point in time from the device when a specific frame made it to the wire. I have to enable that functionality using the mentioned ioctl() call first, and then check the meta area (located in the umem right before the frame payload) while consuming the completion queue/ring. Correct?
If so, we now have a feedback channel for meta information for/from TX. Are there any plans - or would it be possible - to support Earliest TxTime First (NET_SCHED_ETF) QDisc based on that channel? In the past we had the problem that we we're missing a feedback channel to communicate back invalid lunch times.
Quoted 14 lines
Furthermore, a boolean variable named
xsk_pending_tsis used to hold the transmit completion until the tx hardware timestamp is ready. This is because, for i225/i226, the timestamp notification event comes some time after the transmit completion event. The driver will retrigger hardware irq to clean the packet after retrieve the tx hardware timestamp.Besides,
xsk_metais added into structigc_tx_timestamp_requestas a hook to the metadata location of the transmit packet. When the Tx timestamp interrupt is fired, the interrupt handler will copy the value of Tx hwts into metadata location viaxsk_tx_metadata_complete().This patch is tested with
tools/testing/selftests/bpf/xdp_hw_metadataon Intel ADL-S platform. Below are the test steps and results.
Hi Florian,
Quoted 19 lines · Florian Bezdeka
Quoted 9 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.Let me make sure that I fully understand that: In my own words:
With that applied I'm able to get the point in time from the device when a specific frame made it to the wire. I have to enable that functionality using the mentioned
ioctl()call first, and then check the meta area (located in the umem right before the frame payload) while consuming the completion queue/ring. Correct?
Quoted 5 lines
If so, we now have a feedback channel for meta information for/from TX. Are there any plans - or would it be possible - to support Earliest TxTime First (
NET_SCHED_ETF) QDisc based on that channel? In the past we had the problem that we we're missing a feedback channel to communicate back invalid lunch times.
Just asking: How would that work? AFAIK XDP bypasses the Qdisc layer. Currently invalid Launch Times are accounted in the ETF Qdisc itself. Does that mean every driver has to take care of it?
Thanks,
Kurt
Quoted 21 lines · Kurt Kanzenbach
Hi Florian,
Quoted 18 lines · Florian Bezdeka
Quoted 9 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.Let me make sure that I fully understand that: In my own words:
With that applied I'm able to get the point in time from the device when a specific frame made it to the wire. I have to enable that functionality using the mentioned
ioctl()call first, and then check the meta area (located in the umem right before the frame payload) while consuming the completion queue/ring. Correct?
Hi Florian,
Yes, you are right. But before you pass the frame to driver, make sure you request Tx metadata hardware timestamp feature by setting XDP_TXMD_FLAGS_TIMESTAMP flag.
You can refer to tools/testing/selftests/bpf/xdp_hw_metadata.c on how to do it.
Quoted 7 lines
Quoted 6 lines
If so, we now have a feedback channel for meta information for/from TX. Are there any plans - or would it be possible - to support Earliest TxTime First (
NET_SCHED_ETF) QDisc based on that channel? In the past we had the problem that we we're missing a feedback channel to communicate back invalid lunch times.
Quoted 6 lines
Just asking: How would that work? AFAIK XDP bypasses the Qdisc layer. Currently invalid Launch Times are accounted in the ETF Qdisc itself. Does that mean every driver has to take care of it?
Thanks,
Kurt
Florian & Kurt,
Yes, me and Stanislav are trying to add Earliest TxTime First / Launch Time to the framework. Please refer to [1] for the patchset. The metadata framework will just pass the Launch time value to driver, and driver need to handle the rest.
In the patchset, I am enabling it on stmmac driver only, but we need more drivers to check whether the design is feasible for different drivers, cause each driver is having their own limitation on launch time. Therefore, after this tx hwts patch accepted, I will try to enable launch time on igc driver, and submit new version.
Kurt is right that current metadata framework is lacking a way to feedback whether the launch time is invalid or not. Maybe we can try to enable launch time without feedback, then discuss about the status report design.
[1] https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
Thanks & Regards
Siang
Quoted 23 lines · Yoong Siang
Quoted 21 lines · Kurt Kanzenbach
Hi Florian,
Quoted 18 lines · Florian Bezdeka
Quoted 9 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.Let me make sure that I fully understand that: In my own words:
With that applied I'm able to get the point in time from the device when a specific frame made it to the wire. I have to enable that functionality using the mentioned
ioctl()call first, and then check the meta area (located in the umem right before the frame payload) while consuming the completion queue/ring. Correct?
Quoted 7 lines
Hi Florian,
Yes, you are right. But before you pass the frame to driver, make sure you request Tx metadata hardware timestamp feature by setting
XDP_TXMD_FLAGS_TIMESTAMPflag.
You can refer totools/testing/selftests/bpf/xdp_hw_metadata.con how to do it.
Got it. Thanks!
Quoted 17 lines
Quoted 8 lines
Quoted 7 lines
If so, we now have a feedback channel for meta information for/from TX. Are there any plans - or would it be possible - to support Earliest TxTime First (
NET_SCHED_ETF) QDisc based on that channel? In the past we had the problem that we we're missing a feedback channel to communicate back invalid lunch times.Quoted 6 lines
Just asking: How would that work? AFAIK XDP bypasses the Qdisc layer. Currently invalid Launch Times are accounted in the ETF Qdisc itself. Does that mean every driver has to take care of it?
Thanks,
KurtFlorian & Kurt,
Quoted 7 lines
Yes, me and Stanislav are trying to add Earliest TxTime First / Launch Time to the framework. Please refer to [1] for the patchset. The metadata framework will just pass the Launch time value to driver, and driver need to handle the rest.
In the patchset, I am enabling it on stmmac driver only, but we need more drivers to check whether the design is feasible for different drivers, cause each driver is having their own limitation on launch time. Therefore, after this tx hwts patch accepted, I will try to enable launch time on igc driver, and submit new version.
Nice to hear! Keep me in the loop and let me know if I could support somehow.
Quoted 4 lines
Kurt is right that current metadata framework is lacking a way to feedback whether the launch time is invalid or not. Maybe we can try to enable launch time without feedback, then discuss about the status report design.
In case the launch time is invalid - couldn't we simply skip the frame and "forward" it back to the application (completion queue/ring) after adjusting some meta-information (like the TX timestamps in this patch) telling the application what happened?
Thanks a lot!
Florian
Quoted 5 lines
[1] https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
Thanks & Regards
Siang
Quoted 58 lines · Florian Bezdeka
Quoted 23 lines · Yoong Siang
Quoted 21 lines · Kurt Kanzenbach
Hi Florian,
Quoted 18 lines · Florian Bezdeka
Quoted 9 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.Let me make sure that I fully understand that: In my own words:
With that applied I'm able to get the point in time from the device when a specific frame made it to the wire. I have to enable that functionality using the mentioned
ioctl()call first, and then check the meta area (located in the umem right before the frame payload) while consuming the completion queue/ring. Correct?Quoted 7 lines
Hi Florian,
Yes, you are right. But before you pass the frame to driver, make sure you request Tx metadata hardware timestamp feature by setting
XDP_TXMD_FLAGS_TIMESTAMPflag.
You can refer totools/testing/selftests/bpf/xdp_hw_metadata.con how to do it.Got it. Thanks!
Quoted 12 lines
Quoted 12 lines
Quoted 7 lines
If so, we now have a feedback channel for meta information for/from TX. Are there any plans - or would it be possible - to support Earliest TxTime First (
NET_SCHED_ETF) QDisc based on that channel? In the past we had the problem that we we're missing a feedback channel to communicate back invalid lunch times.Just asking: How would that work? AFAIK XDP bypasses the Qdisc layer. Currently invalid Launch Times are accounted in the ETF Qdisc itself. Does that mean every driver has to take care of it?
Quoted 6 lines
Quoted 2 lines
Thanks,
KurtFlorian & Kurt,
Yes, me and Stanislav are trying to add Earliest TxTime First / Launch Time to the
framework.
Quoted 5 lines
Please refer to [1] for the patchset. The metadata framework will just pass the Launch time value to driver, and driver need to handle the rest.
In the patchset, I am enabling it on stmmac driver only, but we need more drivers to check whether the design is feasible for different drivers, cause each driver is having their own limitation on launch time. Therefore, after this tx hwts patch
Quoted 5 lines
accepted,
Quoted 1 line
I will try to enable launch time on igc driver, and submit new version.
Nice to hear! Keep me in the loop and let me know if I could support somehow.
Sure, will keep you in loop.
Do you mind to share, which Ethernet driver you are working on?
Quoted 11 lines
Quoted 4 lines
Kurt is right that current metadata framework is lacking a way to feedback whether the launch time is invalid or not. Maybe we can try to enable launch time without
feedback,
Quoted 1 line
then discuss about the status report design.
In case the launch time is invalid - couldn't we simply skip the frame and "forward" it back to the application (completion queue/ring) after adjusting some meta-information (like the TX timestamps in this patch) telling the application what happened?
I not sure whether driver level need to do the validation job for launch time,
Or we can just let the NIC behave according to its own design,
whether it want to drop the packet, or transmit the packet immediately, or transmit the packet at maximum supported launch time. We can discuss further when I submit new version of [1].
Quoted 11 lines
Thanks a lot!
FlorianQuoted 2 lines
[1]
https://patchwork.kernel.org/project/netdevbpf/cover/20231203165129.1740512-1-
[email protected]/Quoted 3 lines
Thanks & Regards
Siang
Quoted 5 lines · Yoong Siang
Quoted 2 lines
Nice to hear! Keep me in the loop and let me know if I could support somehow.
Sure, will keep you in loop.
Do you mind to share, which Ethernet driver you are working on?
I'm not really working "on" a driver (right now), but "with" a couple of them. Most XDP investigations on our side are currently running on i225/i226 cards. Other well known candidates are x550 cards as well as some Mellanox cards.
Quoted 97 lines · Song Yoong Siang
This patch adds support to per-packet Tx hardware timestamp request to
AF_XDPzero-copy packet via XDP Tx metadata framework. Please note that user needs to enable Tx HW timestamp capability viaigc_ioctl()with SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0 (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have four sets of timestamping registers. *skb and
*xsk_tx_bufferpointers are used to indicate whether the timestamping register is already occupied.Furthermore, a boolean variable named
xsk_pending_tsis used to hold the transmit completion until the tx hardware timestamp is ready. This is because, for i225/i226, the timestamp notification event comes some time after the transmit completion event. The driver will retrigger hardware irq to clean the packet after retrieve the tx hardware timestamp.Besides,
xsk_metais added into structigc_tx_timestamp_requestas a hook to the metadata location of the transmit packet. When the Tx timestamp interrupt is fired, the interrupt handler will copy the value of Tx hwts into metadata location viaxsk_tx_metadata_complete().This patch is tested with
tools/testing/selftests/bpf/xdp_hw_metadataon Intel ADL-S platform. Below are the test steps and results.Test Step 1: Run
xdp_hw_metadataapp
./xdp_hw_metadata <iface> >/dev/shm/result.logTest Step 2: Enable Tx hardware timestamp
hwstamp_ctl-i <iface> -t 1 -r 1Test Step 3: Run ptp4l and phc2sys for time synchronization
Test Step 4: Generate UDP packets with 1ms interval for 10s
trafgen --dev <iface> '{eth(da=<addr>), udp(dp=9091)}' -t 1ms -n 10000Test Step 5: Rerun Step 1-3 with 10s iperf3 as background traffic
Test Step 6: Rerun Step 1-4 with 10s iperf3 as background traffic
Based on iperf3 results below, the impact of holding tx completion to throughput is not observable.
Result of last UDP packet (no. 10000) in Step 4:
poll: 1 (0) skip=99 fail=0 redir=10000xsk_ring_cons__peek: 10x5640a37972d0: rx_desc[9999]->addr=f2110 addr=f2110 comp_addr=f2110 EoPrx_hash: 0x2049BE1D with RSS type:0x1 HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to User RX-time sec:0.0000 (14.990 usec) XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User RX-time sec:0.0000 (4.271 usec) No rx_vlan_tci or rx_vlan_proto, err=-95 0x5640a37972d0: ping-pong with csum=ab19 (want 315b) csum_start=34 csum_offset=6 0x5640a37972d0: complete tx idx=9999 addr=f010 HW TX-complete-time: 1679819246793036971 (sec:1679819246.7930) delta to User TX-complete-time sec:0.0001 (77.656 usec) XDP RX-time: 1679819246792981987 (sec:1679819246.7930) delta to User TX-complete-time sec:0.0001 (132.640 usec) HW RX-time: 1679819246792971268 (sec:1679819246.7930) delta to HW TX-complete-time sec:0.0001 (65.703 usec)
0x5640a37972d0: complete rx idx=10127 addr=f2110Result of iperf3 without tx hwts request in step 5:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.05 sec 2.74 GBytes 2.34 Gbits/sec receiverResult of iperf3 running parallel with trafgen command in step 6:
[ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.00 sec 2.74 GBytes 2.36 Gbits/sec 0 sender [ 5] 0.00-10.04 sec 2.74 GBytes 2.34 Gbits/sec receiverCo-developed-by Lai Peter Jun Ann <[email protected]>Signed-off-by Lai Peter Jun Ann <[email protected]>Signed-off-by Song Yoong Siang <[email protected]>Acked-by John Fastabend <[email protected]>---
V1: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
V2: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/
V3: https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/changelog:
V1 -> V2
- In structigc_tx_timestamp_request, keep a pointer toigc_tx_buffer, instead of pointingxsk_pending_ts(Vinicius).
- In structigc_tx_timestamp_request, introducebuffer_typeto indicate whether skb origc_tx_bufferpointer should be use (Vinicius).
- In structigc_metadata_request, removeigc_adapterpointer (Vinicius).
- When request tx hwts, copy the value ofcmd_type, instead of using pointer (Vinicius).
- For boolean variable, use true and false, instead of 1 and 0 (Vinicius).
- Inigc_xsk_request_timestamp(), make an early return if none of the 4 ts registers is available (Vinicius).
- Create helper functions to clear tx buffer and skb for tstamp (John).
- Perform throughput test with mix traffic (Vinicius & John). V2 -> V3
- Improve tstamp reg searching loop for better readability (John).
- Inigc_ptp_free_tx_buffer(), add comment to inform user thattstamp->xsk_tx_bufferandtstamp->skbare in union (John).
V3 -> V4
- Add protection withxp_tx_metadata_enabled(Kurt & Maciej).
---
Quoted 5 lines
--- drivers/net/ethernet/intel/igc/igc.h | 71 ++++++++------ drivers/net/ethernet/intel/igc/igc_main.c | 113 ++++++++++++++++++++-- drivers/net/ethernet/intel/igc/igc_ptp.c | 51 ++++++++-- 3 files changed, 195 insertions(+), 40 deletions(-)