Skip to content

Commit 5f6188a

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: do not change tcp_wstamp_ns in tcp_mstamp_refresh
In EDT design, I made the mistake of using tcp_wstamp_ns to store the last tcp_clock_ns() sample and to store the pacing virtual timer. This causes major regressions at high speed flows. Introduce tcp_clock_cache to store last tcp_clock_ns(). This is needed because some arches have slow high-resolution kernel time service. tcp_wstamp_ns is only updated when a packet is sent. Note that we can remove tcp_mstamp in the future since tcp_mstamp is essentially tcp_clock_cache/1000, so the apparent socket size increase is temporary. Fixes: 9799ccb ("tcp: add tcp_wstamp_ns socket field") Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1a3aea2 commit 5f6188a

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

include/linux/tcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ struct tcp_sock {
249249
u32 tlp_high_seq; /* snd_nxt at the time of TLP retransmit. */
250250

251251
u64 tcp_wstamp_ns; /* departure time for next sent data packet */
252+
u64 tcp_clock_cache; /* cache last tcp_clock_ns() (see tcp_mstamp_refresh()) */
252253

253254
/* RTT measurement */
254255
u64 tcp_mstamp; /* most recent packet received/sent */

net/ipv4/tcp_output.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ void tcp_mstamp_refresh(struct tcp_sock *tp)
5252
{
5353
u64 val = tcp_clock_ns();
5454

55-
/* departure time for next data packet */
56-
if (val > tp->tcp_wstamp_ns)
57-
tp->tcp_wstamp_ns = val;
55+
if (val > tp->tcp_clock_cache)
56+
tp->tcp_clock_cache = val;
5857

5958
val = div_u64(val, NSEC_PER_USEC);
6059
if (val > tp->tcp_mstamp)
@@ -1050,6 +1049,10 @@ static int __tcp_transmit_skb(struct sock *sk, struct sk_buff *skb,
10501049
if (unlikely(!skb))
10511050
return -ENOBUFS;
10521051
}
1052+
1053+
/* TODO: might take care of jitter here */
1054+
tp->tcp_wstamp_ns = max(tp->tcp_wstamp_ns, tp->tcp_clock_cache);
1055+
10531056
skb->skb_mstamp_ns = tp->tcp_wstamp_ns;
10541057

10551058
inet = inet_sk(sk);

net/ipv4/tcp_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static void tcp_probe_timer(struct sock *sk)
360360
*/
361361
start_ts = tcp_skb_timestamp(skb);
362362
if (!start_ts)
363-
skb->skb_mstamp_ns = tp->tcp_wstamp_ns;
363+
skb->skb_mstamp_ns = tp->tcp_clock_cache;
364364
else if (icsk->icsk_user_timeout &&
365365
(s32)(tcp_time_stamp(tp) - start_ts) > icsk->icsk_user_timeout)
366366
goto abort;

0 commit comments

Comments
 (0)