Skip to content

Commit b04c332

Browse files
edumazetdavem330
authored andcommitted
tcp: add tcp_rtt_tsopt_us()
Before adding usec TS support, add tcp_rtt_tsopt_us() helper to factorize code. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9d0c00f commit b04c332

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

net/ipv4/tcp_input.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,21 @@ static inline void tcp_rcv_rtt_measure(struct tcp_sock *tp)
693693
tp->rcv_rtt_est.time = tp->tcp_mstamp;
694694
}
695695

696+
static s32 tcp_rtt_tsopt_us(const struct tcp_sock *tp)
697+
{
698+
u32 delta, delta_us;
699+
700+
delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr;
701+
702+
if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) {
703+
if (!delta)
704+
delta = 1;
705+
delta_us = delta * (USEC_PER_SEC / TCP_TS_HZ);
706+
return delta_us;
707+
}
708+
return -1;
709+
}
710+
696711
static inline void tcp_rcv_rtt_measure_ts(struct sock *sk,
697712
const struct sk_buff *skb)
698713
{
@@ -704,15 +719,10 @@ static inline void tcp_rcv_rtt_measure_ts(struct sock *sk,
704719

705720
if (TCP_SKB_CB(skb)->end_seq -
706721
TCP_SKB_CB(skb)->seq >= inet_csk(sk)->icsk_ack.rcv_mss) {
707-
u32 delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr;
708-
u32 delta_us;
709-
710-
if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) {
711-
if (!delta)
712-
delta = 1;
713-
delta_us = delta * (USEC_PER_SEC / TCP_TS_HZ);
714-
tcp_rcv_rtt_update(tp, delta_us, 0);
715-
}
722+
s32 delta = tcp_rtt_tsopt_us(tp);
723+
724+
if (delta >= 0)
725+
tcp_rcv_rtt_update(tp, delta, 0);
716726
}
717727
}
718728

@@ -3146,17 +3156,10 @@ static bool tcp_ack_update_rtt(struct sock *sk, const int flag,
31463156
* left edge of the send window.
31473157
* See draft-ietf-tcplw-high-performance-00, section 3.3.
31483158
*/
3149-
if (seq_rtt_us < 0 && tp->rx_opt.saw_tstamp && tp->rx_opt.rcv_tsecr &&
3150-
flag & FLAG_ACKED) {
3151-
u32 delta = tcp_time_stamp_ts(tp) - tp->rx_opt.rcv_tsecr;
3152-
3153-
if (likely(delta < INT_MAX / (USEC_PER_SEC / TCP_TS_HZ))) {
3154-
if (!delta)
3155-
delta = 1;
3156-
seq_rtt_us = delta * (USEC_PER_SEC / TCP_TS_HZ);
3157-
ca_rtt_us = seq_rtt_us;
3158-
}
3159-
}
3159+
if (seq_rtt_us < 0 && tp->rx_opt.saw_tstamp &&
3160+
tp->rx_opt.rcv_tsecr && flag & FLAG_ACKED)
3161+
seq_rtt_us = ca_rtt_us = tcp_rtt_tsopt_us(tp);
3162+
31603163
rs->rtt_us = ca_rtt_us; /* RTT of last (S)ACKed packet (or -1) */
31613164
if (seq_rtt_us < 0)
31623165
return false;

0 commit comments

Comments
 (0)