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