Skip to content

Commit a84f0a6

Browse files
committed
Expose both send and receive rate in rate_sample
1 parent 1fa9835 commit a84f0a6

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

include/net/tcp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ struct rate_sample {
893893
u32 prior_delivered; /* tp->delivered at "prior_mstamp" */
894894
s32 delivered; /* number of packets delivered over interval */
895895
long interval_us; /* time for tp->delivered to incr "delivered" */
896+
long snd_int_us; /* snd interval for delivered packets */
897+
long rcv_int_us; /* rcv interval for delivered packets */
896898
long rtt_us; /* RTT of last (S)ACKed packet (or -1) */
897899
int losses; /* number of packets marked lost upon ACK */
898900
u32 acked_sacked; /* number of packets newly (S)ACKed upon ACK */

net/ipv4/tcp_rate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ void tcp_rate_gen(struct sock *sk, u32 delivered, u32 lost,
140140
snd_us = rs->interval_us; /* send phase */
141141
ack_us = skb_mstamp_us_delta(now, &rs->prior_mstamp); /* ack phase */
142142
rs->interval_us = max(snd_us, ack_us);
143+
/* Record both segment send and ack receive intervals. */
144+
rs->snd_int_us = snd_us;
145+
rs->rcv_int_us = ack_us;
143146

144147
/* Normally we expect interval_us >= min-rtt.
145148
* Note that rate may still be over-estimated when a spuriously

net/ipv4/tcp_testrate.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ static int rate_sample_valid(const struct rate_sample *rs)
4343

4444
void tcp_testrate_cong_control(struct sock *sk, const struct rate_sample *rs)
4545
{
46-
u64 bw_bps; /* delivered bandwidth in bytes per second */
46+
u64 snd_bw_bps; /* send bandwidth in bytes per second */
47+
u64 rcv_bw_bps; /* recv bandwidth in bytes per second */
4748
u32 diff_bps; /* difference in delivered and set bandwidths */
4849
u64 segs_in_flight; /* compute desired cwnd as rate * rtt */
4950

@@ -52,16 +53,26 @@ void tcp_testrate_cong_control(struct sock *sk, const struct rate_sample *rs)
5253
/* Report rate mismatches beyond a threshold of BW_ERROR_PERC_THRESH
5354
percent. */
5455
if (rate_sample_valid(rs)) {
55-
bw_bps = (u64)rs->delivered * MTU * S_TO_US;
56-
do_div(bw_bps, rs->interval_us);
57-
diff_bps = ca->rate - bw_bps;
58-
if (ca->rate > bw_bps &&
56+
rcv_bw_bps = snd_bw_bps = (u64)rs->delivered * MTU * S_TO_US;
57+
/* Compute send rate either using the send time or receive time. */
58+
if (rs->snd_int_us > 0)
59+
do_div(snd_bw_bps, rs->snd_int_us);
60+
else
61+
do_div(snd_bw_bps, rs->interval_us);
62+
/* Compute receive rate using receive time, if possible. */
63+
if (rs->rcv_int_us > 0)
64+
do_div(rcv_bw_bps, rs->rcv_int_us);
65+
/* Check rate mismatch through a threshold difference between the set and
66+
achieved send rates. */
67+
diff_bps = ca->rate - snd_bw_bps;
68+
if (ca->rate > snd_bw_bps &&
5969
diff_bps > (BW_ERROR_PERC_THRESH * (ca->rate / 100))) {
60-
pr_info("tcp_testrate found a rate mismatch %d %d %ld %lld\n",
70+
pr_info("tcp_testrate found a rate mismatch %d %d %ld %lld %lld\n",
6171
diff_bps,
6272
rs->delivered,
6373
rs->interval_us,
64-
bw_bps);
74+
snd_bw_bps,
75+
rcv_bw_bps);
6576
ca->mismatch_cnt++;
6677
}
6778

0 commit comments

Comments
 (0)