RE: [net-next,v2] tcp: Improve setsockopt() TCP_USER_TIMEOUT accuracy

From: David Laight
Date: Wed Jul 04 2018 - 10:55:38 EST


From: Neal Cardwell
> Sent: 04 July 2018 15:14
>
> On Tue, Jul 3, 2018 at 8:06 PM Jon Maxwell <jmaxwell37@xxxxxxxxx> wrote:
> >
> > Signed-off-by: Jon Maxwell <jmaxwell37@xxxxxxxxx>
> > ---
> > net/ipv4/tcp_timer.c | 48 +++++++++++++++++++++++++++++++++++++++---------
> > 1 file changed, 39 insertions(+), 9 deletions(-)
> >
> > diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
> > index 3b3611729928..d129e670d02a 100644
> > --- a/net/ipv4/tcp_timer.c
> > +++ b/net/ipv4/tcp_timer.c
...
> > +static __u32 tcp_clamp_rto_to_user_timeout(struct sock *sk)
> > +{
> > + struct inet_connection_sock *icsk = inet_csk(sk);
> > + __u32 rto = icsk->icsk_rto;

Why cache rto past all the function calls until it is needed?

> > + __u32 elapsed, user_timeout;
> > + unsigned int start_ts;
>
> I'd suggest u32 here for start_ts (per the rationale above).
>
> > +
> > + start_ts = tcp_retransmit_stamp(sk);
> > + if (!icsk->icsk_user_timeout || !start_ts)
> > + return rto;
> > + elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts;
> > + user_timeout = jiffies_to_msecs(icsk->icsk_user_timeout);
> > + if (elapsed >= user_timeout)
> > + rto = 1; /* user timeout has passed; fire ASAP */
> > + else
> > + rto = min(rto, (__u32)msecs_to_jiffies(user_timeout - elapsed));
>
> My sense is that min_t would be preferred here, e.g:
>
> rto = min_t(__u32, rto, msecs_to_jiffies(user_timeout - elapsed));

Think I'd just write the conditional...

> > + return rto;
> > +}

Looks to me like it doesn't correctly allow for the conversions
between millisecond and jiffies either.
I suspect the msecs_to_jiffies() call can return zero (unless it rounds up).
Coding with a signed 'time until user timeout' might make it simpler.

David