diff options
author | Jon Maxwell <jmaxwell37@gmail.com> | 2018-07-18 21:14:44 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-07-21 13:28:55 -0400 |
commit | b701a99e431db784714c32fc6b68123045714679 (patch) | |
tree | b5ec36b84c8ca0ed31442df0c3c8e456709fb570 /net/ipv4/tcp_timer.c | |
parent | a7fa37703d495310819d0a6747e5b32362305374 (diff) |
tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy
Create the tcp_clamp_rto_to_user_timeout() helper routine. To calculate
the correct rto, so that the TCP_USER_TIMEOUT socket option is more
accurate. Taking suggestions and feedback into account from
Eric Dumazet, Neal Cardwell and David Laight. Due to the 1st commit we
can avoid the msecs_to_jiffies() and jiffies_to_msecs() dance.
Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_timer.c')
-rw-r--r-- | net/ipv4/tcp_timer.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index d212f183dd2d..a242f8874629 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c | |||
@@ -36,6 +36,21 @@ u32 tcp_retransmit_stamp(const struct sock *sk) | |||
36 | return start_ts; | 36 | return start_ts; |
37 | } | 37 | } |
38 | 38 | ||
39 | static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk) | ||
40 | { | ||
41 | struct inet_connection_sock *icsk = inet_csk(sk); | ||
42 | u32 elapsed, start_ts; | ||
43 | |||
44 | start_ts = tcp_retransmit_stamp(sk); | ||
45 | if (!icsk->icsk_user_timeout || !start_ts) | ||
46 | return icsk->icsk_rto; | ||
47 | elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts; | ||
48 | if (elapsed >= icsk->icsk_user_timeout) | ||
49 | return 1; /* user timeout has passed; fire ASAP */ | ||
50 | else | ||
51 | return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(icsk->icsk_user_timeout - elapsed)); | ||
52 | } | ||
53 | |||
39 | /** | 54 | /** |
40 | * tcp_write_err() - close socket and save error info | 55 | * tcp_write_err() - close socket and save error info |
41 | * @sk: The socket the error has appeared on. | 56 | * @sk: The socket the error has appeared on. |
@@ -544,7 +559,8 @@ out_reset_timer: | |||
544 | /* Use normal (exponential) backoff */ | 559 | /* Use normal (exponential) backoff */ |
545 | icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX); | 560 | icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX); |
546 | } | 561 | } |
547 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX); | 562 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, |
563 | tcp_clamp_rto_to_user_timeout(sk), TCP_RTO_MAX); | ||
548 | if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1 + 1, 0)) | 564 | if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1 + 1, 0)) |
549 | __sk_dst_reset(sk); | 565 | __sk_dst_reset(sk); |
550 | 566 | ||