Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp862817imm; Wed, 4 Jul 2018 07:16:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdaKnjFacAVoblmlcThSaHqr28fW48388Sebda8LBoiuRFn6udQf4EX5TRtbyIXWzlRlquk X-Received: by 2002:a63:1350:: with SMTP id 16-v6mr493680pgt.214.1530713778886; Wed, 04 Jul 2018 07:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530713778; cv=none; d=google.com; s=arc-20160816; b=PEWRMI6/otGYnL63qjH0yNGEcNEs5voYsRaka7wu06hVtZ/haIf8C8QxX1q9CNoXJo VHGXFcaP3KiuCSbVyE0V4/nsdmnO3W31Ovo3Y92CZKaWgxKSHIf9YxDcXmguxHBmQVCZ keJAt6qvbXkquYxMFmZI4vBCN+UZGAKFjmIn5jG8XBWYmvygYBcFJSMX0kBFX7+iojcJ ECeeXEcowV4D2pu33elT+beRxIMc9F3VfVLw1B14CnkW4maBP4jA57ieoNZlunbbFYGT ycW+f6SePXGUmucZMk0W4e8MW7yOQn1DwT1XNaTJD8oq6uo0yBfOIpJQPQOHVb9a1itq 98Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=ROZLDKQ/3ed5KSDetkjMa2yR/VRR1pqSCvqld/x69F4=; b=TYS/5Lq7Glgt3/RyPfZ3arECLHZCgo/QFKGoRGn1fQ4uIw7YB4Gj57hg7OU9ltPO/G EIVJ9jQgNMFYxGFcwPMMj+bRan+zzt2H6p4OTzc4Is8qZdZhZXtfr6DwswXtPiEiOKCA xiOHEVPbjOQCTNhgl7BpExefNBqvynb16oBK1kPAC/RCaiGJeDEtXzkhNNOzPbXnIrRj z4NOqKvu+jJJ2i3N1bTv+fsNZ6c3K54Fnma/qi3LG2cbi+GXw/ZbY0iPOHjJd30jVVef ceN3WpVZ7CLK5GAFpTvkxRmGnmPGGWjQO088GoYHn0sAM1uhdC5Tkm1dDRhAaLNMODh8 k/9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RYeK3K9D; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10-v6si3840313pfg.258.2018.07.04.07.16.03; Wed, 04 Jul 2018 07:16:18 -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=@google.com header.s=20161025 header.b=RYeK3K9D; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752451AbeGDOOR (ORCPT + 99 others); Wed, 4 Jul 2018 10:14:17 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:54537 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbeGDOOP (ORCPT ); Wed, 4 Jul 2018 10:14:15 -0400 Received: by mail-wm0-f67.google.com with SMTP id i139-v6so5948672wmf.4 for ; Wed, 04 Jul 2018 07:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ROZLDKQ/3ed5KSDetkjMa2yR/VRR1pqSCvqld/x69F4=; b=RYeK3K9D2y5fN7PuIEu84RK7mu+wERaPGGGW5IN1E5NyDBe2l+QEn5NBM0s8ZJo3gx 5gt3pVQxKAlc+6HdQuVcdPqFOyxWvqJEk2EN9sNcybpG4FIRhib2TL+GuFW2oiKzizFj xJWXHXnba+oPqLUY4mkVygNnvewbdpsLQmiayT0pxlQoNJCVCNPbWaZ2E7ExKnpRy05l uD6cprX81MucFnJv34oBi8FracfGxBhZedQB4arqDoubxyxFFFLCmNs6WmTUL01IDHS1 vQ5APeoBTXxgz++U24Wnqy/f8S2c6UvB1Io9bkaqUfrg51uC/8RURD/LLZumpFIowShK IpbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ROZLDKQ/3ed5KSDetkjMa2yR/VRR1pqSCvqld/x69F4=; b=tgjP4bbm5YKqzZB/9VFNFIdBwJAjZSymWeWiJ5Y/ATde7ZEWrOAMm0fuTdeHCTRuZc 2Wix9krRcRZNjhMbQatqzUmD72hA5F9DdCm4rR+0yuMQJJE591J+XUTPJiN2W2OLAbtm xPES3c0+oAnN1fT/Xxc5of6OcuuSeIA37FhhFVgmd+Wq/HKLFSCeF637e3rqSTneoNFu ewuKTlBPExIdhaN7CGB2OoXBbkdDilVZMq8vyQyA/xmAX0BnCzsM3yAvkaatyViluj7g hDfsU/4YWZBEryfokP0WXpGeT/+HR8dSj4OxMV2qr7qhgRw8CR5P1a9vvRejsDTYTHn9 B/nw== X-Gm-Message-State: APt69E2MiKwiBxFPI4LbiM4Ke4ccCl3VN0B4+/k+uJTq8dEXCrDu/yMV gO3xvQyBqXN9O3HjMTfSYX0I82NQB47W50fvNMTw9g== X-Received: by 2002:a1c:2482:: with SMTP id k124-v6mr1597165wmk.87.1530713653369; Wed, 04 Jul 2018 07:14:13 -0700 (PDT) MIME-Version: 1.0 References: <20180704000608.17360-1-jmaxwell37@gmail.com> In-Reply-To: <20180704000608.17360-1-jmaxwell37@gmail.com> From: Neal Cardwell Date: Wed, 4 Jul 2018 10:13:56 -0400 Message-ID: Subject: Re: [net-next,v2] tcp: Improve setsockopt() TCP_USER_TIMEOUT accuracy To: Jonathan Maxwell Cc: David Miller , Eric Dumazet , Alexey Kuznetsov , Hideaki YOSHIFUJI , Netdev , LKML , jmaxwell@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 3, 2018 at 8:06 PM Jon Maxwell wrote: > > Signed-off-by: Jon Maxwell > --- > 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 > @@ -22,6 +22,39 @@ > #include > #include > > +unsigned int tcp_retransmit_stamp(struct sock *sk) > +{ > + unsigned int start_ts = tcp_sk(sk)->retrans_stamp; Since retrans_stamp and tcp_skb_timestamp() are both u32, I'd suggest using u32 for the local variable start_ts and the return type of the function. > + > + if (unlikely(!start_ts)) { > + struct sk_buff *head = tcp_rtx_queue_head(sk); > + > + if (!head) > + return false; Looks like a copy-and-paste holdover: since this function is returning an integer, I would suggest returning 0 rather than false. > + start_ts = tcp_skb_timestamp(head); > + } > + return start_ts; > +} > + > +static __u32 tcp_clamp_rto_to_user_timeout(struct sock *sk) > +{ > + struct inet_connection_sock *icsk = inet_csk(sk); > + __u32 rto = icsk->icsk_rto; > + __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)); > + return rto; > +} > + > /** > * tcp_write_err() - close socket and save error info > * @sk: The socket the error has appeared on. > @@ -166,14 +199,9 @@ static bool retransmits_timed_out(struct sock *sk, > if (!inet_csk(sk)->icsk_retransmits) > return false; > > - start_ts = tcp_sk(sk)->retrans_stamp; > - if (unlikely(!start_ts)) { > - struct sk_buff *head = tcp_rtx_queue_head(sk); > - > - if (!head) > - return false; > - start_ts = tcp_skb_timestamp(head); > - } > + start_ts = tcp_retransmit_stamp(sk); > + if (!start_ts) > + return false; > > if (likely(timeout == 0)) { > linear_backoff_thresh = ilog2(TCP_RTO_MAX/rto_base); > @@ -407,6 +435,7 @@ void tcp_retransmit_timer(struct sock *sk) > struct tcp_sock *tp = tcp_sk(sk); > struct net *net = sock_net(sk); > struct inet_connection_sock *icsk = inet_csk(sk); > + __u32 rto; > > if (tp->fastopen_rsk) { > WARN_ON_ONCE(sk->sk_state != TCP_SYN_RECV && > @@ -535,7 +564,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); > + rto = tcp_clamp_rto_to_user_timeout(sk); > + inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, rto, TCP_RTO_MAX); > if (retransmits_timed_out(sk, net->ipv4.sysctl_tcp_retries1 + 1, 0)) > __sk_dst_reset(sk); Thanks! neal