Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 103641
b: refs/heads/master
c: c1e20f7
h: refs/heads/master
i:
  103639: 597405e
v: v3
  • Loading branch information
Stephen Hemminger authored and David S. Miller committed Jul 19, 2008
1 parent adb881e commit 028336f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 30ee42be00b7a50929a73cb617f70b1d3219eb69
refs/heads/master: c1e20f7c8b9ccbafc9ea78f2b406738728ce6b81
12 changes: 12 additions & 0 deletions trunk/include/net/dst.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ static inline u32 dst_mtu(const struct dst_entry *dst)
return mtu;
}

/* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */
static inline unsigned long dst_metric_rtt(const struct dst_entry *dst, int metric)
{
return msecs_to_jiffies(dst_metric(dst, metric));
}

static inline void set_dst_metric_rtt(struct dst_entry *dst, int metric,
unsigned long rtt)
{
dst->metrics[metric-1] = jiffies_to_msecs(rtt);
}

static inline u32
dst_allfrag(const struct dst_entry *dst)
{
Expand Down
31 changes: 18 additions & 13 deletions trunk/net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ static u32 tcp_rto_min(struct sock *sk)
u32 rto_min = TCP_RTO_MIN;

if (dst && dst_metric_locked(dst, RTAX_RTO_MIN))
rto_min = dst_metric(dst, RTAX_RTO_MIN);
rto_min = dst_metric_rtt(dst, RTAX_RTO_MIN);
return rto_min;
}

Expand Down Expand Up @@ -729,6 +729,7 @@ void tcp_update_metrics(struct sock *sk)
if (dst && (dst->flags & DST_HOST)) {
const struct inet_connection_sock *icsk = inet_csk(sk);
int m;
unsigned long rtt;

if (icsk->icsk_backoff || !tp->srtt) {
/* This session failed to estimate rtt. Why?
Expand All @@ -740,20 +741,22 @@ void tcp_update_metrics(struct sock *sk)
return;
}

m = dst_metric(dst, RTAX_RTT) - tp->srtt;
rtt = dst_metric_rtt(dst, RTAX_RTT);
m = rtt - tp->srtt;

/* If newly calculated rtt larger than stored one,
* store new one. Otherwise, use EWMA. Remember,
* rtt overestimation is always better than underestimation.
*/
if (!(dst_metric_locked(dst, RTAX_RTT))) {
if (m <= 0)
dst->metrics[RTAX_RTT - 1] = tp->srtt;
set_dst_metric_rtt(dst, RTAX_RTT, tp->srtt);
else
dst->metrics[RTAX_RTT - 1] -= (m >> 3);
set_dst_metric_rtt(dst, RTAX_RTT, rtt - (m >> 3));
}

if (!(dst_metric_locked(dst, RTAX_RTTVAR))) {
unsigned long var;
if (m < 0)
m = -m;

Expand All @@ -762,11 +765,13 @@ void tcp_update_metrics(struct sock *sk)
if (m < tp->mdev)
m = tp->mdev;

if (m >= dst_metric(dst, RTAX_RTTVAR))
dst->metrics[RTAX_RTTVAR - 1] = m;
var = dst_metric_rtt(dst, RTAX_RTTVAR);
if (m >= var)
var = m;
else
dst->metrics[RTAX_RTTVAR-1] -=
(dst_metric(dst, RTAX_RTTVAR) - m)>>2;
var -= (var - m) >> 2;

set_dst_metric_rtt(dst, RTAX_RTTVAR, var);
}

if (tp->snd_ssthresh >= 0xFFFF) {
Expand Down Expand Up @@ -897,7 +902,7 @@ static void tcp_init_metrics(struct sock *sk)
if (dst_metric(dst, RTAX_RTT) == 0)
goto reset;

if (!tp->srtt && dst_metric(dst, RTAX_RTT) < (TCP_TIMEOUT_INIT << 3))
if (!tp->srtt && dst_metric_rtt(dst, RTAX_RTT) < (TCP_TIMEOUT_INIT << 3))
goto reset;

/* Initial rtt is determined from SYN,SYN-ACK.
Expand All @@ -914,12 +919,12 @@ static void tcp_init_metrics(struct sock *sk)
* to low value, and then abruptly stops to do it and starts to delay
* ACKs, wait for troubles.
*/
if (dst_metric(dst, RTAX_RTT) > tp->srtt) {
tp->srtt = dst_metric(dst, RTAX_RTT);
if (dst_metric_rtt(dst, RTAX_RTT) > tp->srtt) {
tp->srtt = dst_metric_rtt(dst, RTAX_RTT);
tp->rtt_seq = tp->snd_nxt;
}
if (dst_metric(dst, RTAX_RTTVAR) > tp->mdev) {
tp->mdev = dst_metric(dst, RTAX_RTTVAR);
if (dst_metric_rtt(dst, RTAX_RTTVAR) > tp->mdev) {
tp->mdev = dst_metric_rtt(dst, RTAX_RTTVAR);
tp->mdev_max = tp->rttvar = max(tp->mdev, tcp_rto_min(sk));
}
tcp_set_rto(sk);
Expand Down

0 comments on commit 028336f

Please sign in to comment.