Skip to content

Commit 30cfd0b

Browse files
Stephen HemmingerDavid S. Miller
Stephen Hemminger
authored and
David S. Miller
committed
[TCP]: congestion control API pass RTT in microseconds
This patch changes the API for the callback that is done after an ACK is received. It solves a couple of issues: * Some congestion controls want higher resolution value of RTT (controlled by TCP_CONG_RTT_SAMPLE flag). These don't really want a ktime, but all compute a RTT in microseconds. * Other congestion control could use RTT at jiffies resolution. To keep API consistent the units should be the same for both cases, just the resolution should change. Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6a30235 commit 30cfd0b

12 files changed

+39
-29
lines changed

include/net/tcp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ struct tcp_congestion_ops {
660660
/* new value of cwnd after loss (optional) */
661661
u32 (*undo_cwnd)(struct sock *sk);
662662
/* hook for packet ack accounting (optional) */
663-
void (*pkts_acked)(struct sock *sk, u32 num_acked, ktime_t last);
663+
void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us);
664664
/* get info for inet_diag (optional) */
665665
void (*get_info)(struct sock *sk, u32 ext, struct sk_buff *skb);
666666

net/ipv4/tcp_bic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void bictcp_state(struct sock *sk, u8 new_state)
206206
/* Track delayed acknowledgment ratio using sliding window
207207
* ratio = (15*ratio + sample) / 16
208208
*/
209-
static void bictcp_acked(struct sock *sk, u32 cnt, ktime_t last)
209+
static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt)
210210
{
211211
const struct inet_connection_sock *icsk = inet_csk(sk);
212212

net/ipv4/tcp_cubic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static void bictcp_state(struct sock *sk, u8 new_state)
334334
/* Track delayed acknowledgment ratio using sliding window
335335
* ratio = (15*ratio + sample) / 16
336336
*/
337-
static void bictcp_acked(struct sock *sk, u32 cnt, ktime_t last)
337+
static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us)
338338
{
339339
const struct inet_connection_sock *icsk = inet_csk(sk);
340340

net/ipv4/tcp_htcp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static inline void measure_rtt(struct sock *sk)
9898
}
9999
}
100100

101-
static void measure_achieved_throughput(struct sock *sk, u32 pkts_acked, ktime_t last)
101+
static void measure_achieved_throughput(struct sock *sk, u32 pkts_acked, s32 rtt)
102102
{
103103
const struct inet_connection_sock *icsk = inet_csk(sk);
104104
const struct tcp_sock *tp = tcp_sk(sk);

net/ipv4/tcp_illinois.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,16 @@ static void tcp_illinois_init(struct sock *sk)
8383
}
8484

8585
/* Measure RTT for each ack. */
86-
static void tcp_illinois_acked(struct sock *sk, u32 pkts_acked, ktime_t last)
86+
static void tcp_illinois_acked(struct sock *sk, u32 pkts_acked, s32 rtt)
8787
{
8888
struct illinois *ca = inet_csk_ca(sk);
89-
u32 rtt;
9089

9190
ca->acked = pkts_acked;
9291

93-
if (ktime_equal(last, net_invalid_timestamp()))
92+
/* dup ack, no rtt sample */
93+
if (rtt < 0)
9494
return;
9595

96-
rtt = ktime_to_us(net_timedelta(last));
97-
9896
/* ignore bogus values, this prevents wraparound in alpha math */
9997
if (rtt > RTT_MAX)
10098
rtt = RTT_MAX;

net/ipv4/tcp_input.c

+16-5
Original file line numberDiff line numberDiff line change
@@ -2490,12 +2490,23 @@ static int tcp_clean_rtx_queue(struct sock *sk, __s32 *seq_rtt_p)
24902490
tcp_ack_update_rtt(sk, acked, seq_rtt);
24912491
tcp_ack_packets_out(sk);
24922492

2493-
/* Is the ACK triggering packet unambiguous? */
2494-
if (acked & FLAG_RETRANS_DATA_ACKED)
2495-
last_ackt = net_invalid_timestamp();
2493+
if (ca_ops->pkts_acked) {
2494+
s32 rtt_us = -1;
2495+
2496+
/* Is the ACK triggering packet unambiguous? */
2497+
if (!(acked & FLAG_RETRANS_DATA_ACKED)) {
2498+
/* High resolution needed and available? */
2499+
if (ca_ops->flags & TCP_CONG_RTT_STAMP &&
2500+
!ktime_equal(last_ackt,
2501+
net_invalid_timestamp()))
2502+
rtt_us = ktime_us_delta(ktime_get_real(),
2503+
last_ackt);
2504+
else if (seq_rtt > 0)
2505+
rtt_us = jiffies_to_usecs(seq_rtt);
2506+
}
24962507

2497-
if (ca_ops->pkts_acked)
2498-
ca_ops->pkts_acked(sk, pkts_acked, last_ackt);
2508+
ca_ops->pkts_acked(sk, pkts_acked, rtt_us);
2509+
}
24992510
}
25002511

25012512
#if FASTRETRANS_DEBUG > 0

net/ipv4/tcp_lp.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ static void tcp_lp_rtt_sample(struct sock *sk, u32 rtt)
260260
* newReno in increase case.
261261
* We work it out by following the idea from TCP-LP's paper directly
262262
*/
263-
static void tcp_lp_pkts_acked(struct sock *sk, u32 num_acked, ktime_t last)
263+
static void tcp_lp_pkts_acked(struct sock *sk, u32 num_acked, s32 rtt_us)
264264
{
265265
struct tcp_sock *tp = tcp_sk(sk);
266266
struct lp *lp = inet_csk_ca(sk);
267267

268-
if (!ktime_equal(last, net_invalid_timestamp()))
269-
tcp_lp_rtt_sample(sk, ktime_to_us(net_timedelta(last)));
268+
if (rtt_us > 0)
269+
tcp_lp_rtt_sample(sk, rtt_us);
270270

271271
/* calc inference */
272272
if (tcp_time_stamp > tp->rx_opt.rcv_tsecr)

net/ipv4/tcp_vegas.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ EXPORT_SYMBOL_GPL(tcp_vegas_init);
112112
* o min-filter RTT samples from a much longer window (forever for now)
113113
* to find the propagation delay (baseRTT)
114114
*/
115-
void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, ktime_t last)
115+
void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us)
116116
{
117117
struct vegas *vegas = inet_csk_ca(sk);
118118
u32 vrtt;
119119

120-
if (ktime_equal(last, net_invalid_timestamp()))
120+
if (rtt_us < 0)
121121
return;
122122

123123
/* Never allow zero rtt or baseRTT */
124-
vrtt = ktime_to_us(net_timedelta(last)) + 1;
124+
vrtt = rtt_us + 1;
125125

126126
/* Filter to find propagation delay: */
127127
if (vrtt < vegas->baseRTT)

net/ipv4/tcp_vegas.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct vegas {
1717

1818
extern void tcp_vegas_init(struct sock *sk);
1919
extern void tcp_vegas_state(struct sock *sk, u8 ca_state);
20-
extern void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, ktime_t last);
20+
extern void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us);
2121
extern void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event);
2222
extern void tcp_vegas_get_info(struct sock *sk, u32 ext, struct sk_buff *skb);
2323

net/ipv4/tcp_veno.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ static void tcp_veno_init(struct sock *sk)
6969
}
7070

7171
/* Do rtt sampling needed for Veno. */
72-
static void tcp_veno_pkts_acked(struct sock *sk, u32 cnt, ktime_t last)
72+
static void tcp_veno_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us)
7373
{
7474
struct veno *veno = inet_csk_ca(sk);
7575
u32 vrtt;
7676

77-
if (ktime_equal(last, net_invalid_timestamp()))
77+
if (rtt_us < 0)
7878
return;
7979

8080
/* Never allow zero rtt or baseRTT */
81-
vrtt = ktime_to_us(net_timedelta(last)) + 1;
81+
vrtt = rtt_us + 1;
8282

8383
/* Filter to find propagation delay: */
8484
if (vrtt < veno->basertt)

net/ipv4/tcp_westwood.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ static void westwood_filter(struct westwood *w, u32 delta)
100100
* Called after processing group of packets.
101101
* but all westwood needs is the last sample of srtt.
102102
*/
103-
static void tcp_westwood_pkts_acked(struct sock *sk, u32 cnt, ktime_t last)
103+
static void tcp_westwood_pkts_acked(struct sock *sk, u32 cnt, s32 rtt)
104104
{
105105
struct westwood *w = inet_csk_ca(sk);
106-
if (cnt > 0)
107-
w->rtt = tcp_sk(sk)->srtt >> 3;
106+
107+
if (rtt > 0)
108+
w->rtt = usecs_to_jiffies(rtt);
108109
}
109110

110111
/*

net/ipv4/tcp_yeah.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ static void tcp_yeah_init(struct sock *sk)
5858
}
5959

6060

61-
static void tcp_yeah_pkts_acked(struct sock *sk, u32 pkts_acked, ktime_t last)
61+
static void tcp_yeah_pkts_acked(struct sock *sk, u32 pkts_acked, s32 rtt_us)
6262
{
6363
const struct inet_connection_sock *icsk = inet_csk(sk);
6464
struct yeah *yeah = inet_csk_ca(sk);
6565

6666
if (icsk->icsk_ca_state == TCP_CA_Open)
6767
yeah->pkts_acked = pkts_acked;
6868

69-
tcp_vegas_pkts_acked(sk, pkts_acked, last);
69+
tcp_vegas_pkts_acked(sk, pkts_acked, rtt_us);
7070
}
7171

7272
static void tcp_yeah_cong_avoid(struct sock *sk, u32 ack,

0 commit comments

Comments
 (0)