tcp_nanqinlang.c 35 KB

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