From patchwork Fri Apr 27 12:20:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Scheurich X-Patchwork-Id: 905707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ericsson.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.com header.i=@ericsson.com header.b="I+L0o31X"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.com header.i=@ericsson.com header.b="Qp09DbUp"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40XY2b23Xkz9s02 for ; Fri, 27 Apr 2018 22:21:42 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DDA828DC; Fri, 27 Apr 2018 12:20:56 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 0054489F for ; Fri, 27 Apr 2018 12:20:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from sessmg22.ericsson.net (sessmg22.ericsson.net [193.180.251.58]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2BF0CF8 for ; Fri, 27 Apr 2018 12:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1524831651; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qOuUQGyu1kEUblWhDiP04bAfzTZeoQRsdsqLb6z1MUA=; b=I+L0o31XgtBj9Cc4emqaL5w7R8ox3lsQ/RuN/L4HzZpKW9dd9Slr4QW1swUUbrW/ 1RkD+lbY5BpKm5Sj4v9ASFCj59HSjWwOJyFAXgsjX+XAuZrMCzmBpDvl04Q6BXtY z/v7k/ARaLFJ+BLiORsUtVNvYIFBtmPZe/mHYja+bDk=; X-AuditID: c1b4fb3a-d4dff7000000729c-63-5ae315a34390 Received: from ESESSHC020.ericsson.se (Unknown_Domain [153.88.183.78]) by sessmg22.ericsson.net (Symantec Mail Security) with SMTP id F6.8D.29340.3A513EA5; Fri, 27 Apr 2018 14:20:51 +0200 (CEST) Received: from ESESSMR501.ericsson.se (153.88.183.108) by ESESSHC020.ericsson.se (153.88.183.78) with Microsoft SMTP Server (TLS) id 14.3.382.0; Fri, 27 Apr 2018 14:20:50 +0200 Received: from ESESBMB501.ericsson.se (153.88.183.168) by ESESSMR501.ericsson.se (153.88.183.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 27 Apr 2018 14:20:50 +0200 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB501.ericsson.se (153.88.183.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3 via Frontend Transport; Fri, 27 Apr 2018 14:20:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=sq9G6w2hGNbo7zCOeldgmWBTqBuU+lUB0iEllIy8PtA=; b=Qp09DbUp0ZNxTCpAoevTM9tMA1fTRA1ECXXO5hBqYbB5Gco4RDhhC4Qrr2drU8l4L9O3BFn1AzUG1iIikmMdj6YcxNVlnaELJPpprNYrO6siuUu+049M0GgWNWYAaV+CjKqvTIOCJosXTm37pAZN7acFV6QBdhYpaFuNwWbb27c= Received: from ubuntu.eed.ericsson.se (129.192.10.2) by AM3PR07MB0646.eurprd07.prod.outlook.com (2a01:111:e400:8837::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.735.5; Fri, 27 Apr 2018 12:20:48 +0000 From: Jan Scheurich To: Date: Fri, 27 Apr 2018 14:20:33 +0200 Message-ID: <1524831634-7955-3-git-send-email-jan.scheurich@ericsson.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524831634-7955-1-git-send-email-jan.scheurich@ericsson.com> References: <1524831634-7955-1-git-send-email-jan.scheurich@ericsson.com> MIME-Version: 1.0 X-Originating-IP: [129.192.10.2] X-ClientProxiedBy: HE1PR02CA0117.eurprd02.prod.outlook.com (2603:10a6:7:29::46) To AM3PR07MB0646.eurprd07.prod.outlook.com (2a01:111:e400:8837::20) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM3PR07MB0646; X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB0646; 3:/gPfGT2tgAWt/58eSQjeY3zABPzE2/zPUIzWOOQRzLZB95Tc4VjJZqELX2wzY984vH6pV17rqBOrnYrBvz3lP3q7puVQIFuipyTJd75dAk4EGJcy0C3s+/hQa7eMGYQcm3UHfAyVSvWuBihVqQBqX/N1+QltmhCHIERMPCYrTTDLxgt8P1tj/E345uxoAKtUafBSkuuEhIOcVcDWzREJ2jhtZ7CLPE90Ki3PY2/2ZXSjiUFFfFpFFPsPwBKiLNDf; 25:ux42Fv3c9q/r44zsbzfDQNKaiKPgNcJ0V/Jk0tMyjDUUD4J1QORRFOuW0BusPx3RvCMbojvnyDSy7tWfjYfXM2bx8L8Y9ZsLXM/W2LVDVtffzTOSqDQMwuaj1kVCeAFnm6IqBsWOZ9MydJgjZC0HZ9CgfxfGjMedvPTkGP+nPGFZXkSutJ3kkIPuJL4lYigy+qxVpMq1l33QKAt9b+fGJRHtfC8vwtsgPvj+4WNAwizrTtBeGV+wMoG2Mm+nLAhrPD7+P9imKL1d1u/00NUGV2+ylK8MS91iYEdDVmkD6jQXOR0Htz6E6mAUoW2EjE52pQ1EtsA77R4xxR4KkLQd7KYsHfLQdNQ7SW1H6ZJrBiU=; 31:n7qIABsIPaJWVnwiFzc4Wo1tgvgN7sMa0MviDPgGBlwQe9BwS4k5QquFVyFUxMjEE/DO+Y6+YovKosimpDwk0/IVSr3P4jQM2HU1+W1w0IydCAix7hTRpb+Pxksw0QX3LjSXyvtcubjZV3Z8rjY7aiTtOC2VqZzArZ3DvXUWs7TT20IZzrR+OjGV0vyTuwk+xqRAFA89BOevwreJPjJIUQIr+SQ+UFey84PL84zCBuE= X-MS-TrafficTypeDiagnostic: AM3PR07MB0646: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jan.scheurich@ericsson.com; X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB0646; 20:nB5LAy81bDOxcePaJA/YISI95GNRiz7slZkNSMHkVdB2svhbebITuXgGDeMAZO8JKCFzh+Fh0bQ9KeTxMMypH0s0WnFfSqFMxkO5Bjw5a0XWAGMOHJXANpevexAASxaFQPyr6qVA2c/om1CXTodoEaG0gh0m4tARikKhuwJXULsq7K7W2JXtO6Mcvrg0NQsGTZXZ2DdSQtFdXHyPwHOIdc+453f9AiVTa+RjdPrbQyNRww0mx+r0xwBAJid6NHLXh72aM8WMzDmHGdbtKLR+DYoJAx5YIGWARena1tBisxKF38522lQU6y7hrLDFW8H6PpsngYqBkQeKZcd64BUpnyOCZqNmAr6tfK6xcy0ojY5gqBpTkOBoxKaI8zdcDBjgToOFIxXCABlEdAzKvYi6Tjaf9Thtk6VaL4Xt1XoZ6tE8faw5paN3ebUPQdKF6hqiiU16oJnUkIHDKNkbh7toRD64ZMzInLjezWOpPtJxGG3Km48ZQw2bBthBP6s/xTB8; 4:1ZCk1UDf7lJuon6jjc5NmAk0Dva2na7/SoNAbF3B/Fb6jd6CKMd92TiEcMkG6i4EbDtncctIadKFkaUkD+i0O2gf/l/foYHQT21ZOgCk6ATCNxhzjjKY0PmQBcqFASnCWsr7+VMno0i82E7G42xLqY8ucM81a0+I0l5Dz76ON3dXRGEv10QMF9AVsaYmGjnutVIgbQQP9S3H1R2juKQDqQUVLVBN9y1EuUF4sNOJkgmy+wbm0BU36/RuOxXre3NqgPJ/+D4nqfohVRDQNbA7tRKXXrpQarUs29TTYyNK7Jo2F0OSdVdrFmHUxRRjI1OZ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(37575265505322); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231232)(944501410)(52105095)(3002001)(93006095)(93001095)(6041310)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM3PR07MB0646; BCL:0; PCL:0; RULEID:; SRVR:AM3PR07MB0646; X-Forefront-PRVS: 0655F9F006 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(39860400002)(366004)(396003)(39380400002)(199004)(189003)(11346002)(16586007)(486006)(44832011)(2616005)(36756003)(476003)(316002)(51416003)(26005)(52116002)(956004)(446003)(76176011)(50466002)(47776003)(48376002)(16526019)(2906002)(105586002)(186003)(2361001)(66066001)(2351001)(25786009)(106356001)(478600001)(3846002)(86362001)(8936002)(68736007)(81166006)(81156014)(50226002)(305945005)(6116002)(97736004)(8676002)(59450400001)(7736002)(107886003)(6666003)(6916009)(6306002)(386003)(6506007)(4326008)(53936002)(5660300001)(6512007)(6486002)(966005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR07MB0646; H:ubuntu.eed.ericsson.se; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM3PR07MB0646; 23:Q8nZg+6CUXqOtrKoNy3nJYObLDtpMVh1DfgD7eiYj?= KjwiqKHlXiWMkTfyOqVL+ZCmEe/cAlc3G5Dvebwsfna1j5JtASkxuO+kwqa5TuUwsE8DBdi5cMs+vjuvg2iI2vVZUZEWK7KsS8BYfk8mj5Vov61MuRqcliPo0sYATMkWONjTbs62qjYEzPqnlflUfBa3kWQEFXlbgJZC01s8EX8BKrmDR//j50dWVDTQKJH43USuATNPUJ86HMrQGvsLwy/EAfoT/f4Nz9VEBaE7G0P6rXw++XJNpg6IucjgNbYPCjTmQXXdG1BZ4xfDbW/Rb6VunmO5o365899WlHSJIqP50a1r2cwDUXE3wwA6gQ9TTpbiTtOmiyFO/sAUwNBkjLUReM49DnUBY2us6Ce7c20WnMlMoBTA3uEPuwnRYKRMtsHeBRiRm2rRzq3/U/iT/JJXG+9AQ0byyT7Cm/5rM6Hn/B7QbBgqRfs6+abF5nfIZ3OSsKsVFnACeUzhWweetjKDhgZX2cT0grmqUjBUTgO9bGwlTM7Oa24gRqsXd7tRxX4KBIlJSBLoDg5ZAx0T0y0ALe8Yb2lmlNRH5m18YbKnUxiwt9vNzGlABFlFmDPT2ZXJuyTvjHXr5znd5RH/r2DD79Y5d/UpAHXN2cqwiUepgHHH8BgXY4xXl8kjjNlq2sRj9MQulg0mMHoMo/zIjI6ZRQHVfKyGtExYGVpF6HDGMv0I3M3J4WnUkKr0ZHKmco9MDB4P2Jn7aUBazSFwRuciHp1qgI2vFHp4ylzEjk7IJOXNtBYvPsRXOzcMfThjERB4OJyfF4tckvBj2T/Xox5Wmv4+2t4A1F4Y+Q4c/zTKycbfEVZzfeau04FNOxN7ncAA+gKlWW0wYORmNFah7Rfuq3ZTNrsjeXve1v8f7NRwAxlQHLnsm/PJi5OvU17/hzPKC66T4rVPqjylGoXSHpchiW/rjF4TnRJPr/Hk5tRw+lRofxZaP1fSpoKcwHeQBLdszRXdYoVBUx1yLhNv0PwbJetuokasL134jRUyhN2rsd5+9AaceAsfUkniRGBHw2+nJrm5P7E43lp9kH6UES/bX5aiju6AfonvDruYUdbEAhnziairSdkeF7inW3Ea/aSbglMJcLlUbGBiBxjyVyKAw0Be523287l2mSar+ujqL5yfLoTMYa2SBHpfV5reGRVo0FbFBwkyD1vo9gb9FtFhMwaaKpIAZevGmCU/gNUXwkm9YPwBkmqmsB8oHJic9xy9o7e/h5jcxCJ2gapmnLSFf5tD7vKbdqMEmItXsYqqrbiMKPRUPEZ/LbyUynfy0Y= X-Microsoft-Antispam-Message-Info: 4Q6WqyShTN0BETcyBVEeFPeEu2SXTnbPBaPwBhtjHLfWrrrinGuQpw09ki1EZdzHbKleO6vIeiiGeCcgRCHIByQetC+BC338/K433jBrc6yBgrYfDe3f7/GSGjJgwGEpgzsMztjZktTWxCKFw7IrIBufp0/Woyo4K4rs5xSe9Sawgst8mmkO3hgEYkrwgL15 X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB0646; 6:l4oXiGAWfx8aFV7Jv9u0IF0Wzub6PrbEDOLR4TQKRktT9iVvulWiYgCkQsf6ZsZakUKT4PJqyAFMJlr3oovUDBJK2jQL+jSI5nVqJhcMyGPm6l+XUbhDil6jTFdaWQADmIxxnIpfg3smL9gkLCf8QhA5VAyzTg+wKpbSewq2AdAUmdigLySSSXAGTpEdnAfFggZ1CoLuw858r3UhvLCPdlO1tps7qFvmBSMwHR10j0XqjucbJlBZLJX9qm5rZb27zFPSqKf42TtMoZIq/Pdz7Oidi7DGKcWGVfDG+jOjKQEaCiGFIQl04n0OM4bK0ywDdvsrpP+dq6jraydoN9XWnxCin5h7o1Gvyy1wRgcPRld22OWd2HgWbFEUZcEPu/A5m7QvRhlnY0F7EGIocvAty9vfXZytex8s2L2IWUt37jI4dBG/ayaN1/aTV3c/h7U2h0MmCWLwxf8znxnVJ9rmAA==; 5:OMebw6J9fek4/YlGsb12JKIGeuXW7/JCMe5vnWkxw47UYDFPT9ej/DgaoEy1/VxXoQL/6pimDzTMytMRq/v9LvO5d/eJImpzQcQ/XrGteGZE59ZjZ63KFixvR/G/kTGPYnHdTG5DWiOxvH4zFGZsyMWccP012kFqu6a51Ulzzgo=; 24:5j5OtwOpXRw+s69cagpiKZH+6Gt/fnOZ7fId8omReRR/sJRKD5GbfrebSOF/am2oO5c93bbRtELgqUepYkNfjX30IDKVElkrg4W1MPWKo/k= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM3PR07MB0646; 7:onR3QeFqEYZPWGFja05xF/1xu6EK7fuIM+uhwxmzMgeuuzkhkpllgWFTJe/ZJhUpS76Mlvz9sHT7Cj200DUUBxfif3Cv2Zg1EpOupg65yBWcxdJNffOikxi+ngm4XIGA/qTHCfWBUDzlk8N8aRkz0SZt/9p7n9SB6qvFRGeMm9qYdpg6aXbtCbZvipQxt4hokIhT0iafa7UK9Uxx+3/hVn+hFUVUsTqYhOHkrXA3ExtSdfLjHolKok+HD6QcFLXq X-MS-Office365-Filtering-Correlation-Id: 6255fba6-d2aa-41a3-2d12-08d5ac394fae X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2018 12:20:48.7287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6255fba6-d2aa-41a3-2d12-08d5ac394fae X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR07MB0646 X-OriginatorOrg: ericsson.com X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLIsWRmVeSWpSXmKPExsUyM2K7n+5i0cdRBlfmKVi8mtzAaHH09B5m iy+7+hgdmD0Wr5jC6vHs5n9Gj+fXelgCmKO4bFJSczLLUov07RK4Mj587mUtmDSLseL2hrPM DYyPSroYOTkkBEwkPrzbzt7FyMUhJHCEUWLR2b9MEM4WRonr596wQjjfGCU+bLwBVbaESeL5 uSZmEIdF4BOTxIY/e1kgMl1MEhPufAUq4+BgEzCQmL3bAWSJiICkxL/FW9hAbGaBMolV5/eA 2cICERKHN/5nBrFZBFQl2g+fZgWxeQU8JdqP/mCFOFBO4uSxyWA2p4CXxJlfXYwgthBQzavP N9gg6gUlTs58wgIxX0Li4IsXzBC9ChIbt8wEu01CYDqjRMe5x1DN6hJ/D31lgSiSlTh6dg5U 0TZGifm7/rJDOFPYJfZcu8sOUaUlcf7NbzCbUSBWomXrVCaIoh9sEu+XTGGCKMqWeLx/GtRu K4nXv74zQhQtZZa4e/UZG0RCRmLW1nVsEIlHrBL/Tl9ln8CoNwvJI7OQPLKAkWkVo2hxanFx brqRkV5qUWZycXF+nl5easkmRmCiOLjlt9UOxoPPHQ8xCnAwKvHwHhF+HCXEmlhWXJl7iFGC g1lJhHfH7YdRQrwpiZVVqUX58UWlOanFhxilOViUxHmd0iyihATSE0tSs1NTC1KLYLJMHJxS DYySrztDkjRqF2g8uNSW/ZVtwS3BhU+1Z4bxnrgcalp0T93skJKVx/XJ3xUnX5G0DLXPajkQ zbm12lbi27z18qGcDQ0zl3Po6i2zd41hW1e//NX+yFUiVsZf9nvnxy0WtancIKp8x+mV7/c3 ym/nmujOvxJYbP/x99SPf+2e8V66du+2bC7TwbtKLMUZiYZazEXFiQBJ9jx+EAMAAA== X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: nitin.katiyar@ericsson.com, ychen103103@163.com Subject: [ovs-dev] [PATCH v3 2/3] ofproto-dpif: Improve dp_hash selection method for select groups X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The current implementation of the "dp_hash" selection method suffers from two deficiences: 1. The hash mask and hence the number of dp_hash values is just large enough to cover the number of group buckets, but does not consider the case that buckets have different weights. 2. The xlate-time selection of best bucket from the masked dp_hash value often results in bucket load distributions that are quite different from the bucket weights because the number of available masked dp_hash values is too small (2-6 bits compared to 32 bits of a full hash in the default hash selection method). This commit provides a more accurate implementation of the dp_hash select group by applying the well known Webster method for distributing a small number of "seats" fairly over the weighted "parties" (see https://en.wikipedia.org/wiki/Webster/Sainte-Lagu%C3%AB_method). The dp_hash mask is autmatically chosen large enough to provide good enough accuracy even with widely differing weights. This distribution happens at group modification time and the resulting table is stored with the group-dpif struct. At xlation time, we use the masked dp_hash values as index to look up the assigned bucket. If the bucket should not be live, we do a circular search over the mapping table until we find the first live bucket. As the buckets in the table are by construction in pseudo-random order with a frequency according to their weight, this method maintains correct distribution even if one or more buckets are non-live. Xlation is further simplified by storing some derived select group state at group construction in struct group-dpif in a form better suited for xlation purposes. Adapted the unit test case for dp_hash select group accordingly. Signed-off-by: Jan Scheurich Signed-off-by: Nitin Katiyar Co-authored-by: Nitin Katiyar --- include/openvswitch/ofp-group.h | 1 + lib/odp-util.c | 4 +- ofproto/ofproto-dpif-xlate.c | 82 ++++++++++++++-------- ofproto/ofproto-dpif.c | 148 ++++++++++++++++++++++++++++++++++++++++ ofproto/ofproto-dpif.h | 13 ++++ tests/ofproto-dpif.at | 15 ++-- 6 files changed, 227 insertions(+), 36 deletions(-) diff --git a/include/openvswitch/ofp-group.h b/include/openvswitch/ofp-group.h index 8d893a5..af4033d 100644 --- a/include/openvswitch/ofp-group.h +++ b/include/openvswitch/ofp-group.h @@ -47,6 +47,7 @@ struct bucket_counter { /* Bucket for use in groups. */ struct ofputil_bucket { struct ovs_list list_node; + uint16_t aux; /* Padding. Also used for temporary data. */ uint16_t weight; /* Relative weight, for "select" groups. */ ofp_port_t watch_port; /* Port whose state affects whether this bucket * is live. Only required for fast failover diff --git a/lib/odp-util.c b/lib/odp-util.c index 6db241a..2db4e9d 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -595,7 +595,9 @@ format_odp_hash_action(struct ds *ds, const struct ovs_action_hash *hash_act) ds_put_format(ds, "hash("); if (hash_act->hash_alg == OVS_HASH_ALG_L4) { - ds_put_format(ds, "hash_l4(%"PRIu32")", hash_act->hash_basis); + ds_put_format(ds, "l4(%"PRIu32")", hash_act->hash_basis); + } else if (hash_act->hash_alg == OVS_HASH_ALG_SYM_L4) { + ds_put_format(ds, "sym_l4(%"PRIu32")", hash_act->hash_basis); } else { ds_put_format(ds, "Unknown hash algorithm(%"PRIu32")", hash_act->hash_alg); diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 05db090..e6d97a4 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -4380,35 +4380,59 @@ xlate_hash_fields_select_group(struct xlate_ctx *ctx, struct group_dpif *group, } } +static struct ofputil_bucket * +group_dp_hash_best_bucket(struct xlate_ctx *ctx, + const struct group_dpif *group, + uint32_t dp_hash) +{ + struct ofputil_bucket *bucket, *best_bucket = NULL; + uint32_t n_hash = group->hash_mask + 1; + + uint32_t hash = dp_hash &= group->hash_mask; + ctx->wc->masks.dp_hash |= group->hash_mask; + + /* Starting from the original masked dp_hash value iterate over the + * hash mapping table to find the first live bucket. As the buckets + * are quasi-randomly spread over the hash values, this maintains + * a distribution according to bucket weights even when some buckets + * are non-live. */ + for (int i = 0; i < n_hash; i++) { + bucket = group->hash_map[(hash + i) % n_hash]; + if (bucket_is_alive(ctx, bucket, 0)) { + best_bucket = bucket; + break; + } + } + + return best_bucket; +} + static void xlate_dp_hash_select_group(struct xlate_ctx *ctx, struct group_dpif *group, bool is_last_action) { - struct ofputil_bucket *bucket; - /* dp_hash value 0 is special since it means that the dp_hash has not been * computed, as all computed dp_hash values are non-zero. Therefore * compare to zero can be used to decide if the dp_hash value is valid * without masking the dp_hash field. */ if (!ctx->xin->flow.dp_hash) { - uint64_t param = group->up.props.selection_method_param; - - ctx_trigger_recirculate_with_hash(ctx, param >> 32, (uint32_t)param); + enum ovs_hash_alg hash_alg = group->hash_alg; + if (hash_alg > ctx->xbridge->support.max_hash_alg) { + /* Algorithm supported by all datapaths. */ + hash_alg = OVS_HASH_ALG_L4; + } + ctx_trigger_recirculate_with_hash(ctx, hash_alg, group->hash_basis); + if (ctx->xin->xcache) { + ofproto_group_unref(&group->up); + } } else { - uint32_t n_buckets = group->up.n_buckets; - if (n_buckets) { - /* Minimal mask to cover the number of buckets. */ - uint32_t mask = (1 << log_2_ceil(n_buckets)) - 1; - /* Multiplier chosen to make the trivial 1 bit case to - * actually distribute amongst two equal weight buckets. */ - uint32_t basis = 0xc2b73583 * (ctx->xin->flow.dp_hash & mask); - - ctx->wc->masks.dp_hash |= mask; - bucket = group_best_live_bucket(ctx, group, basis); - if (bucket) { - xlate_group_bucket(ctx, bucket, is_last_action); - xlate_group_stats(ctx, group, bucket); - } + struct ofputil_bucket *bucket = + group_dp_hash_best_bucket(ctx, group, ctx->xin->flow.dp_hash); + if (bucket) { + xlate_group_bucket(ctx, bucket, is_last_action); + xlate_group_stats(ctx, group, bucket); + } else if (ctx->xin->xcache) { + ofproto_group_unref(&group->up); } } } @@ -4417,8 +4441,6 @@ static void xlate_select_group(struct xlate_ctx *ctx, struct group_dpif *group, bool is_last_action) { - const char *selection_method = group->up.props.selection_method; - /* Select groups may access flow keys beyond L2 in order to * select a bucket. Recirculate as appropriate to make this possible. */ @@ -4426,15 +4448,19 @@ xlate_select_group(struct xlate_ctx *ctx, struct group_dpif *group, ctx_trigger_freeze(ctx); } - if (selection_method[0] == '\0') { + switch (group->selection_method) { + case SEL_METHOD_DEFAULT: xlate_default_select_group(ctx, group, is_last_action); - } else if (!strcasecmp("hash", selection_method)) { + break; + case SEL_METHOD_HASH: xlate_hash_fields_select_group(ctx, group, is_last_action); - } else if (!strcasecmp("dp_hash", selection_method)) { + break; + case SEL_METHOD_DP_HASH: xlate_dp_hash_select_group(ctx, group, is_last_action); - } else { - /* Parsing of groups should ensure this never happens */ + break; + default: OVS_NOT_REACHED(); + break; } } @@ -4713,8 +4739,8 @@ finish_freezing__(struct xlate_ctx *ctx, uint8_t table) act_hash = nl_msg_put_unspec_uninit(ctx->odp_actions, OVS_ACTION_ATTR_HASH, sizeof *act_hash); - act_hash->hash_alg = OVS_HASH_ALG_L4; /* Make configurable. */ - act_hash->hash_basis = 0; /* Make configurable. */ + act_hash->hash_alg = ctx->dp_hash_alg; + act_hash->hash_basis = ctx->dp_hash_basis; } nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_RECIRC, recirc_id); } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index 7162811..f5ecd8b 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -32,6 +32,7 @@ #include "lacp.h" #include "learn.h" #include "mac-learning.h" +#include "math.h" #include "mcast-snooping.h" #include "multipath.h" #include "netdev-vport.h" @@ -4762,6 +4763,145 @@ group_dpif_credit_stats(struct group_dpif *group, ovs_mutex_unlock(&group->stats_mutex); } +/* Calculate the dp_hash mask needed to provide the least weighted bucket + * with at least one hash value and construct a mapping table from masked + * dp_hash value to group bucket using the Webster method. + * If the caller specifies a non-zero max_hash value, abort and return false + * if more hash values would be required. The absolute maximum number of + * hash values supported is 256. */ + +#define MAX_SELECT_GROUP_HASH_VALUES 256 + +static bool +group_setup_dp_hash_table(struct group_dpif *group, size_t max_hash) +{ + struct ofputil_bucket *bucket; + uint32_t n_buckets = group->up.n_buckets; + double total_weight = 0.0; + uint16_t min_weight = UINT16_MAX; + uint32_t n_hash; + struct webster { + struct ofputil_bucket *bucket; + uint32_t divisor; + double value; + } *webster; + + if (n_buckets == 0) { + VLOG_DBG(" Don't apply dp_hash method without buckets"); + return false; + } + + webster = xcalloc(n_buckets, sizeof(struct webster)); + int i = 0; + LIST_FOR_EACH (bucket, list_node, &group->up.buckets) { + bucket->aux = 0; + if (bucket->weight > 0 && bucket->weight < min_weight) { + min_weight = bucket->weight; + } + total_weight += bucket->weight; + webster[i].bucket = bucket; + webster[i].divisor = 1; + webster[i].value = bucket->weight; + i++; + } + + if (total_weight == 0) { + VLOG_DBG(" Total weight is zero. No active buckets."); + free(webster); + return false; + } + VLOG_DBG(" Minimum weight: %d, total weight: %.0f", + min_weight, total_weight); + + uint32_t min_slots = ceil(total_weight / min_weight); + n_hash = MAX(16, 1L << log_2_ceil(min_slots)); + + if (n_hash > MAX_SELECT_GROUP_HASH_VALUES || + (max_hash != 0 && n_hash > max_hash)) { + VLOG_DBG(" Too many hash values required: %d", n_hash); + return false; + } + + VLOG_DBG(" Using %d hash values:", n_hash); + group->hash_mask = n_hash - 1; + if (group->hash_map) { + free(group->hash_map); + } + group->hash_map = xcalloc(n_hash, sizeof(struct ofputil_bucket *)); + + /* Use Webster method to distribute hash values over buckets. */ + for (int hash = 0; hash < n_hash; hash++) { + struct webster *winner = &webster[0]; + for (i = 1; i < n_buckets; i++) { + if (webster[i].value > winner->value) { + winner = &webster[i]; + } + } + winner->divisor += 2; + winner->value = (double) winner->bucket->weight / winner->divisor; + group->hash_map[hash] = winner->bucket; + winner->bucket->aux++; + } + + LIST_FOR_EACH (bucket, list_node, &group->up.buckets) { + double target = (n_hash * bucket->weight) / total_weight; + VLOG_DBG(" Bucket %d: weight=%d, target=%.2f hits=%d", + bucket->bucket_id, bucket->weight, + target, bucket->aux); + } + + free(webster); + return true; +} + +static void +group_set_selection_method(struct group_dpif *group) +{ + const struct ofputil_group_props *props = &group->up.props; + const char *selection_method = props->selection_method; + + if (selection_method[0] == '\0') { + VLOG_DBG("No selection method specified."); + group->selection_method = SEL_METHOD_DEFAULT; + } else if (!strcmp(selection_method, "dp_hash")) { + VLOG_DBG("Selection method specified: dp_hash."); + /* Try to use dp_hash if possible at all. */ + if (group_setup_dp_hash_table(group, 0)) { + group->selection_method = SEL_METHOD_DP_HASH; + group->hash_alg = props->selection_method_param >> 32; + if (group->hash_alg >= __OVS_HASH_MAX) { + VLOG_DBG(" Invalid dp_hash algorithm %d. " + "Defaulting to OVS_HASH_ALG_L4", group->hash_alg); + group->hash_alg = OVS_HASH_ALG_L4; + } + group->hash_basis = (uint32_t) props->selection_method_param; + VLOG_DBG("Use dp_hash with %d hash values using algorithm %d.", + group->hash_mask + 1, group->hash_alg); + } else { + /* Fall back to original default hashing in slow path. */ + VLOG_DBG(" Falling back to default hash method."); + group->selection_method = SEL_METHOD_DEFAULT; + } + } else if (!strcmp(selection_method, "hash")) { + VLOG_DBG("Selection method specified: hash."); + if (props->fields.values_size > 0) { + /* Controller has specified hash fields. */ + struct ds s = DS_EMPTY_INITIALIZER; + oxm_format_field_array(&s, &props->fields); + VLOG_DBG(" Hash fields: %s", ds_cstr(&s)); + ds_destroy(&s); + group->selection_method = SEL_METHOD_HASH; + } else { + /* No hash fields. Fall back to original default hashing. */ + VLOG_DBG(" No hash fields. Falling back to default hash method."); + group->selection_method = SEL_METHOD_DEFAULT; + } + } else { + /* Parsing of groups should ensure this never happens */ + OVS_NOT_REACHED(); + } +} + static enum ofperr group_construct(struct ofgroup *group_) { @@ -4770,6 +4910,10 @@ group_construct(struct ofgroup *group_) ovs_mutex_init_adaptive(&group->stats_mutex); ovs_mutex_lock(&group->stats_mutex); group_construct_stats(group); + group->hash_map = NULL; + if (group->up.type == OFPGT11_SELECT) { + group_set_selection_method(group); + } ovs_mutex_unlock(&group->stats_mutex); return 0; } @@ -4779,6 +4923,10 @@ group_destruct(struct ofgroup *group_) { struct group_dpif *group = group_dpif_cast(group_); ovs_mutex_destroy(&group->stats_mutex); + if (group->hash_map) { + free(group->hash_map); + group->hash_map = NULL; + } } static enum ofperr diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index d654947..e95fead 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -119,6 +119,12 @@ rule_dpif_is_internal(const struct rule_dpif *rule) /* Groups. */ +enum group_selection_method { + SEL_METHOD_DEFAULT, + SEL_METHOD_DP_HASH, + SEL_METHOD_HASH, +}; + struct group_dpif { struct ofgroup up; @@ -129,6 +135,12 @@ struct group_dpif { struct ovs_mutex stats_mutex; uint64_t packet_count OVS_GUARDED; /* Number of packets received. */ uint64_t byte_count OVS_GUARDED; /* Number of bytes received. */ + + enum group_selection_method selection_method; + enum ovs_hash_alg hash_alg; /* dp_hash algorithm to be applied. */ + uint32_t hash_basis; /* Basis for dp_hash. */ + uint32_t hash_mask; /* Used to mask dp_hash (2^N - 1).*/ + struct ofputil_bucket **hash_map; /* Map hash values to buckets. */ }; void group_dpif_credit_stats(struct group_dpif *, @@ -137,6 +149,7 @@ void group_dpif_credit_stats(struct group_dpif *, struct group_dpif *group_dpif_lookup(struct ofproto_dpif *, uint32_t group_id, ovs_version_t version, bool take_ref); + /* Backers. * diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index 60f28e2..8d6c172 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -500,11 +500,12 @@ for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do AT_CHECK([ovs-appctl netdev-dummy/receive p1 $pkt]) done -AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/dp_hash(.*\/0x1)/dp_hash(0xXXXX\/0x1)/' | sed 's/packets.*actions:1/actions:1/' | strip_ufid | strip_used | sort], [0], [dnl +AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/dp_hash(.*\/0xf)/dp_hash(0xXXXX\/0xf)/' | sed 's/packets.*actions:1/actions:1/' | \ + strip_ufid | strip_used | sort | uniq], [0], [dnl flow-dump from non-dpdk interfaces: -recirc_id(0),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(src=192.168.0.1,frag=no), packets:15, bytes:1590, used:0.0s, actions:hash(hash_l4(0)),recirc(0x1) -recirc_id(0x1),dp_hash(0xXXXX/0x1),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(frag=no), actions:10 -recirc_id(0x1),dp_hash(0xXXXX/0x1),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(frag=no), actions:11 +recirc_id(0),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(src=192.168.0.1,frag=no), packets:15, bytes:1590, used:0.0s, actions:hash(l4(0)),recirc(0x1) +recirc_id(0x1),dp_hash(0xXXXX/0xf),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(frag=no), actions:10 +recirc_id(0x1),dp_hash(0xXXXX/0xf),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(frag=no), actions:11 ]) AT_CHECK([ovs-appctl revalidator/purge], [0]) @@ -516,10 +517,10 @@ for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do AT_CHECK([ovs-appctl netdev-dummy/receive p1 $pkt]) done -AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/dp_hash(.*\/0x1)/dp_hash(0xXXXX\/0x1)/' | sed 's/\(actions:1\)[[01]]/\1X/' | strip_ufid | strip_used | sort], [0], [dnl +AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/dp_hash(.*\/0xf)/dp_hash(0xXXXX\/0xf)/' | sed 's/\(actions:1\)[[01]]/\1X/' | strip_ufid | strip_used | sort], [0], [dnl flow-dump from non-dpdk interfaces: -recirc_id(0),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(src=192.168.0.1,frag=no), packets:15, bytes:1590, used:0.0s, actions:hash(hash_l4(0)),recirc(0x2) -recirc_id(0x2),dp_hash(0xXXXX/0x1),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(frag=no), packets:15, bytes:1590, used:0.0s, actions:1X +recirc_id(0),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(src=192.168.0.1,frag=no), packets:15, bytes:1590, used:0.0s, actions:hash(l4(0)),recirc(0x2) +recirc_id(0x2),dp_hash(0xXXXX/0xf),in_port(1),packet_type(ns=0,id=0),eth_type(0x0800),ipv4(frag=no), packets:15, bytes:1590, used:0.0s, actions:1X ]) OVS_VSWITCHD_STOP