diff options
author | Yuchung Cheng <ycheng@google.com> | 2019-01-16 18:05:32 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-01-17 18:12:26 -0500 |
commit | 01a523b071618abbc634d1958229fe3bd2dfa5fa (patch) | |
tree | 043afd9aa6674b92fb0bd7d6c97eb7220df3ba0b /net/ipv4/tcp_timer.c | |
parent | c7d13c8faa74f4e8ef191f88a252cefab6805b38 (diff) |
tcp: create a helper to model exponential backoff
Create a helper to model TCP exponential backoff for the next patch.
This is pure refactor w no behavior change.
Signed-off-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Neal Cardwell <ncardwell@google.com>
Reviewed-by: Soheil Hassas Yeganeh <soheil@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 | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index 074de38bafbd..bcc2f5783e57 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c | |||
@@ -159,7 +159,20 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk) | |||
159 | tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); | 159 | tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | static unsigned int tcp_model_timeout(struct sock *sk, | |
163 | unsigned int boundary, | ||
164 | unsigned int rto_base) | ||
165 | { | ||
166 | unsigned int linear_backoff_thresh, timeout; | ||
167 | |||
168 | linear_backoff_thresh = ilog2(TCP_RTO_MAX / rto_base); | ||
169 | if (boundary <= linear_backoff_thresh) | ||
170 | timeout = ((2 << boundary) - 1) * rto_base; | ||
171 | else | ||
172 | timeout = ((2 << linear_backoff_thresh) - 1) * rto_base + | ||
173 | (boundary - linear_backoff_thresh) * TCP_RTO_MAX; | ||
174 | return jiffies_to_msecs(timeout); | ||
175 | } | ||
163 | /** | 176 | /** |
164 | * retransmits_timed_out() - returns true if this connection has timed out | 177 | * retransmits_timed_out() - returns true if this connection has timed out |
165 | * @sk: The current socket | 178 | * @sk: The current socket |
@@ -177,23 +190,15 @@ static bool retransmits_timed_out(struct sock *sk, | |||
177 | unsigned int boundary, | 190 | unsigned int boundary, |
178 | unsigned int timeout) | 191 | unsigned int timeout) |
179 | { | 192 | { |
180 | const unsigned int rto_base = TCP_RTO_MIN; | 193 | unsigned int start_ts; |
181 | unsigned int linear_backoff_thresh, start_ts; | ||
182 | 194 | ||
183 | if (!inet_csk(sk)->icsk_retransmits) | 195 | if (!inet_csk(sk)->icsk_retransmits) |
184 | return false; | 196 | return false; |
185 | 197 | ||
186 | start_ts = tcp_sk(sk)->retrans_stamp; | 198 | start_ts = tcp_sk(sk)->retrans_stamp; |
187 | if (likely(timeout == 0)) { | 199 | if (likely(timeout == 0)) |
188 | linear_backoff_thresh = ilog2(TCP_RTO_MAX/rto_base); | 200 | timeout = tcp_model_timeout(sk, boundary, TCP_RTO_MIN); |
189 | 201 | ||
190 | if (boundary <= linear_backoff_thresh) | ||
191 | timeout = ((2 << boundary) - 1) * rto_base; | ||
192 | else | ||
193 | timeout = ((2 << linear_backoff_thresh) - 1) * rto_base + | ||
194 | (boundary - linear_backoff_thresh) * TCP_RTO_MAX; | ||
195 | timeout = jiffies_to_msecs(timeout); | ||
196 | } | ||
197 | return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0; | 202 | return (s32)(tcp_time_stamp(tcp_sk(sk)) - start_ts - timeout) >= 0; |
198 | } | 203 | } |
199 | 204 | ||