Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp230135imm; Tue, 17 Jul 2018 17:49:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfdt34KEvcftPWVFky0oOLS2EYdl2ddk7y4c/UqrkbUzOHD9bagsoTDu5vCpT5wV7s0XwPs X-Received: by 2002:a62:d8c:: with SMTP id 12-v6mr2932634pfn.202.1531874945063; Tue, 17 Jul 2018 17:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531874945; cv=none; d=google.com; s=arc-20160816; b=SCwI89EMlwmehmrY9FUUNiaanwRUTHj7/1IUYnDOXUqhTHDtF2Bj7jZyECTOAVWNbP NzGbTpaSY61udzb5gc+NybSxTqT8sUstwQhDb9CzcAC9Q1QQxGeK0L1+KH304xJ+T0R3 nd0Etg3dz5WTXtcyguDk0/e7HkVB5hkrb9xy3ojAeeramUt8UDWojHV0R0f4HErIabMr BO8QoWNVxF84ZzbJlVmrQ4PtTA+guESYKAcbb+XvyXUJhakhfKgi16BD7FJTBbnZLd0x 4214H+T5jcJTaq5cb6nj9G7qUfH8w9z/ROppWwfezdJPZaCda6uMs3LMe2aN/2SVfJko +eBQ== 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 :dkim-signature:arc-authentication-results; bh=RqJusamQIL7japm3Kmcrl0lH6/aiRAPCWoDSN4NNiGQ=; b=nvNam8BAe5l+HKoCYcAwPlUXLXEBGRc/ylhNX08QzYTGfiAcj9l3/t5LxF53uvmukY uc7EmRMblZTXMf0tvUvVEQlwz8H6y11+FcUbRRBQlimd7ULPjPqLJJijOEC06GhPGXD+ PepE8ovDEEZyUUFr4PP1Z+B+me22VliUqnbo6cVMmMOCUqutGs/l0QFdq80Y1FJGrZRP Rh1Ndsfao6C9VXcEAqqBA28ROtPg098Zhyv5Ap25KtSVlY/eIVwpUGXY1i2sRq/kvscz 6Jnvpy61/WqW7b2nXDKpgPRikPQZUuZDqhpAyN88pAmPG1xFWKIHQMT4jxfNG4Gv/o8I 0ltQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C31HiFon; 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=pass (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 o61-v6si1963874pld.109.2018.07.17.17.48.49; Tue, 17 Jul 2018 17:49:05 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C31HiFon; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731650AbeGRBWi (ORCPT + 99 others); Tue, 17 Jul 2018 21:22:38 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:45416 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730043AbeGRBWh (ORCPT ); Tue, 17 Jul 2018 21:22:37 -0400 Received: by mail-pl0-f65.google.com with SMTP id 94-v6so1191253ple.12; Tue, 17 Jul 2018 17:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RqJusamQIL7japm3Kmcrl0lH6/aiRAPCWoDSN4NNiGQ=; b=C31HiFonyGr7EeRX8YopLTvlvpT9oLlEpigN0Ai0jqCx56XL5HdEKhAjADw70xGJdl QQRhIWy9ssGzFrjAsbaYlDJoQQ41qbmXcnfozFR1D2rpv5/F5L+8vvDfcmpBzQuynbjK zc7SlONbcb+O6wRPaogk8aB13VBgAAan0qAI7iYX9Ejgz7hrY/3etHaRTqvmf6hRyTIb WuvKidhR7rN1IlNQmNvCf1QZf12vNc+Zgs0/fpKdqmfH/DwbG6Fu7Qy18xlApdYwGmuj qhuqgjb9TQrbBtGHkYEkaAXw7kUTiN0UXF1UI707GZ006L3CkOaCSsbk8WXYkb20rfk+ maXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RqJusamQIL7japm3Kmcrl0lH6/aiRAPCWoDSN4NNiGQ=; b=IVYmK1jqJJezSTec/cZ54/jRU/zwzW8GYvDKHPwKnNqxT0X0u+sW5HbkxuGF6o2i2k ZJ+YHVjldj/TOb4kGKnO4z3AHf05hPV0w6cpUwK9BCmLLGGTSY5akTBHEEA2STsbxKnf hg8t05qpFikhusYuYQNE8+R1N2PD8Fmy+4gIkV4mr1VM8zHtmAMUKyP603ZHq2A/+egd 0bXOPmXFvbNPstya2XIQbaxn91epC0e/tahX8BiPV7Uni2CQTeaGi5399vJyOxHo/OsR d43xwa3aOt1QWyoOzeJ4tyLGu37+5JFV0uCte/UPoDOC7eAJJtIE7UMHmiNOT8hkNjgq 0/BQ== X-Gm-Message-State: AOUpUlHRrVT9RvDvAtMlwI/7mvHs1VUVy4kKxj+ldh2//jIGCM5P1dje xVX27DE0RK2vUr4FPTn9Z/o= X-Received: by 2002:a17:902:bd93:: with SMTP id q19-v6mr3684132pls.238.1531874846984; Tue, 17 Jul 2018 17:47:26 -0700 (PDT) Received: from 192-168-1-101.tpgi.com.com ([61.68.123.183]) by smtp.gmail.com with ESMTPSA id b62-v6sm9190775pfm.97.2018.07.17.17.47.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jul 2018 17:47:25 -0700 (PDT) From: Jon Maxwell To: davem@davemloft.net Cc: edumazet@google.com, eric.dumazet@gmail.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: tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy Date: Wed, 18 Jul 2018 10:46:39 +1000 Message-Id: <20180718004639.30154-4-jmaxwell37@gmail.com> X-Mailer: git-send-email 2.13.6 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