Skip to content

Commit 8127837

Browse files
committed
Merge branch 'trace-add-tracepoint-for-tcp_sendmsg_locked'
Breno Leitao says: ==================== trace: add tracepoint for tcp_sendmsg_locked() Meta has been using BPF programs to monitor tcp_sendmsg() for years, indicating significant interest in observing this important functionality. Adding a proper tracepoint provides a stable API for all users who need visibility into TCP message transmission. David Ahern is using a similar functionality with a custom patch[1]. So, this means we have more than a single use case for this request, and it might be a good idea to have such feature upstream. Link: https://lore.kernel.org/all/[email protected]/ [1] v2: https://lore.kernel.org/[email protected] v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 82e4013 + 0f08335 commit 8127837

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

include/linux/socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr
168168
return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
169169
}
170170

171-
static inline size_t msg_data_left(struct msghdr *msg)
171+
static inline size_t msg_data_left(const struct msghdr *msg)
172172
{
173173
return iov_iter_count(&msg->msg_iter);
174174
}

include/trace/events/tcp.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@ TRACE_EVENT(tcp_retransmit_synack,
259259
__entry->saddr_v6, __entry->daddr_v6)
260260
);
261261

262+
TRACE_EVENT(tcp_sendmsg_locked,
263+
TP_PROTO(const struct sock *sk, const struct msghdr *msg,
264+
const struct sk_buff *skb, int size_goal),
265+
266+
TP_ARGS(sk, msg, skb, size_goal),
267+
268+
TP_STRUCT__entry(
269+
__field(const void *, skb_addr)
270+
__field(int, skb_len)
271+
__field(int, msg_left)
272+
__field(int, size_goal)
273+
),
274+
275+
TP_fast_assign(
276+
__entry->skb_addr = skb;
277+
__entry->skb_len = skb ? skb->len : 0;
278+
__entry->msg_left = msg_data_left(msg);
279+
__entry->size_goal = size_goal;
280+
),
281+
282+
TP_printk("skb_addr %p skb_len %d msg_left %d size_goal %d",
283+
__entry->skb_addr, __entry->skb_len, __entry->msg_left,
284+
__entry->size_goal));
285+
262286
DECLARE_TRACE(tcp_cwnd_reduction_tp,
263287
TP_PROTO(const struct sock *sk, int newly_acked_sacked,
264288
int newly_lost, int flag),

kernel/bpf/btf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6541,6 +6541,7 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {
65416541
{ "xprt_put_cong", 0x10 },
65426542
/* tcp */
65436543
{ "tcp_send_reset", 0x11 },
6544+
{ "tcp_sendmsg_locked", 0x100 },
65446545
/* tegra_apb_dma */
65456546
{ "tegra_dma_tx_status", 0x100 },
65466547
/* timer_migration */

net/ipv4/tcp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
11601160
if (skb)
11611161
copy = size_goal - skb->len;
11621162

1163+
trace_tcp_sendmsg_locked(sk, msg, skb, size_goal);
1164+
11631165
if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) {
11641166
bool first_skb;
11651167

0 commit comments

Comments
 (0)