From patchwork Tue Mar 20 18:16:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Scheurich X-Patchwork-Id: 888381 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="G9YEa5Z+"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.com header.i=@ericsson.com header.b="SlAcYrXM"; 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 405LkJ3qrPz9ryk for ; Wed, 21 Mar 2018 05:17:10 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 50BDAF25; Tue, 20 Mar 2018 18:17:07 +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 16B02F23 for ; Tue, 20 Mar 2018 18:17:06 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from sesbmg22.ericsson.net (sesbmg22.ericsson.net [193.180.251.48]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 68A932F5 for ; Tue, 20 Mar 2018 18:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/simple; q=dns/txt; i=@ericsson.com; t=1521569822; 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=4fDnfgpO5ic5/rq4RsbHDdakrHKyk8151CwDUXfHpd0=; b=G9YEa5Z+/Md0PXm0u+fckaczmq/d6AHAoUiqL6GCcjxFeJuZfYEcCTOsLw9aGLVV OmDpwoHpEHihlgg9cCvpqPDQk5aTivGUuaWeLIhptPSW47ZdjDM5GkcncWus4oBg yh6peSNXdWoGd3m3N7xCOcks1reqEIhEyl624zBufLI=; X-AuditID: c1b4fb30-6ebff7000000095a-80-5ab1501e533f Received: from ESESSHC005.ericsson.se (Unknown_Domain [153.88.183.33]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id 38.0D.02394.E1051BA5; Tue, 20 Mar 2018 19:17:02 +0100 (CET) Received: from ESESSMR505.ericsson.se (153.88.183.127) by ESESSHC005.ericsson.se (153.88.183.33) with Microsoft SMTP Server (TLS) id 14.3.382.0; Tue, 20 Mar 2018 19:17:02 +0100 Received: from ESESSMB502.ericsson.se (153.88.183.163) by ESESSMR505.ericsson.se (153.88.183.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.26; Tue, 20 Mar 2018 19:17:01 +0100 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (153.88.183.157) by ESESSMB502.ericsson.se (153.88.183.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.26 via Frontend Transport; Tue, 20 Mar 2018 19:17:01 +0100 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=TsubB6H9b+a2zA3+8LFiZsBG474BgDG2STx2MVveu+4=; b=SlAcYrXMRFPnZj/DDyA3WxY4OSFCCJqpmSRhStIAzTsBRLI2jPBZ5LaxR3qPGFhldWO5QG45dSotbOrBCUIRHCisEQ5EmiwMZ/JMHjqAbsDuptoDkpe3oNSiyCap5w2QsP+tR2P3z5u9cU5eYzYU90jW2ZHwBbpfrbbrQ0C4XJ8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jan.scheurich@ericsson.com; Received: from ubuntu.eed.ericsson.se (129.192.10.2) by DB3PR07MB0650.eurprd07.prod.outlook.com (2a01:111:e400:943d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.609.6; Tue, 20 Mar 2018 18:16:55 +0000 From: Jan Scheurich To: Date: Tue, 20 Mar 2018 19:16:17 +0100 Message-ID: <1521569778-7283-3-git-send-email-jan.scheurich@ericsson.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1521569778-7283-1-git-send-email-jan.scheurich@ericsson.com> References: <1521569778-7283-1-git-send-email-jan.scheurich@ericsson.com> MIME-Version: 1.0 X-Originating-IP: [129.192.10.2] X-ClientProxiedBy: DB6PR1001CA0031.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:55::17) To DB3PR07MB0650.eurprd07.prod.outlook.com (2a01:111:e400:943d::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1cb52c47-391c-4853-962e-08d58e8ec3b2 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB3PR07MB0650; X-Microsoft-Exchange-Diagnostics: 1; DB3PR07MB0650; 3:LI05LiPYPnjIUMVZQNPCa1upx+DT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FG4GJC7RA4v/e6cjFrh3nV9yx9sBKBsHm1H+3yG6ESGzO8GE1nQZD9oTLMW0tDY2WTpoTdRMmEqaWPWfugNDH9/h1jjjmnUdtoR2V+XHvG1djk18J8GqE4E8IqN2qJZJoMW61kPtfxEUY45rDXSPhlwojb6iOuAqEqIcMj39GMegBU1AKG6Q2ClObynNz/GSZjTC1+CNvWD3qad+VKJgpSU/lYzzXC3V6DrZc2iXOKN0d5MW2xxR2RNf0Wwgyd6G1I0eTWeJOtMqZrq+UpROjLxa1iPn4//rioPRHe5hV5+dTVpElR3rqkCABRDpG6E4; 4:MHpg0+raR+BL6Siw62UGFxq08UmgvIAvF/rn4pA0AvEbBDB/qiyKwQXWl8RCBSDz+158+mK6YFqKHYA7+xRoyYQY7s0d7StKrWxPsxPG/ggbh7GT3hS4gvCHKfNyFuOg8JQm4x4GHImfPEvD8D7kRClEflTdEXhBjqsHsR5m5cmzCTV7sXq72pp5i58ARCF57UHN5b1ZkY1EegwghHa1XHN84tuOjXcSJy0N43NJ6hYxwZi/ZFi1b061RkDolLlMCQNhc1F9M68ge7rlxyS1pv0g4aPtooDNUEDd+pqoYfFKgFTOpvVSmkq+DkcmTJLd 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)(8121501046)(5005006)(3231221)(944501313)(52105095)(93006095)(93001095)(3002001)(10201501046)(6041310)(20161123564045)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(6072148)(201708071742011); SRVR:DB3PR07MB0650; BCL:0; PCL:0; RULEID:; SRVR:DB3PR07MB0650; X-Forefront-PRVS: 061725F016 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(396003)(39860400002)(366004)(39380400002)(199004)(189003)(81156014)(7736002)(86362001)(8676002)(36756003)(68736007)(59450400001)(5660300001)(2351001)(966005)(51416003)(8936002)(76176011)(305945005)(97736004)(52116002)(3846002)(105586002)(6116002)(81166006)(6916009)(2950100002)(53936002)(6306002)(386003)(6512007)(6506007)(186003)(106356001)(6486002)(478600001)(50226002)(316002)(16586007)(50466002)(47776003)(48376002)(6666003)(2906002)(26005)(25786009)(4326008)(107886003)(16526019)(66066001)(2361001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR07MB0650; H:ubuntu.eed.ericsson.se; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB3PR07MB0650; 23:m1zQBDvPk480C0mOKOQtYPcwFjnxLbiBtWIGBCB/+?= 6DojM+OmIsg9sEsQprhgbp7fYHJ3d2VkgwMVNegYEqIY59KXgj8EX39PgY3VxtvtrbBplSrMKoEiyQUiy7CYY+p3nlgZN1EFHfzJSC7MEfcQ893jaupGTGk1bDIwzU43mDLGmLmaWF4MUvf105tXEBE76q5jf330y07aPVScOFP6Prisl2XYUp/EanUkfl3hbEOx1SX6G/KpPqL2WU6EL4vVeTXiuiDbf1Icu8l+sJ52r/2bObnE40Y4HMsDs19g319xkCainCqeQCBe72aPd4llhpMGLhya0CG3JqP3h5axLKIzoe9lUXjKs25CYsQM1oyHBiWyHYEUPb5mDIaAspePBnqEGnFJELU2AaoGWNqccHlcJXhgRHYheei3ep97yZ576SU7vVF2ycVV19tojE9zCyiFogYh8SK70UETCHKL8rXoYiy5ULdSIbgPolZp6uTtzbijZ/AhFlvFDioUWlChOHi0JGaMwWStX2IxkhezHYpcvISeCkl7EP7EzrtcKNC0uQ2NUeWXlZvsY6d6st+ekxRLPZUsfQCi5KBotg62/0lLxNEOW5RwxayNrfi7mNr7jDbgid5pu6lbTtNuovBv4tixGvotGM5akNFPtzDX1xieIkBQi69IWTN+/CrXr7M630ulPOi70Kh9+cDiy4XvsnH9WC4we8VVb2/Xft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GXNnaz1L+AneM09O9jJo4HzUT7k1M7mx1aCI6s9Z+fThKQOyH9HtjurLYYFZdn4tOPzShZilr/rnDOXEDdbwdqhaCoacaWr50fISLpdHPR36Pcnr7Mp9oBDD15dmezjciUTrxumi3++797JePuFmn1PvyqXEyg==; 5:8AKI5POwFb4Kb+UCbnqkVAv5GKYNqP0Ua/eo8ecUGXm0esiweucrbFgoyCJYIXn0b/NVVHAGd+vjOPBb17BVqwjfcmkGkbZFz7a4Hm17T/HSifRUNgZBKtfPNLeOcklhy9aIM9jCY0absfDvLb7e6vwNWEh8NEMtEYpS1hUHlMo=; 24:kw1TrsPvjZeIyXuOwXtdXqD0pvwHSL3y4HFXD1R0dq/hcvO1fkGArFfRPFMHTVcugAe1ccDgBsh5h/OE9vUOye0zKj8d7lApkjweePqTd98= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB3PR07MB0650; 7:JffTmRaL0KL24QZf9b6C5CX8/Xz9bj4Jq/ALVd3+AkmkDKILWDm25dycAhGj8jIlyWfgLYf5uX1+y5TiUPLeWHA2tRgLXFhA4ZahHAeDyD06Y9TRhRBZYREdRMvKIiKS1mo+NqZzUQ4/pbZkvyIE3PQbUC0p/fZ4dPQaI5VT/gOyimMx06x6Hujln0SJ6ykHk5IJ0CqIdOsNtHXeMIR/m6sAUbgTeLNR9Pr+3as1WV+IoMgSRic2+Ecak2IAk7U1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Mar 2018 18:16:55.9652 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1cb52c47-391c-4853-962e-08d58e8ec3b2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR07MB0650 X-OriginatorOrg: ericsson.com X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAIsWRmVeSWpSXmKPExsUyM2K7oq5cwMYog1k/NCyOnt7DbPFlVx+j A5PH4hVTWD2e3fzPGMAUxWWTkpqTWZZapG+XwJUx5/VSpoJ3pRUTr69lb2DsDu9i5OSQEDCR mLhgK3sXIxeHkMBhRol3i6YwQzhbGCUat21ihHC+M0q82vgCylnKJLHl3mcWEIdF4BOTxOfL J5lBhjEKxEq0bJ3KBFHVxSRxee8BoBYODjYBA4nZux1AakQEJCX+Ld7CBmIzC6RKTLq4ggWk RFggVOJ9ZwBImEVAVeJATwcTiM0r4CnR9nktM8StchInj01mBbE5BbwktjYvZwGxhYBqtvfN Z4GoF5Q4OfMJC8R4CYmDL15A9SpIbNwyE+xmCYGZjBKPDk9nh2hWl/h76CsLRJGsxNGzc6Bs X4nVdxZANexnlDj+5xSU08AusXD9bjaIKi2JyxPvsUMkfrBJ3H+6DmpftsTXO3uhiqwkXv/6 zghRtJRZ4t7xp+wQCRmJiT9fM09g1JuF5PZZSG5fwMi0ilG0OLU4KTfdyEgvtSgzubg4P08v L7VkEyMwHRzc8ttgB+PL546HGAU4GJV4eD2sN0YJsSaWFVfmHmKU4GBWEuHNVAAK8aYkVlal FuXHF5XmpBYfYpTmYFES5z3pyRslJJCeWJKanZpakFoEk2Xi4JRqYJxlWaJ5/cu6Wfd/XDaO jp+7fXf1biYp9aO59l+tPwk3sMZ7Oq388q/BIzbCQcOwb67xBN+pseeXFDUYP3/LHi5SZlpy S9hr+WSTpdkLRWyUNb6I8FpvF5tbfqm3R/Jm9YHVb499cpYTX6bgtsUvfsHFPRX9c87WNX84 yl+8YvJtz4kPry+4Ol2JpTgj0VCLuag4EQBDubWqAwMAAA== 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 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. Signed-off-by: Jan Scheurich Signed-off-by: Nitin Katiyar Co-authored-by: Nitin Katiyar Signed-off-by: Jan Scheurich --- include/openvswitch/ofp-group.h | 1 + ofproto/ofproto-dpif-xlate.c | 70 ++++++++++++-------- ofproto/ofproto-dpif.c | 142 ++++++++++++++++++++++++++++++++++++++++ ofproto/ofproto-dpif.h | 13 ++++ 4 files changed, 200 insertions(+), 26 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/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index bc6429c..021a4d8 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -4232,35 +4232,51 @@ 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); + ctx_trigger_recirculate_with_hash(ctx, group->hash_alg, + group->hash_basis); } 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); } } } @@ -4269,8 +4285,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. */ @@ -4278,15 +4292,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; } } diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index c92c5be..383d04e 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" @@ -4717,6 +4718,139 @@ 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[group->up.n_buckets]; + int i = 0; + + LIST_FOR_EACH (bucket, list_node, &group->up.buckets) { + bucket->aux = 0; + if (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++; + } + + 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_INFO(" Too many hash values required: %d", n_hash); + return false; + } + + VLOG_INFO(" 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++) { + VLOG_DBG(" Hash value: %d", hash); + double max_val = 0.0; + struct webster *winner; + for (i = 0; i < n_buckets; i++) { + VLOG_DBG(" Webster[%d]: divisor=%d value=%.2f", + i, webster[i].divisor, webster[i].value); + if (webster[i].value > max_val) { + max_val = webster[i].value; + winner = &webster[i]; + } + } + VLOG_DBG(" Winner: %d", winner->bucket->bucket_id); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" + /* winner is a reference to a webster[] element initialized above. */ + winner->divisor += 2; + winner->value = (double) winner->bucket->weight / winner->divisor; + group->hash_map[hash] = winner->bucket; + winner->bucket->aux++; +#pragma GCC diagnostic pop + } + + LIST_FOR_EACH (bucket, list_node, &group->up.buckets) { + double target = (n_hash * bucket->weight) / total_weight; + VLOG_INFO(" Bucket %d: weight=%d, target=%f.2 hits=%d", + bucket->bucket_id, bucket->weight, + target, bucket->aux); + } + + return true; +} + +static void +group_set_selection_method(struct group_dpif *group) +{ + struct ofputil_group_props *props = &group->up.props; + char *selection_method = props->selection_method; + + if (selection_method[0] == '\0') { + VLOG_INFO("No selection method specified."); + group->selection_method = SEL_METHOD_DEFAULT; + + } else if (!strcmp(selection_method, "dp_hash")) { + VLOG_INFO("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_INFO(" 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; + } else { + /* Fall back to original default hashing in slow path. */ + VLOG_INFO(" Falling back to default hash method."); + group->selection_method = SEL_METHOD_DEFAULT; + } + } else if (!strcmp(selection_method, "hash")) { + VLOG_INFO("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_INFO(" 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_INFO(" 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_) { @@ -4725,6 +4859,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; } @@ -4734,6 +4872,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 90432fa..6a58b48 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. *