diff --git a/include/zephyr/tracing/tracing.h b/include/zephyr/tracing/tracing.h index e02c0a3d8f5..1e6889dc2a6 100644 --- a/include/zephyr/tracing/tracing.h +++ b/include/zephyr/tracing/tracing.h @@ -2049,6 +2049,19 @@ */ #define sys_port_trace_net_recv_data_exit(iface, pkt, ret) +/** + * @brief Trace network data send + * @param pkt Network packet to send + */ +#define sys_port_trace_net_send_data_enter(pkt) + +/** + * @brief Trace network data send attempt + * @param pkt Received network packet + * @param ret Return value + */ +#define sys_port_trace_net_send_data_exit(pkt, ret) + /** @} */ /* end of subsys_tracing_apis_net */ /** diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index 7afb15be1a8..8ab2fb93a3c 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -380,13 +380,18 @@ drop: int net_send_data(struct net_pkt *pkt) { int status; + int ret; + + SYS_PORT_TRACING_FUNC_ENTER(net, send_data, pkt); if (!pkt || !pkt->frags) { - return -ENODATA; + ret = -ENODATA; + goto err; } if (!net_pkt_iface(pkt)) { - return -EINVAL; + ret = -EINVAL; + goto err; } net_pkt_trim_buffer(pkt); @@ -400,7 +405,8 @@ int net_send_data(struct net_pkt *pkt) * we just silently drop the packet by returning 0. */ if (status == -ENOMSG) { - return 0; + ret = 0; + goto err; } return status; @@ -410,11 +416,13 @@ int net_send_data(struct net_pkt *pkt) */ NET_DBG("Loopback pkt %p back to us", pkt); processing_data(pkt, true); - return 0; + ret = 0; + goto err; } if (net_if_send_data(net_pkt_iface(pkt), pkt) == NET_DROP) { - return -EIO; + ret = -EIO; + goto err; } if (IS_ENABLED(CONFIG_NET_STATISTICS)) { @@ -428,7 +436,12 @@ int net_send_data(struct net_pkt *pkt) } } - return 0; + ret = 0; + +err: + SYS_PORT_TRACING_FUNC_EXIT(net, send_data, pkt, ret); + + return ret; } static void net_rx(struct net_if *iface, struct net_pkt *pkt) diff --git a/subsys/tracing/ctf/ctf_top.c b/subsys/tracing/ctf/ctf_top.c index 81599e124f4..b9c8fb82c64 100644 --- a/subsys/tracing/ctf/ctf_top.c +++ b/subsys/tracing/ctf/ctf_top.c @@ -654,3 +654,39 @@ void sys_trace_net_recv_data_exit(struct net_if *iface, struct net_pkt *pkt, int (uint32_t)(uintptr_t)pkt, (int32_t)ret); } + +void sys_trace_net_send_data_enter(struct net_pkt *pkt) +{ + struct net_if *iface; + int ifindex; + + iface = net_pkt_iface(pkt); + if (iface == NULL) { + ifindex = -1; + } else { + ifindex = net_if_get_by_iface(iface); + } + + ctf_top_net_send_data_enter((int32_t)ifindex, + (uint32_t)(uintptr_t)iface, + (uint32_t)(uintptr_t)pkt, + (uint32_t)net_pkt_get_len(pkt)); +} + +void sys_trace_net_send_data_exit(struct net_pkt *pkt, int ret) +{ + struct net_if *iface; + int ifindex; + + iface = net_pkt_iface(pkt); + if (iface == NULL) { + ifindex = -1; + } else { + ifindex = net_if_get_by_iface(iface); + } + + ctf_top_net_send_data_exit((int32_t)ifindex, + (uint32_t)(uintptr_t)iface, + (uint32_t)(uintptr_t)pkt, + (int32_t)ret); +} diff --git a/subsys/tracing/ctf/ctf_top.h b/subsys/tracing/ctf/ctf_top.h index b9c96440ab0..8c734ab361d 100644 --- a/subsys/tracing/ctf/ctf_top.h +++ b/subsys/tracing/ctf/ctf_top.h @@ -153,6 +153,8 @@ typedef enum { CTF_EVENT_SOCKET_SOCKETPAIR_EXIT = 0x5B, CTF_EVENT_NET_RECV_DATA_ENTER = 0x5C, CTF_EVENT_NET_RECV_DATA_EXIT = 0x5D, + CTF_EVENT_NET_SEND_DATA_ENTER = 0x5E, + CTF_EVENT_NET_SEND_DATA_EXIT = 0x5F, } ctf_event_t; @@ -626,5 +628,18 @@ static inline void ctf_top_net_recv_data_exit(int32_t if_index, uint32_t iface, if_index, iface, pkt, ret); } +static inline void ctf_top_net_send_data_enter(int32_t if_index, uint32_t iface, uint32_t pkt, + uint32_t len) +{ + CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_NET_SEND_DATA_ENTER), + if_index, iface, pkt, len); +} + +static inline void ctf_top_net_send_data_exit(int32_t if_index, uint32_t iface, uint32_t pkt, + int32_t ret) +{ + CTF_EVENT(CTF_LITERAL(uint8_t, CTF_EVENT_NET_SEND_DATA_EXIT), + if_index, iface, pkt, ret); +} #endif /* SUBSYS_DEBUG_TRACING_CTF_TOP_H */ diff --git a/subsys/tracing/ctf/tracing_ctf.h b/subsys/tracing/ctf/tracing_ctf.h index 785b7554f47..9e0ea544a90 100644 --- a/subsys/tracing/ctf/tracing_ctf.h +++ b/subsys/tracing/ctf/tracing_ctf.h @@ -573,12 +573,18 @@ void sys_trace_socket_socketpair_exit(int sock_A, int sock_B, int ret); sys_trace_net_recv_data_enter(iface, pkt) #define sys_port_trace_net_recv_data_exit(iface, pkt, ret) \ sys_trace_net_recv_data_exit(iface, pkt, ret) +#define sys_port_trace_net_send_data_enter(pkt) \ + sys_trace_net_send_data_enter(pkt) +#define sys_port_trace_net_send_data_exit(pkt, ret) \ + sys_trace_net_send_data_exit(pkt, ret) struct net_if; struct net_pkt; void sys_trace_net_recv_data_enter(struct net_if *iface, struct net_pkt *pkt); void sys_trace_net_recv_data_exit(struct net_if *iface, struct net_pkt *pkt, int ret); +void sys_trace_net_send_data_enter(struct net_pkt *pkt); +void sys_trace_net_send_data_exit(struct net_pkt *pkt, int ret); #ifdef __cplusplus } diff --git a/subsys/tracing/ctf/tsdl/metadata b/subsys/tracing/ctf/tsdl/metadata index 0d713e93de3..8ef7ea676f7 100644 --- a/subsys/tracing/ctf/tsdl/metadata +++ b/subsys/tracing/ctf/tsdl/metadata @@ -729,3 +729,25 @@ event { int32_t result; }; }; + +event { + name = net_send_data_enter; + id = 0x5E; + fields := struct { + int32_t if_index; + uint32_t iface; + uint32_t pkt; + uint32_t pkt_len; + }; +}; + +event { + name = net_send_data_exit; + id = 0x5F; + fields := struct { + int32_t if_index; + uint32_t iface; + uint32_t pkt; + int32_t result; + }; +}; diff --git a/subsys/tracing/test/tracing_test.h b/subsys/tracing/test/tracing_test.h index 49e1a23522a..265b38d3596 100644 --- a/subsys/tracing/test/tracing_test.h +++ b/subsys/tracing/test/tracing_test.h @@ -734,6 +734,8 @@ void sys_trace_k_event_init(struct k_event *event); #define sys_port_trace_net_recv_data_enter(iface, pkt) #define sys_port_trace_net_recv_data_exit(iface, pkt, ret) +#define sys_port_trace_net_send_data_enter(pkt) +#define sys_port_trace_net_send_data_exit(pkt, ret) #define sys_trace_sys_init_enter(...) #define sys_trace_sys_init_exit(...) diff --git a/subsys/tracing/user/tracing_user.h b/subsys/tracing/user/tracing_user.h index c55a758f3aa..7d421db27be 100644 --- a/subsys/tracing/user/tracing_user.h +++ b/subsys/tracing/user/tracing_user.h @@ -385,6 +385,8 @@ void sys_trace_sys_init_exit(const struct init_entry *entry, int level, int resu #define sys_port_trace_net_recv_data_enter(iface, pkt) #define sys_port_trace_net_recv_data_exit(iface, pkt, ret) +#define sys_port_trace_net_send_data_enter(pkt) +#define sys_port_trace_net_send_data_exit(pkt, ret) #ifdef __cplusplus }