* [net-next, 1/3] tcp: convert icsk_user_timeout from jiffies to msecs
@ 2018-07-12 0:36 Jon Maxwell
[not found] ` <f65200d8942d4eca92f854e63d2d5286@AcuMS.aculab.com>
0 siblings, 1 reply; 2+ messages in thread
From: Jon Maxwell @ 2018-07-12 0:36 UTC (permalink / raw)
To: davem
Cc: edumazet, ncardwell, David.Laight, kuznet, yoshfuji, netdev,
linux-kernel, jmaxwell
This is a preparatory commit for an upcoming patch that improves the socket
TCP_USER_TIMEOUT option accuracy. Implement Eric Dumazets idea to convert
icsk->icsk_user_timeout from jiffies to msecs. To eliminate the
msecs_to_jiffies() and jiffies_to_msecs() dance in future.
There will 3 patches in this series. [net-next, 2/3] will create a seperate
helper routine called tcp_retransmit_stamp() as per Neal Cardwells suggestion.
Finally [net-next, 3/3] will implement a new routine called
tcp_clamp_rto_to_user_timeout() to calculate the rto so that TCP_USER_TIMEOUT
is more accurate. As a result of the final patch it won't have the
msecs_to_jiffies() and jiffies_to_msecs() dance that David Laight was concerned
about.
Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
---
net/ipv4/tcp.c | 4 ++--
net/ipv4/tcp_timer.c | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index e3704a49164b..9d900162f16a 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2984,7 +2984,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
if (val < 0)
err = -EINVAL;
else
- icsk->icsk_user_timeout = msecs_to_jiffies(val);
+ icsk->icsk_user_timeout = val;
break;
case TCP_FASTOPEN:
@@ -3440,7 +3440,7 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
break;
case TCP_USER_TIMEOUT:
- val = jiffies_to_msecs(icsk->icsk_user_timeout);
+ val = icsk->icsk_user_timeout;
break;
case TCP_FASTOPEN:
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 3b3611729928..fa34984d0b12 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -183,8 +183,9 @@ static bool retransmits_timed_out(struct sock *sk,
else
timeout = ((2 << linear_backoff_thresh) - 1) * rto_base +
(boundary - linear_backoff_thresh) * TCP_RTO_MAX;
+ timeout = jiffies_to_msecs(timeout);
}
- return (tcp_time_stamp(tcp_sk(sk)) - start_ts) >= jiffies_to_msecs(timeout);
+ return (tcp_time_stamp(tcp_sk(sk)) - start_ts) >= timeout;
}
/* A write timeout has occurred. Process the after effects. */
@@ -337,8 +338,7 @@ static void tcp_probe_timer(struct sock *sk)
if (!start_ts)
skb->skb_mstamp = tp->tcp_mstamp;
else if (icsk->icsk_user_timeout &&
- (s32)(tcp_time_stamp(tp) - start_ts) >
- jiffies_to_msecs(icsk->icsk_user_timeout))
+ (s32)(tcp_time_stamp(tp) - start_ts) > icsk->icsk_user_timeout)
goto abort;
max_probes = sock_net(sk)->ipv4.sysctl_tcp_retries2;
@@ -672,7 +672,7 @@ static void tcp_keepalive_timer (struct timer_list *t)
* to determine when to timeout instead.
*/
if ((icsk->icsk_user_timeout != 0 &&
- elapsed >= icsk->icsk_user_timeout &&
+ elapsed >= msecs_to_jiffies(icsk->icsk_user_timeout) &&
icsk->icsk_probes_out > 0) ||
(icsk->icsk_user_timeout == 0 &&
icsk->icsk_probes_out >= keepalive_probes(tp))) {
--
2.13.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [net-next, 1/3] tcp: convert icsk_user_timeout from jiffies to msecs
[not found] ` <f65200d8942d4eca92f854e63d2d5286@AcuMS.aculab.com>
@ 2018-07-12 12:35 ` Eric Dumazet
0 siblings, 0 replies; 2+ messages in thread
From: Eric Dumazet @ 2018-07-12 12:35 UTC (permalink / raw)
To: David Laight
Cc: jmaxwell37, David Miller, Neal Cardwell, Alexey Kuznetsov,
Hideaki YOSHIFUJI, netdev, LKML, jmaxwell
On Thu, Jul 12, 2018 at 1:57 AM David Laight <David.Laight@aculab.com> wrote:
>
> From: Jon Maxwell Sent: 12 July 2018 01:36
> ...
> > - (s32)(tcp_time_stamp(tp) - start_ts) >
> > - jiffies_to_msecs(icsk->icsk_user_timeout))
> > + (s32)(tcp_time_stamp(tp) - start_ts) > icsk->icsk_user_timeout)
>
> That has never been tested properly.
> icsk_user_timeout is u32 so the comparison is unsigned and the (s32) cast
> has no effect.
>
The existing code had this ' bug' already.
Please do not blame this patch, and send a patch if you believe there
is an issue ?
In my opinion, the (s32) here is a reminder for the reader of the
width of the expression,
more than anything, since there is no chance the result can be negative.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-12 12:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-12 0:36 [net-next, 1/3] tcp: convert icsk_user_timeout from jiffies to msecs Jon Maxwell
[not found] ` <f65200d8942d4eca92f854e63d2d5286@AcuMS.aculab.com>
2018-07-12 12:35 ` Eric Dumazet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).