1/*- 2 * Copyright (c) 2009-2010 3 * Swinburne University of Technology, Melbourne, Australia 4 * Copyright (c) 2010 Lawrence Stewart <lstewart@freebsd.org> 5 * Copyright (c) 2010-2011 The FreeBSD Foundation 6 * All rights reserved. 7 * 8 * This software was developed at the Centre for Advanced Internet 9 * Architectures, Swinburne University of Technology, by David Hayes and 10 * Lawrence Stewart, made possible in part by a grant from the Cisco University 11 * Research Program Fund at Community Foundation Silicon Valley. 12 * 13 * Portions of this software were developed at the Centre for Advanced Internet 14 * Architectures, Swinburne University of Technology, Melbourne, Australia by 15 * David Hayes under sponsorship from the FreeBSD Foundation. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39/* 40 * An implementation of the Vegas congestion control algorithm for FreeBSD, 41 * based on L. S. Brakmo and L. L. Peterson, "TCP Vegas: end to end congestion 42 * avoidance on a global internet", IEEE J. Sel. Areas Commun., vol. 13, no. 8, 43 * pp. 1465-1480, Oct. 1995. The original Vegas duplicate ack policy has not 44 * been implemented, since clock ticks are not as coarse as they were (i.e. 45 * 500ms) when Vegas was designed. Also, packets are timed once per RTT as in 46 * the original paper. 47 * 48 * Originally released as part of the NewTCP research project at Swinburne 49 * University of Technology's Centre for Advanced Internet Architectures, 50 * Melbourne, Australia, which was made possible in part by a grant from the 51 * Cisco University Research Program Fund at Community Foundation Silicon 52 * Valley. More details are available at: 53 * http://caia.swin.edu.au/urp/newtcp/ 54 */ 55 56#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 2009-2010 3 * Swinburne University of Technology, Melbourne, Australia 4 * Copyright (c) 2010 Lawrence Stewart <lstewart@freebsd.org> 5 * Copyright (c) 2010-2011 The FreeBSD Foundation 6 * All rights reserved. 7 * 8 * This software was developed at the Centre for Advanced Internet 9 * Architectures, Swinburne University of Technology, by David Hayes and 10 * Lawrence Stewart, made possible in part by a grant from the Cisco University 11 * Research Program Fund at Community Foundation Silicon Valley. 12 * 13 * Portions of this software were developed at the Centre for Advanced Internet 14 * Architectures, Swinburne University of Technology, Melbourne, Australia by 15 * David Hayes under sponsorship from the FreeBSD Foundation. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions 19 * are met: 20 * 1. Redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer. 22 * 2. Redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39/* 40 * An implementation of the Vegas congestion control algorithm for FreeBSD, 41 * based on L. S. Brakmo and L. L. Peterson, "TCP Vegas: end to end congestion 42 * avoidance on a global internet", IEEE J. Sel. Areas Commun., vol. 13, no. 8, 43 * pp. 1465-1480, Oct. 1995. The original Vegas duplicate ack policy has not 44 * been implemented, since clock ticks are not as coarse as they were (i.e. 45 * 500ms) when Vegas was designed. Also, packets are timed once per RTT as in 46 * the original paper. 47 * 48 * Originally released as part of the NewTCP research project at Swinburne 49 * University of Technology's Centre for Advanced Internet Architectures, 50 * Melbourne, Australia, which was made possible in part by a grant from the 51 * Cisco University Research Program Fund at Community Foundation Silicon 52 * Valley. More details are available at: 53 * http://caia.swin.edu.au/urp/newtcp/ 54 */ 55 56#include <sys/cdefs.h>
|
77#include <netinet/cc/cc_module.h> 78 79#include <netinet/khelp/h_ertt.h> 80 81#define CAST_PTR_INT(X) (*((int*)(X))) 82 83/* 84 * Private signal type for rate based congestion signal. 85 * See <netinet/cc.h> for appropriate bit-range to use for private signals. 86 */ 87#define CC_VEGAS_RATE 0x01000000 88 89static void vegas_ack_received(struct cc_var *ccv, uint16_t ack_type); 90static void vegas_cb_destroy(struct cc_var *ccv); 91static int vegas_cb_init(struct cc_var *ccv); 92static void vegas_cong_signal(struct cc_var *ccv, uint32_t signal_type); 93static void vegas_conn_init(struct cc_var *ccv); 94static int vegas_mod_init(void); 95 96struct vegas { 97 int slow_start_toggle; 98}; 99 100static int32_t ertt_id; 101 102static VNET_DEFINE(uint32_t, vegas_alpha) = 1; 103static VNET_DEFINE(uint32_t, vegas_beta) = 3; 104#define V_vegas_alpha VNET(vegas_alpha) 105#define V_vegas_beta VNET(vegas_beta) 106 107static MALLOC_DEFINE(M_VEGAS, "vegas data", 108 "Per connection data required for the Vegas congestion control algorithm"); 109 110struct cc_algo vegas_cc_algo = { 111 .name = "vegas", 112 .ack_received = vegas_ack_received, 113 .cb_destroy = vegas_cb_destroy, 114 .cb_init = vegas_cb_init, 115 .cong_signal = vegas_cong_signal, 116 .conn_init = vegas_conn_init, 117 .mod_init = vegas_mod_init 118}; 119 120/* 121 * The vegas window adjustment is done once every RTT, as indicated by the 122 * ERTT_NEW_MEASUREMENT flag. This flag is reset once the new measurment data 123 * has been used. 124 */ 125static void 126vegas_ack_received(struct cc_var *ccv, uint16_t ack_type) 127{ 128 struct ertt *e_t; 129 struct vegas *vegas_data; 130 long actual_tx_rate, expected_tx_rate, ndiff; 131 132 e_t = khelp_get_osd(CCV(ccv, osd), ertt_id); 133 vegas_data = ccv->cc_data; 134 135 if (e_t->flags & ERTT_NEW_MEASUREMENT) { /* Once per RTT. */ 136 if (e_t->minrtt && e_t->markedpkt_rtt) { 137 expected_tx_rate = e_t->marked_snd_cwnd / e_t->minrtt; 138 actual_tx_rate = e_t->bytes_tx_in_marked_rtt / 139 e_t->markedpkt_rtt; 140 ndiff = (expected_tx_rate - actual_tx_rate) * 141 e_t->minrtt / CCV(ccv, t_maxseg); 142 143 if (ndiff < V_vegas_alpha) { 144 if (CCV(ccv, snd_cwnd) <= 145 CCV(ccv, snd_ssthresh)) { 146 vegas_data->slow_start_toggle = 147 vegas_data->slow_start_toggle ? 148 0 : 1; 149 } else { 150 vegas_data->slow_start_toggle = 0; 151 CCV(ccv, snd_cwnd) = 152 min(CCV(ccv, snd_cwnd) + 153 CCV(ccv, t_maxseg), 154 TCP_MAXWIN << CCV(ccv, snd_scale)); 155 } 156 } else if (ndiff > V_vegas_beta) { 157 /* Rate-based congestion. */ 158 vegas_cong_signal(ccv, CC_VEGAS_RATE); 159 vegas_data->slow_start_toggle = 0; 160 } 161 } 162 e_t->flags &= ~ERTT_NEW_MEASUREMENT; 163 } 164 165 if (vegas_data->slow_start_toggle) 166 newreno_cc_algo.ack_received(ccv, ack_type); 167} 168 169static void 170vegas_cb_destroy(struct cc_var *ccv) 171{ 172 173 if (ccv->cc_data != NULL) 174 free(ccv->cc_data, M_VEGAS); 175} 176 177static int 178vegas_cb_init(struct cc_var *ccv) 179{ 180 struct vegas *vegas_data; 181 182 vegas_data = malloc(sizeof(struct vegas), M_VEGAS, M_NOWAIT); 183 184 if (vegas_data == NULL) 185 return (ENOMEM); 186 187 vegas_data->slow_start_toggle = 1; 188 ccv->cc_data = vegas_data; 189 190 return (0); 191} 192 193/* 194 * If congestion has been triggered triggered by the Vegas measured rates, it is 195 * handled here, otherwise it falls back to newreno's congestion handling. 196 */ 197static void 198vegas_cong_signal(struct cc_var *ccv, uint32_t signal_type) 199{ 200 struct vegas *vegas_data; 201 int presignalrecov; 202 203 vegas_data = ccv->cc_data; 204 205 if (IN_RECOVERY(CCV(ccv, t_flags))) 206 presignalrecov = 1; 207 else 208 presignalrecov = 0; 209 210 switch(signal_type) { 211 case CC_VEGAS_RATE: 212 if (!IN_RECOVERY(CCV(ccv, t_flags))) { 213 CCV(ccv, snd_cwnd) = max(2 * CCV(ccv, t_maxseg), 214 CCV(ccv, snd_cwnd) - CCV(ccv, t_maxseg)); 215 if (CCV(ccv, snd_cwnd) < CCV(ccv, snd_ssthresh)) 216 /* Exit slow start. */ 217 CCV(ccv, snd_ssthresh) = CCV(ccv, snd_cwnd); 218 } 219 break; 220 221 default: 222 newreno_cc_algo.cong_signal(ccv, signal_type); 223 } 224 225 if (IN_RECOVERY(CCV(ccv, t_flags)) && !presignalrecov) 226 vegas_data->slow_start_toggle = 227 (CCV(ccv, snd_cwnd) < CCV(ccv, snd_ssthresh)) ? 1 : 0; 228} 229 230static void 231vegas_conn_init(struct cc_var *ccv) 232{ 233 struct vegas *vegas_data; 234 235 vegas_data = ccv->cc_data; 236 vegas_data->slow_start_toggle = 1; 237} 238 239static int 240vegas_mod_init(void) 241{ 242 243 ertt_id = khelp_get_id("ertt"); 244 if (ertt_id <= 0) { 245 printf("%s: h_ertt module not found\n", __func__); 246 return (ENOENT); 247 } 248 249 vegas_cc_algo.after_idle = newreno_cc_algo.after_idle; 250 vegas_cc_algo.post_recovery = newreno_cc_algo.post_recovery; 251 252 return (0); 253} 254 255static int 256vegas_alpha_handler(SYSCTL_HANDLER_ARGS) 257{ 258 int error; 259 uint32_t new; 260 261 new = V_vegas_alpha; 262 error = sysctl_handle_int(oidp, &new, 0, req); 263 if (error == 0 && req->newptr != NULL) { 264 if (CAST_PTR_INT(req->newptr) < 1 || 265 CAST_PTR_INT(req->newptr) > V_vegas_beta) 266 error = EINVAL; 267 else 268 V_vegas_alpha = new; 269 } 270 271 return (error); 272} 273 274static int 275vegas_beta_handler(SYSCTL_HANDLER_ARGS) 276{ 277 int error; 278 uint32_t new; 279 280 new = V_vegas_beta; 281 error = sysctl_handle_int(oidp, &new, 0, req); 282 if (error == 0 && req->newptr != NULL) { 283 if (CAST_PTR_INT(req->newptr) < 1 || 284 CAST_PTR_INT(req->newptr) < V_vegas_alpha) 285 error = EINVAL; 286 else 287 V_vegas_beta = new; 288 } 289 290 return (error); 291} 292 293SYSCTL_DECL(_net_inet_tcp_cc_vegas); 294SYSCTL_NODE(_net_inet_tcp_cc, OID_AUTO, vegas, CTLFLAG_RW, NULL, 295 "Vegas related settings"); 296 297SYSCTL_PROC(_net_inet_tcp_cc_vegas, OID_AUTO, alpha, 298 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW, 299 &VNET_NAME(vegas_alpha), 1, &vegas_alpha_handler, "IU", 300 "vegas alpha, specified as number of \"buffers\" (0 < alpha < beta)"); 301 302SYSCTL_PROC(_net_inet_tcp_cc_vegas, OID_AUTO, beta, 303 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW, 304 &VNET_NAME(vegas_beta), 3, &vegas_beta_handler, "IU", 305 "vegas beta, specified as number of \"buffers\" (0 < alpha < beta)"); 306 307DECLARE_CC_MODULE(vegas, &vegas_cc_algo); 308MODULE_DEPEND(vegas, ertt, 1, 1, 1);
| 76#include <netinet/cc/cc_module.h> 77 78#include <netinet/khelp/h_ertt.h> 79 80#define CAST_PTR_INT(X) (*((int*)(X))) 81 82/* 83 * Private signal type for rate based congestion signal. 84 * See <netinet/cc.h> for appropriate bit-range to use for private signals. 85 */ 86#define CC_VEGAS_RATE 0x01000000 87 88static void vegas_ack_received(struct cc_var *ccv, uint16_t ack_type); 89static void vegas_cb_destroy(struct cc_var *ccv); 90static int vegas_cb_init(struct cc_var *ccv); 91static void vegas_cong_signal(struct cc_var *ccv, uint32_t signal_type); 92static void vegas_conn_init(struct cc_var *ccv); 93static int vegas_mod_init(void); 94 95struct vegas { 96 int slow_start_toggle; 97}; 98 99static int32_t ertt_id; 100 101static VNET_DEFINE(uint32_t, vegas_alpha) = 1; 102static VNET_DEFINE(uint32_t, vegas_beta) = 3; 103#define V_vegas_alpha VNET(vegas_alpha) 104#define V_vegas_beta VNET(vegas_beta) 105 106static MALLOC_DEFINE(M_VEGAS, "vegas data", 107 "Per connection data required for the Vegas congestion control algorithm"); 108 109struct cc_algo vegas_cc_algo = { 110 .name = "vegas", 111 .ack_received = vegas_ack_received, 112 .cb_destroy = vegas_cb_destroy, 113 .cb_init = vegas_cb_init, 114 .cong_signal = vegas_cong_signal, 115 .conn_init = vegas_conn_init, 116 .mod_init = vegas_mod_init 117}; 118 119/* 120 * The vegas window adjustment is done once every RTT, as indicated by the 121 * ERTT_NEW_MEASUREMENT flag. This flag is reset once the new measurment data 122 * has been used. 123 */ 124static void 125vegas_ack_received(struct cc_var *ccv, uint16_t ack_type) 126{ 127 struct ertt *e_t; 128 struct vegas *vegas_data; 129 long actual_tx_rate, expected_tx_rate, ndiff; 130 131 e_t = khelp_get_osd(CCV(ccv, osd), ertt_id); 132 vegas_data = ccv->cc_data; 133 134 if (e_t->flags & ERTT_NEW_MEASUREMENT) { /* Once per RTT. */ 135 if (e_t->minrtt && e_t->markedpkt_rtt) { 136 expected_tx_rate = e_t->marked_snd_cwnd / e_t->minrtt; 137 actual_tx_rate = e_t->bytes_tx_in_marked_rtt / 138 e_t->markedpkt_rtt; 139 ndiff = (expected_tx_rate - actual_tx_rate) * 140 e_t->minrtt / CCV(ccv, t_maxseg); 141 142 if (ndiff < V_vegas_alpha) { 143 if (CCV(ccv, snd_cwnd) <= 144 CCV(ccv, snd_ssthresh)) { 145 vegas_data->slow_start_toggle = 146 vegas_data->slow_start_toggle ? 147 0 : 1; 148 } else { 149 vegas_data->slow_start_toggle = 0; 150 CCV(ccv, snd_cwnd) = 151 min(CCV(ccv, snd_cwnd) + 152 CCV(ccv, t_maxseg), 153 TCP_MAXWIN << CCV(ccv, snd_scale)); 154 } 155 } else if (ndiff > V_vegas_beta) { 156 /* Rate-based congestion. */ 157 vegas_cong_signal(ccv, CC_VEGAS_RATE); 158 vegas_data->slow_start_toggle = 0; 159 } 160 } 161 e_t->flags &= ~ERTT_NEW_MEASUREMENT; 162 } 163 164 if (vegas_data->slow_start_toggle) 165 newreno_cc_algo.ack_received(ccv, ack_type); 166} 167 168static void 169vegas_cb_destroy(struct cc_var *ccv) 170{ 171 172 if (ccv->cc_data != NULL) 173 free(ccv->cc_data, M_VEGAS); 174} 175 176static int 177vegas_cb_init(struct cc_var *ccv) 178{ 179 struct vegas *vegas_data; 180 181 vegas_data = malloc(sizeof(struct vegas), M_VEGAS, M_NOWAIT); 182 183 if (vegas_data == NULL) 184 return (ENOMEM); 185 186 vegas_data->slow_start_toggle = 1; 187 ccv->cc_data = vegas_data; 188 189 return (0); 190} 191 192/* 193 * If congestion has been triggered triggered by the Vegas measured rates, it is 194 * handled here, otherwise it falls back to newreno's congestion handling. 195 */ 196static void 197vegas_cong_signal(struct cc_var *ccv, uint32_t signal_type) 198{ 199 struct vegas *vegas_data; 200 int presignalrecov; 201 202 vegas_data = ccv->cc_data; 203 204 if (IN_RECOVERY(CCV(ccv, t_flags))) 205 presignalrecov = 1; 206 else 207 presignalrecov = 0; 208 209 switch(signal_type) { 210 case CC_VEGAS_RATE: 211 if (!IN_RECOVERY(CCV(ccv, t_flags))) { 212 CCV(ccv, snd_cwnd) = max(2 * CCV(ccv, t_maxseg), 213 CCV(ccv, snd_cwnd) - CCV(ccv, t_maxseg)); 214 if (CCV(ccv, snd_cwnd) < CCV(ccv, snd_ssthresh)) 215 /* Exit slow start. */ 216 CCV(ccv, snd_ssthresh) = CCV(ccv, snd_cwnd); 217 } 218 break; 219 220 default: 221 newreno_cc_algo.cong_signal(ccv, signal_type); 222 } 223 224 if (IN_RECOVERY(CCV(ccv, t_flags)) && !presignalrecov) 225 vegas_data->slow_start_toggle = 226 (CCV(ccv, snd_cwnd) < CCV(ccv, snd_ssthresh)) ? 1 : 0; 227} 228 229static void 230vegas_conn_init(struct cc_var *ccv) 231{ 232 struct vegas *vegas_data; 233 234 vegas_data = ccv->cc_data; 235 vegas_data->slow_start_toggle = 1; 236} 237 238static int 239vegas_mod_init(void) 240{ 241 242 ertt_id = khelp_get_id("ertt"); 243 if (ertt_id <= 0) { 244 printf("%s: h_ertt module not found\n", __func__); 245 return (ENOENT); 246 } 247 248 vegas_cc_algo.after_idle = newreno_cc_algo.after_idle; 249 vegas_cc_algo.post_recovery = newreno_cc_algo.post_recovery; 250 251 return (0); 252} 253 254static int 255vegas_alpha_handler(SYSCTL_HANDLER_ARGS) 256{ 257 int error; 258 uint32_t new; 259 260 new = V_vegas_alpha; 261 error = sysctl_handle_int(oidp, &new, 0, req); 262 if (error == 0 && req->newptr != NULL) { 263 if (CAST_PTR_INT(req->newptr) < 1 || 264 CAST_PTR_INT(req->newptr) > V_vegas_beta) 265 error = EINVAL; 266 else 267 V_vegas_alpha = new; 268 } 269 270 return (error); 271} 272 273static int 274vegas_beta_handler(SYSCTL_HANDLER_ARGS) 275{ 276 int error; 277 uint32_t new; 278 279 new = V_vegas_beta; 280 error = sysctl_handle_int(oidp, &new, 0, req); 281 if (error == 0 && req->newptr != NULL) { 282 if (CAST_PTR_INT(req->newptr) < 1 || 283 CAST_PTR_INT(req->newptr) < V_vegas_alpha) 284 error = EINVAL; 285 else 286 V_vegas_beta = new; 287 } 288 289 return (error); 290} 291 292SYSCTL_DECL(_net_inet_tcp_cc_vegas); 293SYSCTL_NODE(_net_inet_tcp_cc, OID_AUTO, vegas, CTLFLAG_RW, NULL, 294 "Vegas related settings"); 295 296SYSCTL_PROC(_net_inet_tcp_cc_vegas, OID_AUTO, alpha, 297 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW, 298 &VNET_NAME(vegas_alpha), 1, &vegas_alpha_handler, "IU", 299 "vegas alpha, specified as number of \"buffers\" (0 < alpha < beta)"); 300 301SYSCTL_PROC(_net_inet_tcp_cc_vegas, OID_AUTO, beta, 302 CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW, 303 &VNET_NAME(vegas_beta), 3, &vegas_beta_handler, "IU", 304 "vegas beta, specified as number of \"buffers\" (0 < alpha < beta)"); 305 306DECLARE_CC_MODULE(vegas, &vegas_cc_algo); 307MODULE_DEPEND(vegas, ertt, 1, 1, 1);
|