xsk: TX metadata
Subsystems (13)
v3 cover xsk: TX metadata
This series implements initial TX metadata (offloads) for AF_XDP. See patch #2 for the main implementation and mlx5/stmmac ones for the example on how to consume the metadata on the device side.
Starting with two types of offloads:
- request TX timestamp (and write it back into the metadata area)
- request TX checksum offload
Changes since v2:
- fix compile issue with XDP_SOCKETS=n (Vinicius Costa Gomes and Intel bots)
- include stmmac support by Song Yoong Siang
v2: https://lore.kernel.org/bpf/[email protected]/T/#t
Performance (mlx5):
I've implemented a small xskgen tool to try to saturate single tx queue:
https://github.com/fomichev/xskgen/tree/master
Here are the performance numbers with some analysis.
1. Baseline. Running with commit eb62e6aef940 ("Merge branch 'bpf:
Support bpf_get_func_ip helper in uprobes'"), nothing from this series:
- with 1400 bytes of payload: 98 gbps, 8 mpps
./xskgen -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.189130 sec, 98.357623 gbps 8.409509 mpps
- with 200 bytes of payload: 49 gbps, 23 mpps
./xskgen -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000064 packets 20960134144 bits, took 0.422235 sec, 49.640921 gbps 23.683645 mpps
2. Adding single commit that supports reserving tx_metadata_len changes nothing numbers-wise.
- baseline for 1400
./xskgen -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.189247 sec, 98.347946 gbps 8.408682 mpps
- baseline for 200
./xskgen -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 20960000000 bits, took 0.421248 sec, 49.756913 gbps 23.738985 mpps
3. Adding -M flag causes xskgen to reserve the metadata and fill it, but doesn't set XDP_TX_METADATA descriptor option.
- new baseline for 1400 (with only filling the metadata)
./xskgen -M -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.188767 sec, 98.387657 gbps 8.412077 mpps
- new baseline for 200 (with only filling the metadata)
./xskgen -M -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 20960000000 bits, took 0.410213 sec, 51.095407 gbps 24.377579 mpps
(the numbers go sligtly up here, not really sure why, maybe some cache-related
side-effects?
4. Next, I'm running the same test but with the commit that adds actual general infra to parse XDP_TX_METADATA (but no driver support). Essentially applying "xsk: add TX timestamp and TX checksum offload support" from this series. Numbers are the same.
- fill metadata for 1400
./xskgen -M -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.188430 sec, 98.415557 gbps 8.414463 mpps
- fill metadata for 200
./xskgen -M -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 20960000000 bits, took 0.411559 sec, 50.928299 gbps 24.297853 mpps
- request metadata for 1400
./xskgen -m -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.188723 sec, 98.391299 gbps 8.412389 mpps
- request metadata for 200
./xskgen -m -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000064 packets 20960134144 bits, took 0.411240 sec, 50.968131 gbps 24.316856 mpps
5. Now, for the most interesting part, I'm adding mlx5 driver support. The mpps for 200 bytes case goes down from 23 mpps to 19 mpps, but _only_ when I enable the metadata. This looks like a side effect of me pushing extra metadata pointer via mlx5e_xdpi_fifo_push. Hence, this part is wrapped into 'if (xp_tx_metadata_enabled)' to not affect the existing non-metadata use-cases. Since this is not regressing existing workloads, I'm not spending any time trying to optimize it more (and leaving it up to mlx owners to purse if they see any good way to do it).
- same baseline
./xskgen -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.189434 sec, 98.332484 gbps 8.407360 mpps
./xskgen -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000128 packets 20960268288 bits, took 0.425254 sec, 49.288821 gbps 23.515659 mpps
- fill metadata for 1400
./xskgen -M -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.189528 sec, 98.324714 gbps 8.406696 mpps
- fill metadata for 200
./xskgen -M -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000128 packets 20960268288 bits, took 0.519085 sec, 40.379260 gbps 19.264914 mpps
- request metadata for 1400
./xskgen -m -s 1400 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000000 packets 116960000000 bits, took 1.189329 sec, 98.341165 gbps 8.408102 mpps
- request metadata for 200
./xskgen -m -s 200 -b eth3 10:70:fd:48:10:77 10:70:fd:48:10:87 fe80::1270:fdff:fe48:1077 fe80::1270:fdff:fe48:1087 1 1 sent 10000128 packets 20960268288 bits, took 0.519929 sec, 40.313713 gbps 19.233642 mpps
Song Yoong Siang (1):
net: stmmac: Add Tx HWTS support to XDP ZC
Stanislav Fomichev (9):
xsk: Support tx_metadata_len
xsk: add TX timestamp and TX checksum offload support
tools: ynl: print xsk-features from the sample net/mlx5e: Implement AF_XDP TX timestamp and checksum offload selftests/xsk: Support tx_metadata_len selftests/bpf: Add csum helpers
selftests/bpf: Add TX side to xdp_metadata selftests/bpf: Add TX side to xdp_hw_metadata
xsk: document tx_metadata_len layout
Documentation/netlink/specs/netdev.yaml | 19 ++ Documentation/networking/index.rst | 1 + Documentation/networking/xsk-tx-metadata.rst | 77 +++++++ drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 72 ++++++- .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 11 +- .../ethernet/mellanox/mlx5/core/en/xsk/tx.c | 17 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac.h | 12 ++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 63 +++++- include/linux/netdevice.h | 27 +++ include/linux/skbuff.h | 14 +- include/net/xdp_sock.h | 81 +++++++ include/net/xdp_sock_drv.h | 13 ++ include/net/xsk_buff_pool.h | 7 + include/uapi/linux/if_xdp.h | 41 ++++ include/uapi/linux/netdev.h | 16 ++ net/core/netdev-genl.c | 12 +- net/xdp/xdp_umem.c | 4 + net/xdp/xsk.c | 51 ++++- net/xdp/xsk_buff_pool.c | 1 + net/xdp/xsk_queue.h | 19 +- tools/include/uapi/linux/if_xdp.h | 55 ++++- tools/include/uapi/linux/netdev.h | 16 ++ tools/net/ynl/generated/netdev-user.c | 19 ++ tools/net/ynl/generated/netdev-user.h | 3 + tools/net/ynl/samples/netdev.c | 6 + tools/testing/selftests/bpf/network_helpers.h | 43 ++++ .../selftests/bpf/prog_tests/xdp_metadata.c | 31 ++- tools/testing/selftests/bpf/xdp_hw_metadata.c | 202 +++++++++++++++++- tools/testing/selftests/bpf/xsk.c | 3 + tools/testing/selftests/bpf/xsk.h | 1 + 32 files changed, 896 insertions(+), 46 deletions(-) create mode 100644 Documentation/networking/xsk-tx-metadata.rst
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
PATCH v3 1/10 xsk: Support tx_metadata_len
For zerocopy mode, tx_desc->addr can point to the arbitrary offset and carry some TX metadata in the headroom. For copy mode, there is no way currently to populate skb metadata.
Introduce new tx_metadata_len umem config option that indicates how many bytes to treat as metadata. Metadata bytes come prior to tx_desc address (same as in RX case).
The size of the metadata has the same constraints as XDP:
- less than 256 bytes
- 4-byte aligned
- non-zero
This data is not interpreted in any way right now.
--- include/net/xdp_sock.h | 1 + include/net/xsk_buff_pool.h | 1 + include/uapi/linux/if_xdp.h | 1 + net/xdp/xdp_umem.c | 4 ++++ net/xdp/xsk.c | 12 +++++++++++- net/xdp/xsk_buff_pool.c | 1 + net/xdp/xsk_queue.h | 17 ++++++++++------- tools/include/uapi/linux/if_xdp.h | 1 + 8 files changed, 30 insertions(+), 8 deletions(-)
include/net/xdp_sock.h +1 -0
@@ -30,6 +30,7 @@ struct xdp_umem {struct user_struct *user;refcount_t users;u8 flags; +u8 tx_metadata_len;bool zc;struct page **pgs;int id;
include/net/xsk_buff_pool.h +1 -0
@@ -77,6 +77,7 @@ struct xsk_buff_pool {u32 chunk_size;u32 chunk_shift;u32 frame_len; +u8 tx_metadata_len;/* inherited from umem */ u8 cached_need_wakeup;bool uses_need_wakeup;bool dma_need_sync;
include/uapi/linux/if_xdp.h +1 -0
@@ -76,6 +76,7 @@ struct xdp_umem_reg {__u32 chunk_size;__u32 headroom;__u32 flags; +__u32 tx_metadata_len; };struct xdp_statistics {
net/xdp/xdp_umem.c +4 -0
@@ -199,6 +199,9 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)if (headroom >= chunk_size -XDP_PACKET_HEADROOM )return -EINVAL ; +if (mr->tx_metadata_len >256 || mr->tx_metadata_len %4 ) +return -EINVAL ; + umem->size = size; umem->headroom = headroom; umem->chunk_size = chunk_size;
@@ -207,6 +210,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) umem->pgs =NULL ; umem->user =NULL ; umem->flags = mr->flags; + umem->tx_metadata_len = mr->tx_metadata_len;INIT_LIST_HEAD (&umem->xsk_dma_list);refcount_set (&umem->users,1 );
net/xdp/xsk.c +11 -1
@@ -1255,6 +1255,14 @@ struct xdp_umem_reg_v1 {__u32 headroom; }; +struct xdp_umem_reg_v2 { +__u64 addr;/* Start of packet data area */ +__u64 len;/* Length of packet data area */ +__u32 chunk_size; +__u32 headroom; +__u32 flags; +}; +static int xsk_setsockopt (struct socket *sock,int level,int optname,sockptr_t optval,unsigned int optlen) {
@@ -1298,8 +1306,10 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname,if (optlen <sizeof (struct xdp_umem_reg_v1 ))return -EINVAL ; -else if (optlen <sizeof (mr)) +else if (optlen <sizeof (struct xdp_umem_reg_v2 )) mr_size =sizeof (struct xdp_umem_reg_v1 ); +else if (optlen <sizeof (mr)) + mr_size =sizeof (struct xdp_umem_reg_v2 );if (copy_from_sockptr (&mr, optval, mr_size))return -EFAULT ;
net/xdp/xsk_buff_pool.c +1 -0
@@ -85,6 +85,7 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,XDP_PACKET_HEADROOM ; pool->umem = umem; pool->addrs = umem->addrs; + pool->tx_metadata_len = umem->tx_metadata_len;INIT_LIST_HEAD (&pool->free_list);INIT_LIST_HEAD (&pool->xskb_list);INIT_LIST_HEAD (&pool->xsk_tx_list);
net/xdp/xsk_queue.h +10 -7
@@ -143,15 +143,17 @@ static inline bool xp_unused_options_set(u32 options)static inline bool xp_aligned_validate_desc (struct xsk_buff_pool *pool,struct xdp_desc *desc) { -u64 offset = desc->addr & (pool->chunk_size -1 ); +u64 addr = desc->addr - pool->tx_metadata_len; +u64 len = desc->len + pool->tx_metadata_len; +u64 offset = addr & (pool->chunk_size -1 );if (!desc->len)return false; -if (offset + desc->len > pool->chunk_size) +if (offset + len > pool->chunk_size)return false; -if (desc->addr >= pool->addrs_cnt) +if (addr >= pool->addrs_cnt)return false;if (xp_unused_options_set (desc->options))
@@ -162,16 +164,17 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,static inline bool xp_unaligned_validate_desc (struct xsk_buff_pool *pool,struct xdp_desc *desc) { -u64 addr =xp_unaligned_add_offset_to_addr (desc->addr); +u64 addr =xp_unaligned_add_offset_to_addr (desc->addr) - pool->tx_metadata_len; +u64 len = desc->len + pool->tx_metadata_len;if (!desc->len)return false; -if (desc->len > pool->chunk_size) +if (len > pool->chunk_size)return false; -if (addr >= pool->addrs_cnt || addr + desc->len > pool->addrs_cnt || -xp_desc_crosses_non_contig_pg (pool, addr, desc->len)) +if (addr >= pool->addrs_cnt || addr + len > pool->addrs_cnt || +xp_desc_crosses_non_contig_pg (pool, addr, len))return false;if (xp_unused_options_set (desc->options))
tools/include/uapi/linux/if_xdp.h +1 -0
@@ -76,6 +76,7 @@ struct xdp_umem_reg {__u32 chunk_size;__u32 headroom;__u32 flags; +__u32 tx_metadata_len; };struct xdp_statistics {
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
PATCH v3 2/10 xsk: add TX timestamp and TX checksum offload support
In reply to Stanislav FomichevThis change actually defines the (initial) metadata layout that should be used by AF_XDP userspace (xsk_tx_metadata). The first field is flags which requests appropriate offloads, followed by the offload-specific fields. The supported per-device offloads are exported via netlink (new xsk-flags).
The offloads themselves are still implemented in a bit of a framework-y fashion that's left from my initial kfunc attempt. I'm introducing new xsk_tx_metadata_ops which drivers are supposed to implement. The drivers are also supposed to call xsk_tx_metadata_request/xsk_tx_metadata_complete in the right places. Since xsk_tx_metadata_{request,_complete} are static inline, we don't incur any extra overhead doing indirect calls.
The benefit of this scheme is as follows:
- keeps all metadata layout parsing away from driver code
- makes it easy to grep and see which drivers implement what
- don't need any extra flags to maintain to keep track of what offloads are implemented; if the callback is implemented - the offload is supported (used by netlink reporting code)
Two offloads are defined right now:
1. XDP_TX_METADATA_CHECKSUM: skb-style csum_start+csum_offset
2. XDP_TX_METADATA_TIMESTAMP: writes TX timestamp back into metadata area upon completion (tx_timestamp field)
The offloads are also implemented for copy mode:
1. Extra XDP_TX_METADATA_CHECKSUM_SW to trigger skb_checksum_help; this might be useful as a reference implementation and for testing
2. XDP_TX_METADATA_TIMESTAMP writes SW timestamp from the skb destructor (note I'm reusing hwtstamps to pass metadata pointer)
The struct is forward-compatible and can be extended in the future by appending more fields.
--- Documentation/netlink/specs/netdev.yaml | 19 ++++++ include/linux/netdevice.h | 27 +++++++++ include/linux/skbuff.h | 14 ++++- include/net/xdp_sock.h | 80 +++++++++++++++++++++++++ include/net/xdp_sock_drv.h | 13 ++++ include/net/xsk_buff_pool.h | 6 ++ include/uapi/linux/if_xdp.h | 40 +++++++++++++ include/uapi/linux/netdev.h | 16 +++++ net/core/netdev-genl.c | 12 +++- net/xdp/xsk.c | 39 ++++++++++++ net/xdp/xsk_queue.h | 2 +- tools/include/uapi/linux/if_xdp.h | 54 +++++++++++++++-- tools/include/uapi/linux/netdev.h | 16 +++++ tools/net/ynl/generated/netdev-user.c | 19 ++++++ tools/net/ynl/generated/netdev-user.h | 3 + 15 files changed, 352 insertions(+), 8 deletions(-)
Documentation/netlink/specs/netdev.yaml +19 -0
@@ -55,6 +55,19 @@ name: netdev name: hash doc: Device is capable of exposing receive packet hash via bpf_xdp_metadata_rx_hash(). + - + type: flags + name: xsk-flags + render-max: true + entries: + - + name: tx-timestamp + doc: + HW timestamping egress packets is supported by the driver. + - + name: tx-checksum + doc: + L3 checksum HW offload is supported by the driver. attribute-sets: -
@@ -88,6 +101,11 @@ name: netdev type: u64 enum: xdp-rx-metadata enum-as-flags: true + - + name: xsk-features + doc: Bitmask of enabled AF_XDP features. + type: u64 + enum: xsk-flags operations: list:
@@ -105,6 +123,7 @@ name: netdev - xdp-features - xdp-zc-max-segs - xdp-rx-metadata-features + - xsk-features dump: reply: *dev-all -
include/linux/netdevice.h +27 -0
@@ -1650,6 +1650,31 @@ struct net_device_ops { struct netlink_ext_ack *extack); }; +/* +* This structure defines the AF_XDP TX metadata hooks for network devices. +* The following hooks can be defined; unless noted otherwise, they are +* optional and can be filled with a null pointer. +* +* int (*tmo_request_timestamp)(void *priv) +* This function is called when AF_XDP frame requested egress timestamp. +* +* int (*tmo_fill_timestamp)(void *priv) +* This function is called when AF_XDP frame, that had requested +* egress timestamp, received a completion. The hook needs to return +* the actual HW timestamp. +* +* int (*tmo_request_checksum)(u16 csum_start, u16 csum_offset, void *priv) +* This function is called when AF_XDP frame requested HW checksum +* offload. csum_start indicates position where checksumming should start. +* csum_offset indicates position where checksum should be stored. +* +*/ +struct xsk_tx_metadata_ops { +void (*tmo_request_timestamp)(void *priv); +u64 (*tmo_fill_timestamp)(void *priv); +void (*tmo_request_checksum)(u16 csum_start,u16 csum_offset,void *priv); +}; +/** * enum netdev_priv_flags - &struct net_device priv_flags *
@@ -1838,6 +1863,7 @@ enum netdev_ml_priv_type {* @netdev_ops: Includes several pointers to callbacks, * if one wants to override the ndo_*() functions * @xdp_metadata_ops: Includes pointers to XDP metadata callbacks. +* @xsk_tx_metadata_ops: Includes pointers to AF_XDP TX metadata callbacks. * @ethtool_ops: Management operations * @l3mdev_ops: Layer 3 master device operations * @ndisc_ops: Includes callbacks for different IPv6 neighbour
@@ -2097,6 +2123,7 @@ struct net_device {unsigned long long priv_flags;const struct net_device_ops *netdev_ops;const struct xdp_metadata_ops *xdp_metadata_ops; +const struct xsk_tx_metadata_ops *xsk_tx_metadata_ops;int ifindex;unsigned short gflags;unsigned short hard_header_len;
include/linux/skbuff.h +13 -1
@@ -566,6 +566,15 @@ struct ubuf_info_msgzc {int mm_account_pinned_pages (struct mmpin *mmp,size_t size);void mm_unaccount_pinned_pages (struct mmpin *mmp); +/* Preserve some data across TX submission and completion. +* +* Note, this state is stored in the driver. Extending the layout +* might need some special care. +*/ +struct xsk_tx_metadata_compl { +__u64 *tx_timestamp; +}; +/* This data is invariant across clones and lives at * the end of the header data, ie. at skb->end. */
@@ -578,7 +587,10 @@ struct skb_shared_info {/* Warning: this field is not always filled in (UFO)! */ unsigned short gso_segs;struct sk_buff *frag_list; -struct skb_shared_hwtstamps hwtstamps; +union { +struct skb_shared_hwtstamps hwtstamps; +struct xsk_tx_metadata_compl xsk_meta; + };unsigned int gso_type;u32 tskey;
include/net/xdp_sock.h +80 -0
92 lines not on this page · raw message
include/net/xdp_sock_drv.h +13 -0
@@ -165,6 +165,14 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr)return xp_raw_get_data (pool, addr); } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct xsk_buff_pool *pool,u64 addr) +{ +if (!pool->tx_metadata_len) +return NULL ; + +return xp_raw_get_data (pool, addr) - pool->tx_metadata_len; +} +static inline void xsk_buff_dma_sync_for_cpu (struct xdp_buff *xdp,struct xsk_buff_pool *pool) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
@@ -324,6 +332,11 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr)return NULL ; } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct xsk_buff_pool *pool,u64 addr) +{ +return NULL ; +} +static inline void xsk_buff_dma_sync_for_cpu (struct xdp_buff *xdp,struct xsk_buff_pool *pool) { }
include/net/xsk_buff_pool.h +6 -0
@@ -33,6 +33,7 @@ struct xdp_buff_xsk { };#define XSK_CHECK_PRIV_TYPE (t) BUILD_BUG_ON(sizeof(t) > offsetofend(struct xdp_buff_xsk, cb)) +#define XSK_TX_COMPL_FITS (t) BUILD_BUG_ON(sizeof(struct xsk_tx_metadata_compl) > sizeof(t))struct xsk_dma_map {dma_addr_t *dma_pages;
@@ -234,4 +235,9 @@ static inline u64 xp_get_handle(struct xdp_buff_xsk *xskb) return xskb->orig_addr + (offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT); } +static inline bool xp_tx_metadata_enabled (const struct xsk_buff_pool *pool) +{ +return pool->tx_metadata_len >0 ; +} +#endif /* XSK_BUFF_POOL_H_ */
include/uapi/linux/if_xdp.h +40 -0
@@ -106,6 +106,43 @@ struct xdp_options {#define XSK_UNALIGNED_BUF_ADDR_MASK \ ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1) +/* Request transmit timestamp. Upon completion, put it into tx_timestamp +* field of struct xsk_tx_metadata. +*/ +#define XDP_TX_METADATA_TIMESTAMP (1 << 0) + +/* Request transmit checksum offload. Checksum start position and offset +* are communicated via csum_start and csum_offset fields of struct +* xsk_tx_metadata. +*/ +#define XDP_TX_METADATA_CHECKSUM (1 << 1) + +/* Force checksum calculation in software. Can be used for testing or +* working around potential HW issues. This option causes performance +* degradation and only works in XDP_COPY mode. +*/ +#define XDP_TX_METADATA_CHECKSUM_SW (1 << 2) + +struct xsk_tx_metadata { +union { +struct { +__u32 flags; + +/* XDP_TX_METADATA_CHECKSUM */ + +/* Offset from desc->addr where checksumming should start. */ +__u16 csum_start; +/* Offset from csum_start where checksum should be stored. */ +__u16 csum_offset; + }; + +struct { +/* XDP_TX_METADATA_TIMESTAMP */ +__u64 tx_timestamp; + } completion; + }; +}; +/* Rx/Tx descriptor */ struct xdp_desc {__u64 addr;
@@ -122,4 +159,7 @@ struct xdp_desc {*/ #define XDP_PKT_CONTD (1 << 0) +/* TX packet carries valid metadata. */ +#define XDP_TX_METADATA (1 << 1) +#endif /* _LINUX_IF_XDP_H */
include/uapi/linux/netdev.h +16 -0
@@ -53,12 +53,28 @@ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_MASK = 3, }; +/** +* enum netdev_xsk_flags +* @NETDEV_XSK_FLAGS_TX_TIMESTAMP: HW timestamping egress packets is supported +* by the driver. +* @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the +* driver. +*/ +enum netdev_xsk_flags { +NETDEV_XSK_FLAGS_TX_TIMESTAMP =1 , +NETDEV_XSK_FLAGS_TX_CHECKSUM =2 , + +/* private: */ +NETDEV_XSK_FLAGS_MASK =3 , +}; +enum {NETDEV_A_DEV_IFINDEX =1 ,NETDEV_A_DEV_PAD ,NETDEV_A_DEV_XDP_FEATURES ,NETDEV_A_DEV_XDP_ZC_MAX_SEGS ,NETDEV_A_DEV_XDP_RX_METADATA_FEATURES , +NETDEV_A_DEV_XSK_FEATURES , __NETDEV_A_DEV_MAX,NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX -1 )
net/core/netdev-genl.c +11 -1
@@ -14,6 +14,7 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, const struct genl_info *info) {u64 xdp_rx_meta =0 ; +u64 xsk_features =0 ;void *hdr; hdr =genlmsg_iput (rsp, info);
@@ -26,11 +27,20 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, XDP_METADATA_KFUNC_xxx#undef XDP_METADATA_KFUNC +if (netdev->xsk_tx_metadata_ops) { +if (netdev->xsk_tx_metadata_ops->tmo_fill_timestamp) + xsk_features |=NETDEV_XSK_FLAGS_TX_TIMESTAMP ; +if (netdev->xsk_tx_metadata_ops->tmo_request_checksum) + xsk_features |=NETDEV_XSK_FLAGS_TX_CHECKSUM ; + } +if (nla_put_u32 (rsp,NETDEV_A_DEV_IFINDEX , netdev->ifindex) ||nla_put_u64_64bit (rsp,NETDEV_A_DEV_XDP_FEATURES , netdev->xdp_features,NETDEV_A_DEV_PAD ) ||nla_put_u64_64bit (rsp,NETDEV_A_DEV_XDP_RX_METADATA_FEATURES , - xdp_rx_meta,NETDEV_A_DEV_PAD )) { + xdp_rx_meta,NETDEV_A_DEV_PAD ) || +nla_put_u64_64bit (rsp,NETDEV_A_DEV_XSK_FEATURES , + xsk_features,NETDEV_A_DEV_PAD )) {genlmsg_cancel (rsp, hdr);return -EINVAL ; }
net/xdp/xsk.c +39 -0
@@ -543,6 +543,13 @@ static u32 xsk_get_num_desc(struct sk_buff *skb)static void xsk_destruct_skb (struct sk_buff *skb) { +struct xsk_tx_metadata_compl *compl = &skb_shinfo (skb)->xsk_meta; + +if (compl->tx_timestamp) { +/* sw completion timestamp, not a real one */ + *compl->tx_timestamp =ktime_get_tai_fast_ns (); + } +xsk_cq_submit_locked (xdp_sk (skb->sk),xsk_get_num_desc (skb));sock_wfree (skb); }
@@ -627,8 +634,10 @@ static struct sk_buff *xsk_build_skb_zerocopy(struct xdp_sock *xs,static struct sk_buff *xsk_build_skb (struct xdp_sock *xs,struct xdp_desc *desc) { +struct xsk_tx_metadata *meta =NULL ;struct net_device *dev = xs->dev;struct sk_buff *skb = xs->skb; +bool first_frag = false;int err;if (dev->priv_flags &IFF_TX_SKB_NO_LINEAR ) {
@@ -659,6 +668,8 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,kfree_skb (skb); goto free_err; } + + first_frag = true; }else {int nr_frags =skb_shinfo (skb)->nr_frags;struct page *page;
@@ -681,12 +692,40 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,skb_add_rx_frag (skb, nr_frags, page,0 , len,0 ); } + +if (first_frag && desc->options &XDP_TX_METADATA ) { +if (unlikely (xs->pool->tx_metadata_len ==0 )) { + err = -EINVAL ; + goto free_err; + } + + meta = buffer - xs->pool->tx_metadata_len; + +if (meta->flags &XDP_TX_METADATA_CHECKSUM ) { +if (unlikely (meta->csum_start + meta->csum_offset + +sizeof (__sum16) > len)) { + err = -EINVAL ; + goto free_err; + } + + skb->csum_start = hr + meta->csum_start; + skb->csum_offset = meta->csum_offset; + skb->ip_summed =CHECKSUM_PARTIAL ; + +if (unlikely (meta->flags &XDP_TX_METADATA_CHECKSUM_SW )) { + err =skb_checksum_help (skb); +if (err) + goto free_err; + } + } + } } skb->dev = dev; skb->priority = xs->sk.sk_priority; skb->mark =READ_ONCE (xs->sk.sk_mark); skb->destructor = xsk_destruct_skb; +xsk_tx_metadata_to_compl (meta, &skb_shinfo (skb)->xsk_meta);xsk_set_destructor_arg (skb);return skb;
net/xdp/xsk_queue.h +1 -1
@@ -137,7 +137,7 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)static inline bool xp_unused_options_set (u32 options) { -return options & ~XDP_PKT_CONTD ; +return options & ~(XDP_PKT_CONTD |XDP_TX_METADATA ); } static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,
tools/include/uapi/linux/if_xdp.h +49 -5
75 lines not on this page · raw message
tools/include/uapi/linux/netdev.h +16 -0
@@ -53,12 +53,28 @@ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_MASK = 3, }; +/** +* enum netdev_xsk_flags +* @NETDEV_XSK_FLAGS_TX_TIMESTAMP: HW timestamping egress packets is supported +* by the driver. +* @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the +* driver. +*/ +enum netdev_xsk_flags { +NETDEV_XSK_FLAGS_TX_TIMESTAMP =1 , +NETDEV_XSK_FLAGS_TX_CHECKSUM =2 , + +/* private: */ +NETDEV_XSK_FLAGS_MASK =3 , +}; +enum {NETDEV_A_DEV_IFINDEX =1 ,NETDEV_A_DEV_PAD ,NETDEV_A_DEV_XDP_FEATURES ,NETDEV_A_DEV_XDP_ZC_MAX_SEGS ,NETDEV_A_DEV_XDP_RX_METADATA_FEATURES , +NETDEV_A_DEV_XSK_FEATURES , __NETDEV_A_DEV_MAX,NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX -1 )
tools/net/ynl/generated/netdev-user.c +19 -0
@@ -58,6 +58,19 @@ const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value)return netdev_xdp_rx_metadata_strmap[value]; } +static const char *const netdev_xsk_flags_strmap[] = { + [0 ] ="tx-timestamp" , + [1 ] ="tx-checksum" , +}; + +const char *netdev_xsk_flags_str (enum netdev_xsk_flags value) +{ + value =ffs (value) -1 ; +if (value <0 || value >= (int )MNL_ARRAY_SIZE (netdev_xsk_flags_strmap)) +return NULL ; +return netdev_xsk_flags_strmap[value]; +} +/* Policies */ struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX +1 ] = { [NETDEV_A_DEV_IFINDEX ] = { .name ="ifindex" , .type =YNL_PT_U32 , },
@@ -65,6 +78,7 @@ struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = { [NETDEV_A_DEV_XDP_FEATURES] = { .name = "xdp-features", .type = YNL_PT_U64, }, [NETDEV_A_DEV_XDP_ZC_MAX_SEGS] = { .name = "xdp-zc-max-segs", .type = YNL_PT_U32, }, [NETDEV_A_DEV_XDP_RX_METADATA_FEATURES] = { .name = "xdp-rx-metadata-features", .type = YNL_PT_U64, }, + [NETDEV_A_DEV_XSK_FEATURES] = { .name = "xsk-features", .type = YNL_PT_U64, }, };struct ynl_policy_nest netdev_dev_nest = {
@@ -116,6 +130,11 @@ int netdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data)return MNL_CB_ERROR ; dst->_present.xdp_rx_metadata_features =1 ; dst->xdp_rx_metadata_features =mnl_attr_get_u64 (attr); + }else if (type ==NETDEV_A_DEV_XSK_FEATURES ) { +if (ynl_attr_validate (yarg, attr)) +return MNL_CB_ERROR ; + dst->_present.xsk_features =1 ; + dst->xsk_features =mnl_attr_get_u64 (attr); } }
tools/net/ynl/generated/netdev-user.h +3 -0
@@ -19,6 +19,7 @@ extern const struct ynl_family ynl_netdev_family;const char *netdev_op_str (int op);const char *netdev_xdp_act_str (enum netdev_xdp_act value);const char *netdev_xdp_rx_metadata_str (enum netdev_xdp_rx_metadata value); +const char *netdev_xsk_flags_str (enum netdev_xsk_flags value);/* Common nested types */ /* ============== NETDEV_CMD_DEV_GET ============== */
@@ -50,12 +51,14 @@ struct netdev_dev_get_rsp { __u32 xdp_features:1; __u32 xdp_zc_max_segs:1; __u32 xdp_rx_metadata_features:1; + __u32 xsk_features:1; } _present;__u32 ifindex;__u64 xdp_features;__u32 xdp_zc_max_segs;__u64 xdp_rx_metadata_features; +__u64 xsk_features; };void netdev_dev_get_rsp_free (struct netdev_dev_get_rsp *rsp);
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
RE: [PATCH bpf-next v3 02/10] xsk: add TX timestamp and TX checksum offload support
Quoted 105 lines · Stanislav Fomichev
This change actually defines the (initial) metadata layout that should be used by
AF_XDPuserspace (xsk_tx_metadata).
The first field is flags which requests appropriate offloads, followed by the offload- specific fields. The supported per-device offloads are exported via netlink (new xsk-flags).The offloads themselves are still implemented in a bit of a framework-y fashion that's left from my initial kfunc attempt.
I'm introducing newxsk_tx_metadata_opswhich drivers are supposed to implement. The drivers are also supposed to call xsk_tx_metadata_request/xsk_tx_metadata_complete in the right places. Since xsk_tx_metadata_{request,_complete}
are static inline, we don't incur any extra overhead doing indirect calls.The benefit of this scheme is as follows:
- keeps all metadata layout parsing away from driver code
- makes it easy to grep and see which drivers implement what
- don't need any extra flags to maintain to keep track of what offloads are implemented; if the callback is implemented - the offload is supported (used by netlink reporting code)Two offloads are defined right now:
1.XDP_TX_METADATA_CHECKSUM: skb-style csum_start+csum_offset 2.XDP_TX_METADATA_TIMESTAMP: writes TX timestamp back into metadata
area upon completion (tx_timestampfield)The offloads are also implemented for copy mode:
1. ExtraXDP_TX_METADATA_CHECKSUM_SWto triggerskb_checksum_help; this might be useful as a reference implementation and for testing 2.XDP_TX_METADATA_TIMESTAMPwrites SW timestamp from the skb
destructor (note I'm reusing hwtstamps to pass metadata pointer)The struct is forward-compatible and can be extended in the future by appending more fields.
Signed-off-by Stanislav Fomichev <[email protected]>---
Documentation/netlink/specs/netdev.yaml | 19 ++++++ include/linux/netdevice.h | 27 +++++++++ include/linux/skbuff.h | 14 ++++- include/net/xdp_sock.h | 80 +++++++++++++++++++++++++ include/net/xdp_sock_drv.h | 13 ++++ include/net/xsk_buff_pool.h | 6 ++ include/uapi/linux/if_xdp.h | 40 +++++++++++++ include/uapi/linux/netdev.h | 16 +++++ net/core/netdev-genl.c | 12 +++- net/xdp/xsk.c | 39 ++++++++++++ net/xdp/xsk_queue.h | 2 +- tools/include/uapi/linux/if_xdp.h | 54 +++++++++++++++-- tools/include/uapi/linux/netdev.h | 16 +++++ tools/net/ynl/generated/netdev-user.c | 19 ++++++ tools/net/ynl/generated/netdev-user.h | 3 + 15 files changed, 352 insertions(+), 8 deletions(-)Documentation/netlink/specs/netdev.yaml +0
-0@@ -55,6 +55,19 @@ name: netdev name: hash doc: Device is capable of exposing receive packet hash via
bpf_xdp_metadata_rx_hash().Documentation/netlink/specs/netdev.yaml +13
-0+ - + type: flags + name: xsk-flags + render-max: true + entries: + - + name: tx-timestamp + doc: + HW timestamping egress packets is supported by the driver. + - + name: tx-checksum + doc: + L3 checksum HW offload is supported by the driver.attribute-sets:
-Documentation/netlink/specs/netdev.yaml +5
-0@@ -88,6 +101,11 @@ name: netdev type: u64 enum: xdp-rx-metadata enum-as-flags: true + - + name: xsk-features + doc: Bitmask of enabled AF_XDP features. + type: u64 + enum: xsk-flagsoperations:
list:Documentation/netlink/specs/netdev.yaml +1
-0@@ -105,6 +123,7 @@ name: netdev - xdp-features - xdp-zc-max-segs - xdp-rx-metadata-features + - xsk-features dump: reply: *dev-all -include/linux/netdevice.h index renamed from include/linux/netdevice.h +0
-0
7e520c14eb8c..0e1cb026cbe5100644
include/linux/netdevice.h struct net_device_ops { · line 1658
Quoted 9 lines
include/linux/netdevice.h +6
-0@@ -1650,6 +1650,31 @@ struct net_device_ops {struct netlink_ext_ack *extack); }; +/* +* This structure defines the AF_XDP TX metadata hooks for network devices. +* The following hooks can be defined; unless noted otherwise, they are +* optional and can be filled with a null pointer. +* +* int (*tmo_request_timestamp)(void *priv)
Should be "void" instead of "int"
include/linux/netdevice.h struct net_device_ops { · line 1661
Quoted 3 lines
include/linux/netdevice.h +3
-0+* This function is called when AF_XDP frame requested egress timestamp. +* +* int (*tmo_fill_timestamp)(void *priv)
Should be "u64" instead of "int"
include/linux/netdevice.h struct net_device_ops { · line 1666
Quoted 5 lines
include/linux/netdevice.h +5
-0+* This function is called when AF_XDP frame, that had requested +* egress timestamp, received a completion. The hook needs to return +* the actual HW timestamp. +* +* int (*tmo_request_checksum)(u16 csum_start, u16 csum_offset, void *priv)
Should be "void" instead of "int"
Quoted 229 lines
include/linux/netdevice.h +11
-0+* This function is called when AF_XDP frame requested HW checksum +* offload. csum_start indicates position where checksumming should start. +* csum_offset indicates position where checksum should be stored. +* +*/ +struct xsk_tx_metadata_ops { +void (*tmo_request_timestamp)(void *priv); +u64 (*tmo_fill_timestamp)(void *priv); +void (*tmo_request_checksum)(u16 csum_start,u16 csum_offset,void *priv); +}; +/** * enum netdev_priv_flags - &struct net_device priv_flags *
include/linux/netdevice.h +1
-0@@ -1838,6 +1863,7 @@ enum netdev_ml_priv_type {* @netdev_ops: Includes several pointers to callbacks, * if one wants to override the ndo_*() functions * @xdp_metadata_ops: Includes pointers to XDP metadata callbacks. +* @xsk_tx_metadata_ops: Includes pointers to AF_XDP TX metadata callbacks.
* @ethtool_ops: Management operations
* @l3mdev_ops: Layer 3 master device operations
* @ndisc_ops: Includes callbacks for different IPv6 neighbourinclude/linux/netdevice.h +1
-0@@ -2097,6 +2123,7 @@ struct net_device {unsigned long long priv_flags;const struct net_device_ops *netdev_ops;const struct xdp_metadata_ops *xdp_metadata_ops; +const struct xsk_tx_metadata_ops *xsk_tx_metadata_ops;int ifindex;unsigned short gflags;unsigned short hard_header_len;include/linux/skbuff.h index renamed from include/linux/skbuff.h +0
-0
4174c4b82d13..444d35dcd690100644include/linux/skbuff.h +0
-0@@ -566,6 +566,15 @@ struct ubuf_info_msgzc { int
mm_account_pinned_pages(struct mmpin *mmp, size_t size); voidmm_unaccount_pinned_pages(struct mmpin *mmp);include/linux/skbuff.h +9
-0+/* Preserve some data across TX submission and completion. +* +* Note, this state is stored in the driver. Extending the layout +* might need some special care. +*/ +struct xsk_tx_metadata_compl { +__u64 *tx_timestamp; +}; +/* This data is invariant across clones and lives at
* the end of the header data, ie. atskb->end. */include/linux/skbuff.h +4
-1@@ -578,7 +587,10 @@ struct skb_shared_info {/* Warning: this field is not always filled in (UFO)! */ unsigned short gso_segs;struct sk_buff *frag_list; -struct skb_shared_hwtstamps hwtstamps; +union { +struct skb_shared_hwtstamps hwtstamps; +struct xsk_tx_metadata_compl xsk_meta; + };unsigned int gso_type;u32 tskey;include/net/xdp_sock.h index renamed from include/net/xdp_sock.h +0
-0
caa1f04106be..29427a69784d100644include/net/xdp_sock.h +62
-0@@ -92,6 +92,74 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp); void__xsk_map_flush (void ); +/** +* xsk_tx_metadata_to_compl - Save enough relevant metadata +information +* to perform tx completion in the future. +* @meta: pointer to AF_XDP metadata area +* @compl: pointer to output struct xsk_tx_metadata_to_compl +* +* This function should be called by the networking device when +* it prepares AF_XDP egress packet. The value of @compl should be +stored +* and passed to xsk_tx_metadata_complete upon TX completion. +*/ +static inline void xsk_tx_metadata_to_compl (struct xsk_tx_metadata *meta, +struct xsk_tx_metadata_compl *compl) { +if (!meta) +return ; + +if (meta->flags &XDP_TX_METADATA_TIMESTAMP ) + compl->tx_timestamp = &meta->completion.tx_timestamp; +else + compl->tx_timestamp =NULL ; +} + +/** +* xsk_tx_metadata_request - Evaluate AF_XDP TX metadata at submission +* and call appropriate xsk_tx_metadata_ops operation. +* @meta: pointer to AF_XDP metadata area +* @ops: pointer to struct xsk_tx_metadata_ops +* @priv: pointer to driver-private aread +* +* This function should be called by the networking device when +* it prepares AF_XDP egress packet. +*/ +static inline void xsk_tx_metadata_request (const struct xsk_tx_metadata *meta, +const struct xsk_tx_metadata_ops *ops, +void *priv) +{ +if (!meta) +return ; + +if (ops->tmo_request_timestamp) +if (meta->flags &XDP_TX_METADATA_TIMESTAMP ) + ops->tmo_request_timestamp (priv); + +if (ops->tmo_request_checksum) +if (meta->flags &XDP_TX_METADATA_CHECKSUM ) + ops->tmo_request_checksum (meta->csum_start, meta- >csum_offset, +priv); } + +/** +* xsk_tx_metadata_complete - Evaluate AF_XDP TX metadata at +completion +* and call appropriate xsk_tx_metadata_ops operation. +* @compl: pointer to completion metadata produced from +xsk_tx_metadata_to_compl +* @ops: pointer to struct xsk_tx_metadata_ops +* @priv: pointer to driver-private aread +* +* This function should be called by the networking device upon +* AF_XDP egress completion. +*/ +static inline void xsk_tx_metadata_complete(struct xsk_tx_metadata_compl*compl,
include/net/xdp_sock.h +1
-0+ const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +7
-0+ void *priv) +{ +if (!compl) +return ; + + *compl->tx_timestamp = ops->tmo_fill_timestamp (priv); } +#else
static inline int
xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)@@ - 108,6 +176,18 @@ static inline void__xsk_map_flush(void){ }include/net/xdp_sock.h +2
-0+static inline void xsk_tx_metadata_request (struct xsk_tx_metadata *meta, + const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +5
-0+ void *priv) +{ +} + +static inline void xsk_tx_metadata_complete(struct xsk_tx_metadata_compl*compl,
include/net/xdp_sock.h +1
-0+ const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +4
-0+ void *priv) +{ +} +#endif /*
CONFIG_XDP_SOCKETS*/#endif /*
_LINUX_XDP_SOCK_H*/include/net/xdp_sock_drv.h index renamed from include/net/xdp_sock_drv.h +0
-0
1f6fc8c7a84c..e2558ac3e195100644include/net/xdp_sock_drv.h +7
-0@@ -165,6 +165,14 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) return xp_raw_get_data(pool, addr); } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct +xsk_buff_pool *pool,u64 addr) { +if (!pool->tx_metadata_len) +return NULL ; + +return xp_raw_get_data (pool, addr) - pool->tx_metadata_len; } +static inline void xsk_buff_dma_sync_for_cpu(struct
xdp_buff*xdp, structxsk_buff_pool *pool) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);include/net/xdp_sock_drv.h +5
-0@@ -324,6 +332,11 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) return NULL; } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct +xsk_buff_pool *pool,u64 addr) { +return NULL ; +} +static inline void
xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp, struct xsk_buff_pool *pool){ } diff --gita/include/net/xsk_buff_pool.hb/include/net/xsk_buff_pool.hindex1985ffaf9b0c..97f5cc10d79e100644include/net/xsk_buff_pool.h +2
-0@@ -33,6 +33,7 @@ struct xdp_buff_xsk { };#define XSK_CHECK_PRIV_TYPE (t) BUILD_BUG_ON(sizeof(t) > offsetofend(struct xdp_buff_xsk, cb)) +#define XSK_TX_COMPL_FITS (t) BUILD_BUG_ON(sizeof(struct +xsk_tx_metadata_compl) > sizeof(t))struct xsk_dma_map { dma_addr_t *dma_pages;include/net/xsk_buff_pool.h +5
-0@@ -234,4 +235,9 @@ static inline u64 xp_get_handle(struct xdp_buff_xsk *xskb)return xskb->orig_addr + (offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT); } +static inline bool xp_tx_metadata_enabled (const struct xsk_buff_pool +*pool) { +return pool->tx_metadata_len >0 ; +} +#endif /* XSK_BUFF_POOL_H_ */ include/uapi/linux/if_xdp.h index renamed from include/uapi/linux/if_xdp.h +0
-0
2ecf79282c26..ecfd67988283100644
include/uapi/linux/if_xdp.h struct xdp_options { #define · line 113
Quoted 8 lines
include/uapi/linux/if_xdp.h +5
-0@@ -106,6 +106,43 @@ struct xdp_options { #defineXSK_UNALIGNED_BUF_ADDR_MASK \ ((1ULL <<XSK_UNALIGNED_BUF_OFFSET_SHIFT ) -1 ) +/* Request transmit timestamp. Upon completion, put it into +tx_timestamp +* field of struct xsk_tx_metadata. + */ +#define XDP_TX_METADATA_TIMESTAMP (1 << 0)
Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macro
include/uapi/linux/if_xdp.h struct xdp_options { · line 118
Quoted 7 lines
include/uapi/linux/if_xdp.h +7
-0+ +/* Request transmit checksum offload. Checksum start position and +offset +* are communicated via csum_start and csum_offset fields of struct +* xsk_tx_metadata. +*/ +#define XDP_TX_METADATA_CHECKSUM (1 << 1)
Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macro
include/uapi/linux/if_xdp.h struct xdp_options { · line 124
Quoted 6 lines
include/uapi/linux/if_xdp.h +6
-0+ +/* Force checksum calculation in software. Can be used for testing or +* working around potential HW issues. This option causes performance +* degradation and only works in XDP_COPY mode. +*/ +#define XDP_TX_METADATA_CHECKSUM_SW (1 << 2)
Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macro
Quoted 400 lines
include/uapi/linux/if_xdp.h +9
-0+ +struct xsk_tx_metadata { + union { + struct { + __u32 flags; + + /* XDP_TX_METADATA_CHECKSUM */ + + /* Offset from desc->addr where checksumming shouldstart. */
include/uapi/linux/if_xdp.h +2
-0+__u16 csum_start; +/* Offset from csum_start where checksum should be stored. */
include/uapi/linux/if_xdp.h +10
-0+__u16 csum_offset; + }; + +struct { +/* XDP_TX_METADATA_TIMESTAMP */ +__u64 tx_timestamp; + } completion; + }; +}; +/* Rx/Tx descriptor */
struct xdp_desc { __u64 addr;include/uapi/linux/if_xdp.h +3
-0@@ -122,4 +159,7 @@ struct xdp_desc {*/ #define XDP_PKT_CONTD (1 << 0) +/* TX packet carries valid metadata. */ #define XDP_TX_METADATA (1 << +1) +#endif /* _LINUX_IF_XDP_H */ include/uapi/linux/netdev.h index renamed from include/uapi/linux/netdev.h +0
-0
2943a151d4f1..48d5477a668c100644include/uapi/linux/netdev.h +3
-0@@ -53,12 +53,28 @@ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_MASK = 3, }; +/** +* enum netdev_xsk_flags +* @NETDEV_XSK_FLAGS_TX_TIMESTAMP: HW timestamping egress packets is supported
+ * by the driver.
+ * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the
+ * driver.
+ */include/uapi/linux/netdev.h +8
-0+enum netdev_xsk_flags { +NETDEV_XSK_FLAGS_TX_TIMESTAMP =1 , +NETDEV_XSK_FLAGS_TX_CHECKSUM =2 , + +/* private: */ +NETDEV_XSK_FLAGS_MASK =3 , +}; +enum {
NETDEV_A_DEV_IFINDEX= 1,
NETDEV_A_DEV_PAD,
NETDEV_A_DEV_XDP_FEATURES,
NETDEV_A_DEV_XDP_ZC_MAX_SEGS,
NETDEV_A_DEV_XDP_RX_METADATA_FEATURES,include/uapi/linux/netdev.h +1
-0+ NETDEV_A_DEV_XSK_FEATURES,__NETDEV_A_DEV_MAX, NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) diff --git
a/net/core/netdev-genl.cb/net/core/netdev-genl.cindexfe61f85bcf33..5d889c2425fd100644net/core/netdev-genl.c +1
-0@@ -14,6 +14,7 @@ netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, const struct genl_info *info) {u64 xdp_rx_meta =0 ; +u64 xsk_features =0 ;void *hdr;hdr = genlmsg_iput(rsp, info);net/core/netdev-genl.c +0
-0@@ -26,11 +27,20 @@ netdev_nl_dev_fill(struct net_device *netdev, struct
sk_buff*rsp,XDP_METADATA_KFUNC_xxx#undefXDP_METADATA_KFUNCnet/core/netdev-genl.c +7
-0+if (netdev->xsk_tx_metadata_ops) { +if (netdev->xsk_tx_metadata_ops->tmo_fill_timestamp) + xsk_features |=NETDEV_XSK_FLAGS_TX_TIMESTAMP ; +if (netdev->xsk_tx_metadata_ops->tmo_request_checksum) + xsk_features |=NETDEV_XSK_FLAGS_TX_CHECKSUM ; + } +if (nla_put_u32(rsp, NETDEV_A_DEV_IFINDEX, netdev->ifindex) || nla_put_u64_64bit(rsp, NETDEV_A_DEV_XDP_FEATURES, netdev->xdp_features, NETDEV_A_DEV_PAD) || nla_put_u64_64bit(rsp,
NETDEV_A_DEV_XDP_RX_METADATA_FEATURES,net/core/netdev-genl.c +3
-1- xdp_rx_meta, NETDEV_A_DEV_PAD)) { + xdp_rx_meta, NETDEV_A_DEV_PAD) || + nla_put_u64_64bit(rsp, NETDEV_A_DEV_XSK_FEATURES, + xsk_features, NETDEV_A_DEV_PAD)) {genlmsg_cancel(rsp, hdr); return -EINVAL; }net/xdp/xsk.c index c1e12b602213..c427e02c13eb renamed from net/xdp/xsk.c +0
-0100644
net/xdp/xsk.c +9
-0@@ -543,6 +543,13 @@ static u32 xsk_get_num_desc(struct sk_buff *skb)static void xsk_destruct_skb (struct sk_buff *skb) { +struct xsk_tx_metadata_compl *compl = &skb_shinfo (skb)->xsk_meta; + +if (compl->tx_timestamp) { +/* sw completion timestamp, not a real one */ + *compl->tx_timestamp =ktime_get_tai_fast_ns (); + } +xsk_cq_submit_locked (xdp_sk (skb->sk),xsk_get_num_desc (skb));sock_wfree (skb); }@@ -627,8 +634,10 @@ static struct sk_buff *xsk_build_skb_zerocopy(struct xdp_sock *xs, static struct sk_buff *xsk_build_skb(struct xdp_sock *xs, struct xdp_desc *desc) { + struct xsk_tx_metadata *meta = NULL;struct net_device *dev = xs->dev;struct sk_buff *skb = xs->skb; +bool first_frag = false;int err; if (dev->priv_flags & IFF_TX_SKB_NO_LINEAR) { @@ -659,6 +668,8 @@static struct
sk_buff*xsk_build_skb(structxdp_sock*xs,kfree_skb(skb); goto free_err; }net/xdp/xsk.c +2
-0+ + first_frag = true;} else { int nr_frags = skb_shinfo(skb)->nr_frags; struct page *page;net/xdp/xsk.c +11
-0@@ -681,12 +692,40 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,skb_add_rx_frag (skb, nr_frags, page,0 , len,0 ); } + +if (first_frag && desc->options &XDP_TX_METADATA ) { +if (unlikely (xs->pool->tx_metadata_len ==0 )) { + err = -EINVAL ; + goto free_err; + } + + meta = buffer - xs->pool->tx_metadata_len; + +if (meta->flags &XDP_TX_METADATA_CHECKSUM ) { + if (unlikely(meta->csum_start + meta-Quoted 1 line
csum_offset+net/xdp/xsk.c +10
-0+ sizeof(__sum16) > len)) { + err = -EINVAL ; + goto free_err; + } + + skb->csum_start = hr + meta->csum_start; + skb->csum_offset = meta->csum_offset; + skb->ip_summed =CHECKSUM_PARTIAL ; + + if (unlikely(meta->flags &
XDP_TX_METADATA_CHECKSUM_SW)) {net/xdp/xsk.c +6
-0+ err =skb_checksum_help (skb); +if (err) + goto free_err; + } + } + }} skb->dev = dev; skb->priority = xs->sk.sk_priority; skb->mark = READ_ONCE(xs->sk.sk_mark); skb->destructor = xsk_destruct_skb;net/xdp/xsk.c +1
-0+xsk_tx_metadata_to_compl (meta, &skb_shinfo (skb)->xsk_meta);xsk_set_destructor_arg(skb); return skb;net/xdp/xsk_queue.h index renamed from net/xdp/xsk_queue.h +0
-0
c74a1372bcb9..6f2d1621c992100644net/xdp/xsk_queue.h +1
-1@@ -137,7 +137,7 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)static inline bool xp_unused_options_set (u32 options) { -return options & ~XDP_PKT_CONTD ; +return options & ~(XDP_PKT_CONTD |XDP_TX_METADATA ); }static inline bool xp_aligned_validate_desc(struct
xsk_buff_pool*pool, diff --gita/tools/include/uapi/linux/if_xdp.hb/tools/include/uapi/linux/if_xdp.hindex34411a2e5b6c..53ceaae10dd1100644tools/include/uapi/linux/if_xdp.h +3
-3@@ -26,11 +26,11 @@*/ #define XDP_USE_NEED_WAKEUP (1 << 3)/* By setting this option, userspace application indicates that it can -* handle multiple descriptors per packet thus enabling xsk core to split +* handle multiple descriptors per packet thus enabling AF_XDP to split * multi-buffer XDP frames into multiple Rx descriptors. Without this set -* such frames will be dropped by xsk. +* such frames will be dropped. */ -#define XDP_USE_SG (1 << 4) +#define XDP_USE_SG (1 << 4)/* Flags for xsk_umem_config flags */ #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0) @@ -106,6 +106,43@@ struct xdp_options { #define XSK_UNALIGNED_BUF_ADDR_MASK \ ((1ULL << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1)tools/include/uapi/linux/if_xdp.h +27
-0+/* Request transmit timestamp. Upon completion, put it into +tx_timestamp +* field of union xsk_tx_metadata. +*/ +#define XDP_TX_METADATA_TIMESTAMP (1 << 0) + +/* Request transmit checksum offload. Checksum start position and +offset +* are communicated via csum_start and csum_offset fields of union +* xsk_tx_metadata. +*/ +#define XDP_TX_METADATA_CHECKSUM (1 << 1) + +/* Force checksum calculation in software. Can be used for testing or +* working around potential HW issues. This option causes performance +* degradation and only works in XDP_COPY mode. +*/ +#define XDP_TX_METADATA_CHECKSUM_SW (1 << 2) + +struct xsk_tx_metadata { + union { + struct { + __u32 flags; + + /* XDP_TX_METADATA_CHECKSUM */ + + /* Offset from desc->addr where checksumming shouldstart. */
tools/include/uapi/linux/if_xdp.h +2
-0+__u16 csum_start; +/* Offset from csum_start where checksum should be stored. */
tools/include/uapi/linux/if_xdp.h +10
-0+__u16 csum_offset; + }; + +struct { +/* XDP_TX_METADATA_TIMESTAMP */ +__u64 tx_timestamp; + } completion; + }; +}; +/* Rx/Tx descriptor */
struct xdp_desc { __u64 addr;tools/include/uapi/linux/if_xdp.h +12
-2@@ -113,9 +150,16 @@ struct xdp_desc {__u32 options; }; -/* Flag indicating packet constitutes of multiple buffers*/ +/* UMEM descriptor is __u64 */ + +/* Flag indicating that the packet continues with the buffer pointed +out by the +* next frame in the ring. The end of the packet is signalled by +setting this +* bit to zero. For single buffer packets, every descriptor has +'options' set +* to 0 and this maintains backward compatibility. +*/ #define XDP_PKT_CONTD (1 << 0) -/* UMEM descriptor is __u64 */ +/* TX packet carries valid metadata. */ #define XDP_TX_METADATA (1 << +1)#endif /*
_LINUX_IF_XDP_H*/tools/include/uapi/linux/netdev.h +3
-0@@ -53,12 +53,28 @@ enum netdev_xdp_rx_metadata { NETDEV_XDP_RX_METADATA_MASK = 3, }; +/** +* enum netdev_xsk_flags +* @NETDEV_XSK_FLAGS_TX_TIMESTAMP: HW timestamping egress packets is supported
+ * by the driver.
+ * @NETDEV_XSK_FLAGS_TX_CHECKSUM: L3 checksum HW offload is supported by the
+ * driver.
+ */tools/include/uapi/linux/netdev.h +8
-0+enum netdev_xsk_flags { +NETDEV_XSK_FLAGS_TX_TIMESTAMP =1 , +NETDEV_XSK_FLAGS_TX_CHECKSUM =2 , + +/* private: */ +NETDEV_XSK_FLAGS_MASK =3 , +}; +enum {
NETDEV_A_DEV_IFINDEX= 1,
NETDEV_A_DEV_PAD,
NETDEV_A_DEV_XDP_FEATURES,
NETDEV_A_DEV_XDP_ZC_MAX_SEGS,
NETDEV_A_DEV_XDP_RX_METADATA_FEATURES,tools/include/uapi/linux/netdev.h +1
-0+ NETDEV_A_DEV_XSK_FEATURES,__NETDEV_A_DEV_MAX, NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) diff --git
a/tools/net/ynl/generated/netdev-user.cb/tools/net/ynl/generated/netdev-user.cindexb5ffe8cd1144..6283d87dad37100644tools/net/ynl/generated/netdev-user.c +11
-0@@ -58,6 +58,19 @@ const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value)return netdev_xdp_rx_metadata_strmap[value]; } +static const char *const netdev_xsk_flags_strmap[] = { + [0 ] ="tx-timestamp" , + [1 ] ="tx-checksum" , +}; + +const char *netdev_xsk_flags_str (enum netdev_xsk_flags value) { + value =ffs (value) -1 ; +if (value <0 || value >= (int )MNL_ARRAY_SIZE (netdev_xsk_flags_strmap)) +return NULL ; +return netdev_xsk_flags_strmap[value]; } +/* Policies */ struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX +1 ] = {[NETDEV_A_DEV_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, },tools/net/ynl/generated/netdev-user.c +0
-0@@ -65,6 +78,7 @@ struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = { [NETDEV_A_DEV_XDP_FEATURES] = { .name = "xdp-features", .type = YNL_PT_U64, }, [NETDEV_A_DEV_XDP_ZC_MAX_SEGS] = { .name = "xdp-zc-max- segs", .type = YNL_PT_U32, }, [NETDEV_A_DEV_XDP_RX_METADATA_FEATURES] = { .name = "xdp-rx-metadata-features", .type =
YNL_PT_U64, },tools/net/ynl/generated/netdev-user.c +2
-0+ [NETDEV_A_DEV_XSK_FEATURES] = { .name = "xsk-features", .type = +YNL_PT_U64, },};
struct
ynl_policy_nestnetdev_dev_nest= { @@ -116,6 +130,11 @@ intnetdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data)return MNL_CB_ERROR; dst->_present.xdp_rx_metadata_features = 1; dst->xdp_rx_metadata_features =
mnl_attr_get_u64(attr);tools/net/ynl/generated/netdev-user.c +5
-0+ }else if (type ==NETDEV_A_DEV_XSK_FEATURES ) { +if (ynl_attr_validate (yarg, attr)) +return MNL_CB_ERROR ; + dst->_present.xsk_features =1 ; + dst->xsk_features =mnl_attr_get_u64 (attr);} }tools/net/ynl/generated/netdev-user.h +0
-0@@ -19,6 +19,7 @@ extern const struct ynl_family ynl_netdev_family; const char *netdev_op_str(int op); const char *netdev_xdp_act_str(enum netdev_xdp_actvalue); const char *netdev_xdp_rx_metadata_str(enum
netdev_xdp_rx_metadatavalue);
+const char *netdev_xsk_flags_str(enumnetdev_xsk_flagsvalue);/* Common nested types */
/* ==============NETDEV_CMD_DEV_GET============== */ @@ -50,12+51,14 @@ struct netdev_dev_get_rsp { __u32 xdp_features:1; __u32 xdp_zc_max_segs:1; __u32 xdp_rx_metadata_features:1;tools/net/ynl/generated/netdev-user.h +1
-0+ __u32 xsk_features:1;} _present; __u32 ifindex; __u64 xdp_features; __u32 xdp_zc_max_segs; __u64 xdp_rx_metadata_features;tools/net/ynl/generated/netdev-user.h +1
-0+__u64 xsk_features;};
void
netdev_dev_get_rsp_free(struct netdev_dev_get_rsp *rsp); --
2.42.0.582.g8ccd20d70d-goog
Re: [PATCH bpf-next v3 02/10] xsk: add TX timestamp and TX checksum offload support
Quoted 115 lines · Yoong Siang
Quoted 114 lines · Stanislav Fomichev
This change actually defines the (initial) metadata layout that should be used by
AF_XDPuserspace (xsk_tx_metadata).
The first field is flags which requests appropriate offloads, followed by the offload- specific fields. The supported per-device offloads are exported via netlink (new xsk-flags).The offloads themselves are still implemented in a bit of a framework-y fashion that's left from my initial kfunc attempt.
I'm introducing newxsk_tx_metadata_opswhich drivers are supposed to implement. The drivers are also supposed to call xsk_tx_metadata_request/xsk_tx_metadata_complete in the right places. Since xsk_tx_metadata_{request,_complete}
are static inline, we don't incur any extra overhead doing indirect calls.The benefit of this scheme is as follows:
- keeps all metadata layout parsing away from driver code
- makes it easy to grep and see which drivers implement what
- don't need any extra flags to maintain to keep track of what offloads are implemented; if the callback is implemented - the offload is supported (used by netlink reporting code)Two offloads are defined right now:
1.XDP_TX_METADATA_CHECKSUM: skb-style csum_start+csum_offset 2.XDP_TX_METADATA_TIMESTAMP: writes TX timestamp back into metadata
area upon completion (tx_timestampfield)The offloads are also implemented for copy mode:
1. ExtraXDP_TX_METADATA_CHECKSUM_SWto triggerskb_checksum_help; this might be useful as a reference implementation and for testing 2.XDP_TX_METADATA_TIMESTAMPwrites SW timestamp from the skb
destructor (note I'm reusing hwtstamps to pass metadata pointer)The struct is forward-compatible and can be extended in the future by appending more fields.
Signed-off-by Stanislav Fomichev <[email protected]>---
Documentation/netlink/specs/netdev.yaml | 19 ++++++ include/linux/netdevice.h | 27 +++++++++ include/linux/skbuff.h | 14 ++++- include/net/xdp_sock.h | 80 +++++++++++++++++++++++++ include/net/xdp_sock_drv.h | 13 ++++ include/net/xsk_buff_pool.h | 6 ++ include/uapi/linux/if_xdp.h | 40 +++++++++++++ include/uapi/linux/netdev.h | 16 +++++ net/core/netdev-genl.c | 12 +++- net/xdp/xsk.c | 39 ++++++++++++ net/xdp/xsk_queue.h | 2 +- tools/include/uapi/linux/if_xdp.h | 54 +++++++++++++++-- tools/include/uapi/linux/netdev.h | 16 +++++ tools/net/ynl/generated/netdev-user.c | 19 ++++++ tools/net/ynl/generated/netdev-user.h | 3 + 15 files changed, 352 insertions(+), 8 deletions(-)Documentation/netlink/specs/netdev.yaml +0
-0@@ -55,6 +55,19 @@ name: netdev name: hash doc: Device is capable of exposing receive packet hash via
bpf_xdp_metadata_rx_hash().Documentation/netlink/specs/netdev.yaml +13
-0+ - + type: flags + name: xsk-flags + render-max: true + entries: + - + name: tx-timestamp + doc: + HW timestamping egress packets is supported by the driver. + - + name: tx-checksum + doc: + L3 checksum HW offload is supported by the driver.attribute-sets:
-Documentation/netlink/specs/netdev.yaml +5
-0@@ -88,6 +101,11 @@ name: netdev type: u64 enum: xdp-rx-metadata enum-as-flags: true + - + name: xsk-features + doc: Bitmask of enabled AF_XDP features. + type: u64 + enum: xsk-flagsoperations:
list:Documentation/netlink/specs/netdev.yaml +1
-0@@ -105,6 +123,7 @@ name: netdev - xdp-features - xdp-zc-max-segs - xdp-rx-metadata-features + - xsk-features dump: reply: *dev-all -include/linux/netdevice.h index renamed from include/linux/netdevice.h +0
-0
7e520c14eb8c..0e1cb026cbe5100644include/linux/netdevice.h +6
-0@@ -1650,6 +1650,31 @@ struct net_device_ops {struct netlink_ext_ack *extack); }; +/* +* This structure defines the AF_XDP TX metadata hooks for network devices. +* The following hooks can be defined; unless noted otherwise, they are +* optional and can be filled with a null pointer. +* +* int (*tmo_request_timestamp)(void *priv)
[..]
Quoted 8 lines
Should be "void" instead of "int"
Quoted 3 lines
+ * This function is called when
AF_XDPframe requested egress timestamp.
+ *
+ * int (*tmo_fill_timestamp)(void *priv)Should be "u64" instead of "int"
Quoted 7 lines
Quoted 5 lines
+ * This function is called when AF_XDP frame, that had requested + * egress timestamp, received a completion. The hook needs to return + * the actual HW timestamp.+ *
+ * int (*tmo_request_checksum)(u16csum_start, u16csum_offset, void *priv)Should be "void" instead of "int"
Oh, good catch, will update these doc entries!
Quoted 237 lines
Quoted 237 lines
+ * This function is called when AF_XDP frame requested HW checksum + * offload. csum_start indicates position where checksumming should start. + * csum_offset indicates position where checksum should be stored.+ *
+ */include/linux/netdevice.h +4
-0+struct xsk_tx_metadata_ops { +void (*tmo_request_timestamp)(void *priv); +u64 (*tmo_fill_timestamp)(void *priv); + void (*tmo_request_checksum)(u16 csum_start, u16 csum_offset, void*priv);
include/linux/netdevice.h +2
-0+}; +/**
* enumnetdev_priv_flags- &structnet_devicepriv_flags*include/linux/netdevice.h +1
-0@@ -1838,6 +1863,7 @@ enum netdev_ml_priv_type {* @netdev_ops: Includes several pointers to callbacks, * if one wants to override the ndo_*() functions * @xdp_metadata_ops: Includes pointers to XDP metadata callbacks. +* @xsk_tx_metadata_ops: Includes pointers to AF_XDP TX metadata callbacks.
* @ethtool_ops: Management operations
* @l3mdev_ops: Layer 3 master device operations
* @ndisc_ops: Includes callbacks for different IPv6 neighbourinclude/linux/netdevice.h +1
-0@@ -2097,6 +2123,7 @@ struct net_device {unsigned long long priv_flags;const struct net_device_ops *netdev_ops;const struct xdp_metadata_ops *xdp_metadata_ops; +const struct xsk_tx_metadata_ops *xsk_tx_metadata_ops;int ifindex;unsigned short gflags;unsigned short hard_header_len;include/linux/skbuff.h index renamed from include/linux/skbuff.h +0
-0
4174c4b82d13..444d35dcd690100644include/linux/skbuff.h +0
-0@@ -566,6 +566,15 @@ struct ubuf_info_msgzc { int
mm_account_pinned_pages(struct mmpin *mmp, size_t size); voidmm_unaccount_pinned_pages(struct mmpin *mmp);include/linux/skbuff.h +9
-0+/* Preserve some data across TX submission and completion. +* +* Note, this state is stored in the driver. Extending the layout +* might need some special care. +*/ +struct xsk_tx_metadata_compl { +__u64 *tx_timestamp; +}; +/* This data is invariant across clones and lives at
* the end of the header data, ie. atskb->end. */include/linux/skbuff.h +4
-1@@ -578,7 +587,10 @@ struct skb_shared_info {/* Warning: this field is not always filled in (UFO)! */ unsigned short gso_segs;struct sk_buff *frag_list; -struct skb_shared_hwtstamps hwtstamps; +union { +struct skb_shared_hwtstamps hwtstamps; +struct xsk_tx_metadata_compl xsk_meta; + };unsigned int gso_type;u32 tskey;include/net/xdp_sock.h index renamed from include/net/xdp_sock.h +0
-0
caa1f04106be..29427a69784d100644include/net/xdp_sock.h +62
-0@@ -92,6 +92,74 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp); void__xsk_map_flush (void ); +/** +* xsk_tx_metadata_to_compl - Save enough relevant metadata +information +* to perform tx completion in the future. +* @meta: pointer to AF_XDP metadata area +* @compl: pointer to output struct xsk_tx_metadata_to_compl +* +* This function should be called by the networking device when +* it prepares AF_XDP egress packet. The value of @compl should be +stored +* and passed to xsk_tx_metadata_complete upon TX completion. +*/ +static inline void xsk_tx_metadata_to_compl (struct xsk_tx_metadata *meta, +struct xsk_tx_metadata_compl *compl) { +if (!meta) +return ; + +if (meta->flags &XDP_TX_METADATA_TIMESTAMP ) + compl->tx_timestamp = &meta->completion.tx_timestamp; +else + compl->tx_timestamp =NULL ; +} + +/** +* xsk_tx_metadata_request - Evaluate AF_XDP TX metadata at submission +* and call appropriate xsk_tx_metadata_ops operation. +* @meta: pointer to AF_XDP metadata area +* @ops: pointer to struct xsk_tx_metadata_ops +* @priv: pointer to driver-private aread +* +* This function should be called by the networking device when +* it prepares AF_XDP egress packet. +*/ +static inline void xsk_tx_metadata_request (const struct xsk_tx_metadata *meta, +const struct xsk_tx_metadata_ops *ops, +void *priv) +{ +if (!meta) +return ; + +if (ops->tmo_request_timestamp) +if (meta->flags &XDP_TX_METADATA_TIMESTAMP ) + ops->tmo_request_timestamp (priv); + +if (ops->tmo_request_checksum) +if (meta->flags &XDP_TX_METADATA_CHECKSUM ) + ops->tmo_request_checksum (meta->csum_start, meta- >csum_offset, +priv); } + +/** +* xsk_tx_metadata_complete - Evaluate AF_XDP TX metadata at +completion +* and call appropriate xsk_tx_metadata_ops operation. +* @compl: pointer to completion metadata produced from +xsk_tx_metadata_to_compl +* @ops: pointer to struct xsk_tx_metadata_ops +* @priv: pointer to driver-private aread +* +* This function should be called by the networking device upon +* AF_XDP egress completion. +*/ +static inline void xsk_tx_metadata_complete(struct xsk_tx_metadata_compl*compl,
include/net/xdp_sock.h +1
-0+ const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +7
-0+ void *priv) +{ +if (!compl) +return ; + + *compl->tx_timestamp = ops->tmo_fill_timestamp (priv); } +#else
static inline int
xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)@@ - 108,6 +176,18 @@ static inline void__xsk_map_flush(void){ }include/net/xdp_sock.h +2
-0+static inline void xsk_tx_metadata_request (struct xsk_tx_metadata *meta, + const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +5
-0+ void *priv) +{ +} + +static inline void xsk_tx_metadata_complete(struct xsk_tx_metadata_compl*compl,
include/net/xdp_sock.h +1
-0+ const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +4
-0+ void *priv) +{ +} +#endif /*
CONFIG_XDP_SOCKETS*/#endif /*
_LINUX_XDP_SOCK_H*/include/net/xdp_sock_drv.h index renamed from include/net/xdp_sock_drv.h +0
-0
1f6fc8c7a84c..e2558ac3e195100644include/net/xdp_sock_drv.h +7
-0@@ -165,6 +165,14 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) return xp_raw_get_data(pool, addr); } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct +xsk_buff_pool *pool,u64 addr) { +if (!pool->tx_metadata_len) +return NULL ; + +return xp_raw_get_data (pool, addr) - pool->tx_metadata_len; } +static inline void xsk_buff_dma_sync_for_cpu(struct
xdp_buff*xdp, structxsk_buff_pool *pool) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);include/net/xdp_sock_drv.h +5
-0@@ -324,6 +332,11 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) return NULL; } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct +xsk_buff_pool *pool,u64 addr) { +return NULL ; +} +static inline void
xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp, struct xsk_buff_pool *pool){ } diff --gita/include/net/xsk_buff_pool.hb/include/net/xsk_buff_pool.hindex1985ffaf9b0c..97f5cc10d79e100644include/net/xsk_buff_pool.h +2
-0@@ -33,6 +33,7 @@ struct xdp_buff_xsk { };#define XSK_CHECK_PRIV_TYPE (t) BUILD_BUG_ON(sizeof(t) > offsetofend(struct xdp_buff_xsk, cb)) +#define XSK_TX_COMPL_FITS (t) BUILD_BUG_ON(sizeof(struct +xsk_tx_metadata_compl) > sizeof(t))struct xsk_dma_map { dma_addr_t *dma_pages;include/net/xsk_buff_pool.h +5
-0@@ -234,4 +235,9 @@ static inline u64 xp_get_handle(struct xdp_buff_xsk *xskb)return xskb->orig_addr + (offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT); } +static inline bool xp_tx_metadata_enabled (const struct xsk_buff_pool +*pool) { +return pool->tx_metadata_len >0 ; +} +#endif /* XSK_BUFF_POOL_H_ */ include/uapi/linux/if_xdp.h index renamed from include/uapi/linux/if_xdp.h +0
-0
2ecf79282c26..ecfd67988283100644include/uapi/linux/if_xdp.h +5
-0@@ -106,6 +106,43 @@ struct xdp_options { #defineXSK_UNALIGNED_BUF_ADDR_MASK \ ((1ULL <<XSK_UNALIGNED_BUF_OFFSET_SHIFT ) -1 ) +/* Request transmit timestamp. Upon completion, put it into +tx_timestamp +* field of struct xsk_tx_metadata. + */ +#define XDP_TX_METADATA_TIMESTAMP (1 << 0)
[..]
Quoted 14 lines
Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macroinclude/uapi/linux/if_xdp.h struct xdp_options { · line 118
Quoted 7 lines
include/uapi/linux/if_xdp.h +7
-0+ +/* Request transmit checksum offload. Checksum start position and +offset +* are communicated via csum_start and csum_offset fields of struct +* xsk_tx_metadata. +*/ +#define XDP_TX_METADATA_CHECKSUM (1 << 1)Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macro
Quoted 9 lines
include/uapi/linux/if_xdp.h struct xdp_options { · line 124
Quoted 6 lines
include/uapi/linux/if_xdp.h +6
-0+ +/* Force checksum calculation in software. Can be used for testing or +* working around potential HW issues. This option causes performance +* degradation and only works in XDP_COPY mode. +*/ +#define XDP_TX_METADATA_CHECKSUM_SW (1 << 2)Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macro
Will do! Hopefully nothing breaks, let me check...
Re: [PATCH bpf-next v3 02/10] xsk: add TX timestamp and TX checksum offload support
Quoted 401 lines · Stanislav Fomichev
Quoted 115 lines · Yoong Siang
Quoted 114 lines · Stanislav Fomichev
This change actually defines the (initial) metadata layout that should be used by
AF_XDPuserspace (xsk_tx_metadata).
The first field is flags which requests appropriate offloads, followed by the offload- specific fields. The supported per-device offloads are exported via netlink (new xsk-flags).The offloads themselves are still implemented in a bit of a framework-y fashion that's left from my initial kfunc attempt.
I'm introducing newxsk_tx_metadata_opswhich drivers are supposed to implement. The drivers are also supposed to call xsk_tx_metadata_request/xsk_tx_metadata_complete in the right places. Since xsk_tx_metadata_{request,_complete}
are static inline, we don't incur any extra overhead doing indirect calls.The benefit of this scheme is as follows:
- keeps all metadata layout parsing away from driver code
- makes it easy to grep and see which drivers implement what
- don't need any extra flags to maintain to keep track of what offloads are implemented; if the callback is implemented - the offload is supported (used by netlink reporting code)Two offloads are defined right now:
1.XDP_TX_METADATA_CHECKSUM: skb-style csum_start+csum_offset 2.XDP_TX_METADATA_TIMESTAMP: writes TX timestamp back into metadata
area upon completion (tx_timestampfield)The offloads are also implemented for copy mode:
1. ExtraXDP_TX_METADATA_CHECKSUM_SWto triggerskb_checksum_help; this might be useful as a reference implementation and for testing 2.XDP_TX_METADATA_TIMESTAMPwrites SW timestamp from the skb
destructor (note I'm reusing hwtstamps to pass metadata pointer)The struct is forward-compatible and can be extended in the future by appending more fields.
Signed-off-by Stanislav Fomichev <[email protected]>---
Documentation/netlink/specs/netdev.yaml | 19 ++++++ include/linux/netdevice.h | 27 +++++++++ include/linux/skbuff.h | 14 ++++- include/net/xdp_sock.h | 80 +++++++++++++++++++++++++ include/net/xdp_sock_drv.h | 13 ++++ include/net/xsk_buff_pool.h | 6 ++ include/uapi/linux/if_xdp.h | 40 +++++++++++++ include/uapi/linux/netdev.h | 16 +++++ net/core/netdev-genl.c | 12 +++- net/xdp/xsk.c | 39 ++++++++++++ net/xdp/xsk_queue.h | 2 +- tools/include/uapi/linux/if_xdp.h | 54 +++++++++++++++-- tools/include/uapi/linux/netdev.h | 16 +++++ tools/net/ynl/generated/netdev-user.c | 19 ++++++ tools/net/ynl/generated/netdev-user.h | 3 + 15 files changed, 352 insertions(+), 8 deletions(-)Documentation/netlink/specs/netdev.yaml +0
-0@@ -55,6 +55,19 @@ name: netdev name: hash doc: Device is capable of exposing receive packet hash via
bpf_xdp_metadata_rx_hash().Documentation/netlink/specs/netdev.yaml +13
-0+ - + type: flags + name: xsk-flags + render-max: true + entries: + - + name: tx-timestamp + doc: + HW timestamping egress packets is supported by the driver. + - + name: tx-checksum + doc: + L3 checksum HW offload is supported by the driver.attribute-sets:
-Documentation/netlink/specs/netdev.yaml +5
-0@@ -88,6 +101,11 @@ name: netdev type: u64 enum: xdp-rx-metadata enum-as-flags: true + - + name: xsk-features + doc: Bitmask of enabled AF_XDP features. + type: u64 + enum: xsk-flagsoperations:
list:Documentation/netlink/specs/netdev.yaml +1
-0@@ -105,6 +123,7 @@ name: netdev - xdp-features - xdp-zc-max-segs - xdp-rx-metadata-features + - xsk-features dump: reply: *dev-all -include/linux/netdevice.h index renamed from include/linux/netdevice.h +0
-0
7e520c14eb8c..0e1cb026cbe5100644include/linux/netdevice.h +6
-0@@ -1650,6 +1650,31 @@ struct net_device_ops {struct netlink_ext_ack *extack); }; +/* +* This structure defines the AF_XDP TX metadata hooks for network devices. +* The following hooks can be defined; unless noted otherwise, they are +* optional and can be filled with a null pointer. +* +* int (*tmo_request_timestamp)(void *priv) [..]
Quoted 8 lines
Should be "void" instead of "int"
Quoted 3 lines
+ * This function is called when
AF_XDPframe requested egress timestamp.
+ *
+ * int (*tmo_fill_timestamp)(void *priv)Should be "u64" instead of "int"
Quoted 7 lines
Quoted 5 lines
+ * This function is called when AF_XDP frame, that had requested + * egress timestamp, received a completion. The hook needs to return + * the actual HW timestamp.+ *
+ * int (*tmo_request_checksum)(u16csum_start, u16csum_offset, void *priv)Should be "void" instead of "int"
Oh, good catch, will update these doc entries!
Quoted 237 lines
Quoted 237 lines
+ * This function is called when AF_XDP frame requested HW checksum + * offload. csum_start indicates position where checksumming should start. + * csum_offset indicates position where checksum should be stored.+ *
+ */include/linux/netdevice.h +4
-0+struct xsk_tx_metadata_ops { +void (*tmo_request_timestamp)(void *priv); +u64 (*tmo_fill_timestamp)(void *priv); + void (*tmo_request_checksum)(u16 csum_start, u16 csum_offset, void*priv);
include/linux/netdevice.h +2
-0+}; +/**
* enumnetdev_priv_flags- &structnet_devicepriv_flags*include/linux/netdevice.h +1
-0@@ -1838,6 +1863,7 @@ enum netdev_ml_priv_type {* @netdev_ops: Includes several pointers to callbacks, * if one wants to override the ndo_*() functions * @xdp_metadata_ops: Includes pointers to XDP metadata callbacks. +* @xsk_tx_metadata_ops: Includes pointers to AF_XDP TX metadata callbacks.
* @ethtool_ops: Management operations
* @l3mdev_ops: Layer 3 master device operations
* @ndisc_ops: Includes callbacks for different IPv6 neighbourinclude/linux/netdevice.h +1
-0@@ -2097,6 +2123,7 @@ struct net_device {unsigned long long priv_flags;const struct net_device_ops *netdev_ops;const struct xdp_metadata_ops *xdp_metadata_ops; +const struct xsk_tx_metadata_ops *xsk_tx_metadata_ops;int ifindex;unsigned short gflags;unsigned short hard_header_len;include/linux/skbuff.h index renamed from include/linux/skbuff.h +0
-0
4174c4b82d13..444d35dcd690100644include/linux/skbuff.h +0
-0@@ -566,6 +566,15 @@ struct ubuf_info_msgzc { int
mm_account_pinned_pages(struct mmpin *mmp, size_t size); voidmm_unaccount_pinned_pages(struct mmpin *mmp);include/linux/skbuff.h +9
-0+/* Preserve some data across TX submission and completion. +* +* Note, this state is stored in the driver. Extending the layout +* might need some special care. +*/ +struct xsk_tx_metadata_compl { +__u64 *tx_timestamp; +}; +/* This data is invariant across clones and lives at
* the end of the header data, ie. atskb->end. */include/linux/skbuff.h +4
-1@@ -578,7 +587,10 @@ struct skb_shared_info {/* Warning: this field is not always filled in (UFO)! */ unsigned short gso_segs;struct sk_buff *frag_list; -struct skb_shared_hwtstamps hwtstamps; +union { +struct skb_shared_hwtstamps hwtstamps; +struct xsk_tx_metadata_compl xsk_meta; + };unsigned int gso_type;u32 tskey;include/net/xdp_sock.h index renamed from include/net/xdp_sock.h +0
-0
caa1f04106be..29427a69784d100644include/net/xdp_sock.h +62
-0@@ -92,6 +92,74 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp); int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp); void__xsk_map_flush (void ); +/** +* xsk_tx_metadata_to_compl - Save enough relevant metadata +information +* to perform tx completion in the future. +* @meta: pointer to AF_XDP metadata area +* @compl: pointer to output struct xsk_tx_metadata_to_compl +* +* This function should be called by the networking device when +* it prepares AF_XDP egress packet. The value of @compl should be +stored +* and passed to xsk_tx_metadata_complete upon TX completion. +*/ +static inline void xsk_tx_metadata_to_compl (struct xsk_tx_metadata *meta, +struct xsk_tx_metadata_compl *compl) { +if (!meta) +return ; + +if (meta->flags &XDP_TX_METADATA_TIMESTAMP ) + compl->tx_timestamp = &meta->completion.tx_timestamp; +else + compl->tx_timestamp =NULL ; +} + +/** +* xsk_tx_metadata_request - Evaluate AF_XDP TX metadata at submission +* and call appropriate xsk_tx_metadata_ops operation. +* @meta: pointer to AF_XDP metadata area +* @ops: pointer to struct xsk_tx_metadata_ops +* @priv: pointer to driver-private aread +* +* This function should be called by the networking device when +* it prepares AF_XDP egress packet. +*/ +static inline void xsk_tx_metadata_request (const struct xsk_tx_metadata *meta, +const struct xsk_tx_metadata_ops *ops, +void *priv) +{ +if (!meta) +return ; + +if (ops->tmo_request_timestamp) +if (meta->flags &XDP_TX_METADATA_TIMESTAMP ) + ops->tmo_request_timestamp (priv); + +if (ops->tmo_request_checksum) +if (meta->flags &XDP_TX_METADATA_CHECKSUM ) + ops->tmo_request_checksum (meta->csum_start, meta- >csum_offset, +priv); } + +/** +* xsk_tx_metadata_complete - Evaluate AF_XDP TX metadata at +completion +* and call appropriate xsk_tx_metadata_ops operation. +* @compl: pointer to completion metadata produced from +xsk_tx_metadata_to_compl +* @ops: pointer to struct xsk_tx_metadata_ops +* @priv: pointer to driver-private aread +* +* This function should be called by the networking device upon +* AF_XDP egress completion. +*/ +static inline void xsk_tx_metadata_complete(struct xsk_tx_metadata_compl*compl,
include/net/xdp_sock.h +1
-0+ const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +7
-0+ void *priv) +{ +if (!compl) +return ; + + *compl->tx_timestamp = ops->tmo_fill_timestamp (priv); } +#else
static inline int
xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)@@ - 108,6 +176,18 @@ static inline void__xsk_map_flush(void){ }include/net/xdp_sock.h +2
-0+static inline void xsk_tx_metadata_request (struct xsk_tx_metadata *meta, + const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +5
-0+ void *priv) +{ +} + +static inline void xsk_tx_metadata_complete(struct xsk_tx_metadata_compl*compl,
include/net/xdp_sock.h +1
-0+ const struct xsk_tx_metadata_ops*ops,
include/net/xdp_sock.h +4
-0+ void *priv) +{ +} +#endif /*
CONFIG_XDP_SOCKETS*/#endif /*
_LINUX_XDP_SOCK_H*/include/net/xdp_sock_drv.h index renamed from include/net/xdp_sock_drv.h +0
-0
1f6fc8c7a84c..e2558ac3e195100644include/net/xdp_sock_drv.h +7
-0@@ -165,6 +165,14 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) return xp_raw_get_data(pool, addr); } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct +xsk_buff_pool *pool,u64 addr) { +if (!pool->tx_metadata_len) +return NULL ; + +return xp_raw_get_data (pool, addr) - pool->tx_metadata_len; } +static inline void xsk_buff_dma_sync_for_cpu(struct
xdp_buff*xdp, structxsk_buff_pool *pool) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);include/net/xdp_sock_drv.h +5
-0@@ -324,6 +332,11 @@ static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr) return NULL; } +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct +xsk_buff_pool *pool,u64 addr) { +return NULL ; +} +static inline void
xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp, struct xsk_buff_pool *pool){ } diff --gita/include/net/xsk_buff_pool.hb/include/net/xsk_buff_pool.hindex1985ffaf9b0c..97f5cc10d79e100644include/net/xsk_buff_pool.h +2
-0@@ -33,6 +33,7 @@ struct xdp_buff_xsk { };#define XSK_CHECK_PRIV_TYPE (t) BUILD_BUG_ON(sizeof(t) > offsetofend(struct xdp_buff_xsk, cb)) +#define XSK_TX_COMPL_FITS (t) BUILD_BUG_ON(sizeof(struct +xsk_tx_metadata_compl) > sizeof(t))struct xsk_dma_map { dma_addr_t *dma_pages;include/net/xsk_buff_pool.h +5
-0@@ -234,4 +235,9 @@ static inline u64 xp_get_handle(struct xdp_buff_xsk *xskb)return xskb->orig_addr + (offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT); } +static inline bool xp_tx_metadata_enabled (const struct xsk_buff_pool +*pool) { +return pool->tx_metadata_len >0 ; +} +#endif /* XSK_BUFF_POOL_H_ */ include/uapi/linux/if_xdp.h index renamed from include/uapi/linux/if_xdp.h +0
-0
2ecf79282c26..ecfd67988283100644include/uapi/linux/if_xdp.h +5
-0@@ -106,6 +106,43 @@ struct xdp_options { #defineXSK_UNALIGNED_BUF_ADDR_MASK \ ((1ULL <<XSK_UNALIGNED_BUF_OFFSET_SHIFT ) -1 ) +/* Request transmit timestamp. Upon completion, put it into +tx_timestamp +* field of struct xsk_tx_metadata. + */ +#define XDP_TX_METADATA_TIMESTAMP (1 << 0)[..]
Quoted 14 lines
Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macroinclude/uapi/linux/if_xdp.h struct xdp_options { · line 118
Quoted 7 lines
include/uapi/linux/if_xdp.h +7
-0+ +/* Request transmit checksum offload. Checksum start position and +offset +* are communicated via csum_start and csum_offset fields of struct +* xsk_tx_metadata. +*/ +#define XDP_TX_METADATA_CHECKSUM (1 << 1)Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macroQuoted 9 lines
include/uapi/linux/if_xdp.h struct xdp_options { · line 124
Quoted 6 lines
include/uapi/linux/if_xdp.h +6
-0+ +/* Force checksum calculation in software. Can be used for testing or +* working around potential HW issues. This option causes performance +* degradation and only works in XDP_COPY mode. +*/ +#define XDP_TX_METADATA_CHECKSUM_SW (1 << 2)Suggestion from checkpatch.pl:
CHECK: Prefer using the BIT macro
Quoted 1 line
Will do! Hopefully nothing breaks, let me check...
Yeah, looks like this part is not happy, doesn't look like BIT() is exported to UAPI, per:
check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
So I'll revert to << like in the rest of this file.
RE: [PATCH bpf-next v3 02/10] xsk: add TX timestamp and TX checksum offload support
Quoted 5 lines · Stanislav Fomichev
Yeah, looks like this part is not happy, doesn't look like
BIT()is exported to UAPI, per:check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
Noted.
Quoted 2 lines
So I'll revert to << like in the rest of this file.
Sure. I am ok to keep <<
PATCH v3 3/10 tools: ynl: print xsk-features from the sample
In reply to Stanislav FomichevRegenerate the userspace specs and print xsk-features bitmask.
--- tools/net/ynl/samples/netdev.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/net/ynl/samples/netdev.c +6 -0
@@ -44,6 +44,12 @@ static void netdev_print_device(struct netdev_dev_get_rsp *d, unsigned int op)printf (" %s" ,netdev_xdp_rx_metadata_str (1 << i)); } +printf (" xsk-features (%llx):" , d->xsk_features); +for (int i =0 ; d->xsk_features >1U << i; i++) { +if (d->xsk_features & (1U << i)) +printf (" %s" ,netdev_xsk_flags_str (1 << i)); + } +printf (" xdp-zc-max-segs=%u" , d->xdp_zc_max_segs); name =netdev_op_str (op);
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
PATCH v3 4/10 net/mlx5e: Implement AF_XDP TX timestamp and checksum offload
In reply to Stanislav FomichevTX timestamp:
- requires passing clock, not sure I'm passing the correct one (from cq->mdev), but the timestamp value looks convincing
TX checksum:
- looks like device does packet parsing (and doesn't accept custom start/offset), so I'm ignoring user offsets
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 72 ++++++++++++++++--- .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 11 ++- .../ethernet/mellanox/mlx5/core/en/xsk/tx.c | 17 ++++- .../net/ethernet/mellanox/mlx5/core/en_main.c | 1 + 5 files changed, 89 insertions(+), 16 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +3 -1
@@ -476,10 +476,12 @@ struct mlx5e_xdp_info_fifo {struct mlx5e_xdpsq ;struct mlx5e_xmit_data ; +struct xsk_tx_metadata ;typedef int (*mlx5e_fp_xmit_xdp_frame_check )(struct mlx5e_xdpsq *);typedef bool (*mlx5e_fp_xmit_xdp_frame )(struct mlx5e_xdpsq *,struct mlx5e_xmit_data *, -int ); +int , +struct xsk_tx_metadata *);struct mlx5e_xdpsq {/* data path */
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +61 -11
156 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h +8 -3
@@ -33,6 +33,7 @@#define __MLX5_EN_XDP_H__#include <linux/indirect_call_wrapper.h> +#include <net/xdp_sock.h> #include "en.h" #include "en/txrx.h"
@@ -82,7 +83,7 @@ enum mlx5e_xdp_xmit_mode {* num, page_1, page_2, ... , page_num. * * MLX5E_XDP_XMIT_MODE_XSK: -* none. +* frame.xsk_meta. */ #define MLX5E_XDP_FIFO_ENTRIES2DS_MAX_RATIO 4
@@ -97,6 +98,7 @@ union mlx5e_xdp_info {u8 num;struct page *page; } page; +struct xsk_tx_metadata_compl xsk_meta; };struct mlx5e_xsk_param ;
@@ -112,13 +114,16 @@ int mlx5e_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, u32 flags);extern const struct xdp_metadata_ops mlx5e_xdp_metadata_ops; +extern const struct xsk_tx_metadata_ops mlx5e_xsk_tx_metadata_ops; INDIRECT_CALLABLE_DECLARE(bool mlx5e_xmit_xdp_frame_mpwqe(struct mlx5e_xdpsq *sq,struct mlx5e_xmit_data *xdptxd, -int check_result)); +int check_result, +struct xsk_tx_metadata *meta)); INDIRECT_CALLABLE_DECLARE(bool mlx5e_xmit_xdp_frame(struct mlx5e_xdpsq *sq,struct mlx5e_xmit_data *xdptxd, -int check_result)); +int check_result, +struct xsk_tx_metadata *meta)); INDIRECT_CALLABLE_DECLARE(int mlx5e_xmit_xdp_frame_check_mpwqe(struct mlx5e_xdpsq *sq)); INDIRECT_CALLABLE_DECLARE(int mlx5e_xmit_xdp_frame_check(struct mlx5e_xdpsq *sq));
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c +16 -1
@@ -55,12 +55,16 @@ static void mlx5e_xsk_tx_post_err(struct mlx5e_xdpsq *sq, nopwqe =mlx5e_post_nop (&sq->wq, sq->sqn, &sq->pc);mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, *xdpi); +if (xp_tx_metadata_enabled (sq->xsk_pool)) +mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, + (union mlx5e_xdp_info ) { .xsk_meta = {} }); sq->doorbell_cseg = &nopwqe->ctrl; }bool mlx5e_xsk_tx (struct mlx5e_xdpsq *sq,unsigned int budget) {struct xsk_buff_pool *pool = sq->xsk_pool; +struct xsk_tx_metadata *meta =NULL ;union mlx5e_xdp_info xdpi;bool work_done = true;bool flush = false;
@@ -93,12 +97,13 @@ bool mlx5e_xsk_tx(struct mlx5e_xdpsq *sq, unsigned int budget) xdptxd.dma_addr =xsk_buff_raw_get_dma (pool, desc.addr); xdptxd.data =xsk_buff_raw_get_data (pool, desc.addr); xdptxd.len = desc.len; + meta =xsk_buff_get_metadata (pool, desc.addr);xsk_buff_raw_dma_sync_for_device (pool, xdptxd.dma_addr, xdptxd.len); ret =INDIRECT_CALL_2 (sq->xmit_xdp_frame, mlx5e_xmit_xdp_frame_mpwqe, mlx5e_xmit_xdp_frame, sq, &xdptxd, - check_result); + check_result, meta);if (unlikely (!ret)) {if (sq->mpwqe.wqe)mlx5e_xdp_mpwqe_complete (sq);
@@ -106,6 +111,16 @@ bool mlx5e_xsk_tx(struct mlx5e_xdpsq *sq, unsigned int budget)mlx5e_xsk_tx_post_err (sq, &xdpi); }else {mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, xdpi); +if (xp_tx_metadata_enabled (sq->xsk_pool)) { +struct xsk_tx_metadata_compl compl; + +xsk_tx_metadata_to_compl (meta, &compl); +XSK_TX_COMPL_FITS (void *); + +mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, + (union mlx5e_xdp_info ) + { .xsk_meta = compl }); + } } flush = true;
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -0
@@ -5096,6 +5096,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) netdev->netdev_ops = &mlx5e_netdev_ops; netdev->xdp_metadata_ops = &mlx5e_xdp_metadata_ops; + netdev->xsk_tx_metadata_ops = &mlx5e_xsk_tx_metadata_ops;mlx5e_dcbnl_build_netdev (netdev);
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
kernel test robot
build botRe: [PATCH bpf-next v3 04/10] net/mlx5e: Implement AF_XDP TX timestamp and checksum offload
kernel test robot noticed the following build errors:
Hi Stanislav,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Stanislav-Fomichev/xsk-Support-tx_metadata_len/20231004-040718 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20231003200522.1914523-5-sdf%40google.com patch subject: [PATCH bpf-next v3 04/10] net/mlx5e: Implement AF_XDP TX timestamp and checksum offload config: s390-defconfig (https://download.01.org/0day-ci/archive/20231005/[email protected]/config) compiler: s390-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c: In function 'mlx5e_xsk_tx':
>> drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c:117:33: error: implicit declaration of function 'xsk_tx_metadata_to_compl'; did you mean 'xsk_tx_metadata_complete'? [-Werror=implicit-function-declaration]
117 | xsk_tx_metadata_to_compl(meta, &compl);
| ^~~~~~~~~~~~~~~~~~~~~~~~
| xsk_tx_metadata_completecc1: some warnings being treated as errors
vim +117 drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c
63
64 bool mlx5e_xsk_tx(struct mlx5e_xdpsq *sq, unsigned int budget)
65 {
66 struct xsk_buff_pool *pool = sq->xsk_pool;
67 struct xsk_tx_metadata *meta = NULL;
68 union mlx5e_xdp_info xdpi;
69 bool work_done = true;
70 bool flush = false;
71
72 xdpi.mode = MLX5E_XDP_XMIT_MODE_XSK;
73
74 for (; budget; budget--) {
75 int check_result = INDIRECT_CALL_2(sq->xmit_xdp_frame_check,
76 mlx5e_xmit_xdp_frame_check_mpwqe,
77 mlx5e_xmit_xdp_frame_check,
78 sq);
79 struct mlx5e_xmit_data xdptxd = {};
80 struct xdp_desc desc;
81 bool ret;
82
83 if (unlikely(check_result < 0)) {
84 work_done = false;
85 break;
86 }
87
88 if (!xsk_tx_peek_desc(pool, &desc)) {
89 /* TX will get stuck until something wakes it up by
90 * triggering NAPI. Currently it's expected that the
91 * application calls sendto() if there are consumed, but
92 * not completed frames.
93 */
94 break;
95 }
96
97 xdptxd.dma_addr = xsk_buff_raw_get_dma(pool, desc.addr);
98 xdptxd.data = xsk_buff_raw_get_data(pool, desc.addr);
99 xdptxd.len = desc.len;
100 meta = xsk_buff_get_metadata(pool, desc.addr);
101
102 xsk_buff_raw_dma_sync_for_device(pool, xdptxd.dma_addr, xdptxd.len);
103
104 ret = INDIRECT_CALL_2(sq->xmit_xdp_frame, mlx5e_xmit_xdp_frame_mpwqe,
105 mlx5e_xmit_xdp_frame, sq, &xdptxd,
106 check_result, meta);
107 if (unlikely(!ret)) {
108 if (sq->mpwqe.wqe)
109 mlx5e_xdp_mpwqe_complete(sq);
110
111 mlx5e_xsk_tx_post_err(sq, &xdpi);
112 } else {
113 mlx5e_xdpi_fifo_push(&sq->db.xdpi_fifo, xdpi);
114 if (xp_tx_metadata_enabled(sq->xsk_pool)) {
115 struct xsk_tx_metadata_compl compl;
116
> 117 xsk_tx_metadata_to_compl(meta, &compl);Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v3 5/10 net: stmmac: Add Tx HWTS support to XDP ZC
In reply to Stanislav FomichevFrom: Song Yoong Siang <[email protected]>
This patch enables transmit hardware timestamp support to XDP zero copy via XDP Tx metadata framework.
This patchset is tested with tools/testing/selftests/bpf/xdp_hw_metadata on Intel Tiger Lake platform. Below are the test steps and results.
Command on DUT:
sudo ./xdp_hw_metadata <interface name>
sudo hwstamp_ctl -i <interface name> -t 1 -r 1
Command on Link Partner:
echo -n xdp | nc -u -q1 <destination IPv4 addr> 9091
Result:
xsk_ring_cons__peek: 1
0x562e3313b6d0: rx_desc[3]->addr=8e100 addr=8e100 comp_addr=8e100 No rx_hash err=-95
rx_timestamp: 1677763849292380229 (sec:1677763849.2924)
XDP RX-time: 1677763849292641940 (sec:1677763849.2926)
delta sec:0.0003 (261.711 usec)
AF_XDP time: 1677763849292666175 (sec:1677763849.2927)
delta sec:0.0000 (24.235 usec)
0x562e3313b6d0: ping-pong with csum=561c (want 08af)
csum_start=34 csum_offset=6 0x562e3313b6d0: complete tx idx=3 addr=3008
0x562e3313b6d0: tx_timestamp: 1677763849295700005 (sec:1677763849.2957) 0x562e3313b6d0: complete rx idx=131 addr=8e100
Additionally, to double confirm the rx_timestamp and tx_timestamp are taken from PTP Hardware Clock (PHC), we set the value of PHC to a specific value using tools/testing/selftests/ptp/testptp. Below are the test steps and results.
Command to set PHC to a specific value:
sudo ./testptp -d /dev/ptp2 -T 123000000
Result:
xsk_ring_cons__peek: 1
0x562e3313b6d0: rx_desc[7]->addr=9e100 addr=9e100 comp_addr=9e100 No rx_hash err=-95
rx_timestamp: 123000002731730589 (sec:123000002.7317)
XDP RX-time: 1677763869396644361 (sec:1677763869.3966)
delta sec:1554763866.6649 (1554763866664913.750 usec)
AF_XDP time: 1677763869396671376 (sec:1677763869.3967)
delta sec:0.0000 (27.015 usec)
0x562e3313b6d0: ping-pong with csum=561c (want d1bf)
csum_start=34 csum_offset=6 0x562e3313b6d0: complete tx idx=7 addr=7008 0x562e3313b6d0: tx_timestamp: 123000002735048790 (sec:123000002.7350) 0x562e3313b6d0: complete rx idx=135 addr=9e100
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 12 ++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 63 ++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +12 -0
@@ -51,6 +51,7 @@ struct stmmac_tx_info {bool last_segment;bool is_jumbo;enum stmmac_txbuf_type buf_type; +struct xsk_tx_metadata_compl xsk_meta; };#define STMMAC_TBS_AVAIL BIT(0)
@@ -100,6 +101,17 @@ struct stmmac_xdp_buff {struct dma_desc *ndesc; }; +struct stmmac_metadata_request { +struct stmmac_priv *priv; +struct dma_desc *tx_desc; +bool *set_ic; +}; + +struct stmmac_xsk_tx_complete { +struct stmmac_priv *priv; +struct dma_desc *desc; +}; +struct stmmac_rx_queue {u32 rx_count_frames;u32 queue_index;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +62 -1
106 lines not on this page · raw message
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
kernel test robot
build botRe: [PATCH bpf-next v3 05/10] net: stmmac: Add Tx HWTS support to XDP ZC
kernel test robot noticed the following build errors:
Hi Stanislav,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Stanislav-Fomichev/xsk-Support-tx_metadata_len/20231004-040718 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20231003200522.1914523-6-sdf%40google.com patch subject: [PATCH bpf-next v3 05/10] net: stmmac: Add Tx HWTS support to XDP ZC config: riscv-defconfig (https://download.01.org/0day-ci/archive/20231005/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: In function 'stmmac_xdp_xmit_zc':
>> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2554:17: error: implicit declaration of function 'xsk_tx_metadata_to_compl'; did you mean 'xsk_tx_metadata_complete'? [-Werror=implicit-function-declaration]
2554 | xsk_tx_metadata_to_compl(meta, &tx_q->tx_skbuff_dma[entry].xsk_meta);
| ^~~~~~~~~~~~~~~~~~~~~~~~
| xsk_tx_metadata_completecc1: some warnings being treated as errors
vim +2554 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
2464
2465 static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
2466 {
2467 struct netdev_queue *nq = netdev_get_tx_queue(priv->dev, queue);
2468 struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
2469 struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[queue];
2470 struct xsk_buff_pool *pool = tx_q->xsk_pool;
2471 unsigned int entry = tx_q->cur_tx;
2472 struct dma_desc *tx_desc = NULL;
2473 struct xdp_desc xdp_desc;
2474 bool work_done = true;
2475 u32 tx_set_ic_bit = 0;
2476 unsigned long flags;
2477
2478 /* Avoids TX time-out as we are sharing with slow path */
2479 txq_trans_cond_update(nq);
2480
2481 budget = min(budget, stmmac_tx_avail(priv, queue));
2482
2483 while (budget-- > 0) {
2484 struct stmmac_metadata_request meta_req;
2485 struct xsk_tx_metadata *meta = NULL;
2486 dma_addr_t dma_addr;
2487 bool set_ic;
2488
2489 /* We are sharing with slow path and stop XSK TX desc submission when
2490 * available TX ring is less than threshold.
2491 */
2492 if (unlikely(stmmac_tx_avail(priv, queue) < STMMAC_TX_XSK_AVAIL) ||
2493 !netif_carrier_ok(priv->dev)) {
2494 work_done = false;
2495 break;
2496 }
2497
2498 if (!xsk_tx_peek_desc(pool, &xdp_desc))
2499 break;
2500
2501 if (likely(priv->extend_desc))
2502 tx_desc = (struct dma_desc *)(tx_q->dma_etx + entry);
2503 else if (tx_q->tbs & STMMAC_TBS_AVAIL)
2504 tx_desc = &tx_q->dma_entx[entry].basic;
2505 else
2506 tx_desc = tx_q->dma_tx + entry;
2507
2508 dma_addr = xsk_buff_raw_get_dma(pool, xdp_desc.addr);
2509 meta = xsk_buff_get_metadata(pool, xdp_desc.addr);
2510 xsk_buff_raw_dma_sync_for_device(pool, dma_addr, xdp_desc.len);
2511
2512 tx_q->tx_skbuff_dma[entry].buf_type = STMMAC_TXBUF_T_XSK_TX;
2513
2514 /* To return XDP buffer to XSK pool, we simple call
2515 * xsk_tx_completed(), so we don't need to fill up
2516 * 'buf' and 'xdpf'.
2517 */
2518 tx_q->tx_skbuff_dma[entry].buf = 0;
2519 tx_q->xdpf[entry] = NULL;
2520
2521 tx_q->tx_skbuff_dma[entry].map_as_page = false;
2522 tx_q->tx_skbuff_dma[entry].len = xdp_desc.len;
2523 tx_q->tx_skbuff_dma[entry].last_segment = true;
2524 tx_q->tx_skbuff_dma[entry].is_jumbo = false;
2525
2526 stmmac_set_desc_addr(priv, tx_desc, dma_addr);
2527
2528 tx_q->tx_count_frames++;
2529
2530 if (!priv->tx_coal_frames[queue])
2531 set_ic = false;
2532 else if (tx_q->tx_count_frames % priv->tx_coal_frames[queue] == 0)
2533 set_ic = true;
2534 else
2535 set_ic = false;
2536
2537 meta_req.priv = priv;
2538 meta_req.tx_desc = tx_desc;
2539 meta_req.set_ic = &set_ic;
2540 xsk_tx_metadata_request(meta, &stmmac_xsk_tx_metadata_ops, &meta_req);
2541
2542 if (set_ic) {
2543 tx_q->tx_count_frames = 0;
2544 stmmac_set_tx_ic(priv, tx_desc);
2545 tx_set_ic_bit++;
2546 }
2547
2548 stmmac_prepare_tx_desc(priv, tx_desc, 1, xdp_desc.len,
2549 true, priv->mode, true, true,
2550 xdp_desc.len);
2551
2552 stmmac_enable_dma_transmission(priv, priv->ioaddr);
2553
> 2554 xsk_tx_metadata_to_compl(meta, &tx_q->tx_skbuff_dma[entry].xsk_meta);
2555
2556 tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, priv->dma_conf.dma_tx_size);
2557 entry = tx_q->cur_tx;
2558 }
2559 flags = u64_stats_update_begin_irqsave(&txq_stats->syncp);
2560 txq_stats->tx_set_ic_bit += tx_set_ic_bit;
2561 u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
2562
2563 if (tx_desc) {
2564 stmmac_flush_tx_descriptors(priv, queue);
2565 xsk_tx_release(pool);
2566 }
2567
2568 /* Return true if all of the 3 conditions are met
2569 * a) TX Budget is still available
2570 * b) work_done = true when XSK TX desc peek is empty (no more
2571 * pending XSK TX for transmission)
2572 */
2573 return !!budget && work_done;
2574 }
2575
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH bpf-next v3 05/10] net: stmmac: Add Tx HWTS support to XDP ZC
Quoted 19 lines · kernel test robot
Hi Stanislav,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Stanislav-Fomichev/xsk-Support-tx_metadata_len/20231004-040718 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20231003200522.1914523-6-sdf%40google.com patch subject: [PATCH bpf-next v3 05/10] net: stmmac: Add Tx HWTS support to XDP ZC config: riscv-defconfig (https://download.01.org/0day-ci/archive/20231005/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 8 lines
All errors (new ones prefixed by >>):
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: In function 'stmmac_xdp_xmit_zc':Quoted 1 line
Quoted 1 line
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2554:17: error: implicit declaration of function 'xsk_tx_metadata_to_compl'; did you mean 'xsk_tx_metadata_complete'? [-Werror=implicit-function-declaration]2554 | xsk_tx_metadata_to_compl(meta, &tx_q->tx_skbuff_dma[entry].xsk_meta); | ^~~~~~~~~~~~~~~~~~~~~~~~ | xsk_tx_metadata_completecc1: some warnings being treated as errors
Missing "static inline xsk_tx_metadata_to_compl" for !CONFIG_XDP_SOCKETS. Will fix in the patch where I add xsk_tx_metadata_to_compl...
kernel test robot
build botRe: [PATCH bpf-next v3 05/10] net: stmmac: Add Tx HWTS support to XDP ZC
In reply to Stanislav Fomichevkernel test robot noticed the following build errors:
Hi Stanislav,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Stanislav-Fomichev/xsk-Support-tx_metadata_len/20231004-040718 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20231003200522.1914523-6-sdf%40google.com patch subject: [PATCH bpf-next v3 05/10] net: stmmac: Add Tx HWTS support to XDP ZC config: riscv-rv32_defconfig (https://download.01.org/0day-ci/archive/20231006/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231006/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2554:3: error: call to undeclared function 'xsk_tx_metadata_to_compl'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
2554 | xsk_tx_metadata_to_compl(meta, &tx_q->tx_skbuff_dma[entry].xsk_meta);
| ^ drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2554:3: note: did you mean 'xsk_tx_metadata_complete'? include/net/xdp_sock.h:185:20: note: 'xsk_tx_metadata_complete' declared here
185 | static inline void xsk_tx_metadata_complete(struct xsk_tx_metadata_compl *compl,
| ^
1 error generated.
vim +/xsk_tx_metadata_to_compl +2554 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
2464
2465 static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
2466 {
2467 struct netdev_queue *nq = netdev_get_tx_queue(priv->dev, queue);
2468 struct stmmac_tx_queue *tx_q = &priv->dma_conf.tx_queue[queue];
2469 struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[queue];
2470 struct xsk_buff_pool *pool = tx_q->xsk_pool;
2471 unsigned int entry = tx_q->cur_tx;
2472 struct dma_desc *tx_desc = NULL;
2473 struct xdp_desc xdp_desc;
2474 bool work_done = true;
2475 u32 tx_set_ic_bit = 0;
2476 unsigned long flags;
2477
2478 /* Avoids TX time-out as we are sharing with slow path */
2479 txq_trans_cond_update(nq);
2480
2481 budget = min(budget, stmmac_tx_avail(priv, queue));
2482
2483 while (budget-- > 0) {
2484 struct stmmac_metadata_request meta_req;
2485 struct xsk_tx_metadata *meta = NULL;
2486 dma_addr_t dma_addr;
2487 bool set_ic;
2488
2489 /* We are sharing with slow path and stop XSK TX desc submission when
2490 * available TX ring is less than threshold.
2491 */
2492 if (unlikely(stmmac_tx_avail(priv, queue) < STMMAC_TX_XSK_AVAIL) ||
2493 !netif_carrier_ok(priv->dev)) {
2494 work_done = false;
2495 break;
2496 }
2497
2498 if (!xsk_tx_peek_desc(pool, &xdp_desc))
2499 break;
2500
2501 if (likely(priv->extend_desc))
2502 tx_desc = (struct dma_desc *)(tx_q->dma_etx + entry);
2503 else if (tx_q->tbs & STMMAC_TBS_AVAIL)
2504 tx_desc = &tx_q->dma_entx[entry].basic;
2505 else
2506 tx_desc = tx_q->dma_tx + entry;
2507
2508 dma_addr = xsk_buff_raw_get_dma(pool, xdp_desc.addr);
2509 meta = xsk_buff_get_metadata(pool, xdp_desc.addr);
2510 xsk_buff_raw_dma_sync_for_device(pool, dma_addr, xdp_desc.len);
2511
2512 tx_q->tx_skbuff_dma[entry].buf_type = STMMAC_TXBUF_T_XSK_TX;
2513
2514 /* To return XDP buffer to XSK pool, we simple call
2515 * xsk_tx_completed(), so we don't need to fill up
2516 * 'buf' and 'xdpf'.
2517 */
2518 tx_q->tx_skbuff_dma[entry].buf = 0;
2519 tx_q->xdpf[entry] = NULL;
2520
2521 tx_q->tx_skbuff_dma[entry].map_as_page = false;
2522 tx_q->tx_skbuff_dma[entry].len = xdp_desc.len;
2523 tx_q->tx_skbuff_dma[entry].last_segment = true;
2524 tx_q->tx_skbuff_dma[entry].is_jumbo = false;
2525
2526 stmmac_set_desc_addr(priv, tx_desc, dma_addr);
2527
2528 tx_q->tx_count_frames++;
2529
2530 if (!priv->tx_coal_frames[queue])
2531 set_ic = false;
2532 else if (tx_q->tx_count_frames % priv->tx_coal_frames[queue] == 0)
2533 set_ic = true;
2534 else
2535 set_ic = false;
2536
2537 meta_req.priv = priv;
2538 meta_req.tx_desc = tx_desc;
2539 meta_req.set_ic = &set_ic;
2540 xsk_tx_metadata_request(meta, &stmmac_xsk_tx_metadata_ops, &meta_req);
2541
2542 if (set_ic) {
2543 tx_q->tx_count_frames = 0;
2544 stmmac_set_tx_ic(priv, tx_desc);
2545 tx_set_ic_bit++;
2546 }
2547
2548 stmmac_prepare_tx_desc(priv, tx_desc, 1, xdp_desc.len,
2549 true, priv->mode, true, true,
2550 xdp_desc.len);
2551
2552 stmmac_enable_dma_transmission(priv, priv->ioaddr);
2553
> 2554 xsk_tx_metadata_to_compl(meta, &tx_q->tx_skbuff_dma[entry].xsk_meta);
2555
2556 tx_q->cur_tx = STMMAC_GET_ENTRY(tx_q->cur_tx, priv->dma_conf.dma_tx_size);
2557 entry = tx_q->cur_tx;
2558 }
2559 flags = u64_stats_update_begin_irqsave(&txq_stats->syncp);
2560 txq_stats->tx_set_ic_bit += tx_set_ic_bit;
2561 u64_stats_update_end_irqrestore(&txq_stats->syncp, flags);
2562
2563 if (tx_desc) {
2564 stmmac_flush_tx_descriptors(priv, queue);
2565 xsk_tx_release(pool);
2566 }
2567
2568 /* Return true if all of the 3 conditions are met
2569 * a) TX Budget is still available
2570 * b) work_done = true when XSK TX desc peek is empty (no more
2571 * pending XSK TX for transmission)
2572 */
2573 return !!budget && work_done;
2574 }
2575
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v3 6/10 selftests/xsk: Support tx_metadata_len
In reply to Stanislav FomichevAdd new config field and propagate to umem registration setsockopt.
--- tools/testing/selftests/bpf/xsk.c | 3 +++ tools/testing/selftests/bpf/xsk.h | 1 + 2 files changed, 4 insertions(+)
tools/testing/selftests/bpf/xsk.c +3 -0
@@ -115,6 +115,7 @@ static void xsk_set_umem_config(struct xsk_umem_config *cfg, cfg->frame_size =XSK_UMEM__DEFAULT_FRAME_SIZE ; cfg->frame_headroom =XSK_UMEM__DEFAULT_FRAME_HEADROOM ; cfg->flags =XSK_UMEM__DEFAULT_FLAGS ; + cfg->tx_metadata_len =0 ;return ; }
@@ -123,6 +124,7 @@ static void xsk_set_umem_config(struct xsk_umem_config *cfg, cfg->frame_size = usr_cfg->frame_size; cfg->frame_headroom = usr_cfg->frame_headroom; cfg->flags = usr_cfg->flags; + cfg->tx_metadata_len = usr_cfg->tx_metadata_len; } static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
@@ -252,6 +254,7 @@ int xsk_umem__create(struct xsk_umem **umem_ptr, void *umem_area, mr.chunk_size = umem->config.frame_size; mr.headroom = umem->config.frame_headroom; mr.flags = umem->config.flags; + mr.tx_metadata_len = umem->config.tx_metadata_len; err =setsockopt (umem->fd,SOL_XDP ,XDP_UMEM_REG , &mr,sizeof (mr));if (err) {
tools/testing/selftests/bpf/xsk.h +1 -0
@@ -200,6 +200,7 @@ struct xsk_umem_config {__u32 frame_size;__u32 frame_headroom;__u32 flags; +__u32 tx_metadata_len; };int xsk_attach_xdp_program (struct bpf_program *prog,int ifindex,u32 xdp_flags);
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
PATCH v3 7/10 selftests/bpf: Add csum helpers
In reply to Stanislav FomichevChecksum helpers will be used to calculate pseudo-header checksum in AF_XDP metadata selftests.
The helpers are mirroring existing kernel ones:
- csum_tcpudp_magic : IPv4 pseudo header csum
- csum_ipv6_magic : IPv6 pseudo header csum
- csum_fold : fold csum and do one's complement
--- tools/testing/selftests/bpf/network_helpers.h | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)
tools/testing/selftests/bpf/network_helpers.h +43 -0
@@ -70,4 +70,47 @@ struct nstoken;*/ struct nstoken *open_netns (const char *name);void close_netns (struct nstoken *token); + +static __u16 csum_fold (__u32 csum) +{ + csum = (csum &0xffff ) + (csum >>16 ); + csum = (csum &0xffff ) + (csum >>16 ); + +return (__u16 )~csum; +} + +static inline __sum16 csum_tcpudp_magic (__be32 saddr,__be32 daddr, +__u32 len,__u8 proto, +__wsum csum) +{ +__u64 s = csum; + + s += (__u32 )saddr; + s += (__u32 )daddr; + s +=htons (proto + len); + s = (s &0xffffffff ) + (s >>32 ); + s = (s &0xffffffff ) + (s >>32 ); + +return csum_fold ((__u32 )s); +} + +static inline __sum16 csum_ipv6_magic (const struct in6_addr *saddr, +const struct in6_addr *daddr, +__u32 len,__u8 proto, +__wsum csum) +{ +__u64 s = csum; +int i; + +for (i =0 ; i <4 ; i++) + s += (__u32 )saddr->s6_addr32[i]; +for (i =0 ; i <4 ; i++) + s += (__u32 )daddr->s6_addr32[i]; + s +=htons (proto + len); + s = (s &0xffffffff ) + (s >>32 ); + s = (s &0xffffffff ) + (s >>32 ); + +return csum_fold ((__u32 )s); +} +#endif
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
PATCH v3 8/10 selftests/bpf: Add TX side to xdp_metadata
In reply to Stanislav FomichevRequest TX timestamp and make sure it's not empty. Request TX checksum offload (SW-only) and make sure it's resolved to the correct one.
--- .../selftests/bpf/prog_tests/xdp_metadata.c | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_metadata.c +28 -3
@@ -57,6 +57,7 @@ static int open_xsk(int ifindex, struct xsk *xsk) .comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS, .frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE, .flags = XDP_UMEM_UNALIGNED_CHUNK_FLAG, + .tx_metadata_len = sizeof(struct xsk_tx_metadata), };__u32 idx;u64 addr;
@@ -138,6 +139,7 @@ static void ip_csum(struct iphdr *iph)static int generate_packet (struct xsk *xsk,__u16 dst_port) { +struct xsk_tx_metadata *meta;struct xdp_desc *tx_desc;struct udphdr *udph;struct ethhdr *eth;
@@ -151,10 +153,14 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port)return -1 ; tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx); - tx_desc->addr = idx % (UMEM_NUM /2 ) *UMEM_FRAME_SIZE ; + tx_desc->addr = idx % (UMEM_NUM /2 ) *UMEM_FRAME_SIZE +sizeof (struct xsk_tx_metadata );printf ("%p: tx_desc[%u]->addr=%llx\n" , xsk, idx, tx_desc->addr); data =xsk_umem__get_data (xsk->umem_area, tx_desc->addr); + meta = data -sizeof (struct xsk_tx_metadata ); +memset (meta,0 ,sizeof (*meta)); + meta->flags =XDP_TX_METADATA_TIMESTAMP ; + eth = data; iph = (void *)(eth +1 ); udph = (void *)(iph +1 );
@@ -178,11 +184,17 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port) udph->source =htons (AF_XDP_SOURCE_PORT ); udph->dest =htons (dst_port); udph->len =htons (sizeof (*udph) +UDP_PAYLOAD_BYTES ); - udph->check =0 ; + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 );memset (udph +1 ,0xAA ,UDP_PAYLOAD_BYTES ); + meta->flags |=XDP_TX_METADATA_CHECKSUM |XDP_TX_METADATA_CHECKSUM_SW ; + meta->csum_start =sizeof (*eth) +sizeof (*iph); + meta->csum_offset = offsetof(struct udphdr , check); + tx_desc->len =sizeof (*eth) +sizeof (*iph) +sizeof (*udph) +UDP_PAYLOAD_BYTES ; + tx_desc->options |=XDP_TX_METADATA ;xsk_ring_prod__submit (&xsk->tx,1 ); ret =sendto (xsk_socket__fd (xsk->socket),NULL ,0 ,MSG_DONTWAIT ,NULL ,0 );
@@ -194,13 +206,21 @@ static int generate_packet(struct xsk *xsk, __u16 dst_port)static void complete_tx (struct xsk *xsk) { -__u32 idx; +struct xsk_tx_metadata *meta;__u64 addr; +void *data; +__u32 idx;if (ASSERT_EQ (xsk_ring_cons__peek (&xsk->comp,1 , &idx),1 ,"xsk_ring_cons__peek" )) { addr = *xsk_ring_cons__comp_addr (&xsk->comp, idx);printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); + + data =xsk_umem__get_data (xsk->umem_area, addr); + meta = data -sizeof (struct xsk_tx_metadata ); + +ASSERT_NEQ (meta->completion.tx_timestamp,0 ,"tx_timestamp" ); +xsk_ring_cons__release (&xsk->comp,1 ); } }
@@ -221,6 +241,7 @@ static int verify_xsk_metadata(struct xsk *xsk)const struct xdp_desc *rx_desc;struct pollfd fds = {};struct xdp_meta *meta; +struct udphdr *udph;struct ethhdr *eth;struct iphdr *iph;__u64 comp_addr;
@@ -257,6 +278,7 @@ static int verify_xsk_metadata(struct xsk *xsk)ASSERT_EQ (eth->h_proto,htons (ETH_P_IP ),"eth->h_proto" ); iph = (void *)(eth +1 );ASSERT_EQ ((int )iph->version,4 ,"iph->version" ); + udph = (void *)(iph +1 );/* custom metadata */
@@ -270,6 +292,9 @@ static int verify_xsk_metadata(struct xsk *xsk)ASSERT_EQ (meta->rx_hash_type,0 ,"rx_hash_type" ); +/* checksum offload */ +ASSERT_EQ (udph->check,0x1c72 ,"csum" ); +xsk_ring_cons__release (&xsk->rx,1 );refill_rx (xsk, comp_addr);
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
PATCH v3 9/10 selftests/bpf: Add TX side to xdp_hw_metadata
In reply to Stanislav FomichevWhen we get a packet on port 9091, we swap src/dst and send it out. At this point we also request the timestamp and checksum offloads.
Checksum offload is verified by looking at the tcpdump on the other side. The tool prints pseudo-header csum and the final one it expects. The final checksum actually matches the incoming packets checksum because we only flip the src/dst and don't change the payload.
Some other related changes:
- switched to zerocopy mode by default; new flag can be used to force old behavior
- request fixed tx_metadata_len headroom
- some other small fixes (umem size, fill idx+i, etc)
mvbz3:~# ./xdp_hw_metadata eth3 ... 0x1062cb8: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100 rx_hash: 0x2E1B50B9 with RSS type:0x2A rx_timestamp: 1691436369532047139 (sec:1691436369.5320) XDP RX-time: 1691436369261756803 (sec:1691436369.2618) delta sec:-0.2703 (-270290.336 usec) AF_XDP time: 1691436369261878839 (sec:1691436369.2619) delta sec:0.0001 (122.036 usec) 0x1062cb8: ping-pong with csum=3b8e (want de7e) csum_start=54 csum_offset=6 0x1062cb8: complete tx idx=0 addr=10 0x1062cb8: tx_timestamp: 1691436369598419505 (sec:1691436369.5984) 0x1062cb8: complete rx idx=128 addr=80100
mvbz4:~# nc -Nu -q1 ${MVBZ3_LINK_LOCAL_IP}%eth3 9091mvbz4:~# tcpdump -vvx -i eth3 udp
tcpdump: listening on eth3, link-type EN10MB (Ethernet), snapshot length 262144 bytes
12:26:09.301074 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1087.55807 > fe80::1270:fdff:fe48:1077.9091: [bad udp cksum 0x3b8e -> 0xde7e!] UDP, length 3
0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000
0x0010: 1270 fdff fe48 1087 fe80 0000 0000 0000
0x0020: 1270 fdff fe48 1077 d9ff 2383 000b 3b8e
0x0030: 7864 70
12:26:09.301976 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1077.9091 > fe80::1270:fdff:fe48:1087.55807: [udp sum ok] UDP, length 3
0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000
0x0010: 1270 fdff fe48 1077 fe80 0000 0000 0000
0x0020: 1270 fdff fe48 1087 2383 d9ff 000b de7e
0x0030: 7864 70--- tools/testing/selftests/bpf/xdp_hw_metadata.c | 202 +++++++++++++++++- 1 file changed, 192 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/xdp_hw_metadata.c +192 -10
@@ -10,7 +10,9 @@* - rx_hash * * TX: -* - TBD +* - UDP 9091 packets trigger TX reply +* - TX HW timestamp is requested and reported back upon completion +* - TX checksum is requested */ #include <test_progs.h>
@@ -24,14 +26,17 @@#include <linux/net_tstamp.h> #include <linux/udp.h> #include <linux/sockios.h> +#include <linux/if_xdp.h> #include <sys/mman.h> #include <net/if.h> #include <poll.h> #include <time.h> +#include <unistd.h> +#include <libgen.h> #include "xdp_metadata.h" -#define UMEM_NUM 16 +#define UMEM_NUM 256#define UMEM_FRAME_SIZE XSK_UMEM__DEFAULT_FRAME_SIZE#define UMEM_SIZE (UMEM_FRAME_SIZE * UMEM_NUM)#define XDP_FLAGS (XDP_FLAGS_DRV_MODE | XDP_FLAGS_REPLACE)
@@ -51,22 +56,24 @@ struct xsk *rx_xsk;const char *ifname;int ifindex;int rxq; +bool skip_tx;void test__fail (void ) {/* for network_helpers.c */ } -static int open_xsk (int ifindex,struct xsk *xsk,__u32 queue_id) +static int open_xsk (int ifindex,struct xsk *xsk,__u32 queue_id,int flags) {int mmap_flags =MAP_PRIVATE |MAP_ANONYMOUS |MAP_NORESERVE ;const struct xsk_socket_config socket_config = { .rx_size =XSK_RING_PROD__DEFAULT_NUM_DESCS , .tx_size =XSK_RING_PROD__DEFAULT_NUM_DESCS , - .bind_flags =XDP_COPY , + .bind_flags = flags, };const struct xsk_umem_config umem_config = { .fill_size =XSK_RING_PROD__DEFAULT_NUM_DESCS , .comp_size =XSK_RING_CONS__DEFAULT_NUM_DESCS , .frame_size =XSK_UMEM__DEFAULT_FRAME_SIZE , - .flags =XDP_UMEM_UNALIGNED_CHUNK_FLAG , + .flags =XSK_UMEM__DEFAULT_FLAGS , + .tx_metadata_len =sizeof (struct xsk_tx_metadata ), };__u32 idx;u64 addr;
@@ -108,7 +115,7 @@ static int open_xsk(int ifindex, struct xsk *xsk, __u32 queue_id)for (i =0 ; i <UMEM_NUM /2 ; i++) { addr = (UMEM_NUM /2 + i) *UMEM_FRAME_SIZE ;printf ("%p: rx_desc[%d] -> %lx\n" , xsk, i, addr); - *xsk_ring_prod__fill_addr (&xsk->fill, i) = addr; + *xsk_ring_prod__fill_addr (&xsk->fill, idx + i) = addr; }xsk_ring_prod__submit (&xsk->fill, ret);
@@ -129,12 +136,22 @@ static void refill_rx(struct xsk *xsk, __u64 addr)__u32 idx;if (xsk_ring_prod__reserve (&xsk->fill,1 , &idx) ==1 ) { -printf ("%p: complete idx=%u addr=%llx\n" , xsk, idx, addr); +printf ("%p: complete rx idx=%u addr=%llx\n" , xsk, idx, addr); *xsk_ring_prod__fill_addr (&xsk->fill, idx) = addr;xsk_ring_prod__submit (&xsk->fill,1 ); } } +static int kick_tx (struct xsk *xsk) +{ +return sendto (xsk_socket__fd (xsk->socket),NULL ,0 ,MSG_DONTWAIT ,NULL ,0 ); +} + +static int kick_rx (struct xsk *xsk) +{ +return recvfrom (xsk_socket__fd (xsk->socket),NULL ,0 ,MSG_DONTWAIT ,NULL ,NULL ); +} +#define NANOSEC_PER_SEC 1000000000/* 10^9 */ static __u64 gettime (clockid_t clock_id) {
@@ -228,6 +245,117 @@ static void verify_skb_metadata(int fd)printf ("skb hwtstamp is not found!\n" ); } +static bool complete_tx (struct xsk *xsk) +{ +struct xsk_tx_metadata *meta; +__u64 addr; +void *data; +__u32 idx; + +if (!xsk_ring_cons__peek (&xsk->comp,1 , &idx)) +return false; + + addr = *xsk_ring_cons__comp_addr (&xsk->comp, idx); + data =xsk_umem__get_data (xsk->umem_area, addr); + meta = data -sizeof (struct xsk_tx_metadata ); + +printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); +printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, + meta->completion.tx_timestamp, + (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +xsk_ring_cons__release (&xsk->comp,1 ); + +return true; +} + +#define swap (a, b, len) do { \ + for (int i = 0; i < len; i++) { \ + __u8 tmp = ((__u8 *)a)[i]; \ + ((__u8 *)a)[i] = ((__u8 *)b)[i]; \ + ((__u8 *)b)[i] = tmp; \ + } \ +} while (0) + +static void ping_pong (struct xsk *xsk,void *rx_packet) +{ +struct xsk_tx_metadata *meta; +struct ipv6hdr *ip6h =NULL ; +struct iphdr *iph =NULL ; +struct xdp_desc *tx_desc; +struct udphdr *udph; +struct ethhdr *eth; +__sum16 want_csum; +void *data; +__u32 idx; +int ret; +int len; + + ret =xsk_ring_prod__reserve (&xsk->tx,1 , &idx); +if (ret !=1 ) { +printf ("%p: failed to reserve tx slot\n" , xsk); +return ; + } + + tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx); + tx_desc->addr = idx % (UMEM_NUM /2 ) *UMEM_FRAME_SIZE +sizeof (struct xsk_tx_metadata ); + data =xsk_umem__get_data (xsk->umem_area, tx_desc->addr); + + meta = data -sizeof (struct xsk_tx_metadata ); +memset (meta,0 ,sizeof (*meta)); + meta->flags =XDP_TX_METADATA_TIMESTAMP ; + + eth = rx_packet; + +if (eth->h_proto ==htons (ETH_P_IP )) { + iph = (void *)(eth +1 ); + udph = (void *)(iph +1 ); + }else if (eth->h_proto ==htons (ETH_P_IPV6 )) { + ip6h = (void *)(eth +1 ); + udph = (void *)(ip6h +1 ); + }else { +printf ("%p: failed to detect IP version for ping pong %04x\n" , xsk, eth->h_proto); +xsk_ring_prod__cancel (&xsk->tx,1 ); +return ; + } + + len =ETH_HLEN ; +if (ip6h) + len +=sizeof (*ip6h) +ntohs (ip6h->payload_len); +if (iph) + len +=ntohs (iph->tot_len); + +swap (eth->h_dest, eth->h_source,ETH_ALEN ); +if (iph) +swap (&iph->saddr, &iph->daddr,4 ); +else +swap (&ip6h->saddr, &ip6h->daddr,16 ); +swap (&udph->source, &udph->dest,2 ); + + want_csum = udph->check; +if (ip6h) + udph->check = ~csum_ipv6_magic (&ip6h->saddr, &ip6h->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); +else + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); + + meta->flags |=XDP_TX_METADATA_CHECKSUM ; +if (iph) + meta->csum_start =sizeof (*eth) +sizeof (*iph); +else + meta->csum_start =sizeof (*eth) +sizeof (*ip6h); + meta->csum_offset = offsetof(struct udphdr , check); + +printf ("%p: ping-pong with csum=%04x (want %04x) csum_start=%d csum_offset=%d\n" , + xsk,ntohs (udph->check),ntohs (want_csum), meta->csum_start, meta->csum_offset); + +memcpy (data, rx_packet, len);/* don't share umem chunk for simplicity */ + tx_desc->options |=XDP_TX_METADATA ; + tx_desc->len = len; + +xsk_ring_prod__submit (&xsk->tx,1 ); +} +static int verify_metadata (struct xsk *rx_xsk,int rxq,int server_fd,clockid_t clock_id) {const struct xdp_desc *rx_desc;
@@ -250,6 +378,13 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_twhile (true) { errno =0 ; + +for (i =0 ; i < rxq; i++) { + ret =kick_rx (&rx_xsk[i]); +if (ret) +printf ("kick_rx ret=%d\n" , ret); + } + ret =poll (fds, rxq +1 ,1000 ); printf("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n", ret, errno, bpf_obj->bss->pkts_skip,
@@ -280,6 +415,22 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t xsk, idx, rx_desc->addr, addr, comp_addr);verify_xdp_metadata (xsk_umem__get_data (xsk->umem_area, addr), clock_id); + +if (!skip_tx) { +/* mirror the packet back */ +ping_pong (xsk,xsk_umem__get_data (xsk->umem_area, addr)); + + ret =kick_tx (xsk); +if (ret) +printf ("kick_tx ret=%d\n" , ret); + +for (int j =0 ; j <500 ; j++) { +if (complete_tx (xsk)) +break ; +usleep (10 *1000 ); + } + } +xsk_ring_cons__release (&xsk->rx,1 );refill_rx (xsk, comp_addr); }
@@ -404,21 +555,52 @@ static void timestamping_enable(int fd, int val)error (1 , errno,"setsockopt(SO_TIMESTAMPING)" ); } +static void usage (const char *prog) +{ +fprintf (stderr, +"usage: %s [OPTS] <ifname>\n" +"OPTS:\n" +" -r don't generate AF_XDP reply (rx metadata only)\n" +" -c run in copy mode\n" , + prog); +} +int main (int argc,char *argv[]) { +int bind_flags =XDP_USE_NEED_WAKEUP |XDP_ZEROCOPY ;clockid_t clock_id =CLOCK_TAI ;int server_fd =-1 ; +int opt;int ret;int i;struct bpf_program *prog; -if (argc !=2 ) { +while ((opt =getopt (argc, argv,"rc" )) !=-1 ) { +switch (opt) { +case 'r' : + skip_tx = true; +break ; +case 'c' : + bind_flags =XDP_USE_NEED_WAKEUP |XDP_COPY ; +break ; +default : +usage (basename (argv[0 ])); +return 1 ; + } + } + +if (argc <2 ) {fprintf (stderr,"pass device name\n" );return -1 ; } - ifname = argv[1 ]; +if (optind >= argc) { +usage (basename (argv[0 ])); +return 1 ; + } + + ifname = argv[optind]; ifindex =if_nametoindex (ifname); rxq =rxq_num (ifname);
@@ -432,7 +614,7 @@ int main(int argc, char *argv[])for (i =0 ; i < rxq; i++) {printf ("open_xsk(%s, %p, %d)\n" , ifname, &rx_xsk[i], i); - ret =open_xsk (ifindex, &rx_xsk[i], i); + ret =open_xsk (ifindex, &rx_xsk[i], i, bind_flags);if (ret)error (1 , -ret,"open_xsk" );
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog
Jesper Dangaard Brouer
maintainerRe: [PATCH bpf-next v3 09/10] selftests/bpf: Add TX side to xdp_hw_metadata
Quoted 14 lines · Stanislav Fomichev
When we get a packet on port 9091, we swap src/dst and send it out. At this point we also request the timestamp and checksum offloads.
Checksum offload is verified by looking at the tcpdump on the other side. The tool prints pseudo-header csum and the final one it expects. The final checksum actually matches the incoming packets checksum because we only flip the src/dst and don't change the payload.
Some other related changes:
- switched to zerocopy mode by default; new flag can be used to force old behavior
- request fixedtx_metadata_lenheadroom
- some other small fixes (umem size, fill idx+i, etc)
Quoted 6 lines
mvbz3:~# ./xdp_hw_metadata eth3 ... 0x1062cb8: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100 rx_hash: 0x2E1B50B9 with RSS type:0x2A rx_timestamp: 1691436369532047139 (sec:1691436369.5320) XDP RX-time: 1691436369261756803 (sec:1691436369.2618) delta sec:-0.2703 (-270290.336 usec)
I guess system time isn't configured to be in sync with NIC HW time, as delta is a negative offset.
Quoted 1 line
AF_XDPtime: 1691436369261878839 (sec:1691436369.2619) delta sec:0.0001 (122.036 usec)
The AF_XDP time is also software system time and compared to XDP RX-time, it shows a delta of 122 usec. This number indicate to me that the CPU is likely configured with power saving sleep states.
Quoted 3 lines
0x1062cb8: ping-pong with csum=3b8e (want de7e) csum_start=54 csum_offset=60x1062cb8: complete tx idx=0 addr=100x1062cb8:tx_timestamp: 1691436369598419505 (sec:1691436369.5984)
Could we add something that we can relate tx_timestamp to?
Like we do with the other delta calculations, as it helps us to understand/validate if the number we get back is sane. Like negative offset aboves tells us that system time sync isn't configured, and that system have configures C-states.
I suggest delta comparing "tx_timestamp" to "rx_timestamp", as they are the same clock domain. It will tell us the total time spend from HW RX to HW TX, counting all the time used by software "ping-pong".
1691436369.5984-1691436369.5320 = 0.0664 sec = 66.4 ms
When implementing this, it could be (1) practical to store the "rx_timestamp" in the metadata area of the completion packet, or (2) should we have a mechanism for external storage that can be keyed on the umem "addr"?
Quoted 38 lines
0x1062cb8: complete rx idx=128 addr=80100mvbz4:~# nc -Nu -q1 ${MVBZ3_LINK_LOCAL_IP}%eth3 9091mvbz4:~# tcpdump -vvx -i eth3 udp tcpdump: listening on eth3, link-type EN10MB (Ethernet), snapshot length 262144 bytes 12:26:09.301074 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1087.55807 > fe80::1270:fdff:fe48:1077.9091: [bad udp cksum 0x3b8e -> 0xde7e!] UDP, length 3 0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1087 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1077 d9ff 2383 000b 3b8e 0x0030: 7864 70 12:26:09.301976 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1077.9091 > fe80::1270:fdff:fe48:1087.55807: [udp sum ok] UDP, length 3 0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1077 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1087 2383 d9ff 000b de7e 0x0030: 7864 70Signed-off-by Stanislav Fomichev <[email protected]>--- tools/testing/selftests/bpf/xdp_hw_metadata.c | 202 +++++++++++++++++- 1 file changed, 192 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/xdp_hw_metadata.c +3
-1@@ -10,7 +10,9 @@* - rx_hash * * TX: -* - TBD +* - UDP 9091 packets trigger TX reply +* - TX HW timestamp is requested and reported back upon completion +* - TX checksum is requested */ #include <test_progs.h> @@ -24,14 +26,17 @@
[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -51,22 +56,24 @@ struct xsk *rx_xsk;
[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -129,12 +136,22 @@ static void refill_rx(struct xsk *xsk, __u64 addr)
[...]
Quoted 139 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +121
-0@@ -228,6 +245,117 @@ static void verify_skb_metadata(int fd)printf ("skb hwtstamp is not found!\n" ); } +static bool complete_tx (struct xsk *xsk) +{ +struct xsk_tx_metadata *meta; +__u64 addr; +void *data; +__u32 idx; + +if (!xsk_ring_cons__peek (&xsk->comp,1 , &idx)) +return false; + + addr = *xsk_ring_cons__comp_addr (&xsk->comp, idx); + data =xsk_umem__get_data (xsk->umem_area, addr); + meta = data -sizeof (struct xsk_tx_metadata ); + +printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); +printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, + meta->completion.tx_timestamp, + (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +xsk_ring_cons__release (&xsk->comp,1 ); + +return true; +} + +#define swap (a, b, len) do { \ + for (int i = 0; i < len; i++) { \ + __u8 tmp = ((__u8 *)a)[i]; \ + ((__u8 *)a)[i] = ((__u8 *)b)[i]; \ + ((__u8 *)b)[i] = tmp; \ + } \ +} while (0) + +static void ping_pong (struct xsk *xsk,void *rx_packet) +{ +struct xsk_tx_metadata *meta; +struct ipv6hdr *ip6h =NULL ; +struct iphdr *iph =NULL ; +struct xdp_desc *tx_desc; +struct udphdr *udph; +struct ethhdr *eth; +__sum16 want_csum; +void *data; +__u32 idx; +int ret; +int len; + + ret =xsk_ring_prod__reserve (&xsk->tx,1 , &idx); +if (ret !=1 ) { +printf ("%p: failed to reserve tx slot\n" , xsk); +return ; + } + + tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx); + tx_desc->addr = idx % (UMEM_NUM /2 ) *UMEM_FRAME_SIZE +sizeof (struct xsk_tx_metadata ); + data =xsk_umem__get_data (xsk->umem_area, tx_desc->addr); + + meta = data -sizeof (struct xsk_tx_metadata ); +memset (meta,0 ,sizeof (*meta)); + meta->flags =XDP_TX_METADATA_TIMESTAMP ; + + eth = rx_packet; + +if (eth->h_proto ==htons (ETH_P_IP )) { + iph = (void *)(eth +1 ); + udph = (void *)(iph +1 ); + }else if (eth->h_proto ==htons (ETH_P_IPV6 )) { + ip6h = (void *)(eth +1 ); + udph = (void *)(ip6h +1 ); + }else { +printf ("%p: failed to detect IP version for ping pong %04x\n" , xsk, eth->h_proto); +xsk_ring_prod__cancel (&xsk->tx,1 ); +return ; + } + + len =ETH_HLEN ; +if (ip6h) + len +=sizeof (*ip6h) +ntohs (ip6h->payload_len); +if (iph) + len +=ntohs (iph->tot_len); + +swap (eth->h_dest, eth->h_source,ETH_ALEN ); +if (iph) +swap (&iph->saddr, &iph->daddr,4 ); +else +swap (&ip6h->saddr, &ip6h->daddr,16 ); +swap (&udph->source, &udph->dest,2 ); + + want_csum = udph->check; +if (ip6h) + udph->check = ~csum_ipv6_magic (&ip6h->saddr, &ip6h->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); +else + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); + + meta->flags |=XDP_TX_METADATA_CHECKSUM ; +if (iph) + meta->csum_start =sizeof (*eth) +sizeof (*iph); +else + meta->csum_start =sizeof (*eth) +sizeof (*ip6h); + meta->csum_offset = offsetof(struct udphdr , check); + +printf ("%p: ping-pong with csum=%04x (want %04x) csum_start=%d csum_offset=%d\n" , + xsk,ntohs (udph->check),ntohs (want_csum), meta->csum_start, meta->csum_offset); + +memcpy (data, rx_packet, len);/* don't share umem chunk for simplicity */ + tx_desc->options |=XDP_TX_METADATA ; + tx_desc->len = len; + +xsk_ring_prod__submit (&xsk->tx,1 ); +} +static int verify_metadata (struct xsk *rx_xsk,int rxq,int server_fd,clockid_t clock_id) {const struct xdp_desc *rx_desc;@@ -250,6 +378,13 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_twhile (true) { errno =0 ; + +for (i =0 ; i < rxq; i++) { + ret =kick_rx (&rx_xsk[i]); +if (ret) +printf ("kick_rx ret=%d\n" , ret); + } + ret =poll (fds, rxq +1 ,1000 ); printf("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n", ret, errno, bpf_obj->bss->pkts_skip,@@ -280,6 +415,22 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t xsk, idx, rx_desc->addr, addr, comp_addr);verify_xdp_metadata (xsk_umem__get_data (xsk->umem_area, addr), clock_id); + +if (!skip_tx) { +/* mirror the packet back */
tools/testing/selftests/bpf/xdp_hw_metadata.c static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t · line 430
Quoted 10 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +10
-0+ping_pong (xsk,xsk_umem__get_data (xsk->umem_area, addr)); + + ret =kick_tx (xsk); +if (ret) +printf ("kick_tx ret=%d\n" , ret); + +for (int j =0 ; j <500 ; j++) { +if (complete_tx (xsk)) +break ; +usleep (10 *1000 );
I don't fully follow why we need this usleep here.
Quoted 7 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +3
-0+ } + } +xsk_ring_cons__release (&xsk->rx,1 );refill_rx (xsk, comp_addr); }@@ -404,21 +555,52 @@ static void timestamping_enable(int fd, int val)
Re: [PATCH bpf-next v3 09/10] selftests/bpf: Add TX side to xdp_hw_metadata
Quoted 24 lines · Jesper Dangaard Brouer
Quoted 14 lines · Stanislav Fomichev
When we get a packet on port 9091, we swap src/dst and send it out. At this point we also request the timestamp and checksum offloads.
Checksum offload is verified by looking at the tcpdump on the other side. The tool prints pseudo-header csum and the final one it expects. The final checksum actually matches the incoming packets checksum because we only flip the src/dst and don't change the payload.
Some other related changes:
- switched to zerocopy mode by default; new flag can be used to force old behavior
- request fixedtx_metadata_lenheadroom
- some other small fixes (umem size, fill idx+i, etc)Quoted 6 lines
mvbz3:~# ./xdp_hw_metadata eth3 ... 0x1062cb8: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100 rx_hash: 0x2E1B50B9 with RSS type:0x2A rx_timestamp: 1691436369532047139 (sec:1691436369.5320) XDP RX-time: 1691436369261756803 (sec:1691436369.2618) delta sec:-0.2703 (-270290.336 usec)
Quoted 7 lines
I guess system time isn't configured to be in sync with NIC HW time, as delta is a negative offset.
Quoted 1 line
AF_XDPtime: 1691436369261878839 (sec:1691436369.2619) delta sec:0.0001 (122.036 usec)The
AF_XDPtime is also software system time and compared to XDP RX-time, it shows a delta of 122 usec. This number indicate to me that the CPU is likely configured with power saving sleep states.
Yes, I don't do any synchronization and don't disable the sleep states.
Quoted 15 lines
Quoted 3 lines
0x1062cb8: ping-pong with csum=3b8e (want de7e) csum_start=54 csum_offset=60x1062cb8: complete tx idx=0 addr=100x1062cb8:tx_timestamp: 1691436369598419505 (sec:1691436369.5984)Could we add something that we can relate
tx_timestampto?Like we do with the other delta calculations, as it helps us to understand/validate if the number we get back is sane. Like negative offset aboves tells us that system time sync isn't configured, and that system have configures C-states.
I suggest delta comparing "
tx_timestamp" to "rx_timestamp", as they are the same clock domain. It will tell us the total time spend from HW RX to HW TX, counting all the time used by software "ping-pong".
Quoted 6 lines
1691436369.5984-1691436369.5320 = 0.0664 sec = 66.4 ms
When implementing this, it could be (1) practical to store the "
rx_timestamp" in the metadata area of the completion packet, or (2) should we have a mechanism for external storage that can be keyed on the umem "addr"?
Sounds good. I can probably just store last rx_timestamp somewhere in the global var and do a delta on tx? Since the test is single threaded and sequential, not sure we need the mechanism to pass the tstamp around. LMK if you disagree and I'm missing something.
Quoted 183 lines
Quoted 37 lines
0x1062cb8: complete rx idx=128 addr=80100mvbz4:~# nc -Nu -q1 ${MVBZ3_LINK_LOCAL_IP}%eth3 9091mvbz4:~# tcpdump -vvx -i eth3 udp tcpdump: listening on eth3, link-type EN10MB (Ethernet), snapshot length 262144 bytes 12:26:09.301074 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1087.55807 > fe80::1270:fdff:fe48:1077.9091: [bad udp cksum 0x3b8e -> 0xde7e!] UDP, length 3 0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1087 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1077 d9ff 2383 000b 3b8e 0x0030: 7864 70 12:26:09.301976 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1077.9091 > fe80::1270:fdff:fe48:1087.55807: [udp sum ok] UDP, length 3 0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1077 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1087 2383 d9ff 000b de7e 0x0030: 7864 70Signed-off-by Stanislav Fomichev <[email protected]>--- tools/testing/selftests/bpf/xdp_hw_metadata.c | 202 +++++++++++++++++- 1 file changed, 192 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/xdp_hw_metadata.c +3
-1@@ -10,7 +10,9 @@* - rx_hash * * TX: -* - TBD +* - UDP 9091 packets trigger TX reply +* - TX HW timestamp is requested and reported back upon completion +* - TX checksum is requested */ #include <test_progs.h> @@ -24,14 +26,17 @@[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -51,22 +56,24 @@ struct xsk *rx_xsk;[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -129,12 +136,22 @@ static void refill_rx(struct xsk *xsk, __u64 addr)[...]
Quoted 141 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +125
-0@@ -228,6 +245,117 @@ static void verify_skb_metadata(int fd)printf ("skb hwtstamp is not found!\n" ); } +static bool complete_tx (struct xsk *xsk) +{ +struct xsk_tx_metadata *meta; +__u64 addr; +void *data; +__u32 idx; + +if (!xsk_ring_cons__peek (&xsk->comp,1 , &idx)) +return false; + + addr = *xsk_ring_cons__comp_addr (&xsk->comp, idx); + data =xsk_umem__get_data (xsk->umem_area, addr); + meta = data -sizeof (struct xsk_tx_metadata ); + +printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); +printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, + meta->completion.tx_timestamp, + (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +xsk_ring_cons__release (&xsk->comp,1 ); + +return true; +} + +#define swap (a, b, len) do { \ + for (int i = 0; i < len; i++) { \ + __u8 tmp = ((__u8 *)a)[i]; \ + ((__u8 *)a)[i] = ((__u8 *)b)[i]; \ + ((__u8 *)b)[i] = tmp; \ + } \ +} while (0) + +static void ping_pong (struct xsk *xsk,void *rx_packet) +{ +struct xsk_tx_metadata *meta; +struct ipv6hdr *ip6h =NULL ; +struct iphdr *iph =NULL ; +struct xdp_desc *tx_desc; +struct udphdr *udph; +struct ethhdr *eth; +__sum16 want_csum; +void *data; +__u32 idx; +int ret; +int len; + + ret =xsk_ring_prod__reserve (&xsk->tx,1 , &idx); +if (ret !=1 ) { +printf ("%p: failed to reserve tx slot\n" , xsk); +return ; + } + + tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx); + tx_desc->addr = idx % (UMEM_NUM /2 ) *UMEM_FRAME_SIZE +sizeof (struct xsk_tx_metadata ); + data =xsk_umem__get_data (xsk->umem_area, tx_desc->addr); + + meta = data -sizeof (struct xsk_tx_metadata ); +memset (meta,0 ,sizeof (*meta)); + meta->flags =XDP_TX_METADATA_TIMESTAMP ; + + eth = rx_packet; + +if (eth->h_proto ==htons (ETH_P_IP )) { + iph = (void *)(eth +1 ); + udph = (void *)(iph +1 ); + }else if (eth->h_proto ==htons (ETH_P_IPV6 )) { + ip6h = (void *)(eth +1 ); + udph = (void *)(ip6h +1 ); + }else { +printf ("%p: failed to detect IP version for ping pong %04x\n" , xsk, eth->h_proto); +xsk_ring_prod__cancel (&xsk->tx,1 ); +return ; + } + + len =ETH_HLEN ; +if (ip6h) + len +=sizeof (*ip6h) +ntohs (ip6h->payload_len); +if (iph) + len +=ntohs (iph->tot_len); + +swap (eth->h_dest, eth->h_source,ETH_ALEN ); +if (iph) +swap (&iph->saddr, &iph->daddr,4 ); +else +swap (&ip6h->saddr, &ip6h->daddr,16 ); +swap (&udph->source, &udph->dest,2 ); + + want_csum = udph->check; +if (ip6h) + udph->check = ~csum_ipv6_magic (&ip6h->saddr, &ip6h->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); +else + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); + + meta->flags |=XDP_TX_METADATA_CHECKSUM ; +if (iph) + meta->csum_start =sizeof (*eth) +sizeof (*iph); +else + meta->csum_start =sizeof (*eth) +sizeof (*ip6h); + meta->csum_offset = offsetof(struct udphdr , check); + +printf ("%p: ping-pong with csum=%04x (want %04x) csum_start=%d csum_offset=%d\n" , + xsk,ntohs (udph->check),ntohs (want_csum), meta->csum_start, meta->csum_offset); + +memcpy (data, rx_packet, len);/* don't share umem chunk for simplicity */ + tx_desc->options |=XDP_TX_METADATA ; + tx_desc->len = len; + +xsk_ring_prod__submit (&xsk->tx,1 ); +} +static int verify_metadata (struct xsk *rx_xsk,int rxq,int server_fd,clockid_t clock_id) {const struct xdp_desc *rx_desc;@@ -250,6 +378,13 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_twhile (true) { errno =0 ; + +for (i =0 ; i < rxq; i++) { + ret =kick_rx (&rx_xsk[i]); +if (ret) +printf ("kick_rx ret=%d\n" , ret); + } + ret =poll (fds, rxq +1 ,1000 ); printf("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n", ret, errno, bpf_obj->bss->pkts_skip,@@ -280,6 +415,22 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t xsk, idx, rx_desc->addr, addr, comp_addr);verify_xdp_metadata (xsk_umem__get_data (xsk->umem_area, addr), clock_id); + +if (!skip_tx) { +/* mirror the packet back */ +ping_pong (xsk,xsk_umem__get_data (xsk->umem_area, addr)); + + ret =kick_tx (xsk); +if (ret)
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t · line 430
Quoted 6 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +6
-0+printf ("kick_tx ret=%d\n" , ret); + +for (int j =0 ; j <500 ; j++) { +if (complete_tx (xsk)) +break ; +usleep (10 *1000 );I don't fully follow why we need this usleep here.
To avoid the busypoll here (since we don't care too much about perf in the test). But I agree, should be ok to drop, will do.
Re: [PATCH bpf-next v3 09/10] selftests/bpf: Add TX side to xdp_hw_metadata
Quoted 57 lines · Stanislav Fomichev
Quoted 24 lines · Jesper Dangaard Brouer
Quoted 14 lines · Stanislav Fomichev
When we get a packet on port 9091, we swap src/dst and send it out. At this point we also request the timestamp and checksum offloads.
Checksum offload is verified by looking at the tcpdump on the other side. The tool prints pseudo-header csum and the final one it expects. The final checksum actually matches the incoming packets checksum because we only flip the src/dst and don't change the payload.
Some other related changes:
- switched to zerocopy mode by default; new flag can be used to force old behavior
- request fixedtx_metadata_lenheadroom
- some other small fixes (umem size, fill idx+i, etc)Quoted 6 lines
mvbz3:~# ./xdp_hw_metadata eth3 ... 0x1062cb8: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100 rx_hash: 0x2E1B50B9 with RSS type:0x2A rx_timestamp: 1691436369532047139 (sec:1691436369.5320) XDP RX-time: 1691436369261756803 (sec:1691436369.2618) delta sec:-0.2703 (-270290.336 usec)Quoted 7 lines
I guess system time isn't configured to be in sync with NIC HW time, as delta is a negative offset.
Quoted 1 line
AF_XDPtime: 1691436369261878839 (sec:1691436369.2619) delta sec:0.0001 (122.036 usec)The
AF_XDPtime is also software system time and compared to XDP RX-time, it shows a delta of 122 usec. This number indicate to me that the CPU is likely configured with power saving sleep states.Yes, I don't do any synchronization and don't disable the sleep states.
Quoted 15 lines
Quoted 3 lines
0x1062cb8: ping-pong with csum=3b8e (want de7e) csum_start=54 csum_offset=60x1062cb8: complete tx idx=0 addr=100x1062cb8:tx_timestamp: 1691436369598419505 (sec:1691436369.5984)Could we add something that we can relate
tx_timestampto?Like we do with the other delta calculations, as it helps us to understand/validate if the number we get back is sane. Like negative offset aboves tells us that system time sync isn't configured, and that system have configures C-states.
I suggest delta comparing "
tx_timestamp" to "rx_timestamp", as they are the same clock domain. It will tell us the total time spend from HW RX to HW TX, counting all the time used by software "ping-pong".Quoted 6 lines
1691436369.5984-1691436369.5320 = 0.0664 sec = 66.4 ms
When implementing this, it could be (1) practical to store the "
rx_timestamp" in the metadata area of the completion packet, or (2) should we have a mechanism for external storage that can be keyed on the umem "addr"?
Quoted 4 lines
Sounds good. I can probably just store last
rx_timestampsomewhere in the global var and do a delta on tx? Since the test is single threaded and sequential, not sure we need the mechanism to pass the tstamp around. LMK if you disagree and I'm missing something.
I ended up reshuffling current code a bit to basically use clock tai as a reference for every line. Feels like its a bit simpler when everything is referenced against the same clock?
For RX part, I rename existing XDP/AF_XDP to HW/SW and dump them both relative to tai.
0x195d1f0: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100
rx_hash: 0xEE2BBD59 with RSS type:0x2A rx_timestamp: 1696969312125212179 (sec:1696969312.1252) HW RX-time: 1696969312125212179 (sec:1696969312.1252) to CLOCK_TAI delta sec:-0.1339 (-133862.968 usec) SW RX-time: 1696969311991283421 (sec:1696969311.9913) to CLOCK_TAI delta sec:0.0001 (65.790 usec) 0x195d1f0: ping-pong with csum=3b8e (want de5f) csum_start=54 csum_offset=6 0x195d1f0: complete tx idx=0 addr=8 tx_timestamp: 1696969312152959759 (sec:1696969312.1530) SW RX-time: 1696969311991283421 (sec:1696969311.9913) to CLOCK_TAI delta sec:0.0101 (10139.862 usec) HW RX-time: 1696969312125212179 (sec:1696969312.1252) to HW TX-complete-time delta sec:0.0277 (27747.580 usec) HW TX-complete-time: 1696969312152959759 (sec:1696969312.1530) to CLOCK_TAI delta sec:-0.1515 (-151536.476 usec)
For TX part, I add a bunch of reference points:
1) SW RX-time (meta->xdp_timestamp) vs CLOCK_TAI (aka tai-at-complete-time)
2) HW RX-time (meta->rx_timestamp) vs HW TX-complete-time (new af_xdp timestamp)
3) HW TX-complete-time vs CLOCK_TAI
What do you think? See the patch below.
Note: all 3 of the above should, in theory, be more or less constant (with irq moderation / etc disabled). But for me on mlx5 (2) they are not and looks like hw rx timestamp jitters a quite a bit. I don't have a clue rigt now on why, will try to take a separate look, but it's unrelated to the tx side.
tools/testing/selftests/bpf/xdp_hw_metadata.c +34 -21
@@ -57,6 +57,8 @@ const char *ifname;int ifindex;int rxq;bool skip_tx; +__u64 last_hw_rx_timestamp; +__u64 last_sw_rx_timestamp;void test__fail (void ) {/* for network_helpers.c */ }
@@ -167,6 +169,16 @@ static __u64 gettime(clockid_t clock_id)return (__u64 ) t.tv_sec *NANOSEC_PER_SEC + t.tv_nsec; } +static void print_tstamp_delta (const char *name,const char *refname,__u64 tstamp,__u64 reference) +{ +__s64 delta = (__s64 )reference - (__s64 )tstamp; + +printf ("%s: %llu (sec:%0.4f) to %s delta sec:%0.4f (%0.3f usec)\n" , + name, tstamp, (double )tstamp /NANOSEC_PER_SEC , refname, + (double )delta /NANOSEC_PER_SEC , + (double )delta /1000 ); +} +static void verify_xdp_metadata (void *data,clockid_t clock_id) {struct xdp_meta *meta;
@@ -182,22 +194,15 @@ static void verify_xdp_metadata(void *data, clockid_t clock_id)printf ("rx_timestamp: %llu (sec:%0.4f)\n" , meta->rx_timestamp, (double )meta->rx_timestamp /NANOSEC_PER_SEC );if (meta->rx_timestamp) { -__u64 usr_clock =gettime (clock_id); -__u64 xdp_clock = meta->xdp_timestamp; -__s64 delta_X = xdp_clock - meta->rx_timestamp; -__s64 delta_X2U = usr_clock - xdp_clock; - -printf ("XDP RX-time: %llu (sec:%0.4f) delta sec:%0.4f (%0.3f usec)\n" , - xdp_clock, (double )xdp_clock /NANOSEC_PER_SEC , - (double )delta_X /NANOSEC_PER_SEC , - (double )delta_X /1000 ); - -printf ("AF_XDP time: %llu (sec:%0.4f) delta sec:%0.4f (%0.3f usec)\n" , - usr_clock, (double )usr_clock /NANOSEC_PER_SEC , - (double )delta_X2U /NANOSEC_PER_SEC , - (double )delta_X2U /1000 ); - } +__u64 ref_tstamp =gettime (clock_id); + +/* store received timestamps to calculate a delta at tx */ + last_hw_rx_timestamp = meta->rx_timestamp; + last_sw_rx_timestamp = meta->xdp_timestamp; +print_tstamp_delta ("HW RX-time" ,"CLOCK_TAI" , meta->rx_timestamp, ref_tstamp); +print_tstamp_delta ("SW RX-time" ,"CLOCK_TAI" , meta->xdp_timestamp, ref_tstamp); + } }static void verify_skb_metadata (int fd)
@@ -245,7 +250,7 @@ static void verify_skb_metadata(int fd)printf ("skb hwtstamp is not found!\n" ); } -static bool complete_tx (struct xsk *xsk) +static bool complete_tx (struct xsk *xsk,clockid_t clock_id) {struct xsk_tx_metadata *meta;__u64 addr;
@@ -260,9 +265,17 @@ static bool complete_tx(struct xsk *xsk) meta = data -sizeof (struct xsk_tx_metadata );printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); -printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, - meta->completion.tx_timestamp, + +printf ("tx_timestamp: %llu (sec:%0.4f)\n" , meta->completion.tx_timestamp, (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +if (meta->completion.tx_timestamp) { +__u64 ref_tstamp =gettime (clock_id); + +print_tstamp_delta ("HW TX-complete-time" ,"CLOCK_TAI" , meta->completion.tx_timestamp, ref_tstamp); +print_tstamp_delta ("SW RX-time" ,"CLOCK_TAI" , last_sw_rx_timestamp, ref_tstamp); +print_tstamp_delta ("HW RX-time" ,"HW TX-complete-time" , last_hw_rx_timestamp, meta->completion.tx_timestamp); + } +xsk_ring_cons__release (&xsk->comp,1 );return true;
@@ -276,7 +289,7 @@ static bool complete_tx(struct xsk *xsk) } \ }while (0 ) -static void ping_pong(struct xsk *xsk, void *rx_packet) +static void ping_pong(struct xsk *xsk, void *rx_packet, clockid_t clock_id) {struct xsk_tx_metadata *meta;struct ipv6hdr *ip6h =NULL ;
@@ -418,14 +431,14 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_tif (!skip_tx) {/* mirror the packet back */ -ping_pong (xsk,xsk_umem__get_data (xsk->umem_area, addr)); +ping_pong (xsk,xsk_umem__get_data (xsk->umem_area, addr), clock_id); ret =kick_tx (xsk);if (ret)printf ("kick_tx ret=%d\n" , ret);for (int j =0 ; j <500 ; j++) { -if (complete_tx (xsk)) +if (complete_tx (xsk, clock_id))break ;usleep (10 *1000 ); }
Quoted 192 lines
Quoted 183 lines
Quoted 37 lines
0x1062cb8: complete rx idx=128 addr=80100mvbz4:~# nc -Nu -q1 ${MVBZ3_LINK_LOCAL_IP}%eth3 9091mvbz4:~# tcpdump -vvx -i eth3 udp tcpdump: listening on eth3, link-type EN10MB (Ethernet), snapshot length 262144 bytes 12:26:09.301074 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1087.55807 > fe80::1270:fdff:fe48:1077.9091: [bad udp cksum 0x3b8e -> 0xde7e!] UDP, length 3 0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1087 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1077 d9ff 2383 000b 3b8e 0x0030: 7864 70 12:26:09.301976 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17) payload length: 11) fe80::1270:fdff:fe48:1077.9091 > fe80::1270:fdff:fe48:1087.55807: [udp sum ok] UDP, length 3 0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1077 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1087 2383 d9ff 000b de7e 0x0030: 7864 70Signed-off-by Stanislav Fomichev <[email protected]>--- tools/testing/selftests/bpf/xdp_hw_metadata.c | 202 +++++++++++++++++- 1 file changed, 192 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/xdp_hw_metadata.c +3
-1@@ -10,7 +10,9 @@* - rx_hash * * TX: -* - TBD +* - UDP 9091 packets trigger TX reply +* - TX HW timestamp is requested and reported back upon completion +* - TX checksum is requested */ #include <test_progs.h> @@ -24,14 +26,17 @@[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -51,22 +56,24 @@ struct xsk *rx_xsk;[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -129,12 +136,22 @@ static void refill_rx(struct xsk *xsk, __u64 addr)[...]
Quoted 141 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +125
-0@@ -228,6 +245,117 @@ static void verify_skb_metadata(int fd)printf ("skb hwtstamp is not found!\n" ); } +static bool complete_tx (struct xsk *xsk) +{ +struct xsk_tx_metadata *meta; +__u64 addr; +void *data; +__u32 idx; + +if (!xsk_ring_cons__peek (&xsk->comp,1 , &idx)) +return false; + + addr = *xsk_ring_cons__comp_addr (&xsk->comp, idx); + data =xsk_umem__get_data (xsk->umem_area, addr); + meta = data -sizeof (struct xsk_tx_metadata ); + +printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); +printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, + meta->completion.tx_timestamp, + (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +xsk_ring_cons__release (&xsk->comp,1 ); + +return true; +} + +#define swap (a, b, len) do { \ + for (int i = 0; i < len; i++) { \ + __u8 tmp = ((__u8 *)a)[i]; \ + ((__u8 *)a)[i] = ((__u8 *)b)[i]; \ + ((__u8 *)b)[i] = tmp; \ + } \ +} while (0) + +static void ping_pong (struct xsk *xsk,void *rx_packet) +{ +struct xsk_tx_metadata *meta; +struct ipv6hdr *ip6h =NULL ; +struct iphdr *iph =NULL ; +struct xdp_desc *tx_desc; +struct udphdr *udph; +struct ethhdr *eth; +__sum16 want_csum; +void *data; +__u32 idx; +int ret; +int len; + + ret =xsk_ring_prod__reserve (&xsk->tx,1 , &idx); +if (ret !=1 ) { +printf ("%p: failed to reserve tx slot\n" , xsk); +return ; + } + + tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx); + tx_desc->addr = idx % (UMEM_NUM /2 ) *UMEM_FRAME_SIZE +sizeof (struct xsk_tx_metadata ); + data =xsk_umem__get_data (xsk->umem_area, tx_desc->addr); + + meta = data -sizeof (struct xsk_tx_metadata ); +memset (meta,0 ,sizeof (*meta)); + meta->flags =XDP_TX_METADATA_TIMESTAMP ; + + eth = rx_packet; + +if (eth->h_proto ==htons (ETH_P_IP )) { + iph = (void *)(eth +1 ); + udph = (void *)(iph +1 ); + }else if (eth->h_proto ==htons (ETH_P_IPV6 )) { + ip6h = (void *)(eth +1 ); + udph = (void *)(ip6h +1 ); + }else { +printf ("%p: failed to detect IP version for ping pong %04x\n" , xsk, eth->h_proto); +xsk_ring_prod__cancel (&xsk->tx,1 ); +return ; + } + + len =ETH_HLEN ; +if (ip6h) + len +=sizeof (*ip6h) +ntohs (ip6h->payload_len); +if (iph) + len +=ntohs (iph->tot_len); + +swap (eth->h_dest, eth->h_source,ETH_ALEN ); +if (iph) +swap (&iph->saddr, &iph->daddr,4 ); +else +swap (&ip6h->saddr, &ip6h->daddr,16 ); +swap (&udph->source, &udph->dest,2 ); + + want_csum = udph->check; +if (ip6h) + udph->check = ~csum_ipv6_magic (&ip6h->saddr, &ip6h->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); +else + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); + + meta->flags |=XDP_TX_METADATA_CHECKSUM ; +if (iph) + meta->csum_start =sizeof (*eth) +sizeof (*iph); +else + meta->csum_start =sizeof (*eth) +sizeof (*ip6h); + meta->csum_offset = offsetof(struct udphdr , check); + +printf ("%p: ping-pong with csum=%04x (want %04x) csum_start=%d csum_offset=%d\n" , + xsk,ntohs (udph->check),ntohs (want_csum), meta->csum_start, meta->csum_offset); + +memcpy (data, rx_packet, len);/* don't share umem chunk for simplicity */ + tx_desc->options |=XDP_TX_METADATA ; + tx_desc->len = len; + +xsk_ring_prod__submit (&xsk->tx,1 ); +} +static int verify_metadata (struct xsk *rx_xsk,int rxq,int server_fd,clockid_t clock_id) {const struct xdp_desc *rx_desc;@@ -250,6 +378,13 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_twhile (true) { errno =0 ; + +for (i =0 ; i < rxq; i++) { + ret =kick_rx (&rx_xsk[i]); +if (ret) +printf ("kick_rx ret=%d\n" , ret); + } + ret =poll (fds, rxq +1 ,1000 ); printf("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n", ret, errno, bpf_obj->bss->pkts_skip,@@ -280,6 +415,22 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t xsk, idx, rx_desc->addr, addr, comp_addr);verify_xdp_metadata (xsk_umem__get_data (xsk->umem_area, addr), clock_id); + +if (!skip_tx) { +/* mirror the packet back */ +ping_pong (xsk,xsk_umem__get_data (xsk->umem_area, addr)); + + ret =kick_tx (xsk); +if (ret)Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t · line 430
Quoted 6 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +6
-0+printf ("kick_tx ret=%d\n" , ret); + +for (int j =0 ; j <500 ; j++) { +if (complete_tx (xsk)) +break ; +usleep (10 *1000 );I don't fully follow why we need this usleep here.
Quoted 2 lines
To avoid the busypoll here (since we don't care too much about perf in the test). But I agree, should be ok to drop, will do.
I take that back, I have to keep it. Otherwise I don't have a good bound on when to stop/abort when waiting for completion. (and the number of loops needs to go from 500 to unsure-how-many).
RE: [PATCH bpf-next v3 09/10] selftests/bpf: Add TX side to xdp_hw_metadata
Quoted 91 lines · Stanislav Fomichev
Quoted 18 lines · Stanislav Fomichev
Quoted 17 lines · Jesper Dangaard Brouer
Quoted 14 lines · Stanislav Fomichev
When we get a packet on port 9091, we swap src/dst and send it out. At this point we also request the timestamp and checksum offloads.
Checksum offload is verified by looking at the tcpdump on the other side. The tool prints pseudo-header csum and the final one it expects. The final checksum actually matches the incoming packets checksum because we only flip the src/dst and don't change the payload.
Some other related changes:
- switched to zerocopy mode by default; new flag can be used to force old behavior
- request fixedtx_metadata_lenheadroom
- some other small fixes (umem size, fill idx+i, etc)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mvbz3:~# ./xdp_hw_metadata eth3 ... 0x1062cb8: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100 rx_hash: 0x2E1B50B9 with RSS type:0x2A rx_timestamp: 1691436369532047139 (sec:1691436369.5320) XDP RX-time: 1691436369261756803 (sec:1691436369.2618) delta sec:-0.2703 (-270290.336 usec)
Quoted 5 lines
Quoted 5 lines
I guess system time isn't configured to be in sync with NIC HW time, as delta is a negative offset.
Quoted 1 line
AF_XDPtime: 1691436369261878839 (sec:1691436369.2619) deltasec:0.0001 (122.036 usec)
Quoted 30 lines
Quoted 3 lines
The
AF_XDPtime is also software system time and compared to XDP RX-time, it shows a delta of 122 usec. This number indicate to me that the CPU is likely configured with power saving sleep states.Yes, I don't do any synchronization and don't disable the sleep states.
Quoted 17 lines
Quoted 5 lines
0x1062cb8: ping-pong with csum=3b8e (want de7e) csum_start=54 csum_offset=60x1062cb8: complete tx idx=0 addr=100x1062cb8:tx_timestamp: 1691436369598419505 (sec:1691436369.5984)Could we add something that we can relate
tx_timestampto?Like we do with the other delta calculations, as it helps us to understand/validate if the number we get back is sane. Like negative offset aboves tells us that system time sync isn't configured, and that system have configures C-states.
I suggest delta comparing "
tx_timestamp" to "rx_timestamp", as they are the same clock domain. It will tell us the total time spend from HW RX to HW TX, counting all the time used by software "ping-pong".Quoted 6 lines
1691436369.5984-1691436369.5320 = 0.0664 sec = 66.4 ms
When implementing this, it could be (1) practical to store the "
rx_timestamp" in the metadata area of the completion packet, or (2) should we have a mechanism for external storage that can be keyed on the umem "addr"?Quoted 4 lines
Sounds good. I can probably just store last
rx_timestampsomewhere in the global var and do a delta on tx? Since the test is single threaded and sequential, not sure we need the mechanism to pass the tstamp around. LMK if you disagree and I'm missing something.I ended up reshuffling current code a bit to basically use clock tai as a reference for every line. Feels like its a bit simpler when everything is referenced against the same clock?
For RX part, I rename existing XDP/AF_XDP to HW/SW and dump them both relative to tai.
0x195d1f0: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100rx_hash: 0xEE2BBD59 with RSS type:0x2A rx_timestamp: 1696969312125212179 (sec:1696969312.1252) HW RX-time: 1696969312125212179 (sec:1696969312.1252) to CLOCK_TAI deltasec:-0.1339 (-133862.968 usec)
SW RX-time: 1696969311991283421 (sec:1696969311.9913) toCLOCK_TAIdelta
sec:0.0001 (65.790 usec)0x195d1f0: ping-pong with csum=3b8e (want de5f) csum_start=54 csum_offset=60x195d1f0: complete tx idx=0 addr=8tx_timestamp: 1696969312152959759 (sec:1696969312.1530) SW RX-time: 1696969311991283421 (sec:1696969311.9913) to CLOCK_TAI deltasec:0.0101 (10139.862 usec)
HW RX-time: 1696969312125212179 (sec:1696969312.1252) to HW TX-
complete-time delta sec:0.0277 (27747.580 usec)
HW TX-complete-time: 1696969312152959759 (sec:1696969312.1530) toCLOCK_TAIdelta sec:-0.1515 (-151536.476 usec)
Quoted 7 lines
For TX part, I add a bunch of reference points:
1) SW RX-time (meta->xdp_timestamp) vsCLOCK_TAI(aka tai-at-complete-time)
2) HW RX-time (meta->rx_timestamp) vs HW TX-complete-time (newaf_xdptimestamp)
3) HW TX-complete-time vsCLOCK_TAIWhat do you think? See the patch below.
Hi Stanislav,
For me, the "CLOCK_TAI" in the printing is a bit confusing because
1. There are two value of tai which refer to different moment but having the same name "CLOCK_TAI"
2. SW RX-time is also a clock tai.
So, I suggest to change the naming:
- HW RX-time: the moment NIC receive the packet (based on PHC)
- XDP RX-time: the moment bpf prog parse the packet (based on tai)
- SW RX-time: the moment user app receive the packet (based on tai)
- HW TX-complete-time: the moment NIC send out the packet (based on PHC)
- SW TX-complete-time: the moment user app know the packet being send out (based on tai)
Thanks & Regards
Siang
Quoted 350 lines
Note: all 3 of the above should, in theory, be more or less constant (with irq moderation / etc disabled). But for me on mlx5 (2) they are not and looks like hw rx timestamp jitters a quite a bit. I don't have a clue rigt now on why, will try to take a separate look, but it's unrelated to the tx side.
tools/testing/selftests/bpf/xdp_hw_metadata.c +18
-15@@ -57,6 +57,8 @@ const char *ifname;int ifindex;int rxq;bool skip_tx; +__u64 last_hw_rx_timestamp; +__u64 last_sw_rx_timestamp;void test__fail (void ) {/* for network_helpers.c */ }@@ -167,6 +169,16 @@ static __u64 gettime(clockid_t clock_id)return (__u64 ) t.tv_sec *NANOSEC_PER_SEC + t.tv_nsec; } +static void print_tstamp_delta (const char *name,const char *refname, +__u64 tstamp,__u64 reference) { +__s64 delta = (__s64 )reference - (__s64 )tstamp; + +printf ("%s: %llu (sec:%0.4f) to %s delta sec:%0.4f (%0.3f usec)\n" , + name, tstamp, (double )tstamp /NANOSEC_PER_SEC , refname, + (double )delta /NANOSEC_PER_SEC , + (double )delta /1000 ); +} +static void verify_xdp_metadata (void *data,clockid_t clock_id) {struct xdp_meta *meta;@@ -182,22 +194,15 @@ static void verify_xdp_metadata(void *data, clockid_t clock_id) printf("rx_timestamp: %llu (sec:%0.4f)\n", meta->rx_timestamp, (double)meta->rx_timestamp / NANOSEC_PER_SEC);if (meta->rx_timestamp) { -__u64 usr_clock =gettime (clock_id); -__u64 xdp_clock = meta->xdp_timestamp; -__s64 delta_X = xdp_clock - meta->rx_timestamp; -__s64 delta_X2U = usr_clock - xdp_clock; - - printf("XDP RX-time: %llu (sec:%0.4f) delta sec:%0.4f (%0.3f usec)\n", - xdp_clock, (double )xdp_clock /NANOSEC_PER_SEC , - (double )delta_X /NANOSEC_PER_SEC , - (double)delta_X / 1000); - - printf("AF_XDP time: %llu (sec:%0.4f) delta sec:%0.4f (%0.3f usec)\n", - usr_clock, (double )usr_clock /NANOSEC_PER_SEC , - (double )delta_X2U /NANOSEC_PER_SEC , - (double)delta_X2U / 1000); - } + __u64 ref_tstamp = gettime(clock_id); + +/* store received timestamps to calculate a delta at tx */ + last_hw_rx_timestamp = meta->rx_timestamp; + last_sw_rx_timestamp = meta->xdp_timestamp; + print_tstamp_delta("HW RX-time", "CLOCK_TAI", meta-Quoted 1 line
rx_timestamp,ref_tstamp);tools/testing/selftests/bpf/xdp_hw_metadata.c +1
-0+ print_tstamp_delta("SW RX-time", "CLOCK_TAI", meta-Quoted 1 line
xdp_timestamp,ref_tstamp);tools/testing/selftests/bpf/xdp_hw_metadata.c +1
-0+ }}
static void
verify_skb_metadata(int fd)@@ -245,7 +250,7 @@ static voidverify_skb_metadata(int fd)printf("skb hwtstamp is not found!\n"); }tools/testing/selftests/bpf/xdp_hw_metadata.c +1
-1-static bool complete_tx (struct xsk *xsk) +static bool complete_tx (struct xsk *xsk,clockid_t clock_id){ struct xsk_tx_metadata *meta; __u64 addr;tools/testing/selftests/bpf/xdp_hw_metadata.c +11
-2@@ -260,9 +265,17 @@ static bool complete_tx(struct xsk *xsk) meta = data -sizeof (struct xsk_tx_metadata );printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); -printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, - meta->completion.tx_timestamp, + +printf ("tx_timestamp: %llu (sec:%0.4f)\n" , +meta->completion.tx_timestamp, (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +if (meta->completion.tx_timestamp) { +__u64 ref_tstamp =gettime (clock_id); + +print_tstamp_delta ("HW TX-complete-time" ,"CLOCK_TAI" , meta- >completion.tx_timestamp, ref_tstamp); +print_tstamp_delta ("SW RX-time" ,"CLOCK_TAI" , last_sw_rx_timestamp, ref_tstamp); +print_tstamp_delta ("HW RX-time" ,"HW TX-complete-time" , last_hw_rx_timestamp, meta->completion.tx_timestamp); + } +xsk_ring_cons__release(&xsk->comp, 1); return true;tools/testing/selftests/bpf/xdp_hw_metadata.c +2
-1@@ -276,7 +289,7 @@ static bool complete_tx(struct xsk *xsk) } \ }while (0 ) -static void ping_pong(struct xsk *xsk, void *rx_packet) +static void ping_pong(struct xsk *xsk, void *rx_packet, clockid_t +clock_id) {struct xsk_tx_metadata *meta;struct ipv6hdr *ip6h = NULL;tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -418,14 +431,14 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int
server_fd,clockid_tif (!skip_tx) { /* mirror the packet back */tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-1- ping_pong(xsk, xsk_umem__get_data(xsk-Quoted 1 line
umem_area, addr));tools/testing/selftests/bpf/xdp_hw_metadata.c +1
-0+ ping_pong(xsk, xsk_umem__get_data(xsk-Quoted 1 line
umem_area, addr),clock_id);ret = kick_tx(xsk); if (ret) printf("kick_tx ret=%d\n", ret); for (int j = 0; j < 500; j++) {tools/testing/selftests/bpf/xdp_hw_metadata.c +1
-1-if (complete_tx (xsk)) +if (complete_tx (xsk, clock_id))break; usleep(10*1000); }Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
0x1062cb8: complete rx idx=128 addr=80100mvbz4:~# nc -Nu -q1 ${MVBZ3_LINK_LOCAL_IP}%eth3 9091mvbz4:~# tcpdump -vvx -i eth3 udp tcpdump: listening on eth3, link-type EN10MB (Ethernet), snapshot length 262144 bytes 12:26:09.301074 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17)payload length: 11) fe80::1270:fdff:fe48:1087.55807 > fe80::1270:fdff:fe48:1077.9091: [bad udp cksum
0x3b8e->0xde7e!] UDP, length 3Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1087 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1077 d9ff 2383 000b 3b8e 0x0030: 7864 7012:26:09.301976 IP6 (flowlabel
0x35fa5, hlim 127, next-header UDP (17)payload length: 11) fe80::1270:fdff:fe48:1077.9091 > fe80::1270:fdff:fe48:1087.55807: [udp sum ok] UDP, length 3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1077 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1087 2383 d9ff 000b de7e 0x0030: 7864 70Signed-off-by Stanislav Fomichev <[email protected]>--- tools/testing/selftests/bpf/xdp_hw_metadata.c | 202+++++++++++++++++-
Quoted 71 lines
Quoted 71 lines
Quoted 19 lines
1 file changed, 192 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-1@@ -10,7 +10,9 @@* - rx_hash * * TX: -* - TBD +* - UDP 9091 packets trigger TX reply +* - TX HW timestamp is requested and reported back upon +completion +* - TX checksum is requested */ #include <test_progs.h> @@ -24,14 +26,17 @@[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -51,22 +56,24 @@ struct xsk *rx_xsk;[...]
Quoted 2 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -129,12 +136,22 @@ static void refill_rx(struct xsk *xsk, __u64 addr)[...]
Quoted 46 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +43
-0@@ -228,6 +245,117 @@ static void verify_skb_metadata(int fd)printf ("skb hwtstamp is not found!\n" ); } +static bool complete_tx (struct xsk *xsk) { +struct xsk_tx_metadata *meta; +__u64 addr; +void *data; +__u32 idx; + +if (!xsk_ring_cons__peek (&xsk->comp,1 , &idx)) +return false; + + addr = *xsk_ring_cons__comp_addr (&xsk->comp, idx); + data =xsk_umem__get_data (xsk->umem_area, addr); + meta = data -sizeof (struct xsk_tx_metadata ); + +printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); +printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, + meta->completion.tx_timestamp, + (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +xsk_ring_cons__release (&xsk->comp,1 ); + +return true; +} + +#define swap (a, b, len) do { \ + for (int i = 0; i < len; i++) { \ + __u8 tmp = ((__u8 *)a)[i]; \ + ((__u8 *)a)[i] = ((__u8 *)b)[i]; \ + ((__u8 *)b)[i] = tmp; \ + } \ +} while (0) + +static void ping_pong (struct xsk *xsk,void *rx_packet) { +struct xsk_tx_metadata *meta; +struct ipv6hdr *ip6h =NULL ; +struct iphdr *iph =NULL ; +struct xdp_desc *tx_desc; +struct udphdr *udph; +struct ethhdr *eth; +__sum16 want_csum; +void *data; +__u32 idx; +int ret; +int len; +Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 297
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+ ret =xsk_ring_prod__reserve (&xsk->tx,1 , &idx); +if (ret !=1 ) { +printf ("%p: failed to reserve tx slot\n" , xsk); +return ; + } + + tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx); + tx_desc->addr = idx % (UMEM_NUM / 2) * UMEM_FRAME_SIZE +
sizeof(struct xsk_tx_metadata);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+ data =xsk_umem__get_data (xsk->umem_area, tx_desc->addr); + + meta = data -sizeof (struct xsk_tx_metadata ); +memset (meta,0 ,sizeof (*meta)); + meta->flags =XDP_TX_METADATA_TIMESTAMP ; + + eth = rx_packet; +Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 313
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+if (eth->h_proto ==htons (ETH_P_IP )) { + iph = (void *)(eth +1 ); + udph = (void *)(iph +1 ); + }else if (eth->h_proto ==htons (ETH_P_IPV6 )) { + ip6h = (void *)(eth +1 ); + udph = (void *)(ip6h +1 ); + }else { + printf("%p: failed to detect IP version for ping pong %04x\n", xsk,
eth->h_proto);Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +16
-0+xsk_ring_prod__cancel (&xsk->tx,1 ); +return ; + } + + len =ETH_HLEN ; +if (ip6h) + len +=sizeof (*ip6h) +ntohs (ip6h->payload_len); +if (iph) + len +=ntohs (iph->tot_len); + +swap (eth->h_dest, eth->h_source,ETH_ALEN ); +if (iph) +swap (&iph->saddr, &iph->daddr,4 ); +else +swap (&ip6h->saddr, &ip6h->daddr,16 ); +swap (&udph->source, &udph->dest,2 );Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 337
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+ + want_csum = udph->check; +if (ip6h) + udph->check = ~csum_ipv6_magic (&ip6h->saddr, &ip6h->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); +else + udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, + ntohs(udph->len),
IPPROTO_UDP, 0);Quoted 9 lines
Quoted 9 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 346
Quoted 9 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +9
-0+ + meta->flags |=XDP_TX_METADATA_CHECKSUM ; +if (iph) + meta->csum_start =sizeof (*eth) +sizeof (*iph); +else + meta->csum_start =sizeof (*eth) +sizeof (*ip6h); + meta->csum_offset = offsetof(struct udphdr , check); + + printf("%p: ping-pong with csum=%04x (want %04x) csum_start=%dcsum_offset=%d\n",
Quoted 4 lines
Quoted 4 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 350
Quoted 4 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-0+ xsk,ntohs (udph->check),ntohs (want_csum), +meta->csum_start, meta->csum_offset); + +memcpy (data, rx_packet, len);/* don't share umem chunk for simplicity */
Quoted 6 lines
Quoted 6 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 356
Quoted 6 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +5
-0+ tx_desc->options |=XDP_TX_METADATA ; + tx_desc->len = len; + +xsk_ring_prod__submit (&xsk->tx,1 ); } + static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t
clock_id)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0{ const struct xdp_desc *rx_desc; @@ -250,6 +378,13 @@ static intverify_metadata(struct xsk
*rx_xsk, int rxq, intserver_fd,clockid_t
while (true) {
errno = 0;tools/testing/selftests/bpf/xdp_hw_metadata.c +3
-0+ +for (i =0 ; i < rxq; i++) { + ret =kick_rx (&rx_xsk[i]);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-0+if (ret) +printf ("kick_rx ret=%d\n" , ret); + } + ret =poll (fds, rxq +1 ,1000 );printf ("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n" , ret, errno, bpf_obj->bss->pkts_skip, @@ -280,6 +415,22@@ static int verify_metadata(struct xsk
*rx_xsk, int rxq, intserver_fd,
clockid_tQuoted 21 lines
Quoted 2 lines
Quoted 2 lines
xsk, idx,
rx_desc->addr, addr,comp_addr);
verify_xdp_metadata(xsk_umem__get_data(xsk-
umem_area, addr),Quoted 5 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c
Quoted 5 lines
clock_id);tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-0+ +if (!skip_tx) { +/* mirror the packet back */ + ping_pong(xsk, xsk_umem__get_data(xsk-
umem_area, addr));Quoted 11 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c
Quoted 9 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +9
-0+ + ret =kick_tx (xsk); +if (ret) +printf ("kick_tx ret=%d\n" , ret); + +for (int j =0 ; j <500 ; j++) { +if (complete_tx (xsk)) +break ; +usleep (10 *1000 );I don't fully follow why we need this usleep here.
Quoted 2 lines
To avoid the busypoll here (since we don't care too much about perf in the test). But I agree, should be ok to drop, will do.
I take that back, I have to keep it. Otherwise I don't have a good bound on when to stop/abort when waiting for completion. (and the number of loops needs to go from 500 to unsure-how-many).
Re: [PATCH bpf-next v3 09/10] selftests/bpf: Add TX side to xdp_hw_metadata
Quoted 107 lines · Yoong Siang
Quoted 91 lines · Stanislav Fomichev
Quoted 18 lines · Stanislav Fomichev
Quoted 17 lines · Jesper Dangaard Brouer
Quoted 14 lines · Stanislav Fomichev
When we get a packet on port 9091, we swap src/dst and send it out. At this point we also request the timestamp and checksum offloads.
Checksum offload is verified by looking at the tcpdump on the other side. The tool prints pseudo-header csum and the final one it expects. The final checksum actually matches the incoming packets checksum because we only flip the src/dst and don't change the payload.
Some other related changes:
- switched to zerocopy mode by default; new flag can be used to force old behavior
- request fixedtx_metadata_lenheadroom
- some other small fixes (umem size, fill idx+i, etc)Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mvbz3:~# ./xdp_hw_metadata eth3 ... 0x1062cb8: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100 rx_hash: 0x2E1B50B9 with RSS type:0x2A rx_timestamp: 1691436369532047139 (sec:1691436369.5320) XDP RX-time: 1691436369261756803 (sec:1691436369.2618) delta sec:-0.2703 (-270290.336 usec)
Quoted 5 lines
Quoted 5 lines
I guess system time isn't configured to be in sync with NIC HW time, as delta is a negative offset.
Quoted 1 line
AF_XDPtime: 1691436369261878839 (sec:1691436369.2619) deltasec:0.0001 (122.036 usec)
Quoted 30 lines
Quoted 3 lines
The
AF_XDPtime is also software system time and compared to XDP RX-time, it shows a delta of 122 usec. This number indicate to me that the CPU is likely configured with power saving sleep states.Yes, I don't do any synchronization and don't disable the sleep states.
Quoted 17 lines
Quoted 5 lines
0x1062cb8: ping-pong with csum=3b8e (want de7e) csum_start=54 csum_offset=60x1062cb8: complete tx idx=0 addr=100x1062cb8:tx_timestamp: 1691436369598419505 (sec:1691436369.5984)Could we add something that we can relate
tx_timestampto?Like we do with the other delta calculations, as it helps us to understand/validate if the number we get back is sane. Like negative offset aboves tells us that system time sync isn't configured, and that system have configures C-states.
I suggest delta comparing "
tx_timestamp" to "rx_timestamp", as they are the same clock domain. It will tell us the total time spend from HW RX to HW TX, counting all the time used by software "ping-pong".Quoted 6 lines
1691436369.5984-1691436369.5320 = 0.0664 sec = 66.4 ms
When implementing this, it could be (1) practical to store the "
rx_timestamp" in the metadata area of the completion packet, or (2) should we have a mechanism for external storage that can be keyed on the umem "addr"?Quoted 4 lines
Sounds good. I can probably just store last
rx_timestampsomewhere in the global var and do a delta on tx? Since the test is single threaded and sequential, not sure we need the mechanism to pass the tstamp around. LMK if you disagree and I'm missing something.I ended up reshuffling current code a bit to basically use clock tai as a reference for every line. Feels like its a bit simpler when everything is referenced against the same clock?
For RX part, I rename existing XDP/AF_XDP to HW/SW and dump them both relative to tai.
0x195d1f0: rx_desc[0]->addr=80100 addr=80100 comp_addr=80100rx_hash: 0xEE2BBD59 with RSS type:0x2A rx_timestamp: 1696969312125212179 (sec:1696969312.1252) HW RX-time: 1696969312125212179 (sec:1696969312.1252) to CLOCK_TAI deltasec:-0.1339 (-133862.968 usec)
SW RX-time: 1696969311991283421 (sec:1696969311.9913) toCLOCK_TAIdelta
sec:0.0001 (65.790 usec)0x195d1f0: ping-pong with csum=3b8e (want de5f) csum_start=54 csum_offset=60x195d1f0: complete tx idx=0 addr=8tx_timestamp: 1696969312152959759 (sec:1696969312.1530) SW RX-time: 1696969311991283421 (sec:1696969311.9913) to CLOCK_TAI deltasec:0.0101 (10139.862 usec)
HW RX-time: 1696969312125212179 (sec:1696969312.1252) to HW TX-
complete-time delta sec:0.0277 (27747.580 usec)
HW TX-complete-time: 1696969312152959759 (sec:1696969312.1530) toCLOCK_TAIdelta sec:-0.1515 (-151536.476 usec)Quoted 7 lines
For TX part, I add a bunch of reference points:
1) SW RX-time (meta->xdp_timestamp) vsCLOCK_TAI(aka tai-at-complete-time)
2) HW RX-time (meta->rx_timestamp) vs HW TX-complete-time (newaf_xdptimestamp)
3) HW TX-complete-time vsCLOCK_TAIWhat do you think? See the patch below.
Hi Stanislav,
For me, the "
CLOCK_TAI" in the printing is a bit confusing because
1. There are two value of tai which refer to different moment but having the same name "CLOCK_TAI"
2. SW RX-time is also a clock tai.
Quoted 6 lines
So, I suggest to change the naming:
- HW RX-time: the moment NIC receive the packet (based on PHC)
- XDP RX-time: the moment bpf prog parse the packet (based on tai)
- SW RX-time: the moment user app receive the packet (based on tai)
- HW TX-complete-time: the moment NIC send out the packet (based on PHC)
- SW TX-complete-time: the moment user app know the packet being send out (based on tai)
SG. Maybe also do s/SW/User/ ? To signify that it's a userspace-level timestamps?
Quoted 353 lines
Thanks & Regards
SiangQuoted 350 lines
Note: all 3 of the above should, in theory, be more or less constant (with irq moderation / etc disabled). But for me on mlx5 (2) they are not and looks like hw rx timestamp jitters a quite a bit. I don't have a clue rigt now on why, will try to take a separate look, but it's unrelated to the tx side.
tools/testing/selftests/bpf/xdp_hw_metadata.c +18
-15@@ -57,6 +57,8 @@ const char *ifname;int ifindex;int rxq;bool skip_tx; +__u64 last_hw_rx_timestamp; +__u64 last_sw_rx_timestamp;void test__fail (void ) {/* for network_helpers.c */ }@@ -167,6 +169,16 @@ static __u64 gettime(clockid_t clock_id)return (__u64 ) t.tv_sec *NANOSEC_PER_SEC + t.tv_nsec; } +static void print_tstamp_delta (const char *name,const char *refname, +__u64 tstamp,__u64 reference) { +__s64 delta = (__s64 )reference - (__s64 )tstamp; + +printf ("%s: %llu (sec:%0.4f) to %s delta sec:%0.4f (%0.3f usec)\n" , + name, tstamp, (double )tstamp /NANOSEC_PER_SEC , refname, + (double )delta /NANOSEC_PER_SEC , + (double )delta /1000 ); +} +static void verify_xdp_metadata (void *data,clockid_t clock_id) {struct xdp_meta *meta;@@ -182,22 +194,15 @@ static void verify_xdp_metadata(void *data, clockid_t clock_id) printf("rx_timestamp: %llu (sec:%0.4f)\n", meta->rx_timestamp, (double)meta->rx_timestamp / NANOSEC_PER_SEC);if (meta->rx_timestamp) { -__u64 usr_clock =gettime (clock_id); -__u64 xdp_clock = meta->xdp_timestamp; -__s64 delta_X = xdp_clock - meta->rx_timestamp; -__s64 delta_X2U = usr_clock - xdp_clock; - - printf("XDP RX-time: %llu (sec:%0.4f) delta sec:%0.4f (%0.3f usec)\n", - xdp_clock, (double )xdp_clock /NANOSEC_PER_SEC , - (double )delta_X /NANOSEC_PER_SEC , - (double)delta_X / 1000); - - printf("AF_XDP time: %llu (sec:%0.4f) delta sec:%0.4f (%0.3f usec)\n", - usr_clock, (double )usr_clock /NANOSEC_PER_SEC , - (double )delta_X2U /NANOSEC_PER_SEC , - (double)delta_X2U / 1000); - } + __u64 ref_tstamp = gettime(clock_id); + +/* store received timestamps to calculate a delta at tx */ + last_hw_rx_timestamp = meta->rx_timestamp; + last_sw_rx_timestamp = meta->xdp_timestamp; + print_tstamp_delta("HW RX-time", "CLOCK_TAI", meta-Quoted 1 line
rx_timestamp,ref_tstamp);+ print_tstamp_delta("SW RX-time", "
CLOCK_TAI", meta-Quoted 1 line
xdp_timestamp,ref_tstamp);+ }
}static void
verify_skb_metadata(int fd)@@ -245,7 +250,7 @@ static voidverify_skb_metadata(int fd)printf("skb hwtstamp is not found!\n"); }tools/testing/selftests/bpf/xdp_hw_metadata.c +1
-1-static bool complete_tx (struct xsk *xsk) +static bool complete_tx (struct xsk *xsk,clockid_t clock_id){ struct xsk_tx_metadata *meta; __u64 addr;tools/testing/selftests/bpf/xdp_hw_metadata.c +13
-3@@ -260,9 +265,17 @@ static bool complete_tx(struct xsk *xsk) meta = data -sizeof (struct xsk_tx_metadata );printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); -printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, - meta->completion.tx_timestamp, + +printf ("tx_timestamp: %llu (sec:%0.4f)\n" , +meta->completion.tx_timestamp, (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +if (meta->completion.tx_timestamp) { +__u64 ref_tstamp =gettime (clock_id); + +print_tstamp_delta ("HW TX-complete-time" ,"CLOCK_TAI" , meta- >completion.tx_timestamp, ref_tstamp); +print_tstamp_delta ("SW RX-time" ,"CLOCK_TAI" , last_sw_rx_timestamp, ref_tstamp); +print_tstamp_delta ("HW RX-time" ,"HW TX-complete-time" , last_hw_rx_timestamp, meta->completion.tx_timestamp); + } +xsk_ring_cons__release (&xsk->comp,1 );return true;@@ -276,7 +289,7 @@ static bool complete_tx(struct xsk *xsk) } \ }while (0 ) -static void ping_pong(struct xsk *xsk, void *rx_packet) +static void ping_pong(struct xsk *xsk, void *rx_packet, clockid_t +clock_id) {struct xsk_tx_metadata *meta;struct ipv6hdr *ip6h =NULL ;@@ -418,14 +431,14 @@ static int verify_metadata(struct xsk *rx_xsk, int rxq, int
server_fd,clockid_tif (!skip_tx) { /* mirror the packet back */- ping_pong(xsk, xsk_umem__get_data(xsk-
Quoted 1 line
umem_area, addr));+ ping_pong(xsk, xsk_umem__get_data(xsk-
Quoted 1 line
umem_area, addr),clock_id);ret = kick_tx(xsk); if (ret) printf("kick_tx ret=%d\n", ret); for (int j = 0; j < 500; j++) {tools/testing/selftests/bpf/xdp_hw_metadata.c +1
-1-if (complete_tx (xsk)) +if (complete_tx (xsk, clock_id))break ;usleep (10 *1000 ); }Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
0x1062cb8: complete rx idx=128 addr=80100mvbz4:~# nc -Nu -q1 ${MVBZ3_LINK_LOCAL_IP}%eth3 9091mvbz4:~# tcpdump -vvx -i eth3 udp tcpdump: listening on eth3, link-type EN10MB (Ethernet), snapshot length 262144 bytes 12:26:09.301074 IP6 (flowlabel 0x35fa5, hlim 127, next-header UDP (17)payload length: 11) fe80::1270:fdff:fe48:1087.55807 > fe80::1270:fdff:fe48:1077.9091: [bad udp cksum
0x3b8e->0xde7e!] UDP, length 3Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1087 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1077 d9ff 2383 000b 3b8e 0x0030: 7864 7012:26:09.301976 IP6 (flowlabel
0x35fa5, hlim 127, next-header UDP (17)payload length: 11) fe80::1270:fdff:fe48:1077.9091 > fe80::1270:fdff:fe48:1087.55807: [udp sum ok] UDP, length 3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
0x0000: 6003 5fa5 000b 117f fe80 0000 0000 0000 0x0010: 1270 fdff fe48 1077 fe80 0000 0000 0000 0x0020: 1270 fdff fe48 1087 2383 d9ff 000b de7e 0x0030: 7864 70Signed-off-by Stanislav Fomichev <[email protected]>--- tools/testing/selftests/bpf/xdp_hw_metadata.c | 202+++++++++++++++++-
Quoted 71 lines
Quoted 71 lines
Quoted 19 lines
1 file changed, 192 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-1@@ -10,7 +10,9 @@* - rx_hash * * TX: -* - TBD +* - UDP 9091 packets trigger TX reply +* - TX HW timestamp is requested and reported back upon +completion +* - TX checksum is requested */ #include <test_progs.h> @@ -24,14 +26,17 @@[...]
Quoted 1 line
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -51,22 +56,24 @@ struct xsk *rx_xsk;[...]
Quoted 2 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0@@ -129,12 +136,22 @@ static void refill_rx(struct xsk *xsk, __u64 addr)[...]
Quoted 46 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +43
-0@@ -228,6 +245,117 @@ static void verify_skb_metadata(int fd)printf ("skb hwtstamp is not found!\n" ); } +static bool complete_tx (struct xsk *xsk) { +struct xsk_tx_metadata *meta; +__u64 addr; +void *data; +__u32 idx; + +if (!xsk_ring_cons__peek (&xsk->comp,1 , &idx)) +return false; + + addr = *xsk_ring_cons__comp_addr (&xsk->comp, idx); + data =xsk_umem__get_data (xsk->umem_area, addr); + meta = data -sizeof (struct xsk_tx_metadata ); + +printf ("%p: complete tx idx=%u addr=%llx\n" , xsk, idx, addr); +printf ("%p: tx_timestamp: %llu (sec:%0.4f)\n" , xsk, + meta->completion.tx_timestamp, + (double )meta->completion.tx_timestamp /NANOSEC_PER_SEC ); +xsk_ring_cons__release (&xsk->comp,1 ); + +return true; +} + +#define swap (a, b, len) do { \ + for (int i = 0; i < len; i++) { \ + __u8 tmp = ((__u8 *)a)[i]; \ + ((__u8 *)a)[i] = ((__u8 *)b)[i]; \ + ((__u8 *)b)[i] = tmp; \ + } \ +} while (0) + +static void ping_pong (struct xsk *xsk,void *rx_packet) { +struct xsk_tx_metadata *meta; +struct ipv6hdr *ip6h =NULL ; +struct iphdr *iph =NULL ; +struct xdp_desc *tx_desc; +struct udphdr *udph; +struct ethhdr *eth; +__sum16 want_csum; +void *data; +__u32 idx; +int ret; +int len; +Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 297
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+ ret =xsk_ring_prod__reserve (&xsk->tx,1 , &idx); +if (ret !=1 ) { +printf ("%p: failed to reserve tx slot\n" , xsk); +return ; + } + + tx_desc =xsk_ring_prod__tx_desc (&xsk->tx, idx); + tx_desc->addr = idx % (UMEM_NUM / 2) * UMEM_FRAME_SIZE +
sizeof(struct xsk_tx_metadata);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+ data =xsk_umem__get_data (xsk->umem_area, tx_desc->addr); + + meta = data -sizeof (struct xsk_tx_metadata ); +memset (meta,0 ,sizeof (*meta)); + meta->flags =XDP_TX_METADATA_TIMESTAMP ; + + eth = rx_packet; +Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 313
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+if (eth->h_proto ==htons (ETH_P_IP )) { + iph = (void *)(eth +1 ); + udph = (void *)(iph +1 ); + }else if (eth->h_proto ==htons (ETH_P_IPV6 )) { + ip6h = (void *)(eth +1 ); + udph = (void *)(ip6h +1 ); + }else { + printf("%p: failed to detect IP version for ping pong %04x\n", xsk,
eth->h_proto);Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +16
-0+xsk_ring_prod__cancel (&xsk->tx,1 ); +return ; + } + + len =ETH_HLEN ; +if (ip6h) + len +=sizeof (*ip6h) +ntohs (ip6h->payload_len); +if (iph) + len +=ntohs (iph->tot_len); + +swap (eth->h_dest, eth->h_source,ETH_ALEN ); +if (iph) +swap (&iph->saddr, &iph->daddr,4 ); +else +swap (&ip6h->saddr, &ip6h->daddr,16 ); +swap (&udph->source, &udph->dest,2 );Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 337
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +8
-0+ + want_csum = udph->check; +if (ip6h) + udph->check = ~csum_ipv6_magic (&ip6h->saddr, &ip6h->daddr, +ntohs (udph->len),IPPROTO_UDP ,0 ); +else + udph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, + ntohs(udph->len),
IPPROTO_UDP, 0);Quoted 9 lines
Quoted 9 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 346
Quoted 9 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +9
-0+ + meta->flags |=XDP_TX_METADATA_CHECKSUM ; +if (iph) + meta->csum_start =sizeof (*eth) +sizeof (*iph); +else + meta->csum_start =sizeof (*eth) +sizeof (*ip6h); + meta->csum_offset = offsetof(struct udphdr , check); + + printf("%p: ping-pong with csum=%04x (want %04x) csum_start=%dcsum_offset=%d\n",
Quoted 4 lines
Quoted 4 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 350
Quoted 4 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-0+ xsk,ntohs (udph->check),ntohs (want_csum), +meta->csum_start, meta->csum_offset); + +memcpy (data, rx_packet, len);/* don't share umem chunk for simplicity */
Quoted 6 lines
Quoted 6 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c static void verify_skb_metadata(int fd) · line 356
Quoted 6 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +5
-0+ tx_desc->options |=XDP_TX_METADATA ; + tx_desc->len = len; + +xsk_ring_prod__submit (&xsk->tx,1 ); } + static int verify_metadata(struct xsk *rx_xsk, int rxq, int server_fd, clockid_t
clock_id)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +0
-0{ const struct xdp_desc *rx_desc; @@ -250,6 +378,13 @@ static intverify_metadata(struct xsk
*rx_xsk, int rxq, intserver_fd,clockid_twhile (true) { errno = 0;tools/testing/selftests/bpf/xdp_hw_metadata.c +3
-0+ +for (i =0 ; i < rxq; i++) { + ret =kick_rx (&rx_xsk[i]);Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-0+if (ret) +printf ("kick_rx ret=%d\n" , ret); + } + ret =poll (fds, rxq +1 ,1000 );printf ("poll: %d (%d) skip=%llu fail=%llu redir=%llu\n" , ret, errno, bpf_obj->bss->pkts_skip, @@ -280,6 +415,22@@ static int verify_metadata(struct xsk
*rx_xsk, int rxq, intserver_fd,
clockid_tQuoted 21 lines
Quoted 2 lines
Quoted 2 lines
xsk, idx, rx_desc->addr, addr, comp_addr); verify_xdp_metadata(xsk_umem__get_data(xsk-
umem_area, addr),Quoted 5 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c
Quoted 5 lines
clock_id);tools/testing/selftests/bpf/xdp_hw_metadata.c +4
-0+ +if (!skip_tx) { +/* mirror the packet back */ + ping_pong(xsk, xsk_umem__get_data(xsk-
umem_area, addr));Quoted 11 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c
Quoted 9 lines
tools/testing/selftests/bpf/xdp_hw_metadata.c +9
-0+ + ret =kick_tx (xsk); +if (ret) +printf ("kick_tx ret=%d\n" , ret); + +for (int j =0 ; j <500 ; j++) { +if (complete_tx (xsk)) +break ; +usleep (10 *1000 );I don't fully follow why we need this usleep here.
Quoted 2 lines
To avoid the busypoll here (since we don't care too much about perf in the test). But I agree, should be ok to drop, will do.
I take that back, I have to keep it. Otherwise I don't have a good bound on when to stop/abort when waiting for completion. (and the number of loops needs to go from 500 to unsure-how-many).
RE: [PATCH bpf-next v3 09/10] selftests/bpf: Add TX side to xdp_hw_metadata
Quoted 1 line · Stanislav Fomichev
On Thu, Oct 12, 2023 at 6:14 PM Song, Yoong Siang <[email protected]> wrote:
[...]
Quoted 10 lines
Quoted 8 lines
So, I suggest to change the naming:
- HW RX-time: the moment NIC receive the packet (based on PHC)
- XDP RX-time: the moment bpf prog parse the packet (based on tai)
- SW RX-time: the moment user app receive the packet (based on tai)
- HW TX-complete-time: the moment NIC send out the packet (based on
PHC)
- SW TX-complete-time: the moment user app know the packet being
send out (based on tai)SG. Maybe also do s/SW/User/ ? To signify that it's a userspace-level timestamps?
sound good.
Quoted 4 lines
Quoted 4 lines
Thanks & Regards
Siang
PATCH v3 10/10 xsk: document tx_metadata_len layout
In reply to Stanislav Fomichev- how to use
- how to query features
- pointers to the examples
--- Documentation/networking/index.rst | 1 + Documentation/networking/xsk-tx-metadata.rst | 77 ++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Documentation/networking/xsk-tx-metadata.rst
Documentation/networking/index.rst +1 -0
@@ -123,6 +123,7 @@ Refer to :ref:`netdev-FAQ` for a guide on netdev development process specifics. xfrm_sync xfrm_sysctl xdp-rx-metadata + xsk-tx-metadata .. only:: subproject and html
Documentation/networking/xsk-tx-metadata.rst new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.42.0.582.g8ccd20d70d-goog