tcp_yeah.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <linux/mm.h>
  2. #include <linux/module.h>
  3. #include <linux/skbuff.h>
  4. #include <linux/inet_diag.h>
  5. #include <net/tcp.h>
  6. /* Vegas variables */
  7. struct vegas {
  8. u32 beg_snd_nxt; /* right edge during last RTT */
  9. u32 beg_snd_una; /* left edge during last RTT */
  10. u32 beg_snd_cwnd; /* saves the size of the cwnd */
  11. u8 doing_vegas_now;/* if true, do vegas for this RTT */
  12. u16 cntRTT; /* # of RTTs measured within last RTT */
  13. u32 minRTT; /* min of RTTs measured within last RTT (in usec) */
  14. u32 baseRTT; /* the min of all Vegas RTT measurements seen (in usec) */
  15. };
  16. /* There are several situations when we must "re-start" Vegas:
  17. *
  18. * o when a connection is established
  19. * o after an RTO
  20. * o after fast recovery
  21. * o when we send a packet and there is no outstanding
  22. * unacknowledged data (restarting an idle connection)
  23. *
  24. * In these circumstances we cannot do a Vegas calculation at the
  25. * end of the first RTT, because any calculation we do is using
  26. * stale info -- both the saved cwnd and congestion feedback are
  27. * stale.
  28. *
  29. * Instead we must wait until the completion of an RTT during
  30. * which we actually receive ACKs.
  31. */
  32. static inline void vegas_enable(struct sock *sk)
  33. {
  34. const struct tcp_sock *tp = tcp_sk(sk);
  35. struct vegas *vegas = inet_csk_ca(sk);
  36. /* Begin taking Vegas samples next time we send something. */
  37. vegas->doing_vegas_now = 1;
  38. /* Set the beginning of the next send window. */
  39. vegas->beg_snd_nxt = tp->snd_nxt;
  40. vegas->cntRTT = 0;
  41. vegas->minRTT = 0x7fffffff;
  42. }
  43. /* Stop taking Vegas samples for now. */
  44. static inline void vegas_disable(struct sock *sk)
  45. {
  46. struct vegas *vegas = inet_csk_ca(sk);
  47. vegas->doing_vegas_now = 0;
  48. }
  49. static void tcp_vegas_init(struct sock *sk)
  50. {
  51. struct vegas *vegas = inet_csk_ca(sk);
  52. vegas->baseRTT = 0x7fffffff;
  53. vegas_enable(sk);
  54. }
  55. static void tcp_vegas_state(struct sock *sk, u8 ca_state)
  56. {
  57. if (ca_state == TCP_CA_Open)
  58. vegas_enable(sk);
  59. else
  60. vegas_disable(sk);
  61. }
  62. /* Do RTT sampling needed for Vegas.
  63. * Basically we:
  64. * o min-filter RTT samples from within an RTT to get the current
  65. * propagation delay + queuing delay (we are min-filtering to try to
  66. * avoid the effects of delayed ACKs)
  67. * o min-filter RTT samples from a much longer window (forever for now)
  68. * to find the propagation delay (baseRTT)
  69. */
  70. static void tcp_vegas_rtt_calc(struct sock *sk, u32 usrtt)
  71. {
  72. struct vegas *vegas = inet_csk_ca(sk);
  73. u32 vrtt = usrtt + 1; /* Never allow zero rtt or baseRTT */
  74. /* Filter to find propagation delay: */
  75. if (vrtt < vegas->baseRTT)
  76. vegas->baseRTT = vrtt;
  77. /* Find the min RTT during the last RTT to find
  78. * the current prop. delay + queuing delay:
  79. */
  80. vegas->minRTT = min(vegas->minRTT, vrtt);
  81. vegas->cntRTT++;
  82. }
  83. /*
  84. * If the connection is idle and we are restarting,
  85. * then we don't want to do any Vegas calculations
  86. * until we get fresh RTT samples. So when we
  87. * restart, we reset our Vegas state to a clean
  88. * slate. After we get acks for this flight of
  89. * packets, _then_ we can make Vegas calculations
  90. * again.
  91. */
  92. static void tcp_vegas_cwnd_event(struct sock *sk, enum tcp_ca_event event)
  93. {
  94. if (event == CA_EVENT_CWND_RESTART ||
  95. event == CA_EVENT_TX_START)
  96. tcp_vegas_init(sk);
  97. }
  98. /* Extract info for Tcp socket info provided via netlink. */
  99. static void tcp_vegas_get_info(struct sock *sk, u32 ext,
  100. struct sk_buff *skb)
  101. {
  102. const struct vegas *ca = inet_csk_ca(sk);
  103. if (ext & (1 << (INET_DIAG_VEGASINFO - 1))) {
  104. struct tcpvegas_info *info;
  105. info = RTA_DATA(__RTA_PUT(skb, INET_DIAG_VEGASINFO,
  106. sizeof(*info)));
  107. info->tcpv_enabled = ca->doing_vegas_now;
  108. info->tcpv_rttcnt = ca->cntRTT;
  109. info->tcpv_rtt = ca->baseRTT;
  110. info->tcpv_minrtt = ca->minRTT;
  111. rtattr_failure: ;
  112. }
  113. }