Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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