Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1154150imm; Wed, 18 Jul 2018 18:16:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeXyJz7MtgxtrUcoWIT5YF4s9COupoPrrSbq0RGGOwGY4gj2Q53/nV+DKbpXmxO7PD4eyuR X-Received: by 2002:a63:4e5f:: with SMTP id o31-v6mr8023907pgl.256.1531963001024; Wed, 18 Jul 2018 18:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531963001; cv=none; d=google.com; s=arc-20160816; b=z83IN9UO6SSCkuzu9E8E5CUEM2Q1xKSsNEOyKCz0ZosNhf3dTxlDeno4637A8sKAUK qxcVXKaG9otvDTT9XMbB8NzkZ94wmHxbedM5+CncWV1IWEL0mCY6mPU8Hhuauyjm5o/m zysMhABMLAPyDAEVMSYd4WBbSm7gct0B5zoAep/uqF335CrABIfeHP4hPeYKAYH8hTpD 1DmD1Cyc2lleLDVwDceENnvFBJEui/SOrridWXeiY1NoQvwY/d0f2Vv4/nl3l3GbTMLv DBeIGSfW7nDofHQKlRVCBVyZYOeolthZ0eaMWaHAZNJQ4FRLf8m8gdGnJYBXaRv9ooBv UoVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=RqJusamQIL7japm3Kmcrl0lH6/aiRAPCWoDSN4NNiGQ=; b=uP0Vrorqqbw4cVMJazqe3ARMVvoGqZuCwRKTDPIGFy4bixGmrRxZoq/51HjYn/fFrc 9Qj+4eXD/sRJ4kHiTQi8D0qO85Wr9j8Dl2ZJBnipUTkC54pIBwBimYV9ua7exHDNE8go nFP1zA4kBuA3cnovyKj3Cd63NalY6oELX1YlKdGIYJt81xLf0jtm07K54pdoc9kPKwk3 4xmR/W8sEzdZHNobifo2XS4POvmOfiLYO4+LianPvNX06wUsLXwhr58zLPLBRJebO4zZ 0D3jdTx2uQJJGFtbqWuv1Fr+FZKOG4F5BMbfCAFHPrwDlvJkjefClGnr18Dke37Zj913 fbnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7-v6si4394986plk.397.2018.07.18.18.16.26; Wed, 18 Jul 2018 18:16:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731183AbeGSB4R (ORCPT + 99 others); Wed, 18 Jul 2018 21:56:17 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47442 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730094AbeGSB4R (ORCPT ); Wed, 18 Jul 2018 21:56:17 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 29C2FCE1C2; Thu, 19 Jul 2018 01:15:44 +0000 (UTC) Received: from 192-168-1-101.tpgi.com.com (vpn2-54-62.bne.redhat.com [10.64.54.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D5192026D69; Thu, 19 Jul 2018 01:15:41 +0000 (UTC) From: Jon Maxwell To: davem@davemloft.net Cc: edumazet@google.com, ncardwell@google.com, David.Laight@aculab.com, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jmaxwell@redhat.com Subject: [PATCH V4 net-next 3/3] tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy Date: Thu, 19 Jul 2018 11:14:44 +1000 Message-Id: <20180719011444.4694-4-jmaxwell37@gmail.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 01:15:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 19 Jul 2018 01:15:44 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jmaxwell37@gmail.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- net/ipv4/tcp_timer.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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) 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 +559,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