Skip to content

Commit 756ee17

Browse files
Lawrence Brakmodavem330
authored andcommitted
tcp: replace cnt & rtt with struct in pkts_acked()
Replace 2 arguments (cnt and rtt) in the congestion control modules' pkts_acked() function with a struct. This will allow adding more information without having to modify existing congestion control modules (tcp_nv in particular needs bytes in flight when packet was sent). As proposed by Neal Cardwell in his comments to the tcp_nv patch. Signed-off-by: Lawrence Brakmo <brakmo@fb.com> Acked-by: Yuchung Cheng <ycheng@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cf88585 commit 756ee17

File tree

13 files changed

+60
-47
lines changed

13 files changed

+60
-47
lines changed

include/net/tcp.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,11 @@ enum tcp_ca_ack_event_flags {
854854

855855
union tcp_cc_info;
856856

857+
struct ack_sample {
858+
u32 pkts_acked;
859+
s32 rtt_us;
860+
};
861+
857862
struct tcp_congestion_ops {
858863
struct list_head list;
859864
u32 key;
@@ -877,7 +882,7 @@ struct tcp_congestion_ops {
877882
/* new value of cwnd after loss (optional) */
878883
u32 (*undo_cwnd)(struct sock *sk);
879884
/* hook for packet ack accounting (optional) */
880-
void (*pkts_acked)(struct sock *sk, u32 num_acked, s32 rtt_us);
885+
void (*pkts_acked)(struct sock *sk, const struct ack_sample *sample);
881886
/* get info for inet_diag (optional) */
882887
size_t (*get_info)(struct sock *sk, u32 ext, int *attr,
883888
union tcp_cc_info *info);

net/ipv4/tcp_bic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ static void bictcp_state(struct sock *sk, u8 new_state)
197197
/* Track delayed acknowledgment ratio using sliding window
198198
* ratio = (15*ratio + sample) / 16
199199
*/
200-
static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt)
200+
static void bictcp_acked(struct sock *sk, const struct ack_sample *sample)
201201
{
202202
const struct inet_connection_sock *icsk = inet_csk(sk);
203203

204204
if (icsk->icsk_ca_state == TCP_CA_Open) {
205205
struct bictcp *ca = inet_csk_ca(sk);
206206

207-
cnt -= ca->delayed_ack >> ACK_RATIO_SHIFT;
208-
ca->delayed_ack += cnt;
207+
ca->delayed_ack += sample->pkts_acked -
208+
(ca->delayed_ack >> ACK_RATIO_SHIFT);
209209
}
210210
}
211211

net/ipv4/tcp_cdg.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,33 +294,33 @@ static void tcp_cdg_cong_avoid(struct sock *sk, u32 ack, u32 acked)
294294
ca->shadow_wnd = max(ca->shadow_wnd, ca->shadow_wnd + incr);
295295
}
296296

297-
static void tcp_cdg_acked(struct sock *sk, u32 num_acked, s32 rtt_us)
297+
static void tcp_cdg_acked(struct sock *sk, const struct ack_sample *sample)
298298
{
299299
struct cdg *ca = inet_csk_ca(sk);
300300
struct tcp_sock *tp = tcp_sk(sk);
301301

302-
if (rtt_us <= 0)
302+
if (sample->rtt_us <= 0)
303303
return;
304304

305305
/* A heuristic for filtering delayed ACKs, adapted from:
306306
* D.A. Hayes. "Timing enhancements to the FreeBSD kernel to support
307307
* delay and rate based TCP mechanisms." TR 100219A. CAIA, 2010.
308308
*/
309309
if (tp->sacked_out == 0) {
310-
if (num_acked == 1 && ca->delack) {
310+
if (sample->pkts_acked == 1 && ca->delack) {
311311
/* A delayed ACK is only used for the minimum if it is
312312
* provenly lower than an existing non-zero minimum.
313313
*/
314-
ca->rtt.min = min(ca->rtt.min, rtt_us);
314+
ca->rtt.min = min(ca->rtt.min, sample->rtt_us);
315315
ca->delack--;
316316
return;
317-
} else if (num_acked > 1 && ca->delack < 5) {
317+
} else if (sample->pkts_acked > 1 && ca->delack < 5) {
318318
ca->delack++;
319319
}
320320
}
321321

322-
ca->rtt.min = min_not_zero(ca->rtt.min, rtt_us);
323-
ca->rtt.max = max(ca->rtt.max, rtt_us);
322+
ca->rtt.min = min_not_zero(ca->rtt.min, sample->rtt_us);
323+
ca->rtt.max = max(ca->rtt.max, sample->rtt_us);
324324
}
325325

326326
static u32 tcp_cdg_ssthresh(struct sock *sk)

net/ipv4/tcp_cubic.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,21 +437,21 @@ static void hystart_update(struct sock *sk, u32 delay)
437437
/* Track delayed acknowledgment ratio using sliding window
438438
* ratio = (15*ratio + sample) / 16
439439
*/
440-
static void bictcp_acked(struct sock *sk, u32 cnt, s32 rtt_us)
440+
static void bictcp_acked(struct sock *sk, const struct ack_sample *sample)
441441
{
442442
const struct tcp_sock *tp = tcp_sk(sk);
443443
struct bictcp *ca = inet_csk_ca(sk);
444444
u32 delay;
445445

446446
/* Some calls are for duplicates without timetamps */
447-
if (rtt_us < 0)
447+
if (sample->rtt_us < 0)
448448
return;
449449

450450
/* Discard delay samples right after fast recovery */
451451
if (ca->epoch_start && (s32)(tcp_time_stamp - ca->epoch_start) < HZ)
452452
return;
453453

454-
delay = (rtt_us << 3) / USEC_PER_MSEC;
454+
delay = (sample->rtt_us << 3) / USEC_PER_MSEC;
455455
if (delay == 0)
456456
delay = 1;
457457

net/ipv4/tcp_htcp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ static inline void measure_rtt(struct sock *sk, u32 srtt)
9999
}
100100

101101
static void measure_achieved_throughput(struct sock *sk,
102-
u32 pkts_acked, s32 rtt)
102+
const struct ack_sample *sample)
103103
{
104104
const struct inet_connection_sock *icsk = inet_csk(sk);
105105
const struct tcp_sock *tp = tcp_sk(sk);
106106
struct htcp *ca = inet_csk_ca(sk);
107107
u32 now = tcp_time_stamp;
108108

109109
if (icsk->icsk_ca_state == TCP_CA_Open)
110-
ca->pkts_acked = pkts_acked;
110+
ca->pkts_acked = sample->pkts_acked;
111111

112-
if (rtt > 0)
113-
measure_rtt(sk, usecs_to_jiffies(rtt));
112+
if (sample->rtt_us > 0)
113+
measure_rtt(sk, usecs_to_jiffies(sample->rtt_us));
114114

115115
if (!use_bandwidth_switch)
116116
return;
@@ -122,7 +122,7 @@ static void measure_achieved_throughput(struct sock *sk,
122122
return;
123123
}
124124

125-
ca->packetcount += pkts_acked;
125+
ca->packetcount += sample->pkts_acked;
126126

127127
if (ca->packetcount >= tp->snd_cwnd - (ca->alpha >> 7 ? : 1) &&
128128
now - ca->lasttime >= ca->minRTT &&

net/ipv4/tcp_illinois.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,31 @@ static void tcp_illinois_init(struct sock *sk)
8282
}
8383

8484
/* Measure RTT for each ack. */
85-
static void tcp_illinois_acked(struct sock *sk, u32 pkts_acked, s32 rtt)
85+
static void tcp_illinois_acked(struct sock *sk, const struct ack_sample *sample)
8686
{
8787
struct illinois *ca = inet_csk_ca(sk);
88+
s32 rtt_us = sample->rtt_us;
8889

89-
ca->acked = pkts_acked;
90+
ca->acked = sample->pkts_acked;
9091

9192
/* dup ack, no rtt sample */
92-
if (rtt < 0)
93+
if (rtt_us < 0)
9394
return;
9495

9596
/* ignore bogus values, this prevents wraparound in alpha math */
96-
if (rtt > RTT_MAX)
97-
rtt = RTT_MAX;
97+
if (rtt_us > RTT_MAX)
98+
rtt_us = RTT_MAX;
9899

99100
/* keep track of minimum RTT seen so far */
100-
if (ca->base_rtt > rtt)
101-
ca->base_rtt = rtt;
101+
if (ca->base_rtt > rtt_us)
102+
ca->base_rtt = rtt_us;
102103

103104
/* and max */
104-
if (ca->max_rtt < rtt)
105-
ca->max_rtt = rtt;
105+
if (ca->max_rtt < rtt_us)
106+
ca->max_rtt = rtt_us;
106107

107108
++ca->cnt_rtt;
108-
ca->sum_rtt += rtt;
109+
ca->sum_rtt += rtt_us;
109110
}
110111

111112
/* Maximum queuing delay */

net/ipv4/tcp_input.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,8 +3248,12 @@ static int tcp_clean_rtx_queue(struct sock *sk, int prior_fackets,
32483248
tcp_rearm_rto(sk);
32493249
}
32503250

3251-
if (icsk->icsk_ca_ops->pkts_acked)
3252-
icsk->icsk_ca_ops->pkts_acked(sk, pkts_acked, ca_rtt_us);
3251+
if (icsk->icsk_ca_ops->pkts_acked) {
3252+
struct ack_sample sample = { .pkts_acked = pkts_acked,
3253+
.rtt_us = ca_rtt_us };
3254+
3255+
icsk->icsk_ca_ops->pkts_acked(sk, &sample);
3256+
}
32533257

32543258
#if FASTRETRANS_DEBUG > 0
32553259
WARN_ON((int)tp->sacked_out < 0);

net/ipv4/tcp_lp.c

Lines changed: 3 additions & 3 deletions
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, s32 rtt_us)
263+
static void tcp_lp_pkts_acked(struct sock *sk, const struct ack_sample *sample)
264264
{
265265
struct tcp_sock *tp = tcp_sk(sk);
266266
struct lp *lp = inet_csk_ca(sk);
267267

268-
if (rtt_us > 0)
269-
tcp_lp_rtt_sample(sk, rtt_us);
268+
if (sample->rtt_us > 0)
269+
tcp_lp_rtt_sample(sk, sample->rtt_us);
270270

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

net/ipv4/tcp_vegas.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ EXPORT_SYMBOL_GPL(tcp_vegas_init);
107107
* o min-filter RTT samples from a much longer window (forever for now)
108108
* to find the propagation delay (baseRTT)
109109
*/
110-
void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us)
110+
void tcp_vegas_pkts_acked(struct sock *sk, const struct ack_sample *sample)
111111
{
112112
struct vegas *vegas = inet_csk_ca(sk);
113113
u32 vrtt;
114114

115-
if (rtt_us < 0)
115+
if (sample->rtt_us < 0)
116116
return;
117117

118118
/* Never allow zero rtt or baseRTT */
119-
vrtt = rtt_us + 1;
119+
vrtt = sample->rtt_us + 1;
120120

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

net/ipv4/tcp_vegas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct vegas {
1717

1818
void tcp_vegas_init(struct sock *sk);
1919
void tcp_vegas_state(struct sock *sk, u8 ca_state);
20-
void tcp_vegas_pkts_acked(struct sock *sk, u32 cnt, s32 rtt_us);
20+
void tcp_vegas_pkts_acked(struct sock *sk, const struct ack_sample *sample);
2121
void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event);
2222
size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
2323
union tcp_cc_info *info);

net/ipv4/tcp_veno.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ 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, s32 rtt_us)
72+
static void tcp_veno_pkts_acked(struct sock *sk,
73+
const struct ack_sample *sample)
7374
{
7475
struct veno *veno = inet_csk_ca(sk);
7576
u32 vrtt;
7677

77-
if (rtt_us < 0)
78+
if (sample->rtt_us < 0)
7879
return;
7980

8081
/* Never allow zero rtt or baseRTT */
81-
vrtt = rtt_us + 1;
82+
vrtt = sample->rtt_us + 1;
8283

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

net/ipv4/tcp_westwood.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ static void westwood_filter(struct westwood *w, u32 delta)
9999
* Called after processing group of packets.
100100
* but all westwood needs is the last sample of srtt.
101101
*/
102-
static void tcp_westwood_pkts_acked(struct sock *sk, u32 cnt, s32 rtt)
102+
static void tcp_westwood_pkts_acked(struct sock *sk,
103+
const struct ack_sample *sample)
103104
{
104105
struct westwood *w = inet_csk_ca(sk);
105106

106-
if (rtt > 0)
107-
w->rtt = usecs_to_jiffies(rtt);
107+
if (sample->rtt_us > 0)
108+
w->rtt = usecs_to_jiffies(sample->rtt_us);
108109
}
109110

110111
/*

net/ipv4/tcp_yeah.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ static void tcp_yeah_init(struct sock *sk)
5656
tp->snd_cwnd_clamp = min_t(u32, tp->snd_cwnd_clamp, 0xffffffff/128);
5757
}
5858

59-
static void tcp_yeah_pkts_acked(struct sock *sk, u32 pkts_acked, s32 rtt_us)
59+
static void tcp_yeah_pkts_acked(struct sock *sk,
60+
const struct ack_sample *sample)
6061
{
6162
const struct inet_connection_sock *icsk = inet_csk(sk);
6263
struct yeah *yeah = inet_csk_ca(sk);
6364

6465
if (icsk->icsk_ca_state == TCP_CA_Open)
65-
yeah->pkts_acked = pkts_acked;
66+
yeah->pkts_acked = sample->pkts_acked;
6667

67-
tcp_vegas_pkts_acked(sk, pkts_acked, rtt_us);
68+
tcp_vegas_pkts_acked(sk, sample);
6869
}
6970

7071
static void tcp_yeah_cong_avoid(struct sock *sk, u32 ack, u32 acked)

0 commit comments

Comments
 (0)