27 #include <linux/module.h>
31 #define BICTCP_BETA_SCALE 1024
37 #define HYSTART_ACK_TRAIN 0x1
38 #define HYSTART_DELAY 0x2
41 #define HYSTART_MIN_SAMPLES 8
42 #define HYSTART_DELAY_MIN (4U<<3)
43 #define HYSTART_DELAY_MAX (16U<<3)
44 #define HYSTART_DELAY_THRESH(x) clamp(x, HYSTART_DELAY_MIN, HYSTART_DELAY_MAX)
69 MODULE_PARM_DESC(bic_scale,
"scale (scaled by 1024) value for bic function (bic_scale/1024)");
76 " 1: packet-train 2: delay 3: both packet-train and delay");
78 MODULE_PARM_DESC(hystart_low_window,
"lower bound cwnd for hybrid slow start");
80 MODULE_PARM_DESC(hystart_ack_delta,
"spacing between ack's indicating train (msecs)");
95 #define ACK_RATIO_SHIFT 4
96 #define ACK_RATIO_LIMIT (32u << ACK_RATIO_SHIFT)
106 static inline void bictcp_reset(
struct bictcp *
ca)
122 static inline u32 bictcp_clock(
void)
131 static inline void bictcp_hystart_reset(
struct sock *
sk)
134 struct bictcp *
ca = inet_csk_ca(sk);
142 static void bictcp_init(
struct sock *
sk)
144 struct bictcp *
ca = inet_csk_ca(sk);
150 bictcp_hystart_reset(sk);
152 if (!hystart && initial_ssthresh)
153 tcp_sk(sk)->snd_ssthresh = initial_ssthresh;
171 static const u8 v[] = {
172 0, 54, 54, 54, 118, 118, 118, 118,
173 123, 129, 134, 138, 143, 147, 151, 156,
174 157, 161, 164, 168, 170, 173, 176, 179,
175 181, 185, 187, 190, 192, 194, 197, 199,
176 200, 202, 204, 206, 209, 211, 213, 215,
177 217, 219, 221, 222, 224, 225, 227, 229,
178 231, 232, 234, 236, 237, 239, 240, 242,
179 244, 245, 246, 248, 250, 251, 252, 254,
185 return ((
u32)v[(
u32)a] + 35) >> 6;
188 b = ((b * 84) >> 8) - 1;
189 shift = (a >> (b * 3));
191 x = ((
u32)(((
u32)v[shift] + 10) << b)) >> 6;
199 x = (2 * x + (
u32)div64_u64(a, (
u64)x * (
u64)(x - 1)));
200 x = ((x * 341) >> 10);
214 if (ca->last_cwnd == cwnd &&
218 ca->last_cwnd = cwnd;
221 if (ca->epoch_start == 0) {
226 if (ca->last_max_cwnd <= cwnd) {
228 ca->bic_origin_point = cwnd;
233 ca->bic_K = cubic_root(cube_factor
234 * (ca->last_max_cwnd - cwnd));
235 ca->bic_origin_point = ca->last_max_cwnd;
258 offs = ca->bic_K -
t;
260 offs = t - ca->bic_K;
263 delta = (cube_rtt_scale * offs * offs *
offs) >> (10+3*
BICTCP_HZ);
265 bic_target = ca->bic_origin_point -
delta;
267 bic_target = ca->bic_origin_point +
delta;
270 if (bic_target > cwnd) {
271 ca->cnt = cwnd / (bic_target - cwnd);
273 ca->cnt = 100 * cwnd;
280 if (ca->last_max_cwnd == 0 && ca->cnt > 20)
284 if (tcp_friendliness) {
285 u32 scale = beta_scale;
286 delta = (cwnd * scale) >> 3;
287 while (ca->ack_cnt > delta) {
288 ca->ack_cnt -=
delta;
292 if (ca->tcp_cwnd > cwnd){
293 delta = ca->tcp_cwnd - cwnd;
294 max_cnt = cwnd /
delta;
295 if (ca->cnt > max_cnt)
305 static void bictcp_cong_avoid(
struct sock *sk,
u32 ack,
u32 in_flight)
308 struct bictcp *ca = inet_csk_ca(sk);
315 bictcp_hystart_reset(sk);
324 static u32 bictcp_recalc_ssthresh(
struct sock *sk)
326 const struct tcp_sock *tp = tcp_sk(sk);
327 struct bictcp *ca = inet_csk_ca(sk);
343 static u32 bictcp_undo_cwnd(
struct sock *sk)
345 struct bictcp *ca = inet_csk_ca(sk);
353 bictcp_reset(inet_csk_ca(sk));
354 bictcp_hystart_reset(sk);
361 struct bictcp *ca = inet_csk_ca(sk);
363 if (!(ca->
found & hystart_detect)) {
364 u32 now = bictcp_clock();
367 if ((
s32)(now - ca->
last_ack) <= hystart_ack_delta) {
388 if (ca->
found & hystart_detect)
396 static void bictcp_acked(
struct sock *sk,
u32 cnt,
s32 rtt_us)
399 const struct tcp_sock *tp = tcp_sk(sk);
400 struct bictcp *ca = inet_csk_ca(sk);
431 hystart_update(sk, delay);
436 .ssthresh = bictcp_recalc_ssthresh,
437 .cong_avoid = bictcp_cong_avoid,
438 .set_state = bictcp_state,
439 .undo_cwnd = bictcp_undo_cwnd,
440 .pkts_acked = bictcp_acked,
445 static int __init cubictcp_register(
void)
455 cube_rtt_scale = (bic_scale * 10);
474 do_div(cube_factor, bic_scale * 10);
477 if (hystart &&
HZ < 1000)
483 static void __exit cubictcp_unregister(
void)