^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * TCP Vegas congestion control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This is based on the congestion detection/avoidance scheme described in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Lawrence S. Brakmo and Larry L. Peterson.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * "TCP Vegas: End to end congestion avoidance on a global internet."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * IEEE Journal on Selected Areas in Communication, 13(8):1465--1480,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * October 1995. Available from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * ftp://ftp.cs.arizona.edu/xkernel/Papers/jsac.ps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * See http://www.cs.arizona.edu/xkernel/ for their implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * The main aspects that distinguish this implementation from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Arizona Vegas implementation are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * o We do not change the loss detection or recovery mechanisms of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Linux in any way. Linux already recovers from losses quite well,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * using fine-grained timers, NewReno, and FACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * o To avoid the performance penalty imposed by increasing cwnd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * only every-other RTT during slow start, we increase during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * every RTT during slow start, just like Reno.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * o Largely to allow continuous cwnd growth during slow start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * we use the rate at which ACKs come back as the "actual"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * rate, rather than the rate at which data is sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * o To speed convergence to the right rate, we set the cwnd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * to achieve the right ("actual") rate when we exit slow start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * o To filter out the noise caused by delayed ACKs, we use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * minimum RTT sample observed during the last RTT to calculate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * the actual rate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * o When the sender re-starts from idle, it waits until it has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * received ACKs for an entire flight of new data before making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * a cwnd adjustment decision. The original Vegas implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * assumed senders never went idle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/inet_diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <net/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "tcp_vegas.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int alpha = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int beta = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int gamma = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) module_param(alpha, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) MODULE_PARM_DESC(alpha, "lower bound of packets in network");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) module_param(beta, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) MODULE_PARM_DESC(beta, "upper bound of packets in network");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) module_param(gamma, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) MODULE_PARM_DESC(gamma, "limit on increase (scale by 2)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* There are several situations when we must "re-start" Vegas:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * o when a connection is established
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * o after an RTO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * o after fast recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * o when we send a packet and there is no outstanding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * unacknowledged data (restarting an idle connection)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * In these circumstances we cannot do a Vegas calculation at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * end of the first RTT, because any calculation we do is using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * stale info -- both the saved cwnd and congestion feedback are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * stale.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Instead we must wait until the completion of an RTT during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * which we actually receive ACKs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static void vegas_enable(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) const struct tcp_sock *tp = tcp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct vegas *vegas = inet_csk_ca(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Begin taking Vegas samples next time we send something. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) vegas->doing_vegas_now = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Set the beginning of the next send window. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) vegas->beg_snd_nxt = tp->snd_nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) vegas->cntRTT = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) vegas->minRTT = 0x7fffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Stop taking Vegas samples for now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static inline void vegas_disable(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct vegas *vegas = inet_csk_ca(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) vegas->doing_vegas_now = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void tcp_vegas_init(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct vegas *vegas = inet_csk_ca(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) vegas->baseRTT = 0x7fffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) vegas_enable(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) EXPORT_SYMBOL_GPL(tcp_vegas_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Do RTT sampling needed for Vegas.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * Basically we:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * o min-filter RTT samples from within an RTT to get the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * propagation delay + queuing delay (we are min-filtering to try to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * avoid the effects of delayed ACKs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * o min-filter RTT samples from a much longer window (forever for now)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * to find the propagation delay (baseRTT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void tcp_vegas_pkts_acked(struct sock *sk, const struct ack_sample *sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct vegas *vegas = inet_csk_ca(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u32 vrtt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (sample->rtt_us < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Never allow zero rtt or baseRTT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) vrtt = sample->rtt_us + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* Filter to find propagation delay: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (vrtt < vegas->baseRTT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) vegas->baseRTT = vrtt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* Find the min RTT during the last RTT to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * the current prop. delay + queuing delay:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) vegas->minRTT = min(vegas->minRTT, vrtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) vegas->cntRTT++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) EXPORT_SYMBOL_GPL(tcp_vegas_pkts_acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) void tcp_vegas_state(struct sock *sk, u8 ca_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (ca_state == TCP_CA_Open)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) vegas_enable(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) vegas_disable(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) EXPORT_SYMBOL_GPL(tcp_vegas_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * If the connection is idle and we are restarting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * then we don't want to do any Vegas calculations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * until we get fresh RTT samples. So when we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * restart, we reset our Vegas state to a clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * slate. After we get acks for this flight of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * packets, _then_ we can make Vegas calculations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (event == CA_EVENT_CWND_RESTART ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) event == CA_EVENT_TX_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) tcp_vegas_init(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) EXPORT_SYMBOL_GPL(tcp_vegas_cwnd_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static inline u32 tcp_vegas_ssthresh(struct tcp_sock *tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return min(tp->snd_ssthresh, tp->snd_cwnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 acked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct tcp_sock *tp = tcp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct vegas *vegas = inet_csk_ca(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!vegas->doing_vegas_now) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) tcp_reno_cong_avoid(sk, ack, acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (after(ack, vegas->beg_snd_nxt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* Do the Vegas once-per-RTT cwnd adjustment. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* Save the extent of the current window so we can use this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * at the end of the next RTT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) vegas->beg_snd_nxt = tp->snd_nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* We do the Vegas calculations only if we got enough RTT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * samples that we can be reasonably sure that we got
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * at least one RTT sample that wasn't from a delayed ACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * If we only had 2 samples total,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * then that means we're getting only 1 ACK per RTT, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * means they're almost certainly delayed ACKs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * If we have 3 samples, we should be OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (vegas->cntRTT <= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* We don't have enough RTT samples to do the Vegas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * calculation, so we'll behave like Reno.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) tcp_reno_cong_avoid(sk, ack, acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) u32 rtt, diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) u64 target_cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* We have enough RTT samples, so, using the Vegas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * algorithm, we determine if we should increase or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * decrease cwnd, and by how much.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Pluck out the RTT we are using for the Vegas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * calculations. This is the min RTT seen during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * last RTT. Taking the min filters out the effects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * of delayed ACKs, at the cost of noticing congestion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * a bit later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) rtt = vegas->minRTT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Calculate the cwnd we should have, if we weren't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * going too fast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * This is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * (actual rate in segments) * baseRTT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) target_cwnd = (u64)tp->snd_cwnd * vegas->baseRTT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) do_div(target_cwnd, rtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Calculate the difference between the window we had,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * and the window we would like to have. This quantity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * is the "Diff" from the Arizona Vegas papers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) diff = tp->snd_cwnd * (rtt-vegas->baseRTT) / vegas->baseRTT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (diff > gamma && tcp_in_slow_start(tp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Going too fast. Time to slow down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * and switch to congestion avoidance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* Set cwnd to match the actual rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * exactly:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * cwnd = (actual rate) * baseRTT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * Then we add 1 because the integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * truncation robs us of full link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * utilization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) tp->snd_cwnd = min(tp->snd_cwnd, (u32)target_cwnd+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) tp->snd_ssthresh = tcp_vegas_ssthresh(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) } else if (tcp_in_slow_start(tp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* Slow start. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) tcp_slow_start(tp, acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* Congestion avoidance. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Figure out where we would like cwnd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * to be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (diff > beta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* The old window was too fast, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * we slow down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) tp->snd_cwnd--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) tp->snd_ssthresh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) = tcp_vegas_ssthresh(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) } else if (diff < alpha) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* We don't have enough extra packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * in the network, so speed up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) tp->snd_cwnd++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Sending just as fast as we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * should be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (tp->snd_cwnd < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) tp->snd_cwnd = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) else if (tp->snd_cwnd > tp->snd_cwnd_clamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) tp->snd_cwnd = tp->snd_cwnd_clamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) tp->snd_ssthresh = tcp_current_ssthresh(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /* Wipe the slate clean for the next RTT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) vegas->cntRTT = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) vegas->minRTT = 0x7fffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Use normal slow start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) else if (tcp_in_slow_start(tp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) tcp_slow_start(tp, acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* Extract info for Tcp socket info provided via netlink. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) size_t tcp_vegas_get_info(struct sock *sk, u32 ext, int *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) union tcp_cc_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) const struct vegas *ca = inet_csk_ca(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) info->vegas.tcpv_enabled = ca->doing_vegas_now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) info->vegas.tcpv_rttcnt = ca->cntRTT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) info->vegas.tcpv_rtt = ca->baseRTT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) info->vegas.tcpv_minrtt = ca->minRTT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) *attr = INET_DIAG_VEGASINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return sizeof(struct tcpvegas_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) EXPORT_SYMBOL_GPL(tcp_vegas_get_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static struct tcp_congestion_ops tcp_vegas __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .init = tcp_vegas_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .ssthresh = tcp_reno_ssthresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) .undo_cwnd = tcp_reno_undo_cwnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .cong_avoid = tcp_vegas_cong_avoid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .pkts_acked = tcp_vegas_pkts_acked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .set_state = tcp_vegas_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) .cwnd_event = tcp_vegas_cwnd_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .get_info = tcp_vegas_get_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .name = "vegas",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int __init tcp_vegas_register(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) BUILD_BUG_ON(sizeof(struct vegas) > ICSK_CA_PRIV_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) tcp_register_congestion_control(&tcp_vegas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static void __exit tcp_vegas_unregister(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) tcp_unregister_congestion_control(&tcp_vegas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) module_init(tcp_vegas_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) module_exit(tcp_vegas_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) MODULE_AUTHOR("Stephen Hemminger");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) MODULE_DESCRIPTION("TCP Vegas");