Skip to contentSkip to conversation

trace: support expression for blob length

PATCH Superseded David Marchand 4 participants 41 messages Jan 24, 2025 – Mar 5, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 trace: support expression for blob length

Support any expression as a blob length by using an intermediate variable in the trace point emitter itself.

This also avoids any side effect on the passed variable.

---
 lib/eal/include/rte_trace_point.h          | 11 +++++----
 lib/eal/include/rte_trace_point_register.h |  3 ++-
 lib/ethdev/ethdev_trace.h                  | 27 ++++++----------------
 3 files changed, 15 insertions(+), 26 deletions(-)
lib/eal/include/rte_trace_point.h +6 -5
index b24db3b6da..62a972db92 100644
@@ -392,13 +392,14 @@ do { \
 
 #define rte_trace_point_emit_blob(in, len) \
 do { \
+	uint8_t size = len; \
 	if (unlikely(in == NULL)) \
 		return; \
-	if (len > RTE_TRACE_BLOB_LEN_MAX) \
-		len = RTE_TRACE_BLOB_LEN_MAX; \
-	__rte_trace_point_emit(len, uint8_t); \
-	memcpy(mem, in, len); \
-	memset(RTE_PTR_ADD(mem, len), 0, RTE_TRACE_BLOB_LEN_MAX - len); \
+	if (size > RTE_TRACE_BLOB_LEN_MAX) \
+		size = RTE_TRACE_BLOB_LEN_MAX; \
+	__rte_trace_point_emit(size, uint8_t); \
+	memcpy(mem, in, size); \
+	memset(RTE_PTR_ADD(mem, size), 0, RTE_TRACE_BLOB_LEN_MAX - size); \
 	mem = RTE_PTR_ADD(mem, RTE_TRACE_BLOB_LEN_MAX); \
 } while (0)
 
lib/eal/include/rte_trace_point_register.h +2 -1
index 748c931830..cb1015eb88 100644
@@ -51,8 +51,9 @@ do { \
 
 #define rte_trace_point_emit_blob(in, len) \
 do { \
+	uint8_t size = len; \
 	RTE_SET_USED(in); \
-	__rte_trace_point_emit(len, uint8_t); \
+	__rte_trace_point_emit(size, uint8_t); \
 	__rte_trace_point_emit_field(RTE_TRACE_BLOB_LEN_MAX, \
 		RTE_STR(in)"[" RTE_STR(RTE_TRACE_BLOB_LEN_MAX)"]", \
 		RTE_STR(uint8_t)); \
lib/ethdev/ethdev_trace.h +7 -20
index 5951ae2d99..c65b78590a 100644
@@ -860,10 +860,8 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_add,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr, uint32_t pool, int ret),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_u32(pool);
 	rte_trace_point_emit_int(ret);
 )
@@ -872,20 +870,16 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_remove,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
 	rte_ethdev_trace_default_mac_addr_set,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
@@ -1102,11 +1096,9 @@ RTE_TRACE_POINT(
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr,
 		int ret),
-	uint8_t len = nb_mc_addr * RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u32(nb_mc_addr);
-	rte_trace_point_emit_blob(mc_addr_set, len);
+	rte_trace_point_emit_blob(mc_addr_set, nb_mc_addr * RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -1214,13 +1206,10 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_get_dcb_info,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_eth_dcb_info *dcb_info, int ret),
-	uint8_t num_user_priorities = RTE_ETH_DCB_NUM_USER_PRIORITIES;
-	uint8_t num_tcs = RTE_ETH_DCB_NUM_TCS;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u8(dcb_info->nb_tcs);
-	rte_trace_point_emit_blob(dcb_info->prio_tc, num_user_priorities);
-	rte_trace_point_emit_blob(dcb_info->tc_bws, num_tcs);
+	rte_trace_point_emit_blob(dcb_info->prio_tc, RTE_ETH_DCB_NUM_USER_PRIORITIES);
+	rte_trace_point_emit_blob(dcb_info->tc_bws, RTE_ETH_DCB_NUM_TCS);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -2126,10 +2115,8 @@ RTE_TRACE_POINT_FP(
 	rte_eth_trace_macaddr_get,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mac_addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(mac_addr->addr_bytes, len);
+	rte_trace_point_emit_blob(mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 /* Called in loop in examples/ip_pipeline */
Signature · 1 line
2.47.1
#1 lore raw

PATCH 2/2 dmadev: avoid copies in tracepoints

No need to copy values in intermediate variables.
Just use the right trace point emitters.

---
 lib/dmadev/rte_dmadev_trace.h    | 20 ++++++--------------
 lib/dmadev/rte_dmadev_trace_fp.h | 12 ++++--------
 2 files changed, 10 insertions(+), 22 deletions(-)
lib/dmadev/rte_dmadev_trace.h +6 -14
index be089c065c..ddf60b9649 100644
@@ -46,11 +46,10 @@ RTE_TRACE_POINT(
 	const struct rte_dma_conf __dev_conf = {0};
 	dev_conf = &__dev_conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int enable_silent = (int)dev_conf->enable_silent;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
 	rte_trace_point_emit_u16(dev_conf->priority);
-	rte_trace_point_emit_int(enable_silent);
+	rte_trace_point_emit_u8(dev_conf->enable_silent);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -83,21 +82,14 @@ RTE_TRACE_POINT(
 	const struct rte_dma_vchan_conf __conf = {0};
 	conf = &__conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int src_port_type = conf->src_port.port_type;
-	int dst_port_type = conf->dst_port.port_type;
-	int direction = conf->direction;
-	uint64_t src_pcie_cfg;
-	uint64_t dst_pcie_cfg;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(direction);
+	rte_trace_point_emit_int(conf->direction);
 	rte_trace_point_emit_u16(conf->nb_desc);
-	rte_trace_point_emit_int(src_port_type);
-	memcpy(&src_pcie_cfg, &conf->src_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_u64(src_pcie_cfg);
-	memcpy(&dst_pcie_cfg, &conf->dst_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_int(dst_port_type);
-	rte_trace_point_emit_u64(dst_pcie_cfg);
+	rte_trace_point_emit_int(conf->src_port.port_type);
+	rte_trace_point_emit_blob(&conf->src_port.pcie, sizeof(uint64_t));
+	rte_trace_point_emit_int(conf->dst_port.port_type);
+	rte_trace_point_emit_blob(&conf->dst_port.pcie, sizeof(uint64_t));
 	rte_trace_point_emit_ptr(conf->auto_free.m2d.pool);
 	rte_trace_point_emit_int(ret);
 )
lib/dmadev/rte_dmadev_trace_fp.h +4 -8
index f5b96838bc..4950f58cd2 100644
@@ -37,10 +37,9 @@ RTE_TRACE_POINT_FP(
 	enum rte_dma_vchan_status __status = 0;
 	status = &__status;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int vchan_status = *status;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(vchan_status);
+	rte_trace_point_emit_int(*status);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -107,13 +106,11 @@ RTE_TRACE_POINT_FP(
 	last_idx = &__last_idx;
 	has_error = &__has_error;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int has_error_val = *has_error;
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
-	rte_trace_point_emit_int(has_error_val);
+	rte_trace_point_emit_u16(*last_idx);
+	rte_trace_point_emit_u8(*has_error);
 	rte_trace_point_emit_u16(ret);
 )
 
@@ -126,11 +123,10 @@ RTE_TRACE_POINT_FP(
 	uint16_t __last_idx = 0;
 	last_idx = &__last_idx;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
+	rte_trace_point_emit_u16(*last_idx);
 	rte_trace_point_emit_ptr(status);
 	rte_trace_point_emit_u16(ret);
 )
Signature · 1 line
2.47.1
Acked-by on v1 1/2
#2 lore raw
In reply to David Marchand
Quoted 19 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, January 24, 2025 9:44 PM
To: [email protected]
Cc: Jerin Jacob <[email protected]>; Sunil Kumar Kori <[email protected]>; Tyler Retzlaff <[email protected]>; Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [EXTERNAL] [PATCH 1/2] trace: support expression for blob length

Support any expression as a blob length by using an intermediate variable in the trace point emitter itself. This also avoids any side effect on the passed variable. Signed-off-by: David Marchand <david. marchand@ redhat. com> --- lib/eal/include/rte_trace_point. h
Support any expression as a blob length by using an intermediate variable in the trace point emitter itself.

Quoted 3 lines

This also avoids any side effect on the passed variable.

#3 lore raw

PATCH v2 1/3 trace: support expression for blob length

In reply to David Marchand

Support any expression as a blob length by using an intermediate variable in the trace point emitter itself.

This also avoids any side effect on the passed variable.

---
Changes since v1:
- removed code relying on arguments in "registering" rte_trace_point_emit_blob implementation (see patch 3),
- moved build check in non registering __rte_trace_point_emit,

---
 lib/eal/include/rte_trace_point.h          | 12 ++++++----
 lib/eal/include/rte_trace_point_register.h |  2 +-
 lib/ethdev/ethdev_trace.h                  | 27 ++++++----------------
 3 files changed, 15 insertions(+), 26 deletions(-)
lib/eal/include/rte_trace_point.h +7 -5
index b24db3b6da..a162502002 100644
@@ -378,6 +378,7 @@ do { \
 
 #define __rte_trace_point_emit(in, type) \
 do { \
+	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(in))); \
 	memcpy(mem, &(in), sizeof(in)); \
 	mem = RTE_PTR_ADD(mem, sizeof(in)); \
 } while (0)
@@ -392,13 +393,14 @@ do { \
 
 #define rte_trace_point_emit_blob(in, len) \
 do { \
+	uint8_t size = len; \
 	if (unlikely(in == NULL)) \
 		return; \
-	if (len > RTE_TRACE_BLOB_LEN_MAX) \
-		len = RTE_TRACE_BLOB_LEN_MAX; \
-	__rte_trace_point_emit(len, uint8_t); \
-	memcpy(mem, in, len); \
-	memset(RTE_PTR_ADD(mem, len), 0, RTE_TRACE_BLOB_LEN_MAX - len); \
+	if (size > RTE_TRACE_BLOB_LEN_MAX) \
+		size = RTE_TRACE_BLOB_LEN_MAX; \
+	__rte_trace_point_emit(size, uint8_t); \
+	memcpy(mem, in, size); \
+	memset(RTE_PTR_ADD(mem, size), 0, RTE_TRACE_BLOB_LEN_MAX - size); \
 	mem = RTE_PTR_ADD(mem, RTE_TRACE_BLOB_LEN_MAX); \
 } while (0)
 
lib/eal/include/rte_trace_point_register.h +1 -1
index 748c931830..1d6198b32f 100644
@@ -37,7 +37,7 @@ RTE_INIT(trace##_init) \
 
 #define __rte_trace_point_emit(in, type) \
 do { \
-	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(in))); \
+	RTE_SET_USED(in); \
 	__rte_trace_point_emit_field(sizeof(type), RTE_STR(in), \
 		RTE_STR(type)); \
 } while (0)
lib/ethdev/ethdev_trace.h +7 -20
index 5951ae2d99..c65b78590a 100644
@@ -860,10 +860,8 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_add,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr, uint32_t pool, int ret),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_u32(pool);
 	rte_trace_point_emit_int(ret);
 )
@@ -872,20 +870,16 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_remove,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
 	rte_ethdev_trace_default_mac_addr_set,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
@@ -1102,11 +1096,9 @@ RTE_TRACE_POINT(
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr,
 		int ret),
-	uint8_t len = nb_mc_addr * RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u32(nb_mc_addr);
-	rte_trace_point_emit_blob(mc_addr_set, len);
+	rte_trace_point_emit_blob(mc_addr_set, nb_mc_addr * RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -1214,13 +1206,10 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_get_dcb_info,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_eth_dcb_info *dcb_info, int ret),
-	uint8_t num_user_priorities = RTE_ETH_DCB_NUM_USER_PRIORITIES;
-	uint8_t num_tcs = RTE_ETH_DCB_NUM_TCS;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u8(dcb_info->nb_tcs);
-	rte_trace_point_emit_blob(dcb_info->prio_tc, num_user_priorities);
-	rte_trace_point_emit_blob(dcb_info->tc_bws, num_tcs);
+	rte_trace_point_emit_blob(dcb_info->prio_tc, RTE_ETH_DCB_NUM_USER_PRIORITIES);
+	rte_trace_point_emit_blob(dcb_info->tc_bws, RTE_ETH_DCB_NUM_TCS);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -2126,10 +2115,8 @@ RTE_TRACE_POINT_FP(
 	rte_eth_trace_macaddr_get,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mac_addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(mac_addr->addr_bytes, len);
+	rte_trace_point_emit_blob(mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 /* Called in loop in examples/ip_pipeline */
Signature · 1 line
2.48.1
#4 lore raw

PATCH v2 2/3 dmadev: avoid copies in tracepoints

No need to copy values in intermediate variables.
Just use the right trace point emitters.

---
 lib/dmadev/rte_dmadev_trace.h    | 20 ++++++--------------
 lib/dmadev/rte_dmadev_trace_fp.h | 12 ++++--------
 2 files changed, 10 insertions(+), 22 deletions(-)
lib/dmadev/rte_dmadev_trace.h +6 -14
index be089c065c..ddf60b9649 100644
@@ -46,11 +46,10 @@ RTE_TRACE_POINT(
 	const struct rte_dma_conf __dev_conf = {0};
 	dev_conf = &__dev_conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int enable_silent = (int)dev_conf->enable_silent;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
 	rte_trace_point_emit_u16(dev_conf->priority);
-	rte_trace_point_emit_int(enable_silent);
+	rte_trace_point_emit_u8(dev_conf->enable_silent);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -83,21 +82,14 @@ RTE_TRACE_POINT(
 	const struct rte_dma_vchan_conf __conf = {0};
 	conf = &__conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int src_port_type = conf->src_port.port_type;
-	int dst_port_type = conf->dst_port.port_type;
-	int direction = conf->direction;
-	uint64_t src_pcie_cfg;
-	uint64_t dst_pcie_cfg;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(direction);
+	rte_trace_point_emit_int(conf->direction);
 	rte_trace_point_emit_u16(conf->nb_desc);
-	rte_trace_point_emit_int(src_port_type);
-	memcpy(&src_pcie_cfg, &conf->src_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_u64(src_pcie_cfg);
-	memcpy(&dst_pcie_cfg, &conf->dst_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_int(dst_port_type);
-	rte_trace_point_emit_u64(dst_pcie_cfg);
+	rte_trace_point_emit_int(conf->src_port.port_type);
+	rte_trace_point_emit_blob(&conf->src_port.pcie, sizeof(uint64_t));
+	rte_trace_point_emit_int(conf->dst_port.port_type);
+	rte_trace_point_emit_blob(&conf->dst_port.pcie, sizeof(uint64_t));
 	rte_trace_point_emit_ptr(conf->auto_free.m2d.pool);
 	rte_trace_point_emit_int(ret);
 )
lib/dmadev/rte_dmadev_trace_fp.h +4 -8
index f5b96838bc..4950f58cd2 100644
@@ -37,10 +37,9 @@ RTE_TRACE_POINT_FP(
 	enum rte_dma_vchan_status __status = 0;
 	status = &__status;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int vchan_status = *status;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(vchan_status);
+	rte_trace_point_emit_int(*status);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -107,13 +106,11 @@ RTE_TRACE_POINT_FP(
 	last_idx = &__last_idx;
 	has_error = &__has_error;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int has_error_val = *has_error;
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
-	rte_trace_point_emit_int(has_error_val);
+	rte_trace_point_emit_u16(*last_idx);
+	rte_trace_point_emit_u8(*has_error);
 	rte_trace_point_emit_u16(ret);
 )
 
@@ -126,11 +123,10 @@ RTE_TRACE_POINT_FP(
 	uint16_t __last_idx = 0;
 	last_idx = &__last_idx;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
+	rte_trace_point_emit_u16(*last_idx);
 	rte_trace_point_emit_ptr(status);
 	rte_trace_point_emit_u16(ret);
 )
Signature · 1 line
2.48.1
#5 lore raw

PATCH v2 3/3 trace: fix undefined behavior in register

In reply to David Marchand

Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each tracepoint and make sure that the emitting macros in rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a __rte_unused for each argument (since emitting macros do nothing with them).
This last part introduces an implementation limit of 15 arguments.

With this change in place, the workaround in dmadev tracepoints can be removed.

---
 lib/dmadev/rte_dmadev_trace.h              | 12 -------
 lib/dmadev/rte_dmadev_trace_fp.h           | 14 --------
 lib/eal/include/rte_trace_point.h          |  4 +++
 lib/eal/include/rte_trace_point_register.h | 42 +++++++++++++++++++---
 4 files changed, 42 insertions(+), 30 deletions(-)
lib/dmadev/rte_dmadev_trace.h +0 -12
index ddf60b9649..9de9b54aad 100644
@@ -22,10 +22,6 @@ extern "C" {
 RTE_TRACE_POINT(
 	rte_dma_trace_info_get,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, struct rte_dma_info *dev_info),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	struct rte_dma_info __dev_info = {0};
-	dev_info = &__dev_info;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_string(dev_info->dev_name);
 	rte_trace_point_emit_u64(dev_info->dev_capa);
@@ -42,10 +38,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_configure,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, const struct rte_dma_conf *dev_conf,
 			     int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_conf __dev_conf = {0};
-	dev_conf = &__dev_conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
 	rte_trace_point_emit_u16(dev_conf->priority);
@@ -78,10 +70,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_vchan_setup,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const struct rte_dma_vchan_conf *conf, int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_vchan_conf __conf = {0};
-	conf = &__conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int(conf->direction);
lib/dmadev/rte_dmadev_trace_fp.h +0 -14
index 4950f58cd2..106eac24be 100644
@@ -33,10 +33,6 @@ RTE_TRACE_POINT_FP(
 	rte_dma_trace_vchan_status,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     enum rte_dma_vchan_status *status, int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	enum rte_dma_vchan_status __status = 0;
-	status = &__status;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int(*status);
@@ -100,12 +96,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     bool *has_error, uint16_t ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	uint16_t __last_idx = 0;
-	bool __has_error = false;
-	last_idx = &__last_idx;
-	has_error = &__has_error;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
@@ -119,10 +109,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     enum rte_dma_status_code *status, uint16_t ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	uint16_t __last_idx = 0;
-	last_idx = &__last_idx;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
lib/eal/include/rte_trace_point.h +4 -0
index a162502002..444175f238 100644
@@ -36,6 +36,8 @@ extern "C" {
 /** The tracepoint object. */
 typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;
 
+#ifndef _RTE_TRACE_POINT_REGISTER_H_
+
 /**
  * Macro to define the tracepoint arguments in RTE_TRACE_POINT macro.
 
@@ -53,6 +55,8 @@ _tp _args \
 	__VA_ARGS__ \
 }
 
+#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
+
 /**
  * Create a tracepoint.
  *
lib/eal/include/rte_trace_point_register.h +38 -4

72 lines not on this page · raw message

Signature · 1 line
2.48.1
#6 lore raw

Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Quoted 17 lines · On Thu, 30 Jan 2025 15:58:49 +0100 David Marchand <[email protected]>…

Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each tracepoint and make sure that the emitting macros in rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a __rte_unused for each argument (since emitting macros do nothing with them).
This last part introduces an implementation limit of 15 arguments.

Quoted 4 lines

With this change in place, the workaround in dmadev tracepoints can be removed.

When I build with -Db_santize=undefined the following warning shows up. It seems related.

In function ‘rte_ethdev_trace_get_dcb_info’,
inlined from ‘rte_eth_dev_get_dcb_info’ at ../lib/ethdev/rte_ethdev.c:6720:2:
../lib/eal/include/rte_trace_point.h:381:9: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]

  381 |         memcpy(mem, &(in), sizeof(in)); \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/eal/include/rte_trace_point.h:53:9: note: in definition of macro ‘__RTE_TRACE_POINT’
   53 |         __VA_ARGS__ \
      |         ^~~~~~~~~~~
../lib/ethdev/ethdev_trace.h:1213:1: note: in expansion of macro ‘RTE_TRACE_POINT’
 1213 | RTE_TRACE_POINT(
      | ^~~~~~~~~~~~~~~
../lib/eal/include/rte_trace_point.h:399:9: note: in expansion of macro ‘__rte_trace_point_emit’
  399 |         __rte_trace_point_emit(len, uint8_t); \
      |         ^~~~~~~~~~~~~~~~~~~~~~
../lib/ethdev/ethdev_trace.h:1223:9: note: in expansion of macro ‘rte_trace_point_emit_blob’
 1223 |         rte_trace_point_emit_blob(dcb_info->tc_bws, num_tcs);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~

In function ‘rte_eth_dev_get_dcb_info’:
cc1: note: destination object is likely at address zero
In function ‘rte_ethdev_trace_get_dcb_info’,
inlined from ‘rte_eth_dev_get_dcb_info’ at ../lib/ethdev/rte_ethdev.c:6720:2:
../lib/eal/include/rte_trace_point.h:401:9: warning: ‘memset’ offset [0, 55] is out of the bounds [0, 0] [-Warray-bounds=]

  401 |         memset(RTE_PTR_ADD(mem, len), 0, RTE_TRACE_BLOB_LEN_MAX - len); \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/eal/include/rte_trace_point.h:53:9: note: in definition of macro ‘__RTE_TRACE_POINT’
   53 |         __VA_ARGS__ \
      |         ^~~~~~~~~~~
../lib/ethdev/ethdev_trace.h:1213:1: note: in expansion of macro ‘RTE_TRACE_POINT’
 1213 | RTE_TRACE_POINT(
      | ^~~~~~~~~~~~~~~

../lib/ethdev/ethdev_trace.h:1222:9: note: in expansion of macro ‘rte_trace_point_emit_blob’
1222 | rte_trace_point_emit_blob(dcb_info->prio_tc, num_user_priorities);

#7 lore raw

Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Quoted 43 lines · Stephen Hemminger
Quoted 17 lines · On Thu, 30 Jan 2025 15:58:49 +0100 David Marchand <[email protected]>…

Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each tracepoint and make sure that the emitting macros in rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a __rte_unused for each argument (since emitting macros do nothing with them).
This last part introduces an implementation limit of 15 arguments.

Quoted 4 lines

With this change in place, the workaround in dmadev tracepoints can be removed.

When I build with -Db_santize=undefined the following warning shows up. It seems related.

In function ‘rte_ethdev_trace_get_dcb_info’,
inlined from ‘rte_eth_dev_get_dcb_info’ at ../lib/ethdev/rte_ethdev.c:6720:2:
../lib/eal/include/rte_trace_point.h:381:9: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]

  381 |         memcpy(mem, &(in), sizeof(in)); \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/eal/include/rte_trace_point.h:53:9: note: in definition of macro ‘__RTE_TRACE_POINT’
   53 |         __VA_ARGS__ \
      |         ^~~~~~~~~~~
../lib/ethdev/ethdev_trace.h:1213:1: note: in expansion of macro ‘RTE_TRACE_POINT’
 1213 | RTE_TRACE_POINT(
      | ^~~~~~~~~~~~~~~
../lib/eal/include/rte_trace_point.h:399:9: note: in expansion of macro ‘__rte_trace_point_emit’
  399 |         __rte_trace_point_emit(len, uint8_t); \
      |         ^~~~~~~~~~~~~~~~~~~~~~
Quoted 2 lines

../lib/ethdev/ethdev_trace.h:1223:9: note: in expansion of macro ‘rte_trace_point_emit_blob’
1223 | rte_trace_point_emit_blob(dcb_info->tc_bws, num_tcs);

This is something I saw with optimisations (like O2 or O3 iirc) too.

Compiling and running with optimisations made GHA vm go out of memory, so I have been testing only with O0 when it comes to ubsan.

In any case, this series is fixing just one undefined behavior. Fixing all build and runtime errors seen with ubsan requires more work.

Signature · 1 line
David Marchand
#8 lore raw

Re: [PATCH v2 3/3] trace: fix undefined behavior in register

In reply to David Marchand

Hello Jerin, Sunil,

Quoted 18 lines · David Marchand

Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each tracepoint and make sure that the emitting macros in rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a __rte_unused for each argument (since emitting macros do nothing with them).
This last part introduces an implementation limit of 15 arguments.

Quoted 4 lines

With this change in place, the workaround in dmadev tracepoints can be removed.

Can I have your opinion and review on this patch?

Thanks.

Signature · 1 line
David Marchand
#9 lore raw

RE: [EXTERNAL] Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Hi David,

I will look into this at earliest and provide feedback.

Thanks

From: David Marchand <[email protected]>
Sent: Friday, February 7, 2025 2:20 PM
To: Jerin Jacob <[email protected]>; Sunil Kumar Kori <[email protected]>
Cc: [email protected]; Chengwen Feng <[email protected]>; Kevin Laatz <[email protected]>; Bruce Richardson <[email protected]>; Tyler Retzlaff <[email protected]>; Andre Muezerie <[email protected]>; Thomas Monjalon <[email protected]>; Stephen Hemminger <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Hello Jerin, Sunil, On Thu, Jan 30, 2025 at 3: 59 PM David Marchand <david. marchand@ redhat. com> wrote: > > Registering a tracepoint handler was resulting so far in undefined > behavior at runtime. > > The RTE_TRACE_POINT_REGISTER()

Hello Jerin, Sunil,

On Thu, Jan 30, 2025 at 3:59 PM David Marchand

Quoted 36 lines · <[email protected]<mailto:[email protected]>> wrote:

Registering a tracepoint handler was resulting so far in undefined

behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler

(which expects arguments) to a void (*)(void).

At runtime, calling this handler while registering resulted in

reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each

tracepoint and make sure that the emitting macros in

rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a

__rte_unused for each argument (since emitting macros do nothing

with them).

This last part introduces an implementation limit of 15 arguments.

Quoted 7 lines

With this change in place, the workaround in dmadev tracepoints can be

removed.

Can I have your opinion and review on this patch?

Thanks.

--

David Marchand

#10 lore raw

RE: [EXTERNAL] Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Hi David,

I tried validating series to see the trace results but babeltrace throws error while reading metadata file and traces can’t be generated. Can you please have a look into this ?

Thanks.

From: Sunil Kumar Kori
Sent: Friday, February 7, 2025 5:09 PM
To: David Marchand <[email protected]>; Jerin Jacob <[email protected]>
Cc: [email protected]; Chengwen Feng <[email protected]>; Kevin Laatz <[email protected]>; Bruce Richardson <[email protected]>; Tyler Retzlaff <[email protected]>; Andre Muezerie <[email protected]>; Thomas Monjalon <[email protected]>; Stephen Hemminger <[email protected]>
Subject: RE: [EXTERNAL] Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Hi David,

I will look into this at earliest and provide feedback.

Thanks

From: David Marchand <[email protected]<mailto:[email protected]>>
Sent: Friday, February 7, 2025 2:20 PM
To: Jerin Jacob <[email protected]<mailto:[email protected]>>; Sunil Kumar Kori <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>; Chengwen Feng <[email protected]<mailto:[email protected]>>; Kevin Laatz <[email protected]<mailto:[email protected]>>; Bruce Richardson <[email protected]<mailto:[email protected]>>; Tyler Retzlaff <[email protected]<mailto:[email protected]>>; Andre Muezerie <[email protected]<mailto:[email protected]>>; Thomas Monjalon <[email protected]<mailto:[email protected]>>; Stephen Hemminger <[email protected]<mailto:[email protected]>>
Subject: [EXTERNAL] Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Hello Jerin, Sunil, On Thu, Jan 30, 2025 at 3: 59 PM David Marchand <david. marchand@ redhat. com> wrote: > > Registering a tracepoint handler was resulting so far in undefined > behavior at runtime. > > The RTE_TRACE_POINT_REGISTER()

Hello Jerin, Sunil,

On Thu, Jan 30, 2025 at 3:59 PM David Marchand

Quoted 36 lines · <[email protected]<mailto:[email protected]>> wrote:

Registering a tracepoint handler was resulting so far in undefined

behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler

(which expects arguments) to a void (*)(void).

At runtime, calling this handler while registering resulted in

reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each

tracepoint and make sure that the emitting macros in

rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a

__rte_unused for each argument (since emitting macros do nothing

with them).

This last part introduces an implementation limit of 15 arguments.

Quoted 7 lines

With this change in place, the workaround in dmadev tracepoints can be

removed.

Can I have your opinion and review on this patch?

Thanks.

--

David Marchand

#11 lore raw

Re: [EXTERNAL] Re: [PATCH v2 3/3] trace: fix undefined behavior in register

Quoted 6 lines · Sunil Kumar Kori

Hi David,

I tried validating series to see the trace results but babeltrace throws error while reading metadata file and traces can’t be generated.

Can you please have a look into this ?

Ok, I see what is wrong, in the dma trace update.
Too bad we don't have something in the CI to catch such issue...

Anyway, do you have comments on this last patch of the series?

Signature · 1 line
David Marchand
#12 lore raw

RE: [EXTERNAL] [PATCH v2 3/3] trace: fix undefined behavior in register

In reply to David Marchand
Quoted 19 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, January 30, 2025 8:29 PM
To: [email protected]
Cc: Chengwen Feng <[email protected]>; Kevin Laatz <[email protected]>; Bruce Richardson <[email protected]>; Jerin Jacob <[email protected]>; Sunil Kumar Kori <[email protected]>; Tyler Retzlaff <[email protected]>
Subject: [EXTERNAL] [PATCH v2 3/3] trace: fix undefined behavior in register

Registering a tracepoint handler was resulting so far in undefined behavior at runtime. The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void). At runtime, calling this handler while
Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

Quoted 4 lines

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

To reduce the complexity of N number of variable argument, I thought reading. SP should be fine(Not writing and corrupting it). Looks like some optimization is dmadev Trace not liking this. I am good with your N arguments scheme.

Quoted 50 lines

+#define RTE_TRACE_POINT_ARGS_COUNT_(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12, _13,_14,_15,N, ...) \

lib/eal/include/rte_trace_point_register.h +4 -0
+	N
+#define RTE_TRACE_POINT_ARGS_COUNT(...) \
+
+RTE_TRACE_POINT_ARGS_COUNT_(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,

4,3
+,2,1,0)

(quoted diff) +31 -0
+
+#define RTE_TRACE_POINT_ARGS_1(a) __rte_unused a #define
+RTE_TRACE_POINT_ARGS_2(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_1(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_3(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_2(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_4(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_3(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_5(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_4(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_6(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_5(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_7(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_6(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_8(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_7(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_9(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_8(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_10(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_9(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_11(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_10(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_12(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_11(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_13(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_12(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_14(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_13(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_15(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_14(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_FUNC(a) RTE_TRACE_POINT_ARGS_ ## a

#define

(quoted diff) +3 -0
+RTE_TRACE_POINT_ARGS_EXPAND(...) __VA_ARGS__ #define
+RTE_TRACE_POINT_ARGS_(N, ...) \
+

RTE_TRACE_POINT_ARGS_EXPAND(RTE_TRACE_POINT_ARGS_FUNC(N))
(__VA_ARGS__)

(quoted diff) +2 -0
+#define RTE_TRACE_POINT_ARGS(...) \
+	(RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0,

__VA_ARGS__),

Review

Quoted 7 lines
(quoted diff) +7 -0
+__VA_ARGS__))
+
+#define __RTE_TRACE_POINT(_mode, _tp, _args, ...) \ extern
+rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args
+{ } \ static __rte_always_inline void \ _tp ## _register (void) \ { \
+	__rte_trace_point_emit_header_##_mode(&__##_tp); \
+	__VA_ARGS__ \

I have not tested this code, Will this calling __rte_trace_point_emit* version of register? If not, CTF spec file not generated properly.
https://github.com/DPDK/dpdk/blob/main/lib/eal/include/rte_trace_point_register.h#L35

#13 lore raw

Re: [EXTERNAL] [PATCH v2 3/3] trace: fix undefined behavior in register

Quoted 10 lines · Jerin Jacob

lib/eal/include/rte_trace_point_register.h extern "C" { · line 55

Quoted 6 lines
lib/eal/include/rte_trace_point_register.h +6 -0
+
+#define __RTE_TRACE_POINT(_mode, _tp, _args, ...) \ extern
+rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args
+{ } \ static __rte_always_inline void \ _tp ## _register (void) \ { \
+     __rte_trace_point_emit_header_##_mode(&__##_tp); \
+     __VA_ARGS__ \

I have not tested this code, Will this calling __rte_trace_point_emit* version of register? If not, CTF spec file not generated properly.
https://github.com/DPDK/dpdk/blob/main/lib/eal/include/rte_trace_point_register.h#L35

Yes, there are issues with this series that I did not catch until recently. This will be fixed in a new revision (that will also add babeltrace calls in CI..).

Signature · 1 line
David Marchand
Acked-by on v2 1/3
#14 lore raw
In reply to David Marchand
Quoted 19 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, January 30, 2025 8:29 PM
To: [email protected]
Cc: Jerin Jacob <[email protected]>; Sunil Kumar Kori <[email protected]>; Tyler Retzlaff <[email protected]>; Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Subject: [EXTERNAL] [PATCH v2 1/3] trace: support expression for blob length

Support any expression as a blob length by using an intermediate variable in the trace point emitter itself. This also avoids any side effect on the passed variable. Signed-off-by: David Marchand <david. marchand@ redhat. com> --- Changes
Support any expression as a blob length by using an intermediate variable in the trace point emitter itself.

Quoted 3 lines

This also avoids any side effect on the passed variable.

#15 lore raw

v3 cover Trace point framework enhancement for dmadev

In reply to David Marchand

dmadev trace points have been working around trace point framework limitations.
One of this workaround blocks enabling dmadev on MSVC.

Traces files were not checked in CI, so this series also adds a new check.

Signature · 27 lines
David Marchand

Changes since v2:
- added check of traces validity in GHA,
- split patch 2 and fixed CTF metadata,


David Marchand (6):
  ci: check traces validity
  trace: support dereferencing arguments
  trace: support expression for blob length
  trace: support dumping binary inside a struct
  dmadev: avoid copies in tracepoints
  trace: fix undefined behavior in register

 .ci/linux-build.sh                         | 10 +++++
 .github/workflows/build.yml                |  2 +-
 lib/dmadev/rte_dmadev_trace.h              | 32 +++------------
 lib/dmadev/rte_dmadev_trace_fp.h           | 26 ++----------
 lib/eal/common/eal_common_trace_ctf.c      | 39 ++++++++++++------
 lib/eal/include/rte_trace_point.h          | 16 +++++---
 lib/eal/include/rte_trace_point_register.h | 46 +++++++++++++++++++---
 lib/ethdev/ethdev_trace.h                  | 27 ++++---------
 8 files changed, 107 insertions(+), 91 deletions(-)

-- 
2.48.1
#16 lore raw

PATCH v3 1/6 ci: check traces validity

We currently do not validate if generated traces can be parsed by a tracing tool.
Add some check.

---
Changes since v2:
- added this check, as v2 was breaking CTF metadata content,

---
 .ci/linux-build.sh          | 10 ++++++++++
 .github/workflows/build.yml |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
.ci/linux-build.sh +10 -0
index fdb5787621..e9272d3931 100755
@@ -44,6 +44,14 @@ catch_coredump() {
     return 1
 }
 
+check_traces() {
+    which babeltrace >/dev/null || return 0
+    for file in $(sudo find $HOME -name metadata); do
+        ! sudo babeltrace $(dirname $file) >/dev/null 2>&1 || continue
+        sudo babeltrace $(dirname $file)
+    done
+}
+
 cross_file=
 
 if [ "$AARCH64" = "true" ]; then
@@ -133,6 +141,7 @@ if [ -z "$cross_file" ]; then
     configure_coredump
     devtools/test-null.sh || failed="true"
     catch_coredump
+    check_traces
     [ "$failed" != "true" ]
 fi
 
@@ -173,6 +182,7 @@ if [ "$RUN_TESTS" = "true" ]; then
     configure_coredump
     sudo meson test -C build --suite fast-tests -t 3 || failed="true"
     catch_coredump
+    check_traces
     [ "$failed" != "true" ]
 fi
 
.github/workflows/build.yml +1 -1
index dcafb4a8f5..72c7366b88 100644
@@ -151,7 +151,7 @@ jobs:
       run: sudo apt install -y crossbuild-essential-riscv64
     - name: Install test tools packages
       if: env.AARCH64 != 'true' || env.PPC64LE != 'true' || env.RISCV64 != 'true' || env.RUN_TESTS == 'true'
-      run: sudo apt install -y gdb jq
+      run: sudo apt install -y babeltrace gdb jq
     - name: Install doc generation packages
       if: env.BUILD_DOCS == 'true'
       run: sudo apt install -y doxygen graphviz man-db python3-sphinx
Signature · 1 line
2.48.1
#17 lore raw

PATCH v3 2/6 trace: support dereferencing arguments

In reply to David Marchand

Rather than use an intermediate variable, allow use of * to dereference a trace point argument.
Update dmadev traces accordingly (and adjust the emitter type).

---
Changes since v2:
- split this change out of patch 2, as it required updating CTF metadata fixup,

---
 lib/dmadev/rte_dmadev_trace_fp.h      | 12 +++------
 lib/eal/common/eal_common_trace_ctf.c | 35 ++++++++++++++++++---------
 2 files changed, 27 insertions(+), 20 deletions(-)
lib/dmadev/rte_dmadev_trace_fp.h +4 -8
index f5b96838bc..4950f58cd2 100644
@@ -37,10 +37,9 @@ RTE_TRACE_POINT_FP(
 	enum rte_dma_vchan_status __status = 0;
 	status = &__status;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int vchan_status = *status;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(vchan_status);
+	rte_trace_point_emit_int(*status);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -107,13 +106,11 @@ RTE_TRACE_POINT_FP(
 	last_idx = &__last_idx;
 	has_error = &__has_error;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int has_error_val = *has_error;
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
-	rte_trace_point_emit_int(has_error_val);
+	rte_trace_point_emit_u16(*last_idx);
+	rte_trace_point_emit_u8(*has_error);
 	rte_trace_point_emit_u16(ret);
 )
 
@@ -126,11 +123,10 @@ RTE_TRACE_POINT_FP(
 	uint16_t __last_idx = 0;
 	last_idx = &__last_idx;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
+	rte_trace_point_emit_u16(*last_idx);
 	rte_trace_point_emit_ptr(status);
 	rte_trace_point_emit_u16(ret);
 )
lib/eal/common/eal_common_trace_ctf.c +23 -12
index 04c4f71462..3e4228ee7f 100644
@@ -373,6 +373,11 @@ rte_trace_metadata_dump(FILE *f)
 
 char *trace_metadata_fixup_field(const char *field)
 {
+	static const char * const tokens[] = {
+		".",
+		"->",
+		"*",
+	};
 	const char *ctf_reserved_words[] = {
 		"align",
 		"event",
@@ -390,23 +395,29 @@ char *trace_metadata_fixup_field(const char *field)
 		return out;
 	}
 
+	for (i = 0; i < RTE_DIM(tokens); i++) {
+		if (strstr(field, tokens[i]) == NULL)
+			continue;
+		goto fixup;
+	}
+
 	/* nothing to replace, return early */
-	if (strstr(field, ".") == NULL && strstr(field, "->") == NULL)
-		return NULL;
+	return NULL;
 
+fixup:
 	out = strdup(field);
 	if (out == NULL)
 		return NULL;
-	p = out;
-	while ((p = strstr(p, ".")) != NULL) {
-		p[0] = '_';
-		p++;
-	}
-	p = out;
-	while ((p = strstr(p, "->")) != NULL) {
-		p[0] = '_';
-		p++;
-		memmove(p, p + 1, strlen(p));
+	for (i = 0; i < RTE_DIM(tokens); i++) {
+		p = out;
+		while ((p = strstr(p, tokens[i])) != NULL) {
+			p[0] = '_';
+			p++;
+			if (strlen(tokens[i]) != 1) {
+				memmove(p, p + (strlen(tokens[i]) - 1),
+					strlen(p) - (strlen(tokens[i]) - 2));
+			}
+		}
 	}
 	return out;
 }
Signature · 1 line
2.48.1
#18 lore raw

RE: [EXTERNAL] [PATCH v3 2/6] trace: support dereferencing arguments

lib/eal/common/eal_common_trace_ctf.c rte_trace_metadata_dump(FILE *f) · line 379

Quoted 13 lines
lib/eal/common/eal_common_trace_ctf.c +5 -0
index 04c4f71462..3e4228ee7f 100644
@@ -373,6 +373,11 @@ rte_trace_metadata_dump(FILE *f)
 
 char *trace_metadata_fixup_field(const char *field)  {
+	static const char * const tokens[] = {
+		".",
+		"->",
+		"*",
+	};

As this patch is intended to support dereferencing operation but as a side effect it applies to multiplication operator too. Hence for A * B, field is generated like A___B (one extra underscore). So IMO, multiplication string shouldn't be used.

Quoted 5 lines
lib/eal/common/eal_common_trace_ctf.c +0 -0
 	const char *ctf_reserved_words[] = {
 		"align",
 		"event",
 

2.48.1

#19 lore raw

Re: [EXTERNAL] [PATCH v3 2/6] trace: support dereferencing arguments

Quoted 8 lines · Sunil Kumar Kori
Quoted 8 lines
lib/eal/common/eal_common_trace_ctf.c +0 -0
index 04c4f71462..3e4228ee7f 100644
@@ -373,6 +373,11 @@ rte_trace_metadata_dump(FILE *f)
 
Quoted 7 lines

lib/eal/common/eal_common_trace_ctf.c rte_trace_metadata_dump(FILE *f) · line 380

Quoted 6 lines
lib/eal/common/eal_common_trace_ctf.c +5 -0
 char *trace_metadata_fixup_field(const char *field)  {
+     static const char * const tokens[] = {
+             ".",
+             "->",
+             "*",
+     };

As this patch is intended to support dereferencing operation but as a side effect it applies to multiplication operator too.

Support for multiplication helps with the next patch too, when passing an array size as a blob length.

Quoted 1 line

Hence for A * B, field is generated like A___B (one extra underscore). So IMO, multiplication string shouldn't be used.

I am not following the consequence.. why should it be prevented?

Signature · 1 line
David Marchand
#20 lore raw

RE: [EXTERNAL] [PATCH v3 2/6] trace: support dereferencing arguments

Quoted 19 lines
Quoted 8 lines · Sunil Kumar Kori
Quoted 8 lines
lib/eal/common/eal_common_trace_ctf.c +0 -0
index 04c4f71462..3e4228ee7f 100644
@@ -373,6 +373,11 @@ rte_trace_metadata_dump(FILE *f)
 
Quoted 7 lines

lib/eal/common/eal_common_trace_ctf.c rte_trace_metadata_dump(FILE *f) · line 380

Quoted 6 lines
lib/eal/common/eal_common_trace_ctf.c +5 -0
 char *trace_metadata_fixup_field(const char *field)  {
+     static const char * const tokens[] = {
+             ".",
+             "->",
+             "*",
+     };

As this patch is intended to support dereferencing operation but as a side

effect it applies to multiplication operator too.

Quoted 7 lines

Support for multiplication helps with the next patch too, when passing an array size as a blob length.

Quoted 1 line

Hence for A * B, field is generated like A___B (one extra underscore). So

IMO, multiplication string shouldn't be used.

I am not following the consequence.. why should it be prevented?

As such there is no consequence on functionality. It's just about readability. For example, num_entries * size will result in num_entries___size which actually not representing that this is used to size. Instead tot_size = num_entries * size and then using tot_size clearly specifies that it is the total size of array.

Quoted 4 lines

--
David Marchand

#21 lore raw

PATCH v3 3/6 trace: support expression for blob length

In reply to David Marchand

Support any expression as a blob length by using an intermediate variable in the trace point emitter itself.
This also avoids any side effect on the passed variable.

On the "register" side, prefix the length variable in the trace metadata with the name of the emitted argument.

With this, we can update ethdev traces and avoid intermediate variables.

---
Changes since v2:
- fixed length field in CTF metadata,

Changes since v1:
- removed code relying on arguments in "registering" rte_trace_point_emit_blob implementation (see patch 3),
- moved build check in non registering __rte_trace_point_emit,

---
 lib/eal/common/eal_common_trace_ctf.c      |  1 +
 lib/eal/include/rte_trace_point.h          | 12 ++++++----
 lib/eal/include/rte_trace_point_register.h |  7 ++++--
 lib/ethdev/ethdev_trace.h                  | 27 ++++++----------------
 4 files changed, 20 insertions(+), 27 deletions(-)
lib/eal/common/eal_common_trace_ctf.c +1 -0
index 3e4228ee7f..6bc8bb9036 100644
@@ -377,6 +377,7 @@ char *trace_metadata_fixup_field(const char *field)
 		".",
 		"->",
 		"*",
+		" ",
 	};
 	const char *ctf_reserved_words[] = {
 		"align",
lib/eal/include/rte_trace_point.h +7 -5
index b24db3b6da..a162502002 100644
@@ -378,6 +378,7 @@ do { \
 
 #define __rte_trace_point_emit(in, type) \
 do { \
+	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(in))); \
 	memcpy(mem, &(in), sizeof(in)); \
 	mem = RTE_PTR_ADD(mem, sizeof(in)); \
 } while (0)
@@ -392,13 +393,14 @@ do { \
 
 #define rte_trace_point_emit_blob(in, len) \
 do { \
+	uint8_t size = len; \
 	if (unlikely(in == NULL)) \
 		return; \
-	if (len > RTE_TRACE_BLOB_LEN_MAX) \
-		len = RTE_TRACE_BLOB_LEN_MAX; \
-	__rte_trace_point_emit(len, uint8_t); \
-	memcpy(mem, in, len); \
-	memset(RTE_PTR_ADD(mem, len), 0, RTE_TRACE_BLOB_LEN_MAX - len); \
+	if (size > RTE_TRACE_BLOB_LEN_MAX) \
+		size = RTE_TRACE_BLOB_LEN_MAX; \
+	__rte_trace_point_emit(size, uint8_t); \
+	memcpy(mem, in, size); \
+	memset(RTE_PTR_ADD(mem, size), 0, RTE_TRACE_BLOB_LEN_MAX - size); \
 	mem = RTE_PTR_ADD(mem, RTE_TRACE_BLOB_LEN_MAX); \
 } while (0)
 
lib/eal/include/rte_trace_point_register.h +5 -2
index 748c931830..8d0959c403 100644
@@ -37,7 +37,7 @@ RTE_INIT(trace##_init) \
 
 #define __rte_trace_point_emit(in, type) \
 do { \
-	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(in))); \
+	RTE_SET_USED(in); \
 	__rte_trace_point_emit_field(sizeof(type), RTE_STR(in), \
 		RTE_STR(type)); \
 } while (0)
@@ -52,7 +52,10 @@ do { \
 #define rte_trace_point_emit_blob(in, len) \
 do { \
 	RTE_SET_USED(in); \
-	__rte_trace_point_emit(len, uint8_t); \
+	RTE_SET_USED(len); \
+	__rte_trace_point_emit_field(sizeof(uint8_t), \
+		RTE_STR(in) "_" RTE_STR(len), \
+		RTE_STR(uint8_t)); \
 	__rte_trace_point_emit_field(RTE_TRACE_BLOB_LEN_MAX, \
 		RTE_STR(in)"[" RTE_STR(RTE_TRACE_BLOB_LEN_MAX)"]", \
 		RTE_STR(uint8_t)); \
lib/ethdev/ethdev_trace.h +7 -20
index 5951ae2d99..c65b78590a 100644
@@ -860,10 +860,8 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_add,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr, uint32_t pool, int ret),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_u32(pool);
 	rte_trace_point_emit_int(ret);
 )
@@ -872,20 +870,16 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_remove,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
 	rte_ethdev_trace_default_mac_addr_set,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
@@ -1102,11 +1096,9 @@ RTE_TRACE_POINT(
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr,
 		int ret),
-	uint8_t len = nb_mc_addr * RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u32(nb_mc_addr);
-	rte_trace_point_emit_blob(mc_addr_set, len);
+	rte_trace_point_emit_blob(mc_addr_set, nb_mc_addr * RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -1214,13 +1206,10 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_get_dcb_info,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_eth_dcb_info *dcb_info, int ret),
-	uint8_t num_user_priorities = RTE_ETH_DCB_NUM_USER_PRIORITIES;
-	uint8_t num_tcs = RTE_ETH_DCB_NUM_TCS;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u8(dcb_info->nb_tcs);
-	rte_trace_point_emit_blob(dcb_info->prio_tc, num_user_priorities);
-	rte_trace_point_emit_blob(dcb_info->tc_bws, num_tcs);
+	rte_trace_point_emit_blob(dcb_info->prio_tc, RTE_ETH_DCB_NUM_USER_PRIORITIES);
+	rte_trace_point_emit_blob(dcb_info->tc_bws, RTE_ETH_DCB_NUM_TCS);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -2126,10 +2115,8 @@ RTE_TRACE_POINT_FP(
 	rte_eth_trace_macaddr_get,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mac_addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(mac_addr->addr_bytes, len);
+	rte_trace_point_emit_blob(mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 /* Called in loop in examples/ip_pipeline */
Signature · 1 line
2.48.1
#22 lore raw

PATCH v3 4/6 trace: support dumping binary inside a struct

In reply to David Marchand

Make it possible to dump any point of a structure by accepting & and () in the CTF metadata.
Update dmadev traces accordingly.

---
Changes since v2:
- split this change out of patch 2, as it required updating CTF metadata fixup,

---
 lib/dmadev/rte_dmadev_trace.h         | 8 ++------
 lib/eal/common/eal_common_trace_ctf.c | 3 +++
 2 files changed, 5 insertions(+), 6 deletions(-)
lib/dmadev/rte_dmadev_trace.h +2 -6
index be089c065c..c5e4babe15 100644
@@ -86,18 +86,14 @@ RTE_TRACE_POINT(
 	int src_port_type = conf->src_port.port_type;
 	int dst_port_type = conf->dst_port.port_type;
 	int direction = conf->direction;
-	uint64_t src_pcie_cfg;
-	uint64_t dst_pcie_cfg;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int(direction);
 	rte_trace_point_emit_u16(conf->nb_desc);
 	rte_trace_point_emit_int(src_port_type);
-	memcpy(&src_pcie_cfg, &conf->src_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_u64(src_pcie_cfg);
-	memcpy(&dst_pcie_cfg, &conf->dst_port.pcie, sizeof(uint64_t));
+	rte_trace_point_emit_blob(&conf->src_port.pcie, sizeof(uint64_t));
 	rte_trace_point_emit_int(dst_port_type);
-	rte_trace_point_emit_u64(dst_pcie_cfg);
+	rte_trace_point_emit_blob(&conf->dst_port.pcie, sizeof(uint64_t));
 	rte_trace_point_emit_ptr(conf->auto_free.m2d.pool);
 	rte_trace_point_emit_int(ret);
 )
lib/eal/common/eal_common_trace_ctf.c +3 -0
index 6bc8bb9036..d9b307e076 100644
@@ -378,6 +378,9 @@ char *trace_metadata_fixup_field(const char *field)
 		"->",
 		"*",
 		" ",
+		"&",
+		"(",
+		")",
 	};
 	const char *ctf_reserved_words[] = {
 		"align",
Signature · 1 line
2.48.1
#23 lore raw

RE: [EXTERNAL] [PATCH v3 4/6] trace: support dumping binary inside a struct

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char *field) · line 383

Quoted 12 lines
lib/eal/common/eal_common_trace_ctf.c +3 -0
index 6bc8bb9036..d9b307e076 100644
@@ -378,6 +378,9 @@ char *trace_metadata_fixup_field(const char *field)
 		"->",
 		"*",
 		" ",
+		"&",
+		"(",
+		")",

Adding brackets makes token names a bit complex. Same name is used in metadata file to dump the traces to the user. With this complex name, user might not understand the purpose of that information.

For example, _conf_src_port_pcie_sizeof_uint64_t_ is created in metafile and same will be dumped. But with this User might not get that which information is provided.

This is the reason; we followed the existing naming convention which is user friendly.

Quoted 5 lines
lib/eal/common/eal_common_trace_ctf.c +0 -1
 	};
 	const char *ctf_reserved_words[] = {
 		"align",
--

2.48.1

#24 lore raw

Re: [EXTERNAL] [PATCH v3 4/6] trace: support dumping binary inside a struct

Quoted 17 lines · Sunil Kumar Kori

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char *field) · line 383

Quoted 13 lines
lib/eal/common/eal_common_trace_ctf.c +3 -0
index 6bc8bb9036..d9b307e076 100644
@@ -378,6 +378,9 @@ char *trace_metadata_fixup_field(const char *field)
              "->",
              "*",
              " ",
+             "&",
+             "(",
+             ")",

Adding brackets makes token names a bit complex. Same name is used in metadata file to dump the traces to the user. With this complex name, user might not understand the purpose of that information.

Quoted 2 lines

For example, _conf_src_port_pcie_sizeof_uint64_t_ is created in metafile and same will be dumped. But with this User might not get that which information is provided.

In practice, as there is no other documentation for a trace point arguments, a user needs to read the trace point definitions. So it seems trivial to me to link a variable name in the trace point emitter, and the metadata in the trace files.

Quoted 2 lines

This is the reason; we followed the existing naming convention which is user friendly.

User friendly? I don't see how this is different with '.' and '->'. What is missing is documentation, as nothing describes this sanitisation in the first place (even before this series).

Signature · 1 line
David Marchand
#25 lore raw

RE: [EXTERNAL] [PATCH v3 4/6] trace: support dumping binary inside a struct

Quoted 30 lines
Quoted 7 lines · Sunil Kumar Kori

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char

Quoted 7 lines
lib/eal/common/eal_common_trace_ctf.c +0 -0
index 6bc8bb9036..d9b307e076 100644
@@ -378,6 +378,9 @@ char *trace_metadata_fixup_field(const char

*field)

Quoted 6 lines

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char *field) · line 383

Quoted 6 lines
lib/eal/common/eal_common_trace_ctf.c +3 -0
              "->",
              "*",
              " ",
+             "&",
+             "(",
+             ")",
Quoted 6 lines

Adding brackets makes token names a bit complex. Same name is used in metadata file to dump the traces to the user. With this complex name, user might not understand the purpose of that information.

For example, _conf_src_port_pcie_sizeof_uint64_t_ is created in metafile and same will be dumped. But with this User might not get that

which information is provided.

In practice, as there is no other documentation for a trace point arguments, a user needs to read the trace point definitions.
So it seems trivial to me to link a variable name in the trace point emitter, and the metadata in the trace files.

Quoted 1 line
Quoted 4 lines
Quoted 1 line

This is the reason; we followed the existing naming convention which is user

friendly.

User friendly? I don't see how this is different with '.' and '->'.

In general, structure fields are given a proper name to represent the purpose. When we use it directly in trace point using '.' or '->' then it remains a meaningful name. Adding more tokens in name, is making them complex and deviating from there meaning.

I am not saying that the mentioned support should not be there. I am just trying to convey that If it is possible to make meaningful names, then that will be more helpful.

Quoted 6 lines

What is missing is documentation, as nothing describes this sanitisation in the first place (even before this series).

--
David Marchand

#26 lore raw

Re: [EXTERNAL] [PATCH v3 4/6] trace: support dumping binary inside a struct

Quoted 34 lines · Sunil Kumar Kori
Quoted 34 lines
Quoted 7 lines · Sunil Kumar Kori

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char

Quoted 7 lines
lib/eal/common/eal_common_trace_ctf.c +0 -0
index 6bc8bb9036..d9b307e076 100644
@@ -378,6 +378,9 @@ char *trace_metadata_fixup_field(const char

*field)

Quoted 6 lines

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char *field) · line 383

Quoted 6 lines
lib/eal/common/eal_common_trace_ctf.c +3 -0
              "->",
              "*",
              " ",
+             "&",
+             "(",
+             ")",
Quoted 6 lines

Adding brackets makes token names a bit complex. Same name is used in metadata file to dump the traces to the user. With this complex name, user might not understand the purpose of that information.

For example, _conf_src_port_pcie_sizeof_uint64_t_ is created in metafile and same will be dumped. But with this User might not get that

which information is provided.

In practice, as there is no other documentation for a trace point arguments, a user needs to read the trace point definitions.
So it seems trivial to me to link a variable name in the trace point emitter, and the metadata in the trace files.

Quoted 2 lines

This is the reason; we followed the existing naming convention which is user

friendly.

Quoted 7 lines
Quoted 1 line

User friendly? I don't see how this is different with '.' and '->'.

In general, structure fields are given a proper name to represent the purpose. When we use it directly in trace point using '.' or '->' then it remains a meaningful name. Adding more tokens in name, is making them complex and deviating from there meaning.

I am not saying that the mentioned support should not be there. I am just trying to convey that If it is possible to make meaningful names, then that will be more helpful.

Hard to preserve such information given the limitations of the C parser (which seems to apply to the CTF format).
I still think that interpretation of the metadata in the traces require looking at the source code, which means that the "readability" objection is weak.

Jerin, opinion please.

Signature · 1 line
David Marchand
#27 lore raw

RE: [EXTERNAL] [PATCH v3 4/6] trace: support dumping binary inside a struct

Quoted 65 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Tuesday, February 18, 2025 7:58 PM
To: Sunil Kumar Kori <[email protected]>; Jerin Jacob <[email protected]>
Cc: [email protected]; [email protected]; Kevin Laatz <[email protected]>; Bruce Richardson <[email protected]>; Tyler Retzlaff <[email protected]>
Subject: Re: [EXTERNAL] [PATCH v3 4/6] trace: support dumping binary inside a struct

On Wed, Feb 12, 2025 at 6: 14 AM Sunil Kumar Kori <skori@ marvell. com>
wrote: > > > On Tue, Feb 11, 2025 at 9: 53 AM Sunil Kumar Kori <skori@ marvell. com> > > wrote: > > > > > > > diff --git a/lib/eal/common/eal_common_trace_ctf. c

Quoted 32 lines · Sunil Kumar Kori
Quoted 32 lines
Quoted 7 lines · Sunil Kumar Kori

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char

Quoted 7 lines
lib/eal/common/eal_common_trace_ctf.c +0 -0
index 6bc8bb9036..d9b307e076 100644
@@ -378,6 +378,9 @@ char *trace_metadata_fixup_field(const char

*field)

Quoted 6 lines

lib/eal/common/eal_common_trace_ctf.c char *trace_metadata_fixup_field(const char *field) · line 383

Quoted 6 lines
lib/eal/common/eal_common_trace_ctf.c +3 -0
              "->",
              "*",
              " ",
+             "&",
+             "(",
+             ")",
Quoted 7 lines

Adding brackets makes token names a bit complex. Same name is used in metadata file to dump the traces to the user. With this complex name, user might not understand the purpose of that information.

For example, _conf_src_port_pcie_sizeof_uint64_t_ is created in metafile and same will be dumped. But with this User might not get that

which information is provided.

In practice, as there is no other documentation for a trace point arguments, a user needs to read the trace point definitions. So it seems trivial to me to link a variable name in the trace point emitter, and the metadata in the trace files.

Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This is the reason; we followed the existing naming convention which is user

friendly.

User friendly? I don't see how this is different with '.' and '->'.

In general, structure fields are given a proper name to represent the purpose. When we use it directly in trace point using '.' or '->' then it remains a

meaningful name.

Quoted 1 line

Adding more tokens in name, is making them complex and deviating from

there meaning.

Quoted 3 lines

I am not saying that the mentioned support should not be there. I am just trying to convey that If it is possible to make meaningful names, then that

will be more helpful.

Quoted 7 lines

Hard to preserve such information given the limitations of the C parser (which seems to apply to the CTF format).
I still think that interpretation of the metadata in the traces require looking at the source code, which means that the "readability"
objection is weak.

Jerin, opinion please.

One side, it reduces the number of lines of code, leveraging all CTF syntax and other side it traces string becomes complex. IMO, We can go with new patch scheme and document the new syntax so that someone parsing babetrace or tracecompass can understand the meaning of _conf_src_port_pcie_sizeof_uint64_t_ (as example)

Quoted 4 lines

--
David Marchand

#28 lore raw

PATCH v3 5/6 dmadev: avoid copies in tracepoints

In reply to David Marchand

No need to copy values in intermediate variables.
Just use the right trace point emitters.

---
Changes since v2:
- split this change into multiple changes,
only kept trivial parts in this patch,

---
 lib/dmadev/rte_dmadev_trace.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
lib/dmadev/rte_dmadev_trace.h +4 -8
index c5e4babe15..ddf60b9649 100644
@@ -46,11 +46,10 @@ RTE_TRACE_POINT(
 	const struct rte_dma_conf __dev_conf = {0};
 	dev_conf = &__dev_conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int enable_silent = (int)dev_conf->enable_silent;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
 	rte_trace_point_emit_u16(dev_conf->priority);
-	rte_trace_point_emit_int(enable_silent);
+	rte_trace_point_emit_u8(dev_conf->enable_silent);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -83,16 +82,13 @@ RTE_TRACE_POINT(
 	const struct rte_dma_vchan_conf __conf = {0};
 	conf = &__conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int src_port_type = conf->src_port.port_type;
-	int dst_port_type = conf->dst_port.port_type;
-	int direction = conf->direction;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(direction);
+	rte_trace_point_emit_int(conf->direction);
 	rte_trace_point_emit_u16(conf->nb_desc);
-	rte_trace_point_emit_int(src_port_type);
+	rte_trace_point_emit_int(conf->src_port.port_type);
 	rte_trace_point_emit_blob(&conf->src_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_int(dst_port_type);
+	rte_trace_point_emit_int(conf->dst_port.port_type);
 	rte_trace_point_emit_blob(&conf->dst_port.pcie, sizeof(uint64_t));
 	rte_trace_point_emit_ptr(conf->auto_free.m2d.pool);
 	rte_trace_point_emit_int(ret);
Signature · 1 line
2.48.1
#29 lore raw

PATCH v3 6/6 trace: fix undefined behavior in register

In reply to David Marchand

Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each tracepoint and make sure that the emitting macros in rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a __rte_unused for each argument (since emitting macros do nothing with them).
This last part introduces an implementation limit of 15 arguments.

With this change in place, the workaround in dmadev tracepoints can be removed.

---
 lib/dmadev/rte_dmadev_trace.h              | 12 ------
 lib/dmadev/rte_dmadev_trace_fp.h           | 14 -------
 lib/eal/include/rte_trace_point.h          |  4 ++
 lib/eal/include/rte_trace_point_register.h | 43 +++++++++++++++++++---
 4 files changed, 42 insertions(+), 31 deletions(-)
lib/dmadev/rte_dmadev_trace.h +0 -12
index ddf60b9649..9de9b54aad 100644
@@ -22,10 +22,6 @@ extern "C" {
 RTE_TRACE_POINT(
 	rte_dma_trace_info_get,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, struct rte_dma_info *dev_info),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	struct rte_dma_info __dev_info = {0};
-	dev_info = &__dev_info;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_string(dev_info->dev_name);
 	rte_trace_point_emit_u64(dev_info->dev_capa);
@@ -42,10 +38,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_configure,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, const struct rte_dma_conf *dev_conf,
 			     int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_conf __dev_conf = {0};
-	dev_conf = &__dev_conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
 	rte_trace_point_emit_u16(dev_conf->priority);
@@ -78,10 +70,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_vchan_setup,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const struct rte_dma_vchan_conf *conf, int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_vchan_conf __conf = {0};
-	conf = &__conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int(conf->direction);
lib/dmadev/rte_dmadev_trace_fp.h +0 -14
index 4950f58cd2..106eac24be 100644
@@ -33,10 +33,6 @@ RTE_TRACE_POINT_FP(
 	rte_dma_trace_vchan_status,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     enum rte_dma_vchan_status *status, int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	enum rte_dma_vchan_status __status = 0;
-	status = &__status;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int(*status);
@@ -100,12 +96,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     bool *has_error, uint16_t ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	uint16_t __last_idx = 0;
-	bool __has_error = false;
-	last_idx = &__last_idx;
-	has_error = &__has_error;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
@@ -119,10 +109,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     enum rte_dma_status_code *status, uint16_t ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	uint16_t __last_idx = 0;
-	last_idx = &__last_idx;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
lib/eal/include/rte_trace_point.h +4 -0
index a162502002..444175f238 100644
@@ -36,6 +36,8 @@ extern "C" {
 /** The tracepoint object. */
 typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;
 
+#ifndef _RTE_TRACE_POINT_REGISTER_H_
+
 /**
  * Macro to define the tracepoint arguments in RTE_TRACE_POINT macro.
 
@@ -53,6 +55,8 @@ _tp _args \
 	__VA_ARGS__ \
 }
 
+#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
+
 /**
  * Create a tracepoint.
  *
lib/eal/include/rte_trace_point_register.h +38 -5

73 lines not on this page · raw message

Signature · 1 line
2.48.1
#30 lore raw

RE: [EXTERNAL] [PATCH v3 0/6] Trace point framework enhancement for dmadev

In reply to David Marchand

Hi David,

I validated the series and its functional now. Traces are generated properly.

Quoted 34 lines

dmadev trace points have been working around trace point framework limitations.
One of this workaround blocks enabling dmadev on MSVC.

Traces files were not checked in CI, so this series also adds a new check.

--
David Marchand

Changes since v2:
- added check of traces validity in GHA,
- split patch 2 and fixed CTF metadata,

David Marchand (6):
ci: check traces validity
trace: support dereferencing arguments
trace: support expression for blob length
trace: support dumping binary inside a struct
dmadev: avoid copies in tracepoints
trace: fix undefined behavior in register

 .ci/linux-build.sh                         | 10 +++++
 .github/workflows/build.yml                |  2 +-
 lib/dmadev/rte_dmadev_trace.h              | 32 +++------------
 lib/dmadev/rte_dmadev_trace_fp.h           | 26 ++----------
 lib/eal/common/eal_common_trace_ctf.c      | 39 ++++++++++++------
 lib/eal/include/rte_trace_point.h          | 16 +++++---
 lib/eal/include/rte_trace_point_register.h | 46 +++++++++++++++++++---
 lib/ethdev/ethdev_trace.h                  | 27 ++++---------
 8 files changed, 107 insertions(+), 91 deletions(-)

--
2.48.1

#31 lore raw

v4 cover Trace point framework enhancement for dmadev

In reply to David Marchand

dmadev trace points have been working around trace point framework limitations.
One of this workaround blocks enabling dmadev on MSVC.

Traces files were not checked in CI, so this series also adds a new check.

Signature · 32 lines
David Marchand

Changes since v3:
- dropped changes to CTF metadata,
- added new helpers for dumping content of pointed at memory,
- changed dmadev to avoid more changes in trace framework,

Changes since v2:
- added check of traces validity in GHA,
- split patch 2 and fixed CTF metadata,


David Marchand (5):
  ci: check traces validity
  dmadev: avoid copies in tracepoints
  trace: support dereferencing pointers
  trace: support expression for blob length
  trace: fix undefined behavior in register

 .ci/linux-build.sh                         | 10 ++++
 .github/workflows/build.yml                |  2 +-
 devtools/libabigail.abignore               |  5 ++
 lib/dmadev/rte_dmadev.h                    | 29 +++++-----
 lib/dmadev/rte_dmadev_trace.h              | 32 ++---------
 lib/dmadev/rte_dmadev_trace_fp.h           | 26 ++-------
 lib/eal/include/rte_trace_point.h          | 66 ++++++++++++++--------
 lib/eal/include/rte_trace_point_register.h | 51 ++++++++++++++---
 lib/ethdev/ethdev_trace.h                  | 27 +++------
 9 files changed, 135 insertions(+), 113 deletions(-)

-- 
2.48.1
#32 lore raw

PATCH v4 1/5 ci: check traces validity

We currently do not validate if generated traces can be parsed by a tracing tool.
Add some check.

---
Changes since v2:
- added this check, as v2 was breaking CTF metadata content,

---
 .ci/linux-build.sh          | 10 ++++++++++
 .github/workflows/build.yml |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
.ci/linux-build.sh +10 -0
index fdb5787621..e9272d3931 100755
@@ -44,6 +44,14 @@ catch_coredump() {
     return 1
 }
 
+check_traces() {
+    which babeltrace >/dev/null || return 0
+    for file in $(sudo find $HOME -name metadata); do
+        ! sudo babeltrace $(dirname $file) >/dev/null 2>&1 || continue
+        sudo babeltrace $(dirname $file)
+    done
+}
+
 cross_file=
 
 if [ "$AARCH64" = "true" ]; then
@@ -133,6 +141,7 @@ if [ -z "$cross_file" ]; then
     configure_coredump
     devtools/test-null.sh || failed="true"
     catch_coredump
+    check_traces
     [ "$failed" != "true" ]
 fi
 
@@ -173,6 +182,7 @@ if [ "$RUN_TESTS" = "true" ]; then
     configure_coredump
     sudo meson test -C build --suite fast-tests -t 3 || failed="true"
     catch_coredump
+    check_traces
     [ "$failed" != "true" ]
 fi
 
.github/workflows/build.yml +1 -1
index aef692ca1f..183b0b1999 100644
@@ -151,7 +151,7 @@ jobs:
       run: sudo apt install -y crossbuild-essential-riscv64
     - name: Install test tools packages
       if: env.AARCH64 != 'true' || env.PPC64LE != 'true' || env.RISCV64 != 'true' || env.RUN_TESTS == 'true'
-      run: sudo apt install -y gdb jq
+      run: sudo apt install -y babeltrace gdb jq
     - name: Install doc generation packages
       if: env.BUILD_DOCS == 'true'
       run: sudo apt install -y doxygen graphviz man-db python3-sphinx
Signature · 1 line
2.48.1
#33 lore raw

PATCH v4 2/5 dmadev: avoid copies in tracepoints

In reply to David Marchand

No need to copy values in intermediate variables.
Use the right trace point emitters.
Update the pcie struct to avoid aliasing warning.

---
Changes since v3:
- added anonymous union around pcie struct (which triggered an abidiff warning that needs waiving) and kept original call to rte_trace_point_emit_u64,

Changes since v2:
- split this change into multiple changes,
only kept trivial parts in this patch,

---
 devtools/libabigail.abignore  |  5 +++++
 lib/dmadev/rte_dmadev.h       | 29 ++++++++++++++++-------------
 lib/dmadev/rte_dmadev_trace.h | 20 ++++++--------------
 3 files changed, 27 insertions(+), 27 deletions(-)
devtools/libabigail.abignore +5 -0
index ce501632b3..88aa1ec981 100644
@@ -36,3 +36,8 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Temporary exceptions till next major ABI version ;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+[suppress_type]
+        name = rte_dma_port_param
+        type_kind = struct
+        has_size_change = no
+        has_data_member = {pcie}
lib/dmadev/rte_dmadev.h +16 -13
index 2f9304a9db..26f9d4b095 100644
@@ -523,19 +523,22 @@ struct rte_dma_port_param {
 		 * and capabilities.
 		 */
 		__extension__
-		struct {
-			uint64_t coreid : 4; /**< PCIe core id used. */
-			uint64_t pfid : 8; /**< PF id used. */
-			uint64_t vfen : 1; /**< VF enable bit. */
-			uint64_t vfid : 16; /**< VF id used. */
-			/** The pasid filed in TLP packet. */
-			uint64_t pasid : 20;
-			/** The attributes filed in TLP packet. */
-			uint64_t attr : 3;
-			/** The processing hint filed in TLP packet. */
-			uint64_t ph : 2;
-			/** The steering tag filed in TLP packet. */
-			uint64_t st : 16;
+		union {
+			struct {
+				uint64_t coreid : 4; /**< PCIe core id used. */
+				uint64_t pfid : 8; /**< PF id used. */
+				uint64_t vfen : 1; /**< VF enable bit. */
+				uint64_t vfid : 16; /**< VF id used. */
+				/** The pasid filed in TLP packet. */
+				uint64_t pasid : 20;
+				/** The attributes filed in TLP packet. */
+				uint64_t attr : 3;
+				/** The processing hint filed in TLP packet. */
+				uint64_t ph : 2;
+				/** The steering tag filed in TLP packet. */
+				uint64_t st : 16;
+			};
+			uint64_t val;
 		} pcie;
 	};
 	uint64_t reserved[2]; /**< Reserved for future fields. */
lib/dmadev/rte_dmadev_trace.h +6 -14
index be089c065c..1beb938168 100644
@@ -46,11 +46,10 @@ RTE_TRACE_POINT(
 	const struct rte_dma_conf __dev_conf = {0};
 	dev_conf = &__dev_conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int enable_silent = (int)dev_conf->enable_silent;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
 	rte_trace_point_emit_u16(dev_conf->priority);
-	rte_trace_point_emit_int(enable_silent);
+	rte_trace_point_emit_u8(dev_conf->enable_silent);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -83,21 +82,14 @@ RTE_TRACE_POINT(
 	const struct rte_dma_vchan_conf __conf = {0};
 	conf = &__conf;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int src_port_type = conf->src_port.port_type;
-	int dst_port_type = conf->dst_port.port_type;
-	int direction = conf->direction;
-	uint64_t src_pcie_cfg;
-	uint64_t dst_pcie_cfg;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(direction);
+	rte_trace_point_emit_int(conf->direction);
 	rte_trace_point_emit_u16(conf->nb_desc);
-	rte_trace_point_emit_int(src_port_type);
-	memcpy(&src_pcie_cfg, &conf->src_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_u64(src_pcie_cfg);
-	memcpy(&dst_pcie_cfg, &conf->dst_port.pcie, sizeof(uint64_t));
-	rte_trace_point_emit_int(dst_port_type);
-	rte_trace_point_emit_u64(dst_pcie_cfg);
+	rte_trace_point_emit_int(conf->src_port.port_type);
+	rte_trace_point_emit_u64(conf->src_port.pcie.val);
+	rte_trace_point_emit_int(conf->dst_port.port_type);
+	rte_trace_point_emit_u64(conf->dst_port.pcie.val);
 	rte_trace_point_emit_ptr(conf->auto_free.m2d.pool);
 	rte_trace_point_emit_int(ret);
 )
Signature · 1 line
2.48.1
#34 lore raw

PATCH v4 3/5 trace: support dereferencing pointers

In reply to David Marchand

Rather than use an intermediate variable, add new helpers that handle dereferencing pointers.
Update dmadev traces accordingly (and adjust the emitter type).

---
Changes since v3:
- started from scratch with different approach, added new helpers to avoid touching ctf metadata,

Changes since v2:
- split this change out of patch 2, as it required updating CTF metadata fixup,

---
 lib/dmadev/rte_dmadev_trace_fp.h           | 12 ++---
 lib/eal/include/rte_trace_point.h          | 52 ++++++++++++++--------
 lib/eal/include/rte_trace_point_register.h |  9 ++--
 3 files changed, 41 insertions(+), 32 deletions(-)
lib/dmadev/rte_dmadev_trace_fp.h +4 -8
index f5b96838bc..f2656c6726 100644
@@ -37,10 +37,9 @@ RTE_TRACE_POINT_FP(
 	enum rte_dma_vchan_status __status = 0;
 	status = &__status;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int vchan_status = *status;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
-	rte_trace_point_emit_int(vchan_status);
+	rte_trace_point_emit_int_ptr(status);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -107,13 +106,11 @@ RTE_TRACE_POINT_FP(
 	last_idx = &__last_idx;
 	has_error = &__has_error;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int has_error_val = *has_error;
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
-	rte_trace_point_emit_int(has_error_val);
+	rte_trace_point_emit_u16_ptr(last_idx);
+	rte_trace_point_emit_u8_ptr(has_error);
 	rte_trace_point_emit_u16(ret);
 )
 
@@ -126,11 +123,10 @@ RTE_TRACE_POINT_FP(
 	uint16_t __last_idx = 0;
 	last_idx = &__last_idx;
 #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
-	int last_idx_val = *last_idx;
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
-	rte_trace_point_emit_int(last_idx_val);
+	rte_trace_point_emit_u16_ptr(last_idx);
 	rte_trace_point_emit_ptr(status);
 	rte_trace_point_emit_u16(ret);
 )
lib/eal/include/rte_trace_point.h +33 -19

77 lines not on this page · raw message

lib/eal/include/rte_trace_point_register.h +4 -5
index 748c931830..ff861c1fba 100644
@@ -35,11 +35,10 @@ RTE_INIT(trace##_init) \
 #define __rte_trace_point_emit_header_fp(t) \
 	__rte_trace_point_emit_header_generic(t)
 
-#define __rte_trace_point_emit(in, type) \
+#define __rte_trace_point_emit(name, in, type) \
 do { \
-	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(in))); \
-	__rte_trace_point_emit_field(sizeof(type), RTE_STR(in), \
-		RTE_STR(type)); \
+	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(*in))); \
+	__rte_trace_point_emit_field(sizeof(type), name, RTE_STR(type)); \
 } while (0)
 
 #define rte_trace_point_emit_string(in) \
@@ -52,7 +51,7 @@ do { \
 #define rte_trace_point_emit_blob(in, len) \
 do { \
 	RTE_SET_USED(in); \
-	__rte_trace_point_emit(len, uint8_t); \
+	__rte_trace_point_emit(RTE_STR(len), &len, uint8_t); \
 	__rte_trace_point_emit_field(RTE_TRACE_BLOB_LEN_MAX, \
 		RTE_STR(in)"[" RTE_STR(RTE_TRACE_BLOB_LEN_MAX)"]", \
 		RTE_STR(uint8_t)); \
Signature · 1 line
2.48.1
Acked-by on v4 3/5
#35 lore raw

RE: [EXTERNAL] [PATCH v4 3/5] trace: support dereferencing pointers

Quoted 14 lines

Rather than use an intermediate variable, add new helpers that handle dereferencing pointers.
Update dmadev traces accordingly (and adjust the emitter type).

---
Changes since v3:
- started from scratch with different approach, added new helpers to avoid touching ctf metadata,

Changes since v2:
- split this change out of patch 2, as it required updating CTF metadata fixup,

Quoted 7 lines
---
 lib/dmadev/rte_dmadev_trace_fp.h           | 12 ++---
 lib/eal/include/rte_trace_point.h          | 52 ++++++++++++++--------
 lib/eal/include/rte_trace_point_register.h |  9 ++--
 3 files changed, 41 insertions(+), 32 deletions(-)

2.48.1

#36 lore raw

PATCH v4 4/5 trace: support expression for blob length

In reply to David Marchand

Support any expression as a blob length by using an intermediate variable in the trace point emitter itself.
This also avoids any side effect on the passed variable.

On the "register" side, prefix the length variable in the trace metadata with the name of the emitted argument.

With this, we can update ethdev traces and avoid intermediate variables.

---
Changes since v2:
- fixed length field in CTF metadata,

Changes since v1:
- removed code relying on arguments in "registering" rte_trace_point_emit_blob implementation (see patch 3),
- moved build check in non registering __rte_trace_point_emit,

---
 lib/eal/include/rte_trace_point.h          | 12 ++++++----
 lib/eal/include/rte_trace_point_register.h |  6 ++++-
 lib/ethdev/ethdev_trace.h                  | 27 ++++++----------------
 3 files changed, 19 insertions(+), 26 deletions(-)
lib/eal/include/rte_trace_point.h +7 -5
index 0780460759..84de233d59 100644
@@ -378,6 +378,7 @@ do { \
 
 #define __rte_trace_point_emit(name, in, type) \
 do { \
+	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(*in))); \
 	memcpy(mem, in, sizeof(*in)); \
 	mem = RTE_PTR_ADD(mem, sizeof(*in)); \
 } while (0)
@@ -392,13 +393,14 @@ do { \
 
 #define rte_trace_point_emit_blob(in, len) \
 do { \
+	uint8_t size = len; \
 	if (unlikely(in == NULL)) \
 		return; \
-	if (len > RTE_TRACE_BLOB_LEN_MAX) \
-		len = RTE_TRACE_BLOB_LEN_MAX; \
-	__rte_trace_point_emit(RTE_STR(len), &len, uint8_t); \
-	memcpy(mem, in, len); \
-	memset(RTE_PTR_ADD(mem, len), 0, RTE_TRACE_BLOB_LEN_MAX - len); \
+	if (size > RTE_TRACE_BLOB_LEN_MAX) \
+		size = RTE_TRACE_BLOB_LEN_MAX; \
+	__rte_trace_point_emit("size", &size, uint8_t); \
+	memcpy(mem, in, size); \
+	memset(RTE_PTR_ADD(mem, size), 0, RTE_TRACE_BLOB_LEN_MAX - size); \
 	mem = RTE_PTR_ADD(mem, RTE_TRACE_BLOB_LEN_MAX); \
 } while (0)
 
lib/eal/include/rte_trace_point_register.h +5 -1
index ff861c1fba..ac391eb28f 100644
@@ -50,8 +50,12 @@ do { \
 
 #define rte_trace_point_emit_blob(in, len) \
 do { \
+	uint8_t size = len; \
 	RTE_SET_USED(in); \
-	__rte_trace_point_emit(RTE_STR(len), &len, uint8_t); \
+	RTE_SET_USED(size); \
+	__rte_trace_point_emit_field(sizeof(uint8_t), \
+		RTE_STR(in) "_size", \
+		RTE_STR(uint8_t)); \
 	__rte_trace_point_emit_field(RTE_TRACE_BLOB_LEN_MAX, \
 		RTE_STR(in)"[" RTE_STR(RTE_TRACE_BLOB_LEN_MAX)"]", \
 		RTE_STR(uint8_t)); \
lib/ethdev/ethdev_trace.h +7 -20
index 5951ae2d99..c65b78590a 100644
@@ -860,10 +860,8 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_add,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr, uint32_t pool, int ret),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_u32(pool);
 	rte_trace_point_emit_int(ret);
 )
@@ -872,20 +870,16 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_mac_addr_remove,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
 	rte_ethdev_trace_default_mac_addr_set,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(addr->addr_bytes, len);
+	rte_trace_point_emit_blob(addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 RTE_TRACE_POINT(
@@ -1102,11 +1096,9 @@ RTE_TRACE_POINT(
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr,
 		int ret),
-	uint8_t len = nb_mc_addr * RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u32(nb_mc_addr);
-	rte_trace_point_emit_blob(mc_addr_set, len);
+	rte_trace_point_emit_blob(mc_addr_set, nb_mc_addr * RTE_ETHER_ADDR_LEN);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -1214,13 +1206,10 @@ RTE_TRACE_POINT(
 	rte_ethdev_trace_get_dcb_info,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_eth_dcb_info *dcb_info, int ret),
-	uint8_t num_user_priorities = RTE_ETH_DCB_NUM_USER_PRIORITIES;
-	uint8_t num_tcs = RTE_ETH_DCB_NUM_TCS;
-
 	rte_trace_point_emit_u16(port_id);
 	rte_trace_point_emit_u8(dcb_info->nb_tcs);
-	rte_trace_point_emit_blob(dcb_info->prio_tc, num_user_priorities);
-	rte_trace_point_emit_blob(dcb_info->tc_bws, num_tcs);
+	rte_trace_point_emit_blob(dcb_info->prio_tc, RTE_ETH_DCB_NUM_USER_PRIORITIES);
+	rte_trace_point_emit_blob(dcb_info->tc_bws, RTE_ETH_DCB_NUM_TCS);
 	rte_trace_point_emit_int(ret);
 )
 
@@ -2126,10 +2115,8 @@ RTE_TRACE_POINT_FP(
 	rte_eth_trace_macaddr_get,
 	RTE_TRACE_POINT_ARGS(uint16_t port_id,
 		const struct rte_ether_addr *mac_addr),
-	uint8_t len = RTE_ETHER_ADDR_LEN;
-
 	rte_trace_point_emit_u16(port_id);
-	rte_trace_point_emit_blob(mac_addr->addr_bytes, len);
+	rte_trace_point_emit_blob(mac_addr->addr_bytes, RTE_ETHER_ADDR_LEN);
 )
 
 /* Called in loop in examples/ip_pipeline */
Signature · 1 line
2.48.1
Acked-by on v4 4/5
#37 lore raw
Quoted 19 lines

Support any expression as a blob length by using an intermediate variable in the trace point emitter itself.
This also avoids any side effect on the passed variable.

On the "register" side, prefix the length variable in the trace metadata with the name of the emitted argument.

With this, we can update ethdev traces and avoid intermediate variables.

---
Changes since v2:
- fixed length field in CTF metadata,

Changes since v1:
- removed code relying on arguments in "registering" rte_trace_point_emit_blob implementation (see patch 3),
- moved build check in non registering __rte_trace_point_emit,

Quoted 7 lines
---
 lib/eal/include/rte_trace_point.h          | 12 ++++++----
 lib/eal/include/rte_trace_point_register.h |  6 ++++-
 lib/ethdev/ethdev_trace.h                  | 27 ++++++----------------
 3 files changed, 19 insertions(+), 26 deletions(-)

2.48.1

#38 lore raw

PATCH v4 5/5 trace: fix undefined behavior in register

In reply to David Marchand

Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each tracepoint and make sure that the emitting macros in rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a __rte_unused for each argument (since emitting macros do nothing with them).
This last part introduces an implementation limit of 15 arguments.

With this change in place, the workaround in dmadev tracepoints can be removed.

---
 lib/dmadev/rte_dmadev_trace.h              | 12 ------
 lib/dmadev/rte_dmadev_trace_fp.h           | 14 -------
 lib/eal/include/rte_trace_point.h          |  4 ++
 lib/eal/include/rte_trace_point_register.h | 44 +++++++++++++++++++---
 4 files changed, 42 insertions(+), 32 deletions(-)
lib/dmadev/rte_dmadev_trace.h +0 -12
index 1beb938168..1de92655f2 100644
@@ -22,10 +22,6 @@ extern "C" {
 RTE_TRACE_POINT(
 	rte_dma_trace_info_get,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, struct rte_dma_info *dev_info),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	struct rte_dma_info __dev_info = {0};
-	dev_info = &__dev_info;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_string(dev_info->dev_name);
 	rte_trace_point_emit_u64(dev_info->dev_capa);
@@ -42,10 +38,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_configure,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, const struct rte_dma_conf *dev_conf,
 			     int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_conf __dev_conf = {0};
-	dev_conf = &__dev_conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
 	rte_trace_point_emit_u16(dev_conf->priority);
@@ -78,10 +70,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_vchan_setup,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const struct rte_dma_vchan_conf *conf, int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_vchan_conf __conf = {0};
-	conf = &__conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int(conf->direction);
lib/dmadev/rte_dmadev_trace_fp.h +0 -14
index f2656c6726..a1374e78b7 100644
@@ -33,10 +33,6 @@ RTE_TRACE_POINT_FP(
 	rte_dma_trace_vchan_status,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     enum rte_dma_vchan_status *status, int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	enum rte_dma_vchan_status __status = 0;
-	status = &__status;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int_ptr(status);
@@ -100,12 +96,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     bool *has_error, uint16_t ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	uint16_t __last_idx = 0;
-	bool __has_error = false;
-	last_idx = &__last_idx;
-	has_error = &__has_error;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
@@ -119,10 +109,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     enum rte_dma_status_code *status, uint16_t ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	uint16_t __last_idx = 0;
-	last_idx = &__last_idx;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
lib/eal/include/rte_trace_point.h +4 -0
index 84de233d59..8a317d31d2 100644
@@ -36,6 +36,8 @@ extern "C" {
 /** The tracepoint object. */
 typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;
 
+#ifndef _RTE_TRACE_POINT_REGISTER_H_
+
 /**
  * Macro to define the tracepoint arguments in RTE_TRACE_POINT macro.
 
@@ -53,6 +55,8 @@ _tp _args \
 	__VA_ARGS__ \
 }
 
+#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
+
 /**
  * Create a tracepoint.
  *
lib/eal/include/rte_trace_point_register.h +38 -6

73 lines not on this page · raw message

Signature · 1 line
2.48.1
Acked-by on v4 5/5
#39 lore raw

RE: [EXTERNAL] [PATCH v4 5/5] trace: fix undefined behavior in register

Quoted 230 lines

Registering a tracepoint handler was resulting so far in undefined behavior at runtime.

The RTE_TRACE_POINT_REGISTER() macro was casting the tracepoint handler (which expects arguments) to a void (*)(void).
At runtime, calling this handler while registering resulted in reading the current stack with no relation to this function prototype.

Instead, declare an additional inline _register() handler for each tracepoint and make sure that the emitting macros in rte_trace_point_register.h only work on arguments name and type.

The original tracepoint handler prototype is adjusted by adding a __rte_unused for each argument (since emitting macros do nothing with them).
This last part introduces an implementation limit of 15 arguments.

With this change in place, the workaround in dmadev tracepoints can be removed.

---
 lib/dmadev/rte_dmadev_trace.h              | 12 ------
 lib/dmadev/rte_dmadev_trace_fp.h           | 14 -------
 lib/eal/include/rte_trace_point.h          |  4 ++
 lib/eal/include/rte_trace_point_register.h | 44 +++++++++++++++++++---
 4 files changed, 42 insertions(+), 32 deletions(-)
(quoted diff) +0 -0

b/lib/dmadev/rte_dmadev_trace.h index 1beb938168..1de92655f2 100644

lib/dmadev/rte_dmadev_trace.h +0 -7
@@ -22,10 +22,6 @@ extern "C" {
 RTE_TRACE_POINT(
 	rte_dma_trace_info_get,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, struct rte_dma_info
 *dev_info), -#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	struct rte_dma_info __dev_info = {0};
-	dev_info = &__dev_info;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_string(dev_info->dev_name);
 	rte_trace_point_emit_u64(dev_info->dev_capa);
@@ -42,10 +38,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_configure,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, const struct rte_dma_conf
 *dev_conf,
 			     int ret),
-#ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_conf __dev_conf = {0};
-	dev_conf = &__dev_conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(dev_conf->nb_vchans);
lib/dmadev/rte_dmadev_trace.h +0 -3
 	rte_trace_point_emit_u16(dev_conf->priority);
@@ -78,10 +70,6 @@ RTE_TRACE_POINT(
 	rte_dma_trace_vchan_setup,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const struct rte_dma_vchan_conf *conf, int ret), -
 #ifdef _RTE_TRACE_POINT_REGISTER_H_
-	const struct rte_dma_vchan_conf __conf = {0};
-	conf = &__conf;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int(conf->direction);
lib/dmadev/rte_dmadev_trace_fp.h +0 -3
index f2656c6726..a1374e78b7 100644
@@ -33,10 +33,6 @@ RTE_TRACE_POINT_FP(
 	rte_dma_trace_vchan_status,
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     enum rte_dma_vchan_status *status, int ret), -
 #ifdef _RTE_TRACE_POINT_REGISTER_H_
-	enum rte_dma_vchan_status __status = 0;
-	status = &__status;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_int_ptr(status);
@@ -100,12 +96,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     bool *has_error, uint16_t ret), -#ifdef

_RTE_TRACE_POINT_REGISTER_H_

lib/dmadev/rte_dmadev_trace_fp.h +0 -8
-	uint16_t __last_idx = 0;
-	bool __has_error = false;
-	last_idx = &__last_idx;
-	has_error = &__has_error;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
@@ -119,10 +109,6 @@ RTE_TRACE_POINT_FP(
 	RTE_TRACE_POINT_ARGS(int16_t dev_id, uint16_t vchan,
 			     const uint16_t nb_cpls, uint16_t *last_idx,
 			     enum rte_dma_status_code *status, uint16_t ret), -
 #ifdef _RTE_TRACE_POINT_REGISTER_H_
-	uint16_t __last_idx = 0;
-	last_idx = &__last_idx;
-#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
 	rte_trace_point_emit_i16(dev_id);
 	rte_trace_point_emit_u16(vchan);
 	rte_trace_point_emit_u16(nb_cpls);
lib/eal/include/rte_trace_point.h +4 -0
index 84de233d59..8a317d31d2 100644
@@ -36,6 +36,8 @@ extern "C" {
 /** The tracepoint object. */
 typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;
 
+#ifndef _RTE_TRACE_POINT_REGISTER_H_
+
 /**
  * Macro to define the tracepoint arguments in RTE_TRACE_POINT macro.
 
@@ -53,6 +55,8 @@ _tp _args \
 	__VA_ARGS__ \
 }
 
+#endif /* _RTE_TRACE_POINT_REGISTER_H_ */
+
 /**
  * Create a tracepoint.
  *
lib/eal/include/rte_trace_point_register.h +1 -0
index ac391eb28f..b036121959 100644
@@ -18,6 +18,43 @@ extern "C" {
 
 RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz);
 
+#define

RTE_TRACE_POINT_ARGS_COUNT_(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_1 2,_13,_14,_15,N, ...) \

lib/eal/include/rte_trace_point_register.h +4 -0
+	N
+#define RTE_TRACE_POINT_ARGS_COUNT(...) \
+
+RTE_TRACE_POINT_ARGS_COUNT_(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,

5,4,3
+,2,1,0)

lib/eal/include/rte_trace_point_register.h +31 -0
+
+#define RTE_TRACE_POINT_ARGS_1(a) __rte_unused a #define
+RTE_TRACE_POINT_ARGS_2(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_1(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_3(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_2(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_4(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_3(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_5(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_4(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_6(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_5(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_7(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_6(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_8(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_7(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_9(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_8(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_10(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_9(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_11(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_10(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_12(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_11(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_13(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_12(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_14(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_13(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_15(a, ...) __rte_unused a,
+RTE_TRACE_POINT_ARGS_14(__VA_ARGS__)
+#define RTE_TRACE_POINT_ARGS_FUNC(a) RTE_TRACE_POINT_ARGS_ ## a

#define

lib/eal/include/rte_trace_point_register.h +3 -0
+RTE_TRACE_POINT_ARGS_EXPAND(...) __VA_ARGS__ #define
+RTE_TRACE_POINT_ARGS_(N, ...) \
+
	RTE_TRACE_POINT_ARGS_EXPAND(RTE_TRACE_POINT_ARGS_FUNC(

N))(__VA_ARGS__)

lib/eal/include/rte_trace_point_register.h +2 -0
+#define RTE_TRACE_POINT_ARGS(...) \
+	(RTE_TRACE_POINT_ARGS_(RTE_TRACE_POINT_ARGS_COUNT(0,

__VA_ARGS__),

lib/eal/include/rte_trace_point_register.h +9 -0
+__VA_ARGS__))
+
+#define __RTE_TRACE_POINT(_mode, _tp, _args, ...) \ extern
+rte_trace_point_t __##_tp; \ static __rte_always_inline void _tp _args
+{ } \ static __rte_always_inline void \ _tp ## _register (void) \ { \
+	__rte_trace_point_emit_header_##_mode(&__##_tp); \
+	__VA_ARGS__ \
+}
+
 #define RTE_TRACE_POINT_REGISTER(trace, name) \  rte_trace_point_t

__rte_section("__rte_trace_point") __##trace; \ static const char __##trace##_name[] = RTE_STR(name); \ @@ -26,7 +63,7 @@ RTE_INIT(trace##_init) \

lib/eal/include/rte_trace_point_register.h +1 -1
 	if (!rte_trace_feature_is_enabled()) \
 		return; \
 	__rte_trace_point_register(&__##trace, __##trace##_name, \
-		(void (*)(void)) trace); \
+		trace ## _register); \
 }
 
 #define __rte_trace_point_emit_header_generic(t) \ @@ -37,22 +74,17 @@

RTE_INIT(trace##_init) \

#define __rte_trace_point_emit(name, in, type) \ do { \

lib/eal/include/rte_trace_point_register.h +0 -1
-	RTE_BUILD_BUG_ON(sizeof(type) != sizeof(typeof(*in))); \
 	__rte_trace_point_emit_field(sizeof(type), name, RTE_STR(type)); \  }

while (0)

#define rte_trace_point_emit_string(in) \ do { \

lib/eal/include/rte_trace_point_register.h +0 -1
-	RTE_SET_USED(in); \

__rte_trace_point_emit_field(__RTE_TRACE_EMIT_STRING_LEN_MAX
, \

lib/eal/include/rte_trace_point_register.h +0 -4
 		RTE_STR(in)"[32]", "string_bounded_t"); \  } while (0)
 
 #define rte_trace_point_emit_blob(in, len) \  do { \
-	uint8_t size = len; \
-	RTE_SET_USED(in); \
-	RTE_SET_USED(size); \
 	__rte_trace_point_emit_field(sizeof(uint8_t), \
 		RTE_STR(in) "_size", \
 		RTE_STR(uint8_t)); \
--
Quoted 1 line

2.48.1

#40 lore raw

Re: [PATCH v4 0/5] Trace point framework enhancement for dmadev

In reply to David Marchand
Quoted 28 lines · David Marchand

dmadev trace points have been working around trace point framework limitations.
One of this workaround blocks enabling dmadev on MSVC.

Traces files were not checked in CI, so this series also adds a new check.

--
David Marchand

Changes since v3:
- dropped changes to CTF metadata,
- added new helpers for dumping content of pointed at memory,
- changed dmadev to avoid more changes in trace framework,

Changes since v2:
- added check of traces validity in GHA,
- split patch 2 and fixed CTF metadata,

David Marchand (5):
ci: check traces validity
dmadev: avoid copies in tracepoints
trace: support dereferencing pointers
trace: support expression for blob length
trace: fix undefined behavior in register

Quoted 10 lines
 .ci/linux-build.sh                         | 10 ++++
 .github/workflows/build.yml                |  2 +-
 devtools/libabigail.abignore               |  5 ++
 lib/dmadev/rte_dmadev.h                    | 29 +++++-----
 lib/dmadev/rte_dmadev_trace.h              | 32 ++---------
 lib/dmadev/rte_dmadev_trace_fp.h           | 26 ++-------
 lib/eal/include/rte_trace_point.h          | 66 ++++++++++++++--------
 lib/eal/include/rte_trace_point_register.h | 51 ++++++++++++++---
 lib/ethdev/ethdev_trace.h                  | 27 +++------
 9 files changed, 135 insertions(+), 113 deletions(-)

Series applied, thanks.

Signature · 1 line
David Marchand