From owner-svn-src-all@FreeBSD.ORG Sat May 28 08:32:17 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9613F106564A; Sat, 28 May 2011 08:32:17 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7C8A08FC0A; Sat, 28 May 2011 08:32:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p4S8WHSE075586; Sat, 28 May 2011 08:32:17 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p4S8WHGc075583; Sat, 28 May 2011 08:32:17 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201105280832.p4S8WHGc075583@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 28 May 2011 08:32:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222412 - in stable/8/sys: modules/cc modules/cc/cc_hd netinet/cc X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2011 08:32:17 -0000 Author: lstewart Date: Sat May 28 08:32:17 2011 New Revision: 222412 URL: http://svn.freebsd.org/changeset/base/222412 Log: MFC 218153: Import a clean-room implementation of the Hamilton-Delay (HD) congestion control algorithm based on the paper "A strategy for fair coexistence of loss and delay-based congestion control algorithms" by Budzisz, Stanojevic, Shorten and Baker. It is implemented as a kernel module compatible with the recently committed modular congestion control framework. HD uses a probabilistic approach to reacting to delay-based congestion. The probability of reducing cwnd is zero when the queuing delay is very small, increasing to a maximum at a set threshold, then back down to zero again when the queuing delay is high. Normal operation keeps the queuing delay below the set threshold. However, since loss-based congestion control algorithms push the queuing delay high when probing for bandwidth, having the probability of reducing cwnd drop back to zero for high delays allows HD to compete with loss-based algorithms. In collaboration with: David Hayes and Grenville Armitage Sponsored by: FreeBSD Foundation Reviewed by: bz and others along the way Added: stable/8/sys/modules/cc/cc_hd/ - copied from r218153, head/sys/modules/cc/cc_hd/ stable/8/sys/netinet/cc/cc_hd.c - copied unchanged from r218153, head/sys/netinet/cc/cc_hd.c Modified: stable/8/sys/modules/cc/Makefile Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/modules/cc/Makefile ============================================================================== --- stable/8/sys/modules/cc/Makefile Sat May 28 08:28:37 2011 (r222411) +++ stable/8/sys/modules/cc/Makefile Sat May 28 08:32:17 2011 (r222412) @@ -1,6 +1,7 @@ # $FreeBSD$ SUBDIR= cc_cubic \ + cc_hd \ cc_htcp \ cc_vegas Copied: stable/8/sys/netinet/cc/cc_hd.c (from r218153, head/sys/netinet/cc/cc_hd.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/8/sys/netinet/cc/cc_hd.c Sat May 28 08:32:17 2011 (r222412, copy of r218153, head/sys/netinet/cc/cc_hd.c) @@ -0,0 +1,254 @@ +/*- + * Copyright (c) 2009-2010 + * Swinburne University of Technology, Melbourne, Australia + * Copyright (c) 2010 Lawrence Stewart + * Copyright (c) 2010-2011 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University, by David Hayes and Lawrence Stewart, + * made possible in part by a grant from the Cisco University Research Program + * Fund at Community Foundation Silicon Valley. + * + * Portions of this software were developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, Melbourne, Australia by + * David Hayes under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * An implementation of the Hamilton Institute's delay-based congestion control + * algorithm for FreeBSD, based on "A strategy for fair coexistence of loss and + * delay-based congestion control algorithms," by L. Budzisz, R. Stanojevic, R. + * Shorten, and F. Baker, IEEE Commun. Lett., vol. 13, no. 7, pp. 555--557, Jul. + * 2009. + * + * Originally released as part of the NewTCP research project at Swinburne + * University's Centre for Advanced Internet Architectures, Melbourne, + * Australia, which was made possible in part by a grant from the Cisco + * University Research Program Fund at Community Foundation Silicon Valley. More + * details are available at: + * http://caia.swin.edu.au/urp/newtcp/ + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#define CAST_PTR_INT(X) (*((int*)(X))) + +/* Largest possible number returned by random(). */ +#define RANDOM_MAX INT_MAX + +static void hd_ack_received(struct cc_var *ccv, uint16_t ack_type); +static int hd_mod_init(void); + +static int ertt_id; + +static VNET_DEFINE(uint32_t, hd_qthresh) = 20; +static VNET_DEFINE(uint32_t, hd_qmin) = 5; +static VNET_DEFINE(uint32_t, hd_pmax) = 5; +#define V_hd_qthresh VNET(hd_qthresh) +#define V_hd_qmin VNET(hd_qmin) +#define V_hd_pmax VNET(hd_pmax) + +struct cc_algo hd_cc_algo = { + .name = "hd", + .ack_received = hd_ack_received, + .mod_init = hd_mod_init +}; + +/* + * Hamilton backoff function. Returns 1 if we should backoff or 0 otherwise. + */ +static __inline int +should_backoff(int qdly, int maxqdly) +{ + unsigned long p; + + if (qdly < V_hd_qthresh) { + p = (((RANDOM_MAX / 100) * V_hd_pmax) / + (V_hd_qthresh - V_hd_qmin)) * (qdly - V_hd_qmin); + } else { + if (qdly > V_hd_qthresh) + p = (((RANDOM_MAX / 100) * V_hd_pmax) / + (maxqdly - V_hd_qthresh)) * (maxqdly - qdly); + else + p = (RANDOM_MAX / 100) * V_hd_pmax; + } + + return (random() < p); +} + +/* + * If the ack type is CC_ACK, and the inferred queueing delay is greater than + * the Qmin threshold, cwnd is reduced probabilistically. When backing off due + * to delay, HD behaves like NewReno when an ECN signal is received. HD behaves + * as NewReno in all other circumstances. + */ +static void +hd_ack_received(struct cc_var *ccv, uint16_t ack_type) +{ + struct ertt *e_t; + int qdly; + + if (ack_type == CC_ACK) { + e_t = khelp_get_osd(CCV(ccv, osd), ertt_id); + + if (e_t->rtt && e_t->minrtt && V_hd_qthresh > 0) { + qdly = e_t->rtt - e_t->minrtt; + + if (qdly > V_hd_qmin && + !IN_RECOVERY(CCV(ccv, t_flags))) { + /* Probabilistic backoff of cwnd. */ + if (should_backoff(qdly, + e_t->maxrtt - e_t->minrtt)) { + /* + * Update cwnd and ssthresh update to + * half cwnd and behave like an ECN (ie + * not a packet loss). + */ + newreno_cc_algo.cong_signal(ccv, + CC_ECN); + return; + } + } + } + } + newreno_cc_algo.ack_received(ccv, ack_type); /* As for NewReno. */ +} + +static int +hd_mod_init(void) +{ + + ertt_id = khelp_get_id("ertt"); + if (ertt_id <= 0) { + printf("%s: h_ertt module not found\n", __func__); + return (ENOENT); + } + + hd_cc_algo.after_idle = newreno_cc_algo.after_idle; + hd_cc_algo.cong_signal = newreno_cc_algo.cong_signal; + hd_cc_algo.post_recovery = newreno_cc_algo.post_recovery; + + return (0); +} + +static int +hd_pmax_handler(SYSCTL_HANDLER_ARGS) +{ + int error; + uint32_t new; + + new = V_hd_pmax; + error = sysctl_handle_int(oidp, &new, 0, req); + if (error == 0 && req->newptr != NULL) { + if (CAST_PTR_INT(req->newptr) == 0 || + CAST_PTR_INT(req->newptr) > 100) + error = EINVAL; + else + V_hd_pmax = new; + } + + return (error); +} + +static int +hd_qmin_handler(SYSCTL_HANDLER_ARGS) +{ + int error; + uint32_t new; + + new = V_hd_qmin; + error = sysctl_handle_int(oidp, &new, 0, req); + if (error == 0 && req->newptr != NULL) { + if (CAST_PTR_INT(req->newptr) > V_hd_qthresh) + error = EINVAL; + else + V_hd_qmin = new; + } + + return (error); +} + +static int +hd_qthresh_handler(SYSCTL_HANDLER_ARGS) +{ + int error; + uint32_t new; + + new = V_hd_qthresh; + error = sysctl_handle_int(oidp, &new, 0, req); + if (error == 0 && req->newptr != NULL) { + if (CAST_PTR_INT(req->newptr) < 1 || + CAST_PTR_INT(req->newptr) < V_hd_qmin) + error = EINVAL; + else + V_hd_qthresh = new; + } + + return (error); +} + +SYSCTL_DECL(_net_inet_tcp_cc_hd); +SYSCTL_NODE(_net_inet_tcp_cc, OID_AUTO, hd, CTLFLAG_RW, NULL, + "Hamilton delay-based congestion control related settings"); + +SYSCTL_VNET_PROC(_net_inet_tcp_cc_hd, OID_AUTO, queue_threshold, + CTLTYPE_UINT|CTLFLAG_RW, &VNET_NAME(hd_qthresh), 20, &hd_qthresh_handler, + "IU", "queueing congestion threshold (qth) in ticks"); + +SYSCTL_VNET_PROC(_net_inet_tcp_cc_hd, OID_AUTO, pmax, + CTLTYPE_UINT|CTLFLAG_RW, &VNET_NAME(hd_pmax), 5, &hd_pmax_handler, + "IU", "per packet maximum backoff probability as a percentage"); + +SYSCTL_VNET_PROC(_net_inet_tcp_cc_hd, OID_AUTO, queue_min, + CTLTYPE_UINT|CTLFLAG_RW, &VNET_NAME(hd_qmin), 5, &hd_qmin_handler, + "IU", "minimum queueing delay threshold (qmin) in ticks"); + +DECLARE_CC_MODULE(hd, &hd_cc_algo); +MODULE_DEPEND(hd, ertt, 1, 1, 1);