tcp_bbr.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. /* Bottleneck Bandwidth and RTT (BBR) congestion control
  2. *
  3. * BBR congestion control computes the sending rate based on the delivery
  4. * rate (throughput) estimated from ACKs. In a nutshell:
  5. *
  6. * On each ACK, update our model of the network path:
  7. * bottleneck_bandwidth = windowed_max(delivered / elapsed, 10 round trips)
  8. * min_rtt = windowed_min(rtt, 10 seconds)
  9. * pacing_rate = pacing_gain * bottleneck_bandwidth
  10. * cwnd = max(cwnd_gain * bottleneck_bandwidth * min_rtt, 4)
  11. *
  12. * The core algorithm does not react directly to packet losses or delays,
  13. * although BBR may adjust the size of next send per ACK when loss is
  14. * observed, or adjust the sending rate if it estimates there is a
  15. * traffic policer, in order to keep the drop rate reasonable.
  16. *
  17. * Here is a state transition diagram for BBR:
  18. *
  19. * |
  20. * V
  21. * +---> STARTUP ----+
  22. * | | |
  23. * | V |
  24. * | DRAIN ----+
  25. * | | |
  26. * | V |
  27. * +---> PROBE_BW ----+
  28. * | ^ | |
  29. * | | | |
  30. * | +----+ |
  31. * | |
  32. * +---- PROBE_RTT <--+
  33. *
  34. * A BBR flow starts in STARTUP, and ramps up its sending rate quickly.
  35. * When it estimates the pipe is full, it enters DRAIN to drain the queue.
  36. * In steady state a BBR flow only uses PROBE_BW and PROBE_RTT.
  37. * A long-lived BBR flow spends the vast majority of its time remaining
  38. * (repeatedly) in PROBE_BW, fully probing and utilizing the pipe's bandwidth
  39. * in a fair manner, with a small, bounded queue. *If* a flow has been
  40. * continuously sending for the entire min_rtt window, and hasn't seen an RTT
  41. * sample that matches or decreases its min_rtt estimate for 10 seconds, then
  42. * it briefly enters PROBE_RTT to cut inflight to a minimum value to re-probe
  43. * the path's two-way propagation delay (min_rtt). When exiting PROBE_RTT, if
  44. * we estimated that we reached the full bw of the pipe then we enter PROBE_BW;
  45. * otherwise we enter STARTUP to try to fill the pipe.
  46. *
  47. * BBR is described in detail in:
  48. * "BBR: Congestion-Based Congestion Control",
  49. * Neal Cardwell, Yuchung Cheng, C. Stephen Gunn, Soheil Hassas Yeganeh,
  50. * Van Jacobson. ACM Queue, Vol. 14 No. 5, September-October 2016.
  51. *
  52. * There is a public e-mail list for discussing BBR development and testing:
  53. * https://groups.google.com/forum/#!forum/bbr-dev
  54. *
  55. * NOTE: BBR might be used with the fq qdisc ("man tc-fq") with pacing enabled,
  56. * otherwise TCP stack falls back to an internal pacing using one high
  57. * resolution timer per TCP socket and may use more resources.
  58. */
  59. #include <linux/module.h>
  60. #include <net/tcp.h>
  61. #include <linux/inet_diag.h>
  62. #include <linux/inet.h>
  63. #include <linux/random.h>
  64. #include <linux/win_minmax.h>
  65. /* Scale factor for rate in pkt/uSec unit to avoid truncation in bandwidth
  66. * estimation. The rate unit ~= (1500 bytes / 1 usec / 2^24) ~= 715 bps.
  67. * This handles bandwidths from 0.06pps (715bps) to 256Mpps (3Tbps) in a u32.
  68. * Since the minimum window is >=4 packets, the lower bound isn't
  69. * an issue. The upper bound isn't an issue with existing technologies.
  70. */
  71. #define BW_SCALE 24
  72. #define BW_UNIT (1 << BW_SCALE)
  73. #define BBR_SCALE 8 /* scaling factor for fractions in BBR (e.g. gains) */
  74. #define BBR_UNIT (1 << BBR_SCALE)
  75. /* BBR has the following modes for deciding how fast to send: */
  76. enum bbr_mode {
  77. BBR_STARTUP, /* ramp up sending rate rapidly to fill pipe */
  78. BBR_DRAIN, /* drain any queue created during startup */
  79. BBR_PROBE_BW, /* discover, share bw: pace around estimated bw */
  80. BBR_PROBE_RTT, /* cut inflight to min to probe min_rtt */
  81. };
  82. /* BBR congestion control block */
  83. struct bbr {
  84. u32 min_rtt_us; /* min RTT in min_rtt_win_sec window */
  85. u32 min_rtt_stamp; /* timestamp of min_rtt_us */
  86. u32 probe_rtt_done_stamp; /* end time for BBR_PROBE_RTT mode */
  87. struct minmax bw; /* Max recent delivery rate in pkts/uS << 24 */
  88. u32 rtt_cnt; /* count of packet-timed rounds elapsed */
  89. u32 next_rtt_delivered; /* scb->tx.delivered at end of round */
  90. u64 cycle_mstamp; /* time of this cycle phase start */
  91. u32 mode:3, /* current bbr_mode in state machine */
  92. prev_ca_state:3, /* CA state on previous ACK */
  93. packet_conservation:1, /* use packet conservation? */
  94. restore_cwnd:1, /* decided to revert cwnd to old value */
  95. round_start:1, /* start of packet-timed tx->ack round? */
  96. idle_restart:1, /* restarting after idle? */
  97. probe_rtt_round_done:1, /* a BBR_PROBE_RTT round at 4 pkts? */
  98. unused:12,
  99. lt_is_sampling:1, /* taking long-term ("LT") samples now? */
  100. lt_rtt_cnt:7, /* round trips in long-term interval */
  101. lt_use_bw:1; /* use lt_bw as our bw estimate? */
  102. u32 lt_bw; /* LT est delivery rate in pkts/uS << 24 */
  103. u32 lt_last_delivered; /* LT intvl start: tp->delivered */
  104. u32 lt_last_stamp; /* LT intvl start: tp->delivered_mstamp */
  105. u32 lt_last_lost; /* LT intvl start: tp->lost */
  106. u32 pacing_gain:10, /* current gain for setting pacing rate */
  107. cwnd_gain:10, /* current gain for setting cwnd */
  108. full_bw_reached:1, /* reached full bw in Startup? */
  109. full_bw_cnt:2, /* number of rounds without large bw gains */
  110. cycle_idx:3, /* current index in pacing_gain cycle array */
  111. has_seen_rtt:1, /* have we seen an RTT sample yet? */
  112. unused_b:5;
  113. u32 prior_cwnd; /* prior cwnd upon entering loss recovery */
  114. u32 full_bw; /* recent bw, to estimate if pipe is full */
  115. };
  116. #define CYCLE_LEN 8 /* number of phases in a pacing gain cycle */
  117. /* Window length of bw filter (in rounds): */
  118. static const int bbr_bw_rtts = CYCLE_LEN + 2;
  119. /* Window length of min_rtt filter (in sec): */
  120. static const u32 bbr_min_rtt_win_sec = 10;
  121. /* Minimum time (in ms) spent at bbr_cwnd_min_target in BBR_PROBE_RTT mode: */
  122. static const u32 bbr_probe_rtt_mode_ms = 200;
  123. /* Skip TSO below the following bandwidth (bits/sec): */
  124. static const int bbr_min_tso_rate = 1200000;
  125. /* We use a high_gain value of 2/ln(2) because it's the smallest pacing gain
  126. * that will allow a smoothly increasing pacing rate that will double each RTT
  127. * and send the same number of packets per RTT that an un-paced, slow-starting
  128. * Reno or CUBIC flow would:
  129. */
  130. static const int bbr_high_gain = BBR_UNIT * 2885 / 1000 + 1;
  131. /* The pacing gain of 1/high_gain in BBR_DRAIN is calculated to typically drain
  132. * the queue created in BBR_STARTUP in a single round:
  133. */
  134. static const int bbr_drain_gain = BBR_UNIT * 1000 / 2885;
  135. /* The gain for deriving steady-state cwnd tolerates delayed/stretched ACKs: */
  136. static const int bbr_cwnd_gain = BBR_UNIT * 2;
  137. /* The pacing_gain values for the PROBE_BW gain cycle, to discover/share bw: */
  138. static const int bbr_pacing_gain[] = {
  139. BBR_UNIT * 5 / 4, /* probe for more available bw */
  140. BBR_UNIT * 3 / 4, /* drain queue and/or yield bw to other flows */
  141. BBR_UNIT, BBR_UNIT, BBR_UNIT, /* cruise at 1.0*bw to utilize pipe, */
  142. BBR_UNIT, BBR_UNIT, BBR_UNIT /* without creating excess queue... */
  143. };
  144. /* Randomize the starting gain cycling phase over N phases: */
  145. static const u32 bbr_cycle_rand = 7;
  146. /* Try to keep at least this many packets in flight, if things go smoothly. For
  147. * smooth functioning, a sliding window protocol ACKing every other packet
  148. * needs at least 4 packets in flight:
  149. */
  150. static const u32 bbr_cwnd_min_target = 4;
  151. /* To estimate if BBR_STARTUP mode (i.e. high_gain) has filled pipe... */
  152. /* If bw has increased significantly (1.25x), there may be more bw available: */
  153. static const u32 bbr_full_bw_thresh = BBR_UNIT * 5 / 4;
  154. /* But after 3 rounds w/o significant bw growth, estimate pipe is full: */
  155. static const u32 bbr_full_bw_cnt = 3;
  156. /* "long-term" ("LT") bandwidth estimator parameters... */
  157. /* The minimum number of rounds in an LT bw sampling interval: */
  158. static const u32 bbr_lt_intvl_min_rtts = 4;
  159. /* If lost/delivered ratio > 20%, interval is "lossy" and we may be policed: */
  160. static const u32 bbr_lt_loss_thresh = 50;
  161. /* If 2 intervals have a bw ratio <= 1/8, their bw is "consistent": */
  162. static const u32 bbr_lt_bw_ratio = BBR_UNIT / 8;
  163. /* If 2 intervals have a bw diff <= 4 Kbit/sec their bw is "consistent": */
  164. static const u32 bbr_lt_bw_diff = 4000 / 8;
  165. /* If we estimate we're policed, use lt_bw for this many round trips: */
  166. static const u32 bbr_lt_bw_max_rtts = 48;
  167. /* Do we estimate that STARTUP filled the pipe? */
  168. static bool bbr_full_bw_reached(const struct sock *sk)
  169. {
  170. const struct bbr *bbr = inet_csk_ca(sk);
  171. return bbr->full_bw_reached;
  172. }
  173. /* Return the windowed max recent bandwidth sample, in pkts/uS << BW_SCALE. */
  174. static u32 bbr_max_bw(const struct sock *sk)
  175. {
  176. struct bbr *bbr = inet_csk_ca(sk);
  177. return minmax_get(&bbr->bw);
  178. }
  179. /* Return the estimated bandwidth of the path, in pkts/uS << BW_SCALE. */
  180. static u32 bbr_bw(const struct sock *sk)
  181. {
  182. struct bbr *bbr = inet_csk_ca(sk);
  183. return bbr->lt_use_bw ? bbr->lt_bw : bbr_max_bw(sk);
  184. }
  185. /* Return rate in bytes per second, optionally with a gain.
  186. * The order here is chosen carefully to avoid overflow of u64. This should
  187. * work for input rates of up to 2.9Tbit/sec and gain of 2.89x.
  188. */
  189. static u64 bbr_rate_bytes_per_sec(struct sock *sk, u64 rate, int gain)
  190. {
  191. unsigned int mss = tcp_sk(sk)->mss_cache;
  192. if (!tcp_needs_internal_pacing(sk))
  193. mss = tcp_mss_to_mtu(sk, mss);
  194. rate *= mss;
  195. rate *= gain;
  196. rate >>= BBR_SCALE;
  197. rate *= USEC_PER_SEC;
  198. return rate >> BW_SCALE;
  199. }
  200. /* Convert a BBR bw and gain factor to a pacing rate in bytes per second. */
  201. static u32 bbr_bw_to_pacing_rate(struct sock *sk, u32 bw, int gain)
  202. {
  203. u64 rate = bw;
  204. rate = bbr_rate_bytes_per_sec(sk, rate, gain);
  205. rate = min_t(u64, rate, sk->sk_max_pacing_rate);
  206. return rate;
  207. }
  208. /* Initialize pacing rate to: high_gain * init_cwnd / RTT. */
  209. static void bbr_init_pacing_rate_from_rtt(struct sock *sk)
  210. {
  211. struct tcp_sock *tp = tcp_sk(sk);
  212. struct bbr *bbr = inet_csk_ca(sk);
  213. u64 bw;
  214. u32 rtt_us;
  215. if (tp->srtt_us) { /* any RTT sample yet? */
  216. rtt_us = max(tp->srtt_us >> 3, 1U);
  217. bbr->has_seen_rtt = 1;
  218. } else { /* no RTT sample yet */
  219. rtt_us = USEC_PER_MSEC; /* use nominal default RTT */
  220. }
  221. bw = (u64)tp->snd_cwnd * BW_UNIT;
  222. do_div(bw, rtt_us);
  223. sk->sk_pacing_rate = bbr_bw_to_pacing_rate(sk, bw, bbr_high_gain);
  224. }
  225. /* Pace using current bw estimate and a gain factor. In order to help drive the
  226. * network toward lower queues while maintaining high utilization and low
  227. * latency, the average pacing rate aims to be slightly (~1%) lower than the
  228. * estimated bandwidth. This is an important aspect of the design. In this
  229. * implementation this slightly lower pacing rate is achieved implicitly by not
  230. * including link-layer headers in the packet size used for the pacing rate.
  231. */
  232. static void bbr_set_pacing_rate(struct sock *sk, u32 bw, int gain)
  233. {
  234. struct tcp_sock *tp = tcp_sk(sk);
  235. struct bbr *bbr = inet_csk_ca(sk);
  236. u32 rate = bbr_bw_to_pacing_rate(sk, bw, gain);
  237. if (unlikely(!bbr->has_seen_rtt && tp->srtt_us))
  238. bbr_init_pacing_rate_from_rtt(sk);
  239. if (bbr_full_bw_reached(sk) || rate > sk->sk_pacing_rate)
  240. sk->sk_pacing_rate = rate;
  241. }
  242. /* override sysctl_tcp_min_tso_segs */
  243. static u32 bbr_min_tso_segs(struct sock *sk)
  244. {
  245. return sk->sk_pacing_rate < (bbr_min_tso_rate >> 3) ? 1 : 2;
  246. }
  247. static u32 bbr_tso_segs_goal(struct sock *sk)
  248. {
  249. struct tcp_sock *tp = tcp_sk(sk);
  250. u32 segs, bytes;
  251. /* Sort of tcp_tso_autosize() but ignoring
  252. * driver provided sk_gso_max_size.
  253. */
  254. bytes = min_t(u32, sk->sk_pacing_rate >> sk->sk_pacing_shift,
  255. GSO_MAX_SIZE - 1 - MAX_TCP_HEADER);
  256. segs = max_t(u32, bytes / tp->mss_cache, bbr_min_tso_segs(sk));
  257. return min(segs, 0x7FU);
  258. }
  259. /* Save "last known good" cwnd so we can restore it after losses or PROBE_RTT */
  260. static void bbr_save_cwnd(struct sock *sk)
  261. {
  262. struct tcp_sock *tp = tcp_sk(sk);
  263. struct bbr *bbr = inet_csk_ca(sk);
  264. if (bbr->prev_ca_state < TCP_CA_Recovery && bbr->mode != BBR_PROBE_RTT)
  265. bbr->prior_cwnd = tp->snd_cwnd; /* this cwnd is good enough */
  266. else /* loss recovery or BBR_PROBE_RTT have temporarily cut cwnd */
  267. bbr->prior_cwnd = max(bbr->prior_cwnd, tp->snd_cwnd);
  268. }
  269. static void bbr_cwnd_event(struct sock *sk, enum tcp_ca_event event)
  270. {
  271. struct tcp_sock *tp = tcp_sk(sk);
  272. struct bbr *bbr = inet_csk_ca(sk);
  273. if (event == CA_EVENT_TX_START && tp->app_limited) {
  274. bbr->idle_restart = 1;
  275. /* Avoid pointless buffer overflows: pace at est. bw if we don't
  276. * need more speed (we're restarting from idle and app-limited).
  277. */
  278. if (bbr->mode == BBR_PROBE_BW)
  279. bbr_set_pacing_rate(sk, bbr_bw(sk), BBR_UNIT);
  280. }
  281. }
  282. /* Find target cwnd. Right-size the cwnd based on min RTT and the
  283. * estimated bottleneck bandwidth:
  284. *
  285. * cwnd = bw * min_rtt * gain = BDP * gain
  286. *
  287. * The key factor, gain, controls the amount of queue. While a small gain
  288. * builds a smaller queue, it becomes more vulnerable to noise in RTT
  289. * measurements (e.g., delayed ACKs or other ACK compression effects). This
  290. * noise may cause BBR to under-estimate the rate.
  291. *
  292. * To achieve full performance in high-speed paths, we budget enough cwnd to
  293. * fit full-sized skbs in-flight on both end hosts to fully utilize the path:
  294. * - one skb in sending host Qdisc,
  295. * - one skb in sending host TSO/GSO engine
  296. * - one skb being received by receiver host LRO/GRO/delayed-ACK engine
  297. * Don't worry, at low rates (bbr_min_tso_rate) this won't bloat cwnd because
  298. * in such cases tso_segs_goal is 1. The minimum cwnd is 4 packets,
  299. * which allows 2 outstanding 2-packet sequences, to try to keep pipe
  300. * full even with ACK-every-other-packet delayed ACKs.
  301. */
  302. static u32 bbr_target_cwnd(struct sock *sk, u32 bw, int gain)
  303. {
  304. struct bbr *bbr = inet_csk_ca(sk);
  305. u32 cwnd;
  306. u64 w;
  307. /* If we've never had a valid RTT sample, cap cwnd at the initial
  308. * default. This should only happen when the connection is not using TCP
  309. * timestamps and has retransmitted all of the SYN/SYNACK/data packets
  310. * ACKed so far. In this case, an RTO can cut cwnd to 1, in which
  311. * case we need to slow-start up toward something safe: TCP_INIT_CWND.
  312. */
  313. if (unlikely(bbr->min_rtt_us == ~0U)) /* no valid RTT samples yet? */
  314. return TCP_INIT_CWND; /* be safe: cap at default initial cwnd*/
  315. w = (u64)bw * bbr->min_rtt_us;
  316. /* Apply a gain to the given value, then remove the BW_SCALE shift. */
  317. cwnd = (((w * gain) >> BBR_SCALE) + BW_UNIT - 1) / BW_UNIT;
  318. /* Allow enough full-sized skbs in flight to utilize end systems. */
  319. cwnd += 3 * bbr_tso_segs_goal(sk);
  320. /* Reduce delayed ACKs by rounding up cwnd to the next even number. */
  321. cwnd = (cwnd + 1) & ~1U;
  322. /* Ensure gain cycling gets inflight above BDP even for small BDPs. */
  323. if (bbr->mode == BBR_PROBE_BW && gain > BBR_UNIT)
  324. cwnd += 2;
  325. return cwnd;
  326. }
  327. /* An optimization in BBR to reduce losses: On the first round of recovery, we
  328. * follow the packet conservation principle: send P packets per P packets acked.
  329. * After that, we slow-start and send at most 2*P packets per P packets acked.
  330. * After recovery finishes, or upon undo, we restore the cwnd we had when
  331. * recovery started (capped by the target cwnd based on estimated BDP).
  332. *
  333. * TODO(ycheng/ncardwell): implement a rate-based approach.
  334. */
  335. static bool bbr_set_cwnd_to_recover_or_restore(
  336. struct sock *sk, const struct rate_sample *rs, u32 acked, u32 *new_cwnd)
  337. {
  338. struct tcp_sock *tp = tcp_sk(sk);
  339. struct bbr *bbr = inet_csk_ca(sk);
  340. u8 prev_state = bbr->prev_ca_state, state = inet_csk(sk)->icsk_ca_state;
  341. u32 cwnd = tp->snd_cwnd;
  342. /* An ACK for P pkts should release at most 2*P packets. We do this
  343. * in two steps. First, here we deduct the number of lost packets.
  344. * Then, in bbr_set_cwnd() we slow start up toward the target cwnd.
  345. */
  346. if (rs->losses > 0)
  347. cwnd = max_t(s32, cwnd - rs->losses, 1);
  348. if (state == TCP_CA_Recovery && prev_state != TCP_CA_Recovery) {
  349. /* Starting 1st round of Recovery, so do packet conservation. */
  350. bbr->packet_conservation = 1;
  351. bbr->next_rtt_delivered = tp->delivered; /* start round now */
  352. /* Cut unused cwnd from app behavior, TSQ, or TSO deferral: */
  353. cwnd = tcp_packets_in_flight(tp) + acked;
  354. } else if (prev_state >= TCP_CA_Recovery && state < TCP_CA_Recovery) {
  355. /* Exiting loss recovery; restore cwnd saved before recovery. */
  356. bbr->restore_cwnd = 1;
  357. bbr->packet_conservation = 0;
  358. }
  359. bbr->prev_ca_state = state;
  360. if (bbr->restore_cwnd) {
  361. /* Restore cwnd after exiting loss recovery or PROBE_RTT. */
  362. cwnd = max(cwnd, bbr->prior_cwnd);
  363. bbr->restore_cwnd = 0;
  364. }
  365. if (bbr->packet_conservation) {
  366. *new_cwnd = max(cwnd, tcp_packets_in_flight(tp) + acked);
  367. return true; /* yes, using packet conservation */
  368. }
  369. *new_cwnd = cwnd;
  370. return false;
  371. }
  372. /* Slow-start up toward target cwnd (if bw estimate is growing, or packet loss
  373. * has drawn us down below target), or snap down to target if we're above it.
  374. */
  375. static void bbr_set_cwnd(struct sock *sk, const struct rate_sample *rs,
  376. u32 acked, u32 bw, int gain)
  377. {
  378. struct tcp_sock *tp = tcp_sk(sk);
  379. struct bbr *bbr = inet_csk_ca(sk);
  380. u32 cwnd = 0, target_cwnd = 0;
  381. if (!acked)
  382. return;
  383. if (bbr_set_cwnd_to_recover_or_restore(sk, rs, acked, &cwnd))
  384. goto done;
  385. /* If we're below target cwnd, slow start cwnd toward target cwnd. */
  386. target_cwnd = bbr_target_cwnd(sk, bw, gain);
  387. if (bbr_full_bw_reached(sk)) /* only cut cwnd if we filled the pipe */
  388. cwnd = min(cwnd + acked, target_cwnd);
  389. else if (cwnd < target_cwnd || tp->delivered < TCP_INIT_CWND)
  390. cwnd = cwnd + acked;
  391. cwnd = max(cwnd, bbr_cwnd_min_target);
  392. done:
  393. tp->snd_cwnd = min(cwnd, tp->snd_cwnd_clamp); /* apply global cap */
  394. if (bbr->mode == BBR_PROBE_RTT) /* drain queue, refresh min_rtt */
  395. tp->snd_cwnd = min(tp->snd_cwnd, bbr_cwnd_min_target);
  396. }
  397. /* End cycle phase if it's time and/or we hit the phase's in-flight target. */
  398. static bool bbr_is_next_cycle_phase(struct sock *sk,
  399. const struct rate_sample *rs)
  400. {
  401. struct tcp_sock *tp = tcp_sk(sk);
  402. struct bbr *bbr = inet_csk_ca(sk);
  403. bool is_full_length =
  404. tcp_stamp_us_delta(tp->delivered_mstamp, bbr->cycle_mstamp) >
  405. bbr->min_rtt_us;
  406. u32 inflight, bw;
  407. /* The pacing_gain of 1.0 paces at the estimated bw to try to fully
  408. * use the pipe without increasing the queue.
  409. */
  410. if (bbr->pacing_gain == BBR_UNIT)
  411. return is_full_length; /* just use wall clock time */
  412. inflight = rs->prior_in_flight; /* what was in-flight before ACK? */
  413. bw = bbr_max_bw(sk);
  414. /* A pacing_gain > 1.0 probes for bw by trying to raise inflight to at
  415. * least pacing_gain*BDP; this may take more than min_rtt if min_rtt is
  416. * small (e.g. on a LAN). We do not persist if packets are lost, since
  417. * a path with small buffers may not hold that much.
  418. */
  419. if (bbr->pacing_gain > BBR_UNIT)
  420. return is_full_length &&
  421. (rs->losses || /* perhaps pacing_gain*BDP won't fit */
  422. inflight >= bbr_target_cwnd(sk, bw, bbr->pacing_gain));
  423. /* A pacing_gain < 1.0 tries to drain extra queue we added if bw
  424. * probing didn't find more bw. If inflight falls to match BDP then we
  425. * estimate queue is drained; persisting would underutilize the pipe.
  426. */
  427. return is_full_length ||
  428. inflight <= bbr_target_cwnd(sk, bw, BBR_UNIT);
  429. }
  430. static void bbr_advance_cycle_phase(struct sock *sk)
  431. {
  432. struct tcp_sock *tp = tcp_sk(sk);
  433. struct bbr *bbr = inet_csk_ca(sk);
  434. bbr->cycle_idx = (bbr->cycle_idx + 1) & (CYCLE_LEN - 1);
  435. bbr->cycle_mstamp = tp->delivered_mstamp;
  436. bbr->pacing_gain = bbr->lt_use_bw ? BBR_UNIT :
  437. bbr_pacing_gain[bbr->cycle_idx];
  438. }
  439. /* Gain cycling: cycle pacing gain to converge to fair share of available bw. */
  440. static void bbr_update_cycle_phase(struct sock *sk,
  441. const struct rate_sample *rs)
  442. {
  443. struct bbr *bbr = inet_csk_ca(sk);
  444. if (bbr->mode == BBR_PROBE_BW && bbr_is_next_cycle_phase(sk, rs))
  445. bbr_advance_cycle_phase(sk);
  446. }
  447. static void bbr_reset_startup_mode(struct sock *sk)
  448. {
  449. struct bbr *bbr = inet_csk_ca(sk);
  450. bbr->mode = BBR_STARTUP;
  451. bbr->pacing_gain = bbr_high_gain;
  452. bbr->cwnd_gain = bbr_high_gain;
  453. }
  454. static void bbr_reset_probe_bw_mode(struct sock *sk)
  455. {
  456. struct bbr *bbr = inet_csk_ca(sk);
  457. bbr->mode = BBR_PROBE_BW;
  458. bbr->pacing_gain = BBR_UNIT;
  459. bbr->cwnd_gain = bbr_cwnd_gain;
  460. bbr->cycle_idx = CYCLE_LEN - 1 - prandom_u32_max(bbr_cycle_rand);
  461. bbr_advance_cycle_phase(sk); /* flip to next phase of gain cycle */
  462. }
  463. static void bbr_reset_mode(struct sock *sk)
  464. {
  465. if (!bbr_full_bw_reached(sk))
  466. bbr_reset_startup_mode(sk);
  467. else
  468. bbr_reset_probe_bw_mode(sk);
  469. }
  470. /* Start a new long-term sampling interval. */
  471. static void bbr_reset_lt_bw_sampling_interval(struct sock *sk)
  472. {
  473. struct tcp_sock *tp = tcp_sk(sk);
  474. struct bbr *bbr = inet_csk_ca(sk);
  475. bbr->lt_last_stamp = div_u64(tp->delivered_mstamp, USEC_PER_MSEC);
  476. bbr->lt_last_delivered = tp->delivered;
  477. bbr->lt_last_lost = tp->lost;
  478. bbr->lt_rtt_cnt = 0;
  479. }
  480. /* Completely reset long-term bandwidth sampling. */
  481. static void bbr_reset_lt_bw_sampling(struct sock *sk)
  482. {
  483. struct bbr *bbr = inet_csk_ca(sk);
  484. bbr->lt_bw = 0;
  485. bbr->lt_use_bw = 0;
  486. bbr->lt_is_sampling = false;
  487. bbr_reset_lt_bw_sampling_interval(sk);
  488. }
  489. /* Long-term bw sampling interval is done. Estimate whether we're policed. */
  490. static void bbr_lt_bw_interval_done(struct sock *sk, u32 bw)
  491. {
  492. struct bbr *bbr = inet_csk_ca(sk);
  493. u32 diff;
  494. if (bbr->lt_bw) { /* do we have bw from a previous interval? */
  495. /* Is new bw close to the lt_bw from the previous interval? */
  496. diff = abs(bw - bbr->lt_bw);
  497. if ((diff * BBR_UNIT <= bbr_lt_bw_ratio * bbr->lt_bw) ||
  498. (bbr_rate_bytes_per_sec(sk, diff, BBR_UNIT) <=
  499. bbr_lt_bw_diff)) {
  500. /* All criteria are met; estimate we're policed. */
  501. bbr->lt_bw = (bw + bbr->lt_bw) >> 1; /* avg 2 intvls */
  502. bbr->lt_use_bw = 1;
  503. bbr->pacing_gain = BBR_UNIT; /* try to avoid drops */
  504. bbr->lt_rtt_cnt = 0;
  505. return;
  506. }
  507. }
  508. bbr->lt_bw = bw;
  509. bbr_reset_lt_bw_sampling_interval(sk);
  510. }
  511. /* Token-bucket traffic policers are common (see "An Internet-Wide Analysis of
  512. * Traffic Policing", SIGCOMM 2016). BBR detects token-bucket policers and
  513. * explicitly models their policed rate, to reduce unnecessary losses. We
  514. * estimate that we're policed if we see 2 consecutive sampling intervals with
  515. * consistent throughput and high packet loss. If we think we're being policed,
  516. * set lt_bw to the "long-term" average delivery rate from those 2 intervals.
  517. */
  518. static void bbr_lt_bw_sampling(struct sock *sk, const struct rate_sample *rs)
  519. {
  520. struct tcp_sock *tp = tcp_sk(sk);
  521. struct bbr *bbr = inet_csk_ca(sk);
  522. u32 lost, delivered;
  523. u64 bw;
  524. u32 t;
  525. if (bbr->lt_use_bw) { /* already using long-term rate, lt_bw? */
  526. if (bbr->mode == BBR_PROBE_BW && bbr->round_start &&
  527. ++bbr->lt_rtt_cnt >= bbr_lt_bw_max_rtts) {
  528. bbr_reset_lt_bw_sampling(sk); /* stop using lt_bw */
  529. bbr_reset_probe_bw_mode(sk); /* restart gain cycling */
  530. }
  531. return;
  532. }
  533. /* Wait for the first loss before sampling, to let the policer exhaust
  534. * its tokens and estimate the steady-state rate allowed by the policer.
  535. * Starting samples earlier includes bursts that over-estimate the bw.
  536. */
  537. if (!bbr->lt_is_sampling) {
  538. if (!rs->losses)
  539. return;
  540. bbr_reset_lt_bw_sampling_interval(sk);
  541. bbr->lt_is_sampling = true;
  542. }
  543. /* To avoid underestimates, reset sampling if we run out of data. */
  544. if (rs->is_app_limited) {
  545. bbr_reset_lt_bw_sampling(sk);
  546. return;
  547. }
  548. if (bbr->round_start)
  549. bbr->lt_rtt_cnt++; /* count round trips in this interval */
  550. if (bbr->lt_rtt_cnt < bbr_lt_intvl_min_rtts)
  551. return; /* sampling interval needs to be longer */
  552. if (bbr->lt_rtt_cnt > 4 * bbr_lt_intvl_min_rtts) {
  553. bbr_reset_lt_bw_sampling(sk); /* interval is too long */
  554. return;
  555. }
  556. /* End sampling interval when a packet is lost, so we estimate the
  557. * policer tokens were exhausted. Stopping the sampling before the
  558. * tokens are exhausted under-estimates the policed rate.
  559. */
  560. if (!rs->losses)
  561. return;
  562. /* Calculate packets lost and delivered in sampling interval. */
  563. lost = tp->lost - bbr->lt_last_lost;
  564. delivered = tp->delivered - bbr->lt_last_delivered;
  565. /* Is loss rate (lost/delivered) >= lt_loss_thresh? If not, wait. */
  566. if (!delivered || (lost << BBR_SCALE) < bbr_lt_loss_thresh * delivered)
  567. return;
  568. /* Find average delivery rate in this sampling interval. */
  569. t = div_u64(tp->delivered_mstamp, USEC_PER_MSEC) - bbr->lt_last_stamp;
  570. if ((s32)t < 1)
  571. return; /* interval is less than one ms, so wait */
  572. /* Check if can multiply without overflow */
  573. if (t >= ~0U / USEC_PER_MSEC) {
  574. bbr_reset_lt_bw_sampling(sk); /* interval too long; reset */
  575. return;
  576. }
  577. t *= USEC_PER_MSEC;
  578. bw = (u64)delivered * BW_UNIT;
  579. do_div(bw, t);
  580. bbr_lt_bw_interval_done(sk, bw);
  581. }
  582. /* Estimate the bandwidth based on how fast packets are delivered */
  583. static void bbr_update_bw(struct sock *sk, const struct rate_sample *rs)
  584. {
  585. struct tcp_sock *tp = tcp_sk(sk);
  586. struct bbr *bbr = inet_csk_ca(sk);
  587. u64 bw;
  588. bbr->round_start = 0;
  589. if (rs->delivered < 0 || rs->interval_us <= 0)
  590. return; /* Not a valid observation */
  591. /* See if we've reached the next RTT */
  592. if (!before(rs->prior_delivered, bbr->next_rtt_delivered)) {
  593. bbr->next_rtt_delivered = tp->delivered;
  594. bbr->rtt_cnt++;
  595. bbr->round_start = 1;
  596. bbr->packet_conservation = 0;
  597. }
  598. bbr_lt_bw_sampling(sk, rs);
  599. /* Divide delivered by the interval to find a (lower bound) bottleneck
  600. * bandwidth sample. Delivered is in packets and interval_us in uS and
  601. * ratio will be <<1 for most connections. So delivered is first scaled.
  602. */
  603. bw = (u64)rs->delivered * BW_UNIT;
  604. do_div(bw, rs->interval_us);
  605. /* If this sample is application-limited, it is likely to have a very
  606. * low delivered count that represents application behavior rather than
  607. * the available network rate. Such a sample could drag down estimated
  608. * bw, causing needless slow-down. Thus, to continue to send at the
  609. * last measured network rate, we filter out app-limited samples unless
  610. * they describe the path bw at least as well as our bw model.
  611. *
  612. * So the goal during app-limited phase is to proceed with the best
  613. * network rate no matter how long. We automatically leave this
  614. * phase when app writes faster than the network can deliver :)
  615. */
  616. if (!rs->is_app_limited || bw >= bbr_max_bw(sk)) {
  617. /* Incorporate new sample into our max bw filter. */
  618. minmax_running_max(&bbr->bw, bbr_bw_rtts, bbr->rtt_cnt, bw);
  619. }
  620. }
  621. /* Estimate when the pipe is full, using the change in delivery rate: BBR
  622. * estimates that STARTUP filled the pipe if the estimated bw hasn't changed by
  623. * at least bbr_full_bw_thresh (25%) after bbr_full_bw_cnt (3) non-app-limited
  624. * rounds. Why 3 rounds: 1: rwin autotuning grows the rwin, 2: we fill the
  625. * higher rwin, 3: we get higher delivery rate samples. Or transient
  626. * cross-traffic or radio noise can go away. CUBIC Hystart shares a similar
  627. * design goal, but uses delay and inter-ACK spacing instead of bandwidth.
  628. */
  629. static void bbr_check_full_bw_reached(struct sock *sk,
  630. const struct rate_sample *rs)
  631. {
  632. struct bbr *bbr = inet_csk_ca(sk);
  633. u32 bw_thresh;
  634. if (bbr_full_bw_reached(sk) || !bbr->round_start || rs->is_app_limited)
  635. return;
  636. bw_thresh = (u64)bbr->full_bw * bbr_full_bw_thresh >> BBR_SCALE;
  637. if (bbr_max_bw(sk) >= bw_thresh) {
  638. bbr->full_bw = bbr_max_bw(sk);
  639. bbr->full_bw_cnt = 0;
  640. return;
  641. }
  642. ++bbr->full_bw_cnt;
  643. bbr->full_bw_reached = bbr->full_bw_cnt >= bbr_full_bw_cnt;
  644. }
  645. /* If pipe is probably full, drain the queue and then enter steady-state. */
  646. static void bbr_check_drain(struct sock *sk, const struct rate_sample *rs)
  647. {
  648. struct bbr *bbr = inet_csk_ca(sk);
  649. if (bbr->mode == BBR_STARTUP && bbr_full_bw_reached(sk)) {
  650. bbr->mode = BBR_DRAIN; /* drain queue we created */
  651. bbr->pacing_gain = bbr_drain_gain; /* pace slow to drain */
  652. bbr->cwnd_gain = bbr_high_gain; /* maintain cwnd */
  653. tcp_sk(sk)->snd_ssthresh =
  654. bbr_target_cwnd(sk, bbr_max_bw(sk), BBR_UNIT);
  655. } /* fall through to check if in-flight is already small: */
  656. if (bbr->mode == BBR_DRAIN &&
  657. tcp_packets_in_flight(tcp_sk(sk)) <=
  658. bbr_target_cwnd(sk, bbr_max_bw(sk), BBR_UNIT))
  659. bbr_reset_probe_bw_mode(sk); /* we estimate queue is drained */
  660. }
  661. /* The goal of PROBE_RTT mode is to have BBR flows cooperatively and
  662. * periodically drain the bottleneck queue, to converge to measure the true
  663. * min_rtt (unloaded propagation delay). This allows the flows to keep queues
  664. * small (reducing queuing delay and packet loss) and achieve fairness among
  665. * BBR flows.
  666. *
  667. * The min_rtt filter window is 10 seconds. When the min_rtt estimate expires,
  668. * we enter PROBE_RTT mode and cap the cwnd at bbr_cwnd_min_target=4 packets.
  669. * After at least bbr_probe_rtt_mode_ms=200ms and at least one packet-timed
  670. * round trip elapsed with that flight size <= 4, we leave PROBE_RTT mode and
  671. * re-enter the previous mode. BBR uses 200ms to approximately bound the
  672. * performance penalty of PROBE_RTT's cwnd capping to roughly 2% (200ms/10s).
  673. *
  674. * Note that flows need only pay 2% if they are busy sending over the last 10
  675. * seconds. Interactive applications (e.g., Web, RPCs, video chunks) often have
  676. * natural silences or low-rate periods within 10 seconds where the rate is low
  677. * enough for long enough to drain its queue in the bottleneck. We pick up
  678. * these min RTT measurements opportunistically with our min_rtt filter. :-)
  679. */
  680. static void bbr_update_min_rtt(struct sock *sk, const struct rate_sample *rs)
  681. {
  682. struct tcp_sock *tp = tcp_sk(sk);
  683. struct bbr *bbr = inet_csk_ca(sk);
  684. bool filter_expired;
  685. /* Track min RTT seen in the min_rtt_win_sec filter window: */
  686. filter_expired = after(tcp_jiffies32,
  687. bbr->min_rtt_stamp + bbr_min_rtt_win_sec * HZ);
  688. if (rs->rtt_us >= 0 &&
  689. (rs->rtt_us <= bbr->min_rtt_us ||
  690. (filter_expired && !rs->is_ack_delayed))) {
  691. bbr->min_rtt_us = rs->rtt_us;
  692. bbr->min_rtt_stamp = tcp_jiffies32;
  693. }
  694. if (bbr_probe_rtt_mode_ms > 0 && filter_expired &&
  695. !bbr->idle_restart && bbr->mode != BBR_PROBE_RTT) {
  696. bbr->mode = BBR_PROBE_RTT; /* dip, drain queue */
  697. bbr->pacing_gain = BBR_UNIT;
  698. bbr->cwnd_gain = BBR_UNIT;
  699. bbr_save_cwnd(sk); /* note cwnd so we can restore it */
  700. bbr->probe_rtt_done_stamp = 0;
  701. }
  702. if (bbr->mode == BBR_PROBE_RTT) {
  703. /* Ignore low rate samples during this mode. */
  704. tp->app_limited =
  705. (tp->delivered + tcp_packets_in_flight(tp)) ? : 1;
  706. /* Maintain min packets in flight for max(200 ms, 1 round). */
  707. if (!bbr->probe_rtt_done_stamp &&
  708. tcp_packets_in_flight(tp) <= bbr_cwnd_min_target) {
  709. bbr->probe_rtt_done_stamp = tcp_jiffies32 +
  710. msecs_to_jiffies(bbr_probe_rtt_mode_ms);
  711. bbr->probe_rtt_round_done = 0;
  712. bbr->next_rtt_delivered = tp->delivered;
  713. } else if (bbr->probe_rtt_done_stamp) {
  714. if (bbr->round_start)
  715. bbr->probe_rtt_round_done = 1;
  716. if (bbr->probe_rtt_round_done &&
  717. after(tcp_jiffies32, bbr->probe_rtt_done_stamp)) {
  718. bbr->min_rtt_stamp = tcp_jiffies32;
  719. bbr->restore_cwnd = 1; /* snap to prior_cwnd */
  720. bbr_reset_mode(sk);
  721. }
  722. }
  723. }
  724. /* Restart after idle ends only once we process a new S/ACK for data */
  725. if (rs->delivered > 0)
  726. bbr->idle_restart = 0;
  727. }
  728. static void bbr_update_model(struct sock *sk, const struct rate_sample *rs)
  729. {
  730. bbr_update_bw(sk, rs);
  731. bbr_update_cycle_phase(sk, rs);
  732. bbr_check_full_bw_reached(sk, rs);
  733. bbr_check_drain(sk, rs);
  734. bbr_update_min_rtt(sk, rs);
  735. }
  736. static void bbr_main(struct sock *sk, const struct rate_sample *rs)
  737. {
  738. struct bbr *bbr = inet_csk_ca(sk);
  739. u32 bw;
  740. bbr_update_model(sk, rs);
  741. bw = bbr_bw(sk);
  742. bbr_set_pacing_rate(sk, bw, bbr->pacing_gain);
  743. bbr_set_cwnd(sk, rs, rs->acked_sacked, bw, bbr->cwnd_gain);
  744. }
  745. static void bbr_init(struct sock *sk)
  746. {
  747. struct tcp_sock *tp = tcp_sk(sk);
  748. struct bbr *bbr = inet_csk_ca(sk);
  749. bbr->prior_cwnd = 0;
  750. tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
  751. bbr->rtt_cnt = 0;
  752. bbr->next_rtt_delivered = 0;
  753. bbr->prev_ca_state = TCP_CA_Open;
  754. bbr->packet_conservation = 0;
  755. bbr->probe_rtt_done_stamp = 0;
  756. bbr->probe_rtt_round_done = 0;
  757. bbr->min_rtt_us = tcp_min_rtt(tp);
  758. bbr->min_rtt_stamp = tcp_jiffies32;
  759. minmax_reset(&bbr->bw, bbr->rtt_cnt, 0); /* init max bw to 0 */
  760. bbr->has_seen_rtt = 0;
  761. bbr_init_pacing_rate_from_rtt(sk);
  762. bbr->restore_cwnd = 0;
  763. bbr->round_start = 0;
  764. bbr->idle_restart = 0;
  765. bbr->full_bw_reached = 0;
  766. bbr->full_bw = 0;
  767. bbr->full_bw_cnt = 0;
  768. bbr->cycle_mstamp = 0;
  769. bbr->cycle_idx = 0;
  770. bbr_reset_lt_bw_sampling(sk);
  771. bbr_reset_startup_mode(sk);
  772. cmpxchg(&sk->sk_pacing_status, SK_PACING_NONE, SK_PACING_NEEDED);
  773. }
  774. static u32 bbr_sndbuf_expand(struct sock *sk)
  775. {
  776. /* Provision 3 * cwnd since BBR may slow-start even during recovery. */
  777. return 3;
  778. }
  779. /* In theory BBR does not need to undo the cwnd since it does not
  780. * always reduce cwnd on losses (see bbr_main()). Keep it for now.
  781. */
  782. static u32 bbr_undo_cwnd(struct sock *sk)
  783. {
  784. struct bbr *bbr = inet_csk_ca(sk);
  785. bbr->full_bw = 0; /* spurious slow-down; reset full pipe detection */
  786. bbr->full_bw_cnt = 0;
  787. bbr_reset_lt_bw_sampling(sk);
  788. return tcp_sk(sk)->snd_cwnd;
  789. }
  790. /* Entering loss recovery, so save cwnd for when we exit or undo recovery. */
  791. static u32 bbr_ssthresh(struct sock *sk)
  792. {
  793. bbr_save_cwnd(sk);
  794. return tcp_sk(sk)->snd_ssthresh;
  795. }
  796. static size_t bbr_get_info(struct sock *sk, u32 ext, int *attr,
  797. union tcp_cc_info *info)
  798. {
  799. if (ext & (1 << (INET_DIAG_BBRINFO - 1)) ||
  800. ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
  801. struct tcp_sock *tp = tcp_sk(sk);
  802. struct bbr *bbr = inet_csk_ca(sk);
  803. u64 bw = bbr_bw(sk);
  804. bw = bw * tp->mss_cache * USEC_PER_SEC >> BW_SCALE;
  805. memset(&info->bbr, 0, sizeof(info->bbr));
  806. info->bbr.bbr_bw_lo = (u32)bw;
  807. info->bbr.bbr_bw_hi = (u32)(bw >> 32);
  808. info->bbr.bbr_min_rtt = bbr->min_rtt_us;
  809. info->bbr.bbr_pacing_gain = bbr->pacing_gain;
  810. info->bbr.bbr_cwnd_gain = bbr->cwnd_gain;
  811. *attr = INET_DIAG_BBRINFO;
  812. return sizeof(info->bbr);
  813. }
  814. return 0;
  815. }
  816. static void bbr_set_state(struct sock *sk, u8 new_state)
  817. {
  818. struct bbr *bbr = inet_csk_ca(sk);
  819. if (new_state == TCP_CA_Loss) {
  820. struct rate_sample rs = { .losses = 1 };
  821. bbr->prev_ca_state = TCP_CA_Loss;
  822. bbr->full_bw = 0;
  823. bbr->round_start = 1; /* treat RTO like end of a round */
  824. bbr_lt_bw_sampling(sk, &rs);
  825. }
  826. }
  827. static struct tcp_congestion_ops tcp_bbr_cong_ops __read_mostly = {
  828. .flags = TCP_CONG_NON_RESTRICTED,
  829. .name = "bbr",
  830. .owner = THIS_MODULE,
  831. .init = bbr_init,
  832. .cong_control = bbr_main,
  833. .sndbuf_expand = bbr_sndbuf_expand,
  834. .undo_cwnd = bbr_undo_cwnd,
  835. .cwnd_event = bbr_cwnd_event,
  836. .ssthresh = bbr_ssthresh,
  837. .min_tso_segs = bbr_min_tso_segs,
  838. .get_info = bbr_get_info,
  839. .set_state = bbr_set_state,
  840. };
  841. static int __init bbr_register(void)
  842. {
  843. BUILD_BUG_ON(sizeof(struct bbr) > ICSK_CA_PRIV_SIZE);
  844. return tcp_register_congestion_control(&tcp_bbr_cong_ops);
  845. }
  846. static void __exit bbr_unregister(void)
  847. {
  848. tcp_unregister_congestion_control(&tcp_bbr_cong_ops);
  849. }
  850. module_init(bbr_register);
  851. module_exit(bbr_unregister);
  852. MODULE_AUTHOR("Van Jacobson <vanj@google.com>");
  853. MODULE_AUTHOR("Neal Cardwell <ncardwell@google.com>");
  854. MODULE_AUTHOR("Yuchung Cheng <ycheng@google.com>");
  855. MODULE_AUTHOR("Soheil Hassas Yeganeh <soheil@google.com>");
  856. MODULE_LICENSE("Dual BSD/GPL");
  857. MODULE_DESCRIPTION("TCP BBR (Bottleneck Bandwidth and RTT)");