Skip to content

Commit 6163849

Browse files
laoardavem330
authored andcommitted
net: introduce a new tracepoint for tcp_rcv_space_adjust
tcp_rcv_space_adjust is called every time data is copied to user space, introducing a tcp tracepoint for which could show us when the packet is copied to user. When a tcp packet arrives, tcp_rcv_established() will be called and with the existed tracepoint tcp_probe we could get the time when this packet arrives. Then this packet will be copied to user, and tcp_rcv_space_adjust will be called and with this new introduced tracepoint we could get the time when this packet is copied to user. With these two tracepoints, we could figure out whether the user program processes this packet immediately or there's latency. Hence in the printk message, sk_cookie is printed as a key to relate tcp_rcv_space_adjust with tcp_probe. Maybe we could export sockfd in this new tracepoint as well, then we could relate this new tracepoint with epoll/read/recv* tracepoints, and finally that could show us the whole lifespan of this packet. But we could also implement that with pid as these functions are executed in process context. Signed-off-by: Yafang Shao <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 48d7a07 commit 6163849

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

include/trace/events/tcp.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/tracepoint.h>
1111
#include <net/ipv6.h>
1212
#include <net/tcp.h>
13+
#include <linux/sock_diag.h>
1314

1415
#define TP_STORE_V4MAPPED(__entry, saddr, daddr) \
1516
do { \
@@ -113,7 +114,7 @@ DEFINE_EVENT(tcp_event_sk_skb, tcp_send_reset,
113114
*/
114115
DECLARE_EVENT_CLASS(tcp_event_sk,
115116

116-
TP_PROTO(const struct sock *sk),
117+
TP_PROTO(struct sock *sk),
117118

118119
TP_ARGS(sk),
119120

@@ -125,6 +126,7 @@ DECLARE_EVENT_CLASS(tcp_event_sk,
125126
__array(__u8, daddr, 4)
126127
__array(__u8, saddr_v6, 16)
127128
__array(__u8, daddr_v6, 16)
129+
__field(__u64, sock_cookie)
128130
),
129131

130132
TP_fast_assign(
@@ -144,24 +146,34 @@ DECLARE_EVENT_CLASS(tcp_event_sk,
144146

145147
TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
146148
sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
149+
150+
__entry->sock_cookie = sock_gen_cookie(sk);
147151
),
148152

149-
TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c",
153+
TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c sock_cookie=%llx",
150154
__entry->sport, __entry->dport,
151155
__entry->saddr, __entry->daddr,
152-
__entry->saddr_v6, __entry->daddr_v6)
156+
__entry->saddr_v6, __entry->daddr_v6,
157+
__entry->sock_cookie)
153158
);
154159

155160
DEFINE_EVENT(tcp_event_sk, tcp_receive_reset,
156161

157-
TP_PROTO(const struct sock *sk),
162+
TP_PROTO(struct sock *sk),
158163

159164
TP_ARGS(sk)
160165
);
161166

162167
DEFINE_EVENT(tcp_event_sk, tcp_destroy_sock,
163168

164-
TP_PROTO(const struct sock *sk),
169+
TP_PROTO(struct sock *sk),
170+
171+
TP_ARGS(sk)
172+
);
173+
174+
DEFINE_EVENT(tcp_event_sk, tcp_rcv_space_adjust,
175+
176+
TP_PROTO(struct sock *sk),
165177

166178
TP_ARGS(sk)
167179
);
@@ -232,6 +244,7 @@ TRACE_EVENT(tcp_probe,
232244
__field(__u32, snd_wnd)
233245
__field(__u32, srtt)
234246
__field(__u32, rcv_wnd)
247+
__field(__u64, sock_cookie)
235248
),
236249

237250
TP_fast_assign(
@@ -256,15 +269,14 @@ TRACE_EVENT(tcp_probe,
256269
__entry->rcv_wnd = tp->rcv_wnd;
257270
__entry->ssthresh = tcp_current_ssthresh(sk);
258271
__entry->srtt = tp->srtt_us >> 3;
272+
__entry->sock_cookie = sock_gen_cookie(sk);
259273
),
260274

261-
TP_printk("src=%pISpc dest=%pISpc mark=%#x length=%d snd_nxt=%#x "
262-
"snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u "
263-
"rcv_wnd=%u",
275+
TP_printk("src=%pISpc dest=%pISpc mark=%#x length=%d snd_nxt=%#x snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u rcv_wnd=%u sock_cookie=%llx",
264276
__entry->saddr, __entry->daddr, __entry->mark,
265277
__entry->length, __entry->snd_nxt, __entry->snd_una,
266278
__entry->snd_cwnd, __entry->ssthresh, __entry->snd_wnd,
267-
__entry->srtt, __entry->rcv_wnd)
279+
__entry->srtt, __entry->rcv_wnd, __entry->sock_cookie)
268280
);
269281

270282
#endif /* _TRACE_TCP_H */

net/ipv4/tcp_input.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ void tcp_rcv_space_adjust(struct sock *sk)
582582
u32 copied;
583583
int time;
584584

585+
trace_tcp_rcv_space_adjust(sk);
586+
585587
tcp_mstamp_refresh(tp);
586588
time = tcp_stamp_us_delta(tp->tcp_mstamp, tp->rcvq_space.time);
587589
if (time < (tp->rcv_rtt_est.rtt_us >> 3) || tp->rcv_rtt_est.rtt_us == 0)

0 commit comments

Comments
 (0)