You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

657 line
19KB

  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * TCP ROCCET: An RTT-Oriented CUBIC Congestion Control
  4. * Extension for 5G and Beyond Networks
  5. *
  6. * TCP ROCCET is a new TCP congestion control
  7. * algorithm suited for current cellular 5G NR beyond networks.
  8. * It extends the kernel default congestion control CUBIC
  9. * and improves its performance, and additionally solves an
  10. * unwanted side effects of CUBIC’s implementation.
  11. * ROCCET uses its own Slow Start, called LAUNCH, where loss
  12. * is not considered as a congestion event.
  13. * The congestion avoidance phase, called ORBITER, uses
  14. * CUBIC's window growth function and adds, based on RTT
  15. * and ACK rate, congestion events.
  16. *
  17. * NOTE: A paper for TCP ROCCET is currently under review.
  18. * A draft of this paper can be found here:
  19. *
  20. *
  21. * Further information about CUBIC:
  22. * TCP CUBIC: Binary Increase Congestion control for TCP v2.3
  23. * Home page:
  24. * http://netsrv.csc.ncsu.edu/twiki/bin/view/Main/BIC
  25. * This is from the implementation of CUBIC TCP in
  26. * Sangtae Ha, Injong Rhee and Lisong Xu,
  27. * "CUBIC: A New TCP-Friendly High-Speed TCP Variant"
  28. * in ACM SIGOPS Operating System Review, July 2008.
  29. * Available from:
  30. * http://netsrv.csc.ncsu.edu/export/cubic_a_new_tcp_2008.pdf
  31. *
  32. * CUBIC integrates a new slow start algorithm, called HyStart.
  33. * The details of HyStart are presented in
  34. * Sangtae Ha and Injong Rhee,
  35. * "Taming the Elephants: New TCP Slow Start", NCSU TechReport 2008.
  36. * Available from:
  37. * http://netsrv.csc.ncsu.edu/export/hystart_techreport_2008.pdf
  38. *
  39. * All testing results are available from:
  40. * http://netsrv.csc.ncsu.edu/wiki/index.php/TCP_Testing
  41. *
  42. * Unless CUBIC is enabled and congestion window is large
  43. * this behaves the same as the original Reno.
  44. */
  45. #include "tcp_roccet.h"
  46. #include "linux/printk.h"
  47. #include <linux/btf.h>
  48. #include <linux/btf_ids.h>
  49. #include <linux/math64.h>
  50. #include <linux/mm.h>
  51. #include <linux/module.h>
  52. #include <net/tcp.h>
  53. /* Scale factor beta calculation (max_cwnd = snd_cwnd * beta) */
  54. #define BICTCP_BETA_SCALE 1024
  55. #define BICTCP_HZ 10 /* BIC HZ 2^10 = 1024 */
  56. /* Alpha value for the sRrTT multiplied by 100.
  57. * Here 20 represents a value of 0.2
  58. */
  59. #define ROCCET_ALPHA_TIMES_100 20
  60. /* The amount of seconds ROCCET stores a minRTT.
  61. * Enable "calculate_min_rtt" first.
  62. */
  63. #define ROCCET_RTT_LOOKBACK_S 10
  64. /* Parameters that are specific to the ROCCET-Algorithm */
  65. static int sr_rtt_upper_bound __read_mostly = 100;
  66. static int ack_rate_diff_ss __read_mostly = 10;
  67. static int ack_rate_diff_ca __read_mostly = 200;
  68. static int calculate_min_rtt __read_mostly = 0;
  69. static int ignore_loss __read_mostly = 0;
  70. static int roccet_minRTT_interpolation_factor __read_mostly = 70;
  71. module_param(sr_rtt_upper_bound, int, 0644);
  72. MODULE_PARM_DESC(sr_rtt_upper_bound, "ROCCET's upper bound for srRTT.");
  73. module_param(ack_rate_diff_ss, int, 0644);
  74. MODULE_PARM_DESC(ack_rate_diff_ss,
  75. "ROCCET's threshold to exit slow start if ACK-rate defer by "
  76. "given amount of segments.");
  77. module_param(ack_rate_diff_ca, int, 0644);
  78. MODULE_PARM_DESC(ack_rate_diff_ca,
  79. "ROCCET's threshold for ack-rate and cum_cwnd, in percantage "
  80. "of the current cwnd.");
  81. module_param(calculate_min_rtt, int, 0644);
  82. MODULE_PARM_DESC(calculate_min_rtt,
  83. "Calculate min RTT if no lower RTT occurs after 10 sec.");
  84. module_param(ignore_loss, int, 0644);
  85. MODULE_PARM_DESC(ignore_loss, "Ignore loss as a congestion event.");
  86. module_param(roccet_minRTT_interpolation_factor, int, 0644);
  87. MODULE_PARM_DESC(
  88. roccet_minRTT_interpolation_factor,
  89. "ROCCET factor for interpolating the current RTT with the last minRTT "
  90. "(minRTT = (factor * currRTT + (100-factor) * minRTT) / 100)");
  91. static int fast_convergence __read_mostly = 1;
  92. static int beta __read_mostly = 717; /* = 717/1024 (BICTCP_BETA_SCALE) */
  93. static int initial_ssthresh __read_mostly;
  94. static int bic_scale __read_mostly = 41;
  95. static int tcp_friendliness __read_mostly = 1;
  96. static u32 cube_rtt_scale __read_mostly;
  97. static u32 beta_scale __read_mostly;
  98. static u64 cube_factor __read_mostly;
  99. /* Note parameters that are used for precomputing scale factors are read-only */
  100. module_param(fast_convergence, int, 0644);
  101. MODULE_PARM_DESC(fast_convergence, "turn on/off fast convergence");
  102. module_param(beta, int, 0644);
  103. MODULE_PARM_DESC(beta, "beta for multiplicative increase");
  104. module_param(initial_ssthresh, int, 0644);
  105. MODULE_PARM_DESC(initial_ssthresh, "initial value of slow start threshold");
  106. module_param(bic_scale, int, 0444);
  107. MODULE_PARM_DESC(
  108. bic_scale,
  109. "scale (scaled by 1024) value for bic function (bic_scale/1024)");
  110. module_param(tcp_friendliness, int, 0644);
  111. MODULE_PARM_DESC(tcp_friendliness, "turn on/off tcp friendliness");
  112. static inline void roccettcp_reset(struct roccettcp *ca)
  113. {
  114. memset(ca, 0, offsetof(struct roccettcp, curr_rtt));
  115. ca->bw_limit.sum_cwnd = 1;
  116. ca->bw_limit.sum_acked = 1;
  117. ca->bw_limit.next_check = 0;
  118. ca->curr_min_rtt_timed.rtt = ~0U;
  119. ca->curr_min_rtt_timed.time = ~0U;
  120. ca->last_rtt = 0;
  121. }
  122. static inline void update_min_rtt(struct sock *sk)
  123. {
  124. struct roccettcp *ca = inet_csk_ca(sk);
  125. u32 now = jiffies_to_usecs(tcp_jiffies32);
  126. if (now - ca->curr_min_rtt_timed.time >
  127. ROCCET_RTT_LOOKBACK_S * USEC_PER_SEC &&
  128. calculate_min_rtt) {
  129. u32 new_min_rtt = max(ca->curr_rtt, 1);
  130. u32 old_min_rtt = ca->curr_min_rtt_timed.rtt;
  131. u32 interpolated_min_rtt =
  132. (new_min_rtt * roccet_minRTT_interpolation_factor +
  133. old_min_rtt *
  134. (100 - roccet_minRTT_interpolation_factor)) /
  135. 100;
  136. ca->curr_min_rtt_timed.rtt = interpolated_min_rtt;
  137. ca->curr_min_rtt_timed.time = now;
  138. }
  139. /* Check if new lower min RTT was found. If so, set it directly */
  140. if (ca->curr_rtt < ca->curr_min_rtt_timed.rtt) {
  141. ca->curr_min_rtt_timed.rtt = max(ca->curr_rtt, 1);
  142. ca->curr_min_rtt_timed.time = now;
  143. }
  144. }
  145. /* Return difference between last and current ack rate.
  146. */
  147. static inline int get_ack_rate_diff(struct roccettcp *ca)
  148. {
  149. return ca->ack_rate.last_rate - ca->ack_rate.curr_rate;
  150. }
  151. /* Update ack rate sampled by 100ms.
  152. */
  153. static inline void update_ack_rate(struct sock *sk)
  154. {
  155. struct roccettcp *ca = inet_csk_ca(sk);
  156. u32 now = jiffies_to_usecs(tcp_jiffies32);
  157. u32 interval = USEC_PER_MSEC * 100;
  158. if ((u32)(now - ca->ack_rate.last_rate_time) >= interval) {
  159. ca->ack_rate.last_rate_time = now;
  160. ca->ack_rate.last_rate = ca->ack_rate.curr_rate;
  161. ca->ack_rate.curr_rate = ca->ack_rate.cnt;
  162. ca->ack_rate.cnt = 0;
  163. } else {
  164. ca->ack_rate.cnt += 1;
  165. }
  166. }
  167. /* Compute srRTT.
  168. */
  169. static inline void update_srrtt(struct sock *sk)
  170. {
  171. struct roccettcp *ca = inet_csk_ca(sk);
  172. if (ca->curr_min_rtt_timed.rtt == 0)
  173. return;
  174. /* Calculate the new rRTT (Scaled by 100).
  175. * 100 * ((sRTT - sRTT_min) / sRTT_min)
  176. */
  177. u32 rRTT = (100 * (ca->curr_rtt - ca->curr_min_rtt_timed.rtt)) /
  178. ca->curr_min_rtt_timed.rtt;
  179. // (1 - alpha) * srRTT + alpha * rRTT
  180. ca->curr_srRTT = ((100 - ROCCET_ALPHA_TIMES_100) * ca->curr_srRTT +
  181. ROCCET_ALPHA_TIMES_100 * rRTT) /
  182. 100;
  183. }
  184. __bpf_kfunc static void roccettcp_init(struct sock *sk)
  185. {
  186. struct roccettcp *ca = inet_csk_ca(sk);
  187. roccettcp_reset(ca);
  188. if (initial_ssthresh)
  189. tcp_sk(sk)->snd_ssthresh = initial_ssthresh;
  190. /* Initial roccet paramters */
  191. ca->roccet_last_event_time_us = 0;
  192. ca->curr_min_rtt = ~0U;
  193. ca->ack_rate.last_rate = 0;
  194. ca->ack_rate.last_rate_time = 0;
  195. ca->ack_rate.curr_rate = 0;
  196. ca->ack_rate.cnt = 0;
  197. }
  198. __bpf_kfunc static void roccettcp_cwnd_event(struct sock *sk,
  199. enum tcp_ca_event event)
  200. {
  201. if (event == CA_EVENT_TX_START) {
  202. struct roccettcp *ca = inet_csk_ca(sk);
  203. u32 now = tcp_jiffies32;
  204. s32 delta;
  205. delta = now - tcp_sk(sk)->lsndtime;
  206. /* We were application limited (idle) for a while.
  207. * Shift epoch_start to keep cwnd growth to cubic curve.
  208. */
  209. if (ca->epoch_start && delta > 0) {
  210. ca->epoch_start += delta;
  211. if (after(ca->epoch_start, now))
  212. ca->epoch_start = now;
  213. }
  214. return;
  215. }
  216. }
  217. /* calculate the cubic root of x using a table lookup followed by one
  218. * Newton-Raphson iteration.
  219. * Avg err ~= 0.195%
  220. */
  221. static u32 cubic_root(u64 a)
  222. {
  223. u32 x, b, shift;
  224. /* cbrt(x) MSB values for x MSB values in [0..63].
  225. * Precomputed then refined by hand - Willy Tarreau
  226. *
  227. * For x in [0..63],
  228. * v = cbrt(x << 18) - 1
  229. * cbrt(x) = (v[x] + 10) >> 6
  230. */
  231. static const u8 v[] = {
  232. /* 0x00 */ 0, 54, 54, 54, 118, 118, 118, 118,
  233. /* 0x08 */ 123, 129, 134, 138, 143, 147, 151, 156,
  234. /* 0x10 */ 157, 161, 164, 168, 170, 173, 176, 179,
  235. /* 0x18 */ 181, 185, 187, 190, 192, 194, 197, 199,
  236. /* 0x20 */ 200, 202, 204, 206, 209, 211, 213, 215,
  237. /* 0x28 */ 217, 219, 221, 222, 224, 225, 227, 229,
  238. /* 0x30 */ 231, 232, 234, 236, 237, 239, 240, 242,
  239. /* 0x38 */ 244, 245, 246, 248, 250, 251, 252, 254,
  240. };
  241. b = fls64(a);
  242. if (b < 7) {
  243. /* a in [0..63] */
  244. return ((u32)v[(u32)a] + 35) >> 6;
  245. }
  246. b = ((b * 84) >> 8) - 1;
  247. shift = (a >> (b * 3));
  248. x = ((u32)(((u32)v[shift] + 10) << b)) >> 6;
  249. /* Newton-Raphson iteration
  250. * 2
  251. * x = ( 2 * x + a / x ) / 3
  252. * k+1 k k
  253. */
  254. x = (2 * x + (u32)div64_u64(a, (u64)x * (u64)(x - 1)));
  255. x = ((x * 341) >> 10);
  256. return x;
  257. }
  258. /* Compute congestion window to use.
  259. */
  260. static inline void bictcp_update(struct roccettcp *ca, u32 cwnd, u32 acked)
  261. {
  262. u32 delta, bic_target, max_cnt;
  263. u64 offs, t;
  264. ca->ack_cnt += acked; /* count the number of ACKed packets */
  265. if (ca->last_cwnd == cwnd &&
  266. (s32)(tcp_jiffies32 - ca->last_time) <= HZ / 32)
  267. return;
  268. /* The CUBIC function can update ca->cnt at most once per jiffy.
  269. * On all cwnd reduction events, ca->epoch_start is set to 0,
  270. * which will force a recalculation of ca->cnt.
  271. */
  272. if (ca->epoch_start && tcp_jiffies32 == ca->last_time)
  273. goto tcp_friendliness;
  274. ca->last_cwnd = cwnd;
  275. ca->last_time = tcp_jiffies32;
  276. if (ca->epoch_start == 0) {
  277. ca->epoch_start = tcp_jiffies32; /* record beginning */
  278. ca->ack_cnt = acked; /* start counting */
  279. ca->tcp_cwnd = cwnd; /* syn with cubic */
  280. if (ca->last_max_cwnd <= cwnd) {
  281. ca->bic_K = 0;
  282. ca->bic_origin_point = cwnd;
  283. } else {
  284. /* Compute new K based on
  285. * (wmax-cwnd) * (srtt>>3 / HZ) / c * 2^(3*bictcp_HZ)
  286. */
  287. ca->bic_K = cubic_root(cube_factor *
  288. (ca->last_max_cwnd - cwnd));
  289. ca->bic_origin_point = ca->last_max_cwnd;
  290. }
  291. }
  292. /* cubic function - calc */
  293. /* calculate c * time^3 / rtt,
  294. * while considering overflow in calculation of time^3
  295. * (so time^3 is done by using 64 bit)
  296. * and without the support of division of 64bit numbers
  297. * (so all divisions are done by using 32 bit)
  298. * also NOTE the unit of those veriables
  299. * time = (t - K) / 2^bictcp_HZ
  300. * c = bic_scale >> 10
  301. * rtt = (srtt >> 3) / HZ
  302. * !!! The following code does not have overflow problems,
  303. * if the cwnd < 1 million packets !!!
  304. */
  305. t = (s32)(tcp_jiffies32 - ca->epoch_start);
  306. t += usecs_to_jiffies(ca->delay_min);
  307. /* change the unit from HZ to bictcp_HZ */
  308. t <<= BICTCP_HZ;
  309. do_div(t, HZ);
  310. if (t < ca->bic_K) /* t - K */
  311. offs = ca->bic_K - t;
  312. else
  313. offs = t - ca->bic_K;
  314. /* c/rtt * (t-K)^3 */
  315. delta = (cube_rtt_scale * offs * offs * offs) >> (10 + 3 * BICTCP_HZ);
  316. if (t < ca->bic_K) /* below origin*/
  317. bic_target = ca->bic_origin_point - delta;
  318. else /* above origin*/
  319. bic_target = ca->bic_origin_point + delta;
  320. /* cubic function - calc bictcp_cnt*/
  321. if (bic_target > cwnd) {
  322. ca->cnt = cwnd / (bic_target - cwnd);
  323. } else {
  324. ca->cnt = 100 * cwnd; /* very small increment*/
  325. }
  326. /* The initial growth of cubic function may be too conservative
  327. * when the available bandwidth is still unknown.
  328. */
  329. if (ca->last_max_cwnd == 0 && ca->cnt > 20)
  330. ca->cnt = 20; /* increase cwnd 5% per RTT */
  331. tcp_friendliness:
  332. /* TCP Friendly */
  333. if (tcp_friendliness) {
  334. u32 scale = beta_scale;
  335. delta = (cwnd * scale) >> 3;
  336. while (ca->ack_cnt > delta) { /* update tcp cwnd */
  337. ca->ack_cnt -= delta;
  338. ca->tcp_cwnd++;
  339. }
  340. if (ca->tcp_cwnd > cwnd) { /* if bic is slower than tcp */
  341. delta = ca->tcp_cwnd - cwnd;
  342. max_cnt = cwnd / delta;
  343. if (ca->cnt > max_cnt)
  344. ca->cnt = max_cnt;
  345. }
  346. }
  347. /* The maximum rate of cwnd increase CUBIC allows is 1 packet per
  348. * 2 packets ACKed, meaning cwnd grows at 1.5x per RTT.
  349. */
  350. ca->cnt = max(ca->cnt, 2U);
  351. }
  352. __bpf_kfunc static void roccettcp_cong_avoid(struct sock *sk, u32 ack,
  353. u32 acked)
  354. {
  355. struct tcp_sock *tp = tcp_sk(sk);
  356. struct roccettcp *ca = inet_csk_ca(sk);
  357. u32 now = jiffies_to_usecs(tcp_jiffies32);
  358. u32 bw_limit_detect = 0;
  359. u32 roccet_xj;
  360. u32 jitter;
  361. if (ca->last_rtt > ca->curr_rtt) {
  362. jitter = ca->last_rtt - ca->curr_rtt;
  363. } else {
  364. jitter = ca->curr_rtt - ca->last_rtt;
  365. }
  366. /* Update roccet paramters */
  367. update_ack_rate(sk);
  368. update_min_rtt(sk);
  369. update_srrtt(sk);
  370. /* ROCCET drain.
  371. * Do not increase the cwnd for 100ms after a roccet congestion event
  372. */
  373. if (now - ca->roccet_last_event_time_us <= 100 * USEC_PER_MSEC)
  374. return;
  375. /* Lift off: Detect an exit point for tcp slow start
  376. * in networks with large buffers of multiple BDP
  377. * Like in cellular networks (5G, ...).
  378. */
  379. if (tcp_in_slow_start(tp) && ca->curr_srRTT > sr_rtt_upper_bound &&
  380. get_ack_rate_diff(ca) >= ack_rate_diff_ss) {
  381. ca->epoch_start = 0;
  382. /* Handle inital slow start. Here we observe the most problems */
  383. if (tp->snd_ssthresh == TCP_INFINITE_SSTHRESH) {
  384. tcp_sk(sk)->snd_ssthresh = tcp_snd_cwnd(tp) / 2;
  385. tcp_snd_cwnd_set(tp, tcp_snd_cwnd(tp) / 2);
  386. } else {
  387. tcp_sk(sk)->snd_ssthresh =
  388. tcp_snd_cwnd(tp) - (tcp_snd_cwnd(tp) / 3);
  389. tcp_snd_cwnd_set(tp, tcp_snd_cwnd(tp) -
  390. (tcp_snd_cwnd(tp) / 3));
  391. }
  392. ca->roccet_last_event_time_us = now;
  393. return;
  394. }
  395. if (tcp_in_slow_start(tp)) {
  396. acked = tcp_slow_start(tp, acked);
  397. if (!acked)
  398. return;
  399. }
  400. if (ca->bw_limit.next_check == 0)
  401. ca->bw_limit.next_check = now + 5 * ca->curr_rtt;
  402. ca->bw_limit.sum_cwnd += tcp_snd_cwnd(tp);
  403. ca->bw_limit.sum_acked += acked;
  404. if (ca->bw_limit.next_check < now) {
  405. /* We send more data as we got acked in the last 5 RTTs */
  406. if ((ca->bw_limit.sum_cwnd * 100) / ca->bw_limit.sum_acked >=
  407. ack_rate_diff_ca)
  408. bw_limit_detect = 1;
  409. /* reset struct and set next end of period */
  410. ca->bw_limit.sum_cwnd = 1;
  411. /* set to 1 to avoid division by zero */
  412. ca->bw_limit.sum_acked = 1;
  413. ca->bw_limit.next_check = now + 5 * ca->curr_rtt;
  414. }
  415. /* Respects the jitter of the connection and add it on top of the upper bound
  416. * for the srRTT
  417. */
  418. roccet_xj = ((jitter * 100) / ca->curr_min_rtt_timed.rtt) +
  419. sr_rtt_upper_bound;
  420. if (roccet_xj < sr_rtt_upper_bound)
  421. roccet_xj = sr_rtt_upper_bound;
  422. if (ca->curr_srRTT > roccet_xj && bw_limit_detect) {
  423. ca->epoch_start = 0;
  424. ca->roccet_last_event_time_us = now;
  425. ca->cnt = 100 * tcp_snd_cwnd(tp);
  426. /* Set Wmax if cwnd is larger than the old Wmax */
  427. if (tcp_snd_cwnd(tp) > ca->last_max_cwnd)
  428. ca->last_max_cwnd = tcp_snd_cwnd(tp);
  429. tcp_snd_cwnd_set(tp, min(tp->snd_cwnd_clamp,
  430. max((tcp_snd_cwnd(tp) * beta) / BICTCP_BETA_SCALE, 2U)));
  431. tp->snd_ssthresh = tcp_snd_cwnd(tp);
  432. return;
  433. }
  434. /* Terminates this function if cwnd is not fully utilized.
  435. * In mobile networks like 5G, this termination causes the cwnd to be frozen at
  436. * an excessively high value. This is because slow start or HyStart massively
  437. * exceed the available bandwidth and leave the cwnd at an excessively high
  438. * value. The cwnd cannot therefore be fully utilized because it is limited by
  439. * the connection capacity.
  440. */
  441. if (!tcp_is_cwnd_limited(sk))
  442. return;
  443. bictcp_update(ca, tcp_snd_cwnd(tp), acked);
  444. tcp_cong_avoid_ai(tp, max(1, ca->cnt), acked);
  445. }
  446. __bpf_kfunc static u32 roccettcp_recalc_ssthresh(struct sock *sk)
  447. {
  448. const struct tcp_sock *tp = tcp_sk(sk);
  449. struct roccettcp *ca = inet_csk_ca(sk);
  450. if (ignore_loss)
  451. return tcp_snd_cwnd(tp);
  452. /* Don't exit slow start if loss occurs. */
  453. if (tcp_in_slow_start(tp))
  454. return tcp_snd_cwnd(tp);
  455. ca->epoch_start = 0; /* end of epoch */
  456. /* Wmax and fast convergence */
  457. if (tcp_snd_cwnd(tp) < ca->last_max_cwnd && fast_convergence)
  458. ca->last_max_cwnd =
  459. (tcp_snd_cwnd(tp) * (BICTCP_BETA_SCALE + beta)) /
  460. (2 * BICTCP_BETA_SCALE);
  461. else
  462. ca->last_max_cwnd = tcp_snd_cwnd(tp);
  463. return max((tcp_snd_cwnd(tp) * beta) / BICTCP_BETA_SCALE, 2U);
  464. }
  465. __bpf_kfunc static void roccettcp_state(struct sock *sk, u8 new_state)
  466. {
  467. struct roccettcp *ca = inet_csk_ca(sk);
  468. if (new_state == TCP_CA_Loss)
  469. roccettcp_reset(ca);
  470. }
  471. __bpf_kfunc static void roccettcp_acked(struct sock *sk,
  472. const struct ack_sample *sample)
  473. {
  474. struct roccettcp *ca = inet_csk_ca(sk);
  475. /* Some calls are for duplicates without timestamps */
  476. if (sample->rtt_us < 0)
  477. return;
  478. /* Discard delay samples right after fast recovery */
  479. if (ca->epoch_start && (s32)(tcp_jiffies32 - ca->epoch_start) < HZ)
  480. return;
  481. u32 delay = sample->rtt_us;
  482. if (delay == 0)
  483. delay = 1;
  484. /* first time call or link delay decreases */
  485. if (ca->delay_min == 0 || ca->delay_min > delay)
  486. ca->delay_min = delay;
  487. /* Get valid sample for roccet */
  488. if (sample->rtt_us > 0) {
  489. ca->last_rtt = ca->curr_rtt;
  490. ca->curr_rtt = sample->rtt_us;
  491. }
  492. }
  493. static struct tcp_congestion_ops roccet_tcp __read_mostly = {
  494. .init = roccettcp_init,
  495. .ssthresh = roccettcp_recalc_ssthresh,
  496. .cong_avoid = roccettcp_cong_avoid,
  497. .set_state = roccettcp_state,
  498. .undo_cwnd = tcp_reno_undo_cwnd,
  499. .cwnd_event = roccettcp_cwnd_event,
  500. .pkts_acked = roccettcp_acked,
  501. .owner = THIS_MODULE,
  502. .name = "roccet",
  503. };
  504. BTF_KFUNCS_START(tcp_roccet_check_kfunc_ids)
  505. BTF_ID_FLAGS(func, roccettcp_init)
  506. BTF_ID_FLAGS(func, roccettcp_recalc_ssthresh)
  507. BTF_ID_FLAGS(func, roccettcp_cong_avoid)
  508. BTF_ID_FLAGS(func, roccettcp_state)
  509. BTF_ID_FLAGS(func, roccettcp_cwnd_event)
  510. BTF_ID_FLAGS(func, roccettcp_acked)
  511. BTF_KFUNCS_END(tcp_roccet_check_kfunc_ids)
  512. static const struct btf_kfunc_id_set tcp_roccet_kfunc_set = {
  513. .owner = THIS_MODULE,
  514. .set = &tcp_roccet_check_kfunc_ids,
  515. };
  516. static int __init roccettcp_register(void)
  517. {
  518. int ret;
  519. BUILD_BUG_ON(sizeof(struct roccettcp) > ICSK_CA_PRIV_SIZE);
  520. /* Precompute a bunch of the scaling factors that are used per-packet
  521. * based on SRTT of 100ms
  522. */
  523. beta_scale =
  524. 8 * (BICTCP_BETA_SCALE + beta) / 3 / (BICTCP_BETA_SCALE - beta);
  525. cube_rtt_scale = (bic_scale * 10); /* 1024*c/rtt */
  526. /* calculate the "K" for (wmax-cwnd) = c/rtt * K^3
  527. * so K = cubic_root( (wmax-cwnd)*rtt/c )
  528. * the unit of K is bictcp_HZ=2^10, not HZ
  529. *
  530. * c = bic_scale >> 10
  531. * rtt = 100ms
  532. *
  533. * the following code has been designed and tested for
  534. * cwnd < 1 million packets
  535. * RTT < 100 seconds
  536. * HZ < 1,000,00 (corresponding to 10 nano-second)
  537. */
  538. /* 1/c * 2^2*bictcp_HZ * srtt */
  539. cube_factor = 1ull << (10 + 3 * BICTCP_HZ); /* 2^40 */
  540. /* divide by bic_scale and by constant Srtt (100ms) */
  541. do_div(cube_factor, bic_scale * 10);
  542. ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
  543. &tcp_roccet_kfunc_set);
  544. if (ret < 0)
  545. return ret;
  546. return tcp_register_congestion_control(&roccet_tcp);
  547. }
  548. static void __exit roccettcp_unregister(void)
  549. {
  550. tcp_unregister_congestion_control(&roccet_tcp);
  551. }
  552. module_init(roccettcp_register);
  553. module_exit(roccettcp_unregister);
  554. MODULE_AUTHOR("Lukas Prause, Tim Füchsel");
  555. MODULE_LICENSE("GPL");
  556. MODULE_DESCRIPTION("ROCCET TCP");
  557. MODULE_VERSION("1.0");