Skip to contentSkip to conversation

tcp: provide tx timestamps for partial writes

PATCH Superseded Soheil Hassas Yeganeh 4 participants 6 messages Jan 2, 2017 – Jan 4, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: provide tx timestamps for partial writes

From: Soheil Hassas Yeganeh <[email protected]>

For TCP sockets, tx timestamps are only captured when the user data is successfully and fully written to the socket. In many cases, however, TCP writes can be partial for which no timestamp is collected.

Collect timestamps when the user data is partially copied into the socket.

Cc Willem de Bruijn <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neal Cardwell <[email protected]>
Cc Martin KaFai Lau <[email protected]>
---
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -2
index 2e3807d..c207b16 100644
@@ -992,8 +992,10 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
 	return copied;
 
 do_error:
-	if (copied)
+	if (copied) {
+		tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
 		goto out;
+	}
 out_err:
 	/* make sure we wake any epoll edge trigger waiter */
 	if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 &&
@@ -1329,8 +1331,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 	}
 
 do_error:
-	if (copied + copied_syn)
+	if (copied + copied_syn) {
+		tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
 		goto out;
+	}
 out_err:
 	err = sk_stream_error(sk, flags, err);
 	/* make sure we wake any epoll edge trigger waiter */
Signature · 1 line
2.8.0.rc3.226.g39d4020
#1 lore raw
Quoted 49 lines · Soheil Hassas Yeganeh

From: Soheil Hassas Yeganeh <[email protected]>

For TCP sockets, tx timestamps are only captured when the user data is successfully and fully written to the socket. In many cases, however, TCP writes can be partial for which no timestamp is collected.

Collect timestamps when the user data is partially copied into the socket.

Cc Willem de Bruijn <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neal Cardwell <[email protected]>
Cc Martin KaFai Lau <[email protected]>
---
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -3
index 2e3807d..c207b16 100644
@@ -992,8 +992,10 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
        return copied;
 
 do_error:
-       if (copied)
+       if (copied) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
                goto out;
+       }
 out_err:
        /* make sure we wake any epoll edge trigger waiter */
        if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 &&
@@ -1329,8 +1331,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
        }
 
 do_error:
-       if (copied + copied_syn)
+       if (copied + copied_syn) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
                goto out;
+       }
 out_err:
        err = sk_stream_error(sk, flags, err);
        /* make sure we wake any epoll edge trigger waiter */
--
Quoted 2 lines

2.8.0.rc3.226.g39d4020

I'm sorry for the incomplete annotation. This is for [net-next].

Thanks,
Soheil

#2 lore raw
Quoted 41 lines · Soheil Hassas Yeganeh
Quoted 39 lines · Soheil Hassas Yeganeh

From: Soheil Hassas Yeganeh <[email protected]>

For TCP sockets, tx timestamps are only captured when the user data is successfully and fully written to the socket. In many cases, however, TCP writes can be partial for which no timestamp is collected.

Collect timestamps when the user data is partially copied into the socket.

Cc Willem de Bruijn <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neal Cardwell <[email protected]>
Cc Martin KaFai Lau <[email protected]>
---
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +3 -1
index 2e3807d..c207b16 100644
@@ -992,8 +992,10 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
        return copied;
 
 do_error:
-       if (copied)
+       if (copied) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
                goto out;
+       }
 out_err:
        /* make sure we wake any epoll edge trigger waiter */
        if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 &&
@@ -1329,8 +1331,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
        }
 
Quoted 4 lines

net/ipv4/tcp.c int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) · line 1335

Quoted 4 lines
net/ipv4/tcp.c +2 -1
 do_error:
-       if (copied + copied_syn)
+       if (copied + copied_syn) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));

Thanks to Willem for noting that this should be sockc.tsflags and not sk->sk_tsflags. I'll send V2 to fix.

Soheil

Quoted 13 lines
Quoted 8 lines
net/ipv4/tcp.c +1 -1
                goto out;
+       }
 out_err:
        err = sk_stream_error(sk, flags, err);
        /* make sure we wake any epoll edge trigger waiter */
--

2.8.0.rc3.226.g39d4020

I'm sorry for the incomplete annotation. This is for [net-next].

Thanks,
Soheil

Acked-by on v1 1/1
#5 lore raw
In reply to Soheil Hassas Yeganeh
Quoted 11 lines · Soheil Hassas Yeganeh

From: Soheil Hassas Yeganeh <[email protected]>

For TCP sockets, tx timestamps are only captured when the user data is successfully and fully written to the socket. In many cases, however, TCP writes can be partial for which no timestamp is collected.

Collect timestamps when the user data is partially copied into the socket.

Quoted 7 lines
Cc Willem de Bruijn <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neal Cardwell <[email protected]>
Cc Martin KaFai Lau <[email protected]>

---

Quoted 34 lines
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -3
index 2e3807d..c207b16 100644
@@ -992,8 +992,10 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
        return copied;
 
 do_error:
-       if (copied)
+       if (copied) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
                goto out;
+       }
 out_err:
        /* make sure we wake any epoll edge trigger waiter */
        if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 &&
@@ -1329,8 +1331,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
        }
 
 do_error:
-       if (copied + copied_syn)
+       if (copied + copied_syn) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
                goto out;
+       }
 out_err:
        err = sk_stream_error(sk, flags, err);
        /* make sure we wake any epoll edge trigger waiter */
--

2.8.0.rc3.226.g39d4020

#3 lore raw
In reply to Soheil Hassas Yeganeh
Quoted 42 lines · Soheil Hassas Yeganeh
Quoted 41 lines · Soheil Hassas Yeganeh
Quoted 39 lines · Soheil Hassas Yeganeh

From: Soheil Hassas Yeganeh <[email protected]>

For TCP sockets, tx timestamps are only captured when the user data is successfully and fully written to the socket. In many cases, however, TCP writes can be partial for which no timestamp is collected.

Collect timestamps when the user data is partially copied into the socket.

Cc Willem de Bruijn <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neal Cardwell <[email protected]>
Cc Martin KaFai Lau <[email protected]>
---
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +3 -1
index 2e3807d..c207b16 100644
@@ -992,8 +992,10 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
        return copied;
 
 do_error:
-       if (copied)
+       if (copied) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
                goto out;
+       }
 out_err:
        /* make sure we wake any epoll edge trigger waiter */
        if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 &&
@@ -1329,8 +1331,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
        }
 
Quoted 7 lines
Quoted 4 lines

net/ipv4/tcp.c int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) · line 1335

Quoted 4 lines
net/ipv4/tcp.c +2 -1
 do_error:
-       if (copied + copied_syn)
+       if (copied + copied_syn) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));

Thanks to Willem for noting that this should be sockc.tsflags and not sk->sk_tsflags. I'll send V2 to fix.

Also, why not factorizing a bit and have a single point calling tcp_tx_timestamp() ?

This would ease code review quite a bit.

net/ipv4/tcp.c +9 -7
index 4a044964da6670829e5c47fef52d2cd76360b59f..11357f3bd1f82fa29129dd3ecf4d270feb4a6b1d 100644
@@ -958,10 +958,8 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
 		copied += copy;
 		offset += copy;
 		size -= copy;
-		if (!size) {
-			tcp_tx_timestamp(sk, sk->sk_tsflags, skb);
+		if (!size)
 			goto out;
-		}
 
 		if (skb->len < size_goal || (flags & MSG_OOB))
 			continue;
@@ -987,8 +985,11 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
 	}
 
 out:
-	if (copied && !(flags & MSG_SENDPAGE_NOTLAST))
-		tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
+	if (copied) {
+		tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
+		if (!(flags & MSG_SENDPAGE_NOTLAST))
+			tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
+	}
 	return copied;
 
 do_error:
@@ -1281,7 +1282,6 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 
 		copied += copy;
 		if (!msg_data_left(msg)) {
-			tcp_tx_timestamp(sk, sockc.tsflags, skb);
 			if (unlikely(flags & MSG_EOR))
 				TCP_SKB_CB(skb)->eor = 1;
 			goto out;
@@ -1312,8 +1312,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 	}
 
 out:
-	if (copied)
+	if (copied) {
+		tcp_tx_timestamp(sk, sockc.tsflags, tcp_write_queue_tail(sk));
 		tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
+	}
 out_nopush:
 	release_sock(sk);
 	return copied + copied_syn;
#4 lore raw
Quoted 52 lines · Eric Dumazet
Quoted 42 lines · Soheil Hassas Yeganeh
Quoted 41 lines · Soheil Hassas Yeganeh
Quoted 39 lines · Soheil Hassas Yeganeh

From: Soheil Hassas Yeganeh <[email protected]>

For TCP sockets, tx timestamps are only captured when the user data is successfully and fully written to the socket. In many cases, however, TCP writes can be partial for which no timestamp is collected.

Collect timestamps when the user data is partially copied into the socket.

Cc Willem de Bruijn <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neal Cardwell <[email protected]>
Cc Martin KaFai Lau <[email protected]>
---
 net/ipv4/tcp.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +3 -1
index 2e3807d..c207b16 100644
@@ -992,8 +992,10 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
        return copied;
 
 do_error:
-       if (copied)
+       if (copied) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
                goto out;
+       }
 out_err:
        /* make sure we wake any epoll edge trigger waiter */
        if (unlikely(skb_queue_len(&sk->sk_write_queue) == 0 &&
@@ -1329,8 +1331,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
        }
 
Quoted 7 lines
Quoted 4 lines

net/ipv4/tcp.c int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) · line 1335

Quoted 4 lines
net/ipv4/tcp.c +2 -1
 do_error:
-       if (copied + copied_syn)
+       if (copied + copied_syn) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));

Thanks to Willem for noting that this should be sockc.tsflags and not sk->sk_tsflags. I'll send V2 to fix.

Quoted 4 lines

Also, why not factorizing a bit and have a single point calling tcp_tx_timestamp() ?

This would ease code review quite a bit.

Thanks Eric! will do in V2.

Quoted 53 lines
net/ipv4/tcp.c +9 -7
index 4a044964da6670829e5c47fef52d2cd76360b59f..11357f3bd1f82fa29129dd3ecf4d270feb4a6b1d 100644
@@ -958,10 +958,8 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
                copied += copy;
                offset += copy;
                size -= copy;
-               if (!size) {
-                       tcp_tx_timestamp(sk, sk->sk_tsflags, skb);
+               if (!size)
                        goto out;
-               }
 
                if (skb->len < size_goal || (flags & MSG_OOB))
                        continue;
@@ -987,8 +985,11 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
        }
 
 out:
-       if (copied && !(flags & MSG_SENDPAGE_NOTLAST))
-               tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
+       if (copied) {
+               tcp_tx_timestamp(sk, sk->sk_tsflags, tcp_write_queue_tail(sk));
+               if (!(flags & MSG_SENDPAGE_NOTLAST))
+                       tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
+       }
        return copied;
 
 do_error:
@@ -1281,7 +1282,6 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 
                copied += copy;
                if (!msg_data_left(msg)) {
-                       tcp_tx_timestamp(sk, sockc.tsflags, skb);
                        if (unlikely(flags & MSG_EOR))
                                TCP_SKB_CB(skb)->eor = 1;
                        goto out;
@@ -1312,8 +1312,10 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
        }
 
 out:
-       if (copied)
+       if (copied) {
+               tcp_tx_timestamp(sk, sockc.tsflags, tcp_write_queue_tail(sk));
                tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
+       }
 out_nopush:
        release_sock(sk);
        return copied + copied_syn;