linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [net-next, 3/3] tcp: convert icsk_user_timeout from jiffies to msecs
@ 2018-07-13  0:49 Jon Maxwell
  2018-07-16 16:00 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Maxwell @ 2018-07-13  0:49 UTC (permalink / raw)
  To: davem
  Cc: edumazet, ncardwell, David.Laight, kuznet, yoshfuji, netdev,
	linux-kernel, jmaxwell

The final patch in this series. 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>
---
 net/ipv4/tcp_timer.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 8ab8c9645294..d4d4b30a6bec 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -36,6 +36,22 @@ u32 tcp_retransmit_stamp(const struct sock *sk)
 	return start_ts;
 }
 
+static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
+{
+	struct inet_connection_sock *icsk = inet_csk(sk);
+	u32 elapsed, start_ts;
+
+	start_ts = tcp_retransmit_stamp(sk);
+	if (!icsk->icsk_user_timeout || !start_ts)
+		return icsk->icsk_rto;
+	elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts;
+	if (elapsed >= icsk->icsk_user_timeout)
+		return 1; /* user timeout has passed; fire ASAP */
+	else
+		return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(icsk->icsk_user_timeout -
+			     elapsed));
+}
+
 /**
  *  tcp_write_err() - close socket and save error info
  *  @sk:  The socket the error has appeared on.
@@ -544,7 +560,8 @@ void tcp_retransmit_timer(struct sock *sk)
 		/* Use normal (exponential) backoff */
 		icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX);
 	}
-	inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX);
+	inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
+				  tcp_clamp_rto_to_user_timeout(sk), TCP_RTO_MAX);
 	if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1 + 1, 0))
 		__sk_dst_reset(sk);
 
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [net-next, 3/3] tcp: convert icsk_user_timeout from jiffies to msecs
  2018-07-13  0:49 [net-next, 3/3] tcp: convert icsk_user_timeout from jiffies to msecs Jon Maxwell
@ 2018-07-16 16:00 ` Eric Dumazet
  2018-07-16 23:17   ` Jonathan Maxwell
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2018-07-16 16:00 UTC (permalink / raw)
  To: Jon Maxwell, davem
  Cc: edumazet, ncardwell, David.Laight, kuznet, yoshfuji, netdev,
	linux-kernel, jmaxwell



On 07/12/2018 05:49 PM, Jon Maxwell wrote:
> The final patch in this series. 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>
> ---
>  net/ipv4/tcp_timer.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
> index 8ab8c9645294..d4d4b30a6bec 100644
> --- a/net/ipv4/tcp_timer.c
> +++ b/net/ipv4/tcp_timer.c
> @@ -36,6 +36,22 @@ u32 tcp_retransmit_stamp(const struct sock *sk)
>  	return start_ts;
>  }
>  
> +static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
> +{
> +	struct inet_connection_sock *icsk = inet_csk(sk);
> +	u32 elapsed, start_ts;
> +
> +	start_ts = tcp_retransmit_stamp(sk);
> +	if (!icsk->icsk_user_timeout || !start_ts)
> +		return icsk->icsk_rto;
> +	elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts;
> +	if (elapsed >= icsk->icsk_user_timeout)
> +		return 1; /* user timeout has passed; fire ASAP */
> +	else
> +		return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(icsk->icsk_user_timeout -
> +			     elapsed));

	if (elapsed >= icsk->icsk_user_timeout)
		return 1; /* user timeout has passed; fire ASAP */

	return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(icsk->icsk_user_timeout - elapsed));

Thanks !

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net-next, 3/3] tcp: convert icsk_user_timeout from jiffies to msecs
  2018-07-16 16:00 ` Eric Dumazet
@ 2018-07-16 23:17   ` Jonathan Maxwell
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Maxwell @ 2018-07-16 23:17 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, Eric Dumazet, Neal Cardwell, David Laight, kuznet,
	yoshfuji, Netdev, LKML, Jon Maxwell

Sorry Eric, my bad. I'll do another version with the indentation fixed and
reformatting of min_t() and resubmit.

On Tue, Jul 17, 2018 at 2:00 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>
> On 07/12/2018 05:49 PM, Jon Maxwell wrote:
>> The final patch in this series. 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>
>> ---
>>  net/ipv4/tcp_timer.c | 19 ++++++++++++++++++-
>>  1 file changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
>> index 8ab8c9645294..d4d4b30a6bec 100644
>> --- a/net/ipv4/tcp_timer.c
>> +++ b/net/ipv4/tcp_timer.c
>> @@ -36,6 +36,22 @@ u32 tcp_retransmit_stamp(const struct sock *sk)
>>       return start_ts;
>>  }
>>
>> +static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
>> +{
>> +     struct inet_connection_sock *icsk = inet_csk(sk);
>> +     u32 elapsed, start_ts;
>> +
>> +     start_ts = tcp_retransmit_stamp(sk);
>> +     if (!icsk->icsk_user_timeout || !start_ts)
>> +             return icsk->icsk_rto;
>> +     elapsed = tcp_time_stamp(tcp_sk(sk)) - start_ts;
>> +     if (elapsed >= icsk->icsk_user_timeout)
>> +             return 1; /* user timeout has passed; fire ASAP */
>> +     else
>> +             return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(icsk->icsk_user_timeout -
>> +                          elapsed));
>
>         if (elapsed >= icsk->icsk_user_timeout)
>                 return 1; /* user timeout has passed; fire ASAP */
>
>         return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(icsk->icsk_user_timeout - elapsed));
>
> Thanks !

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-16 23:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-13  0:49 [net-next, 3/3] tcp: convert icsk_user_timeout from jiffies to msecs Jon Maxwell
2018-07-16 16:00 ` Eric Dumazet
2018-07-16 23:17   ` Jonathan Maxwell

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).