From patchwork Fri Jan 11 07:45:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nitin Katiyar X-Patchwork-Id: 1023416 X-Patchwork-Delegate: ian.stokes@intel.com 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="VK3UjcJa"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.com header.i=@ericsson.com header.b="K8BYuZdc"; 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 43bZld6mjvz9s4s for ; Fri, 11 Jan 2019 18:50:05 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 14B7E1442; Fri, 11 Jan 2019 07:50:02 +0000 (UTC) X-Original-To: ovs-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 047C513B5 for ; Fri, 11 Jan 2019 07:46:04 +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 C8A71A8 for ; Fri, 11 Jan 2019 07:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; d=ericsson.com; s=mailgw201801; c=relaxed/relaxed; q=dns/txt; i=@ericsson.com; t=1547192759; x=1549784759; 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=b/98VLZlArE6GZPTlCB4mmgvVFr+T5Dljd3zD+lk0ao=; b=VK3UjcJaO5OzAlD8JdH7OdevkO1GdIQpuXFKN1fCo+WkzOxVQntfaYLNoypEfG9s ljALG2cgS0KW/aJ+xi5STgfFPx3+IxgoSZ8+ecy+IgakSh0Bv8pGXns1xWmohINw EVmetzg+XxptjBL+ia+IwiM8Cz8e+k4tf7SB6EDwwI8=; X-AuditID: c1b4fb30-41b3a9e00000355c-16-5c3849b79d90 Received: from ESESSMB501.ericsson.se (Unknown_Domain [153.88.183.119]) by sesbmg22.ericsson.net (Symantec Mail Security) with SMTP id A7.0D.13660.7B9483C5; Fri, 11 Jan 2019 08:45:59 +0100 (CET) Received: from ESESBMB503.ericsson.se (153.88.183.170) by ESESSMB501.ericsson.se (153.88.183.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 11 Jan 2019 08:45:49 +0100 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (153.88.183.157) by ESESBMB503.ericsson.se (153.88.183.170) 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, 11 Jan 2019 08:45:49 +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:X-MS-Exchange-SenderADCheck; bh=b/98VLZlArE6GZPTlCB4mmgvVFr+T5Dljd3zD+lk0ao=; b=K8BYuZdcW8YWu7Uo3clIc2ZIcr1dTI3mrZAvENyCd1AScpHX+UGSu/WzCk81jnoCvnTBdgyWhwgEXWUEzyc5Ambe0cZYGVBVObkVokQvhxoecgkjvg3D/1GqiA8WwH7S9ZZYrbCSSfErTuwhixWbNag4BcSS3eF7fWz1gqREvZ4= Received: from HE1PR0702MB3626.eurprd07.prod.outlook.com (52.133.6.24) by HE1PR0702MB3612.eurprd07.prod.outlook.com (52.133.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.7; Fri, 11 Jan 2019 07:45:48 +0000 Received: from HE1PR0702MB3626.eurprd07.prod.outlook.com ([fe80::1574:b839:6817:5995]) by HE1PR0702MB3626.eurprd07.prod.outlook.com ([fe80::1574:b839:6817:5995%3]) with mapi id 15.20.1537.013; Fri, 11 Jan 2019 07:45:48 +0000 From: Nitin Katiyar To: "ovs-dev@openvswitch.org" Thread-Topic: [PATCH v4] Adding support for PMD auto load balancing Thread-Index: AQHUqYGqgJakKBol9kOI/nxRZsDTVA== Date: Fri, 11 Jan 2019 07:45:47 +0000 Message-ID: <1547221636-10725-1-git-send-email-nitin.katiyar@ericsson.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [125.16.213.150] x-mailer: git-send-email 1.9.1 x-clientproxiedby: BMXPR01CA0036.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::22) To HE1PR0702MB3626.eurprd07.prod.outlook.com (2603:10a6:7:8c::24) x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR0702MB3612; 6:pXbNGz+PClZ1sGt7jaqLwinD4R+9ICbRg/aJhRH6JABCIJNwVJqbqiRBbQ+1uMSF24PeIVgWNx1j0fvR3k5keIJLCDh/yToGwy3yLbo1J3MqwIbpgALaB63TQ5km7++5XHl6i+FvfeNvSAYmuMzEBqqHNY8RGIOt8oFCtEjJEyb47gxsSTl+xs6qkpgEVq4wGdce8nvwC5WKj3TeXxkwKFaIP5YGUGIm1X1eOA58yJVYCCXSuIsStwG37FwUqf/eDm3g2OVhPkgbrvDlE0Uf/nWYEgPMgfRFMYsJMYfgiTgyg6b/RldbIE43cZr9qfvOKukvm9H6PUK2ykq8A+yGwFSdlUcAlu/vP0/L+v3jn0FmSCBCoSwL/YYIiVo17rGNFaf7LSh7gDs1Wq1HVbdWsvL2luoMDQHl5qgHfMqPD8ucNE/E7D/4xu1ZDoOKNbuDSc5tu8OiIQlkjCrgArhKhw==; 5:2SC++BA+WXdeEYaLnv2rVH9iVtRZHi399nsY0VuXIooKV0yPnVivaC78ESvZuDb9eZk1OeUm8cP1Qi3rAf+wkzFnsDd9H+JBzlxeUxj2ZsVI1a0/foXacEZPlHXB7FvWfMZobFg+sqJX/yV33UW7FWyl4xoZFYy0/HMEnXWhOk6j+avlgEgbddEvDTIAGAoR/SnHW/EjMbUBoqxuhXP4XA==; 7:5oAZ9N749iyXs1JDecU3YQuIyBrzCJ+Abgydrs7A3HqyndQr9Y7ejeVAQ0BRruDwahesznPMfY6CWEPtF7/nrEwfz09lM86c8qTjJoRVVRUvp3jlz0Ub/UlZwXoAWcxj6xrzmTF+38Ildm9d73kYRQ== x-ms-office365-filtering-correlation-id: 14e820b5-c19b-42cf-e7e8-08d67798cce5 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(2017052603328)(7153060)(7193020); SRVR:HE1PR0702MB3612; x-ms-traffictypediagnostic: HE1PR0702MB3612: x-microsoft-antispam-prvs: x-forefront-prvs: 09144DB0F7 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(376002)(366004)(136003)(39860400002)(396003)(199004)(189003)(45074003)(2906002)(6486002)(486006)(97736004)(2501003)(50226002)(30864003)(316002)(86362001)(14454004)(256004)(25786009)(5640700003)(6436002)(53946003)(6116002)(8936002)(3846002)(6512007)(5660300001)(54906003)(8676002)(81166006)(53936002)(81156014)(99286004)(2351001)(52116002)(2616005)(476003)(386003)(6506007)(186003)(6346003)(102836004)(55236004)(26005)(4326008)(68736007)(44832011)(66066001)(14444005)(71200400001)(71190400001)(36756003)(105586002)(7736002)(6916009)(39060400002)(106356001)(305945005)(478600001)(107886003)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0702MB3612; H:HE1PR0702MB3626.eurprd07.prod.outlook.com; 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) authentication-results: spf=none (sender IP is ) smtp.mailfrom=nitin.katiyar@ericsson.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: qeNZD66oRc2t9eaSM+qZxayLcHxfqaBls94KCmkcpzNtsnDSOivRbUGPZDPPDZ9XYiw9aTQ+zDzTIeZjx3ZNgZNR5BmpKcJ8hJLZYLLuhhxQ2Bb61Ale+7BX9s+7G3/E6L9Tn8MoWrT8WroD5j/Tu6ShAgeW5xsgu9SMQvaoBlgFdki7u3yFRjoCKTclXtdkAk7fILAe80QZgQN0sZ/9YXsxRTTIRWvNHFUlGXRC2J8peroOd1S2MOJkM6/D8sLqTSBNNzXPO6qrkhBrEWvQud+QANNo6sVk1wdvmuwssNAxlHPNohLGjOsXodmNrBNxujXRfu+wAW9oiL6UrP+nR4Tf2krtZWM8NeuALofLit+Oa1tpEKnj5OFdFCSZ3dNtbRipCAE620LQN3My94kJC0A5sUbtcJZzLJaU23vx47s= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 14e820b5-c19b-42cf-e7e8-08d67798cce5 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2019 07:45:46.4209 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0702MB3612 X-OriginatorOrg: ericsson.com X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0hTcRTH+d17t90NFz+X5sFeOIgoai5JGzGkqD+WUFmEhAxq6kVF3Wxb poZgD5NUQqZFW9gixWTNxDFyLjWaZpppTZOyhxT5wARf08pH2rY7of8+55zv9/zOOfxoUmTm hNPpaj2jVasyxVwBZTzbdGlv0zGZUjq4ECOrd83wZFVz40j2cLkIHSIVzaavPMXY0BpSTLcN cuPJRIE8hclMz2G0kbHnBWmG2XfcbOsiyh261UoUoj9zqATxacD7YbXcSJUgAS3CHQhqnUuE ryDCvxDYG+PZQg0Bo1fmkS+gcDkJjuKbAYuBgGfPO7hsMOa19Lson5+LpdDkNvB8HIIPQNdM H88nInEXAptn0P/6RhwLa/enA6Ij8LTK7u1Ee1kCP4vjfGkK7wDb2hu/XIjjoMU6S/oY4U3w +7XVPyuJw+DTiJlgF8JQ0/KWZDkUJn6sclgWg9tazWN5G1Q/HvAPDfgOghKHJXCNPdD7YSTA W6HfXIpY0XUedLqNga7HYXF8iMMWPiPobP5LrrvvtrkpljWw1DIc6LQFSmyGQKd7XJgyeyj2 xgw8qi9C5Uhq+m8Nk/cCJN4FDc5INq2AJ98GCJYjoLL0O8/kv0YwdBtHqAeIY0GhOkaXlJUa FSVhtOnJOp1GLVEzehvyfpsX9mWpA02MH3YhTCNxkNAilylFHFWOLi/LhYAmxSFCzlFvSpii ystntJpz2ouZjM6FNtOUOEy4IgpWinCqSs9kMEw2o12vEjQ/vBAFqU+edglzlaNVZueihupJ fvWxNrw9KYtPnYouS1i6as94qeSGbUgsiO+OWZ5rmK8oPnGZL662OUN22nqDK6j826VBEbL3 8krbpD279oy8zkN4iC8HaWPr1I3Rvp7tjn6LJPRatLC5N6rsQl3O8EzMZEK7ZcVYsAAZjfpH 7WJKl6bat5vU6lT/AL+QbPoyAwAA 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 Subject: [ovs-dev] [PATCH v4] Adding support for PMD auto load balancing 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 Port rx queues that have not been statically assigned to PMDs are currently assigned based on periodically sampled load measurements. The assignment is performed at specific instances – port addition, port deletion, upon reassignment request via CLI etc. Due to change in traffic pattern over time it can cause uneven load among the PMDs and thus resulting in lower overall throughout. This patch enables the support of auto load balancing of PMDs based on measured load of RX queues. Each PMD measures the processing load for each of its associated queues every 10 seconds. If the aggregated PMD load reaches 95% for 6 consecutive intervals then PMD considers itself to be overloaded. If any PMD is overloaded, a dry-run of the PMD assignment algorithm is performed by OVS main thread. The dry-run does NOT change the existing queue to PMD assignments. If the resultant mapping of dry-run indicates an improved distribution of the load then the actual reassignment will be performed. The automatic rebalancing will be disabled by default and has to be enabled via configuration option. The interval (in minutes) between two consecutive rebalancing can also be configured via CLI, default is 1 min. Following example commands can be used to set the auto-lb params: ovs-vsctl set open_vswitch . other_config:pmd-auto-lb="true" ovs-vsctl set open_vswitch . other_config:pmd-auto-lb-rebal-interval="5" Co-authored-by: Rohith Basavaraja Co-authored-by: Venkatesan Pradeep Signed-off-by: Rohith Basavaraja Signed-off-by: Venkatesan Pradeep Signed-off-by: Nitin Katiyar --- Documentation/topics/dpdk/pmd.rst | 41 +++++ NEWS | 1 + lib/dpif-netdev.c | 378 ++++++++++++++++++++++++++++++++++++++ vswitchd/vswitch.xml | 41 +++++ 4 files changed, 461 insertions(+) diff --git a/Documentation/topics/dpdk/pmd.rst b/Documentation/topics/dpdk/pmd.rst index dd9172d..c273b40 100644 --- a/Documentation/topics/dpdk/pmd.rst +++ b/Documentation/topics/dpdk/pmd.rst @@ -183,3 +183,44 @@ or can be triggered by using:: In addition, the output of ``pmd-rxq-show`` was modified to include Rx queue utilization of the PMD as a percentage. Prior to this, tracking of stats was not available. + +Automatic assignment of Port/Rx Queue to PMD Threads (experimental) +------------------------------------------------------------------- + +Cycle or utilization based allocation of Rx queues to PMDs gives efficient +load distribution but it is not adaptive to change in traffic pattern occuring +over the time. This causes uneven load among the PMDs which results in overall +lower throughput. + +To address this automatic load balancing of PMDs can be set by:: + + $ ovs-vsctl set open_vswitch . other_config:pmd-auto-lb="true" + +If pmd-auto-lb is set to true AND cycle based assignment is enabled then auto +load balancing of PMDs is enabled provided there are 2 or more non-isolated +PMDs and at least one of these PMDs is polling more than one RX queue. + +Once auto load balancing is set, each non-isolated PMD measures the processing +load for each of its associated queues every 10 seconds. If the aggregated PMD +load reaches 95% for 6 consecutive intervals then PMD considers itself to be +overloaded. + +If any PMD is overloaded, a dry-run of the PMD assignment algorithm is +performed by OVS main thread. The dry-run does NOT change the existing queue +to PMD assignments. + +If the resultant mapping of dry-run indicates an improved distribution of the +load then the actual reassignment will be performed. + +The minimum time between 2 consecutive PMD auto load balancing iterations can +also be configured by:: + + $ ovs-vsctl set open_vswitch .\ + other_config:pmd-auto-lb-rebal-interval="" + +where ```` is a value in minutes. The default interval is 1 minute +and setting it to 0 will also result in default value i.e. 1 min. + +A user can use this option to avoid frequent trigger of auto load balancing of +PMDs. For e.g. set this (in min) such that it occurs once in few hours or a day +or a week. diff --git a/NEWS b/NEWS index 2de844f..0e9fcb1 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,7 @@ Post-v2.10.0 * Add option for simple round-robin based Rxq to PMD assignment. It can be set with pmd-rxq-assign. * Add support for DPDK 18.11 + * Add support for Auto load balancing of PMDs (experimental) - Add 'symmetric_l3' hash function. - OVS now honors 'updelay' and 'downdelay' for bonds with LACP configured. - ovs-vswitchd: diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 1564db9..81e9cbf 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -80,6 +80,12 @@ VLOG_DEFINE_THIS_MODULE(dpif_netdev); +/* Auto Load Balancing Defaults */ +#define ALB_ACCEPTABLE_IMPROVEMENT 25 +#define ALB_PMD_LOAD_THRESHOLD 95 +#define ALB_PMD_REBALANCE_POLL_INTERVAL 1 /* 1 Min */ +#define MIN_TO_MSEC 60000 + #define FLOW_DUMP_MAX_BATCH 50 /* Use per thread recirc_depth to prevent recirculation loop. */ #define MAX_RECIRC_DEPTH 6 @@ -288,6 +294,13 @@ struct dp_meter { struct dp_meter_band bands[]; }; +struct pmd_auto_lb { + bool auto_lb_requested; /* Auto load balancing requested by user. */ + bool is_enabled; /* Current status of Auto load balancing. */ + uint64_t rebalance_intvl; + uint64_t rebalance_poll_timer; +}; + /* Datapath based on the network device interface from netdev.h. * * @@ -368,6 +381,7 @@ struct dp_netdev { uint64_t last_tnl_conf_seq; struct conntrack conntrack; + struct pmd_auto_lb pmd_alb; }; static void meter_lock(const struct dp_netdev *dp, uint32_t meter_id) @@ -702,6 +716,11 @@ struct dp_netdev_pmd_thread { /* Keep track of detailed PMD performance statistics. */ struct pmd_perf_stats perf_stats; + /* Stats from previous iteration used by automatic pmd + * load balance logic. */ + uint64_t prev_stats[PMD_N_STATS]; + atomic_count pmd_overloaded; + /* Set to true if the pmd thread needs to be reloaded. */ bool need_reload; }; @@ -3734,6 +3753,53 @@ dpif_netdev_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops, } } +/* Enable or Disable PMD auto load balancing. */ +static void +set_pmd_auto_lb(struct dp_netdev *dp) +{ + unsigned int cnt = 0; + struct dp_netdev_pmd_thread *pmd; + struct pmd_auto_lb *pmd_alb = &dp->pmd_alb; + + bool enable_alb = false; + bool multi_rxq = false; + bool pmd_rxq_assign_cyc = dp->pmd_rxq_assign_cyc; + + /* Ensure that there is at least 2 non-isolated PMDs and + * one of them is polling more than one rxq. */ + CMAP_FOR_EACH (pmd, node, &dp->poll_threads) { + if (pmd->core_id == NON_PMD_CORE_ID || pmd->isolated) { + continue; + } + + if (hmap_count(&pmd->poll_list) > 1) { + multi_rxq = true; + } + if (cnt && multi_rxq) { + enable_alb = true; + break; + } + cnt++; + } + + /* Enable auto LB if it is requested and cycle based assignment is true. */ + enable_alb = enable_alb && pmd_rxq_assign_cyc && + pmd_alb->auto_lb_requested; + + if (pmd_alb->is_enabled != enable_alb) { + pmd_alb->is_enabled = enable_alb; + if (pmd_alb->is_enabled) { + VLOG_INFO("PMD auto load balance is enabled " + "(with rebalance interval:%"PRIu64" msec)", + pmd_alb->rebalance_intvl); + } else { + pmd_alb->rebalance_poll_timer = 0; + VLOG_INFO("PMD auto load balance is disabled"); + } + } + +} + /* Applies datapath configuration from the database. Some of the changes are * actually applied in dpif_netdev_run(). */ static int @@ -3748,6 +3814,7 @@ dpif_netdev_set_config(struct dpif *dpif, const struct smap *other_config) DEFAULT_EM_FLOW_INSERT_INV_PROB); uint32_t insert_min, cur_min; uint32_t tx_flush_interval, cur_tx_flush_interval; + uint64_t rebalance_intvl; tx_flush_interval = smap_get_int(other_config, "tx-flush-interval", DEFAULT_TX_FLUSH_INTERVAL); @@ -3819,6 +3886,23 @@ dpif_netdev_set_config(struct dpif *dpif, const struct smap *other_config) pmd_rxq_assign); dp_netdev_request_reconfigure(dp); } + + struct pmd_auto_lb *pmd_alb = &dp->pmd_alb; + pmd_alb->auto_lb_requested = smap_get_bool(other_config, "pmd-auto-lb", + false); + + rebalance_intvl = smap_get_int(other_config, "pmd-auto-lb-rebal-interval", + ALB_PMD_REBALANCE_POLL_INTERVAL); + + /* Input is in min, convert it to msec. */ + rebalance_intvl = + rebalance_intvl ? rebalance_intvl * MIN_TO_MSEC : MIN_TO_MSEC; + + if (pmd_alb->rebalance_intvl != rebalance_intvl) { + pmd_alb->rebalance_intvl = rebalance_intvl; + } + + set_pmd_auto_lb(dp); return 0; } @@ -4762,6 +4846,9 @@ reconfigure_datapath(struct dp_netdev *dp) /* Reload affected pmd threads. */ reload_affected_pmds(dp); + + /* Check if PMD Auto LB is to be enabled */ + set_pmd_auto_lb(dp); } /* Returns true if one of the netdevs in 'dp' requires a reconfiguration */ @@ -4780,6 +4867,236 @@ ports_require_restart(const struct dp_netdev *dp) return false; } +/* Function for calculating variance. */ +static uint64_t +variance(uint64_t a[], int n) +{ + /* Compute mean (average of elements). */ + uint64_t sum = 0; + uint64_t mean = 0; + uint64_t sqDiff = 0; + + if (!n) { + return 0; + } + + for (int i = 0; i < n; i++) { + sum += a[i]; + } + + if (sum) { + mean = sum / n; + + /* Compute sum squared differences with mean. */ + for (int i = 0; i < n; i++) { + sqDiff += (a[i] - mean)*(a[i] - mean); + } + } + return (sqDiff ? (sqDiff / n) : 0); +} + + +/* Returns the variance in the PMDs usage as part of dry run of rxqs + * assignment to PMDs. */ +static bool +get_dry_run_variance(struct dp_netdev *dp, uint32_t *core_list, + uint32_t num, uint64_t *predicted_variance) + OVS_REQUIRES(dp->port_mutex) +{ + struct dp_netdev_port *port; + struct dp_netdev_pmd_thread *pmd; + struct dp_netdev_rxq ** rxqs = NULL; + struct rr_numa *numa = NULL; + struct rr_numa_list rr; + int n_rxqs = 0; + bool ret = false; + uint64_t *pmd_usage; + + if (!predicted_variance) { + return ret; + } + + pmd_usage = xcalloc(num, sizeof(uint64_t)); + + HMAP_FOR_EACH (port, node, &dp->ports) { + if (!netdev_is_pmd(port->netdev)) { + continue; + } + + for (int qid = 0; qid < port->n_rxq; qid++) { + struct dp_netdev_rxq *q = &port->rxqs[qid]; + uint64_t cycle_hist = 0; + + if (q->pmd->isolated) { + continue; + } + + if (n_rxqs == 0) { + rxqs = xmalloc(sizeof *rxqs); + } else { + rxqs = xrealloc(rxqs, sizeof *rxqs * (n_rxqs + 1)); + } + + /* Sum the queue intervals and store the cycle history. */ + for (unsigned i = 0; i < PMD_RXQ_INTERVAL_MAX; i++) { + cycle_hist += dp_netdev_rxq_get_intrvl_cycles(q, i); + } + dp_netdev_rxq_set_cycles(q, RXQ_CYCLES_PROC_HIST, + cycle_hist); + /* Store the queue. */ + rxqs[n_rxqs++] = q; + } + } + if (n_rxqs > 1) { + /* Sort the queues in order of the processing cycles + * they consumed during their last pmd interval. */ + qsort(rxqs, n_rxqs, sizeof *rxqs, compare_rxq_cycles); + } + rr_numa_list_populate(dp, &rr); + + for (int i = 0; i < n_rxqs; i++) { + int numa_id = netdev_get_numa_id(rxqs[i]->port->netdev); + numa = rr_numa_list_lookup(&rr, numa_id); + if (!numa) { + /* Abort if cross NUMA polling. */ + VLOG_DBG("PMD auto lb dry run." + " Aborting due to cross-numa polling."); + goto cleanup; + } + + pmd = rr_numa_get_pmd(numa, true); + VLOG_DBG("PMD auto lb dry run. Predicted: Core %d on numa node %d " + "to be assigned port \'%s\' rx queue %d " + "(measured processing cycles %"PRIu64").", + pmd->core_id, numa_id, + netdev_rxq_get_name(rxqs[i]->rx), + netdev_rxq_get_queue_id(rxqs[i]->rx), + dp_netdev_rxq_get_cycles(rxqs[i], RXQ_CYCLES_PROC_HIST)); + + for (int id = 0; id < num; id++) { + if (pmd->core_id == core_list[id]) { + /* Add the processing cycles of rxq to pmd polling it. */ + pmd_usage[id] += dp_netdev_rxq_get_cycles(rxqs[i], + RXQ_CYCLES_PROC_HIST); + } + } + } + + CMAP_FOR_EACH (pmd, node, &dp->poll_threads) { + uint64_t total_cycles = 0; + + if ((pmd->core_id == NON_PMD_CORE_ID) || pmd->isolated) { + continue; + } + + /* Get the total pmd cycles for an interval. */ + atomic_read_relaxed(&pmd->intrvl_cycles, &total_cycles); + /* Estimate the cycles to cover all intervals. */ + total_cycles *= PMD_RXQ_INTERVAL_MAX; + for (int id = 0; id < num; id++) { + if (pmd->core_id == core_list[id]) { + if (pmd_usage[id]) { + pmd_usage[id] = (pmd_usage[id] * 100) / total_cycles; + } + VLOG_DBG("PMD auto lb dry run. Predicted: Core %d, " + "usage %"PRIu64"", pmd->core_id, pmd_usage[id]); + } + } + } + *predicted_variance = variance(pmd_usage, num); + ret = true; + +cleanup: + rr_numa_list_destroy(&rr); + free(rxqs); + free(pmd_usage); + return ret; +} + +/* Does the dry run of Rxq assignment to PMDs and returns true if it gives + * better distribution of load on PMDs. */ +static bool +pmd_rebalance_dry_run(struct dp_netdev *dp) +{ + struct dp_netdev_pmd_thread *pmd; + uint64_t *curr_pmd_usage; + + uint64_t curr_variance; + uint64_t new_variance; + uint64_t improvement = 0; + uint32_t num_pmds; + uint32_t *pmd_corelist; + struct rxq_poll *poll, *poll_next; + bool ret; + + num_pmds = cmap_count(&dp->poll_threads); + + if (num_pmds > 1) { + curr_pmd_usage = xcalloc(num_pmds, sizeof(uint64_t)); + pmd_corelist = xcalloc(num_pmds, sizeof(uint32_t)); + } else { + return false; + } + + num_pmds = 0; + CMAP_FOR_EACH (pmd, node, &dp->poll_threads) { + uint64_t total_cycles = 0; + uint64_t total_proc = 0; + + if ((pmd->core_id == NON_PMD_CORE_ID) || pmd->isolated) { + continue; + } + + /* Get the total pmd cycles for an interval. */ + atomic_read_relaxed(&pmd->intrvl_cycles, &total_cycles); + /* Estimate the cycles to cover all intervals. */ + total_cycles *= PMD_RXQ_INTERVAL_MAX; + + HMAP_FOR_EACH_SAFE (poll, poll_next, node, &pmd->poll_list) { + uint64_t proc_cycles = 0; + for (unsigned i = 0; i < PMD_RXQ_INTERVAL_MAX; i++) { + proc_cycles += dp_netdev_rxq_get_intrvl_cycles(poll->rxq, i); + } + total_proc += proc_cycles; + } + if (total_proc) { + curr_pmd_usage[num_pmds] = (total_proc * 100) / total_cycles; + } + + VLOG_DBG("PMD auto lb dry run. Current: Core %d, usage %"PRIu64"", + pmd->core_id, curr_pmd_usage[num_pmds]); + + if (atomic_count_get(&pmd->pmd_overloaded)) { + atomic_count_set(&pmd->pmd_overloaded, 0); + } + + pmd_corelist[num_pmds] = pmd->core_id; + num_pmds++; + } + + curr_variance = variance(curr_pmd_usage, num_pmds); + ret = get_dry_run_variance(dp, pmd_corelist, num_pmds, &new_variance); + + if (ret) { + VLOG_DBG("PMD auto lb dry run. Current PMD variance: %"PRIu64"," + " Predicted PMD variance: %"PRIu64"", + curr_variance, new_variance); + + if (new_variance < curr_variance) { + improvement = + ((curr_variance - new_variance) * 100) / curr_variance; + } + if (improvement < ALB_ACCEPTABLE_IMPROVEMENT) { + ret = false; + } + } + + free(curr_pmd_usage); + free(pmd_corelist); + return ret; +} + + /* Return true if needs to revalidate datapath flows. */ static bool dpif_netdev_run(struct dpif *dpif) @@ -4789,6 +5106,9 @@ dpif_netdev_run(struct dpif *dpif) struct dp_netdev_pmd_thread *non_pmd; uint64_t new_tnl_seq; bool need_to_flush = true; + bool pmd_rebalance = false; + long long int now = time_msec(); + struct dp_netdev_pmd_thread *pmd; ovs_mutex_lock(&dp->port_mutex); non_pmd = dp_netdev_get_pmd(dp, NON_PMD_CORE_ID); @@ -4821,6 +5141,32 @@ dpif_netdev_run(struct dpif *dpif) dp_netdev_pmd_unref(non_pmd); } + struct pmd_auto_lb *pmd_alb = &dp->pmd_alb; + if (pmd_alb->is_enabled) { + if (!pmd_alb->rebalance_poll_timer) { + pmd_alb->rebalance_poll_timer = now; + } else if ((pmd_alb->rebalance_poll_timer + + pmd_alb->rebalance_intvl) < now) { + pmd_alb->rebalance_poll_timer = now; + CMAP_FOR_EACH (pmd, node, &dp->poll_threads) { + if (atomic_count_get(&pmd->pmd_overloaded) >= + PMD_RXQ_INTERVAL_MAX) { + pmd_rebalance = true; + break; + } + } + + if (pmd_rebalance && + !dp_netdev_is_reconf_required(dp) && + !ports_require_restart(dp) && + pmd_rebalance_dry_run(dp)) { + VLOG_INFO("PMD auto lb dry run." + " requesting datapath reconfigure."); + dp_netdev_request_reconfigure(dp); + } + } + } + if (dp_netdev_is_reconf_required(dp) || ports_require_restart(dp)) { reconfigure_datapath(dp); } @@ -4979,6 +5325,8 @@ pmd_thread_main(void *f_) reload: pmd_alloc_static_tx_qid(pmd); + atomic_count_init(&pmd->pmd_overloaded, 0); + /* List port/core affinity */ for (i = 0; i < poll_cnt; i++) { VLOG_DBG("Core %d processing port \'%s\' with queue-id %d\n", @@ -7188,9 +7536,39 @@ dp_netdev_pmd_try_optimize(struct dp_netdev_pmd_thread *pmd, struct polled_queue *poll_list, int poll_cnt) { struct dpcls *cls; + uint64_t tot_idle = 0, tot_proc = 0; + unsigned int pmd_load = 0; if (pmd->ctx.now > pmd->rxq_next_cycle_store) { uint64_t curr_tsc; + struct pmd_auto_lb *pmd_alb = &pmd->dp->pmd_alb; + if (pmd_alb->is_enabled && !pmd->isolated + && (pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE] >= + pmd->prev_stats[PMD_CYCLES_ITER_IDLE]) + && (pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY] >= + pmd->prev_stats[PMD_CYCLES_ITER_BUSY])) + { + tot_idle = pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE] - + pmd->prev_stats[PMD_CYCLES_ITER_IDLE]; + tot_proc = pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY] - + pmd->prev_stats[PMD_CYCLES_ITER_BUSY]; + + if (tot_proc) { + pmd_load = ((tot_proc * 100) / (tot_idle + tot_proc)); + } + + if (pmd_load >= ALB_PMD_LOAD_THRESHOLD) { + atomic_count_inc(&pmd->pmd_overloaded); + } else { + atomic_count_set(&pmd->pmd_overloaded, 0); + } + } + + pmd->prev_stats[PMD_CYCLES_ITER_IDLE] = + pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE]; + pmd->prev_stats[PMD_CYCLES_ITER_BUSY] = + pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY]; + /* Get the cycles that were used to process each queue and store. */ for (unsigned i = 0; i < poll_cnt; i++) { uint64_t rxq_cyc_curr = dp_netdev_rxq_get_cycles(poll_list[i].rxq, diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml index 2160910..72f5283 100644 --- a/vswitchd/vswitch.xml +++ b/vswitchd/vswitch.xml @@ -574,6 +574,47 @@ be set to 'skip_sw'.

+ +

+ Configures PMD Auto Load Balancing that allows automatic assignment of + RX queues to PMDs if any of PMDs is overloaded (i.e. processing cycles + > 95%). +

+

+ It uses current scheme of cycle based assignment of RX queues that + are not statically pinned to PMDs. +

+

+ The default value is false. +

+

+ Set this value to true to enable this option. It is + currently disabled by default and an experimental feature. +

+

+ This only comes in effect if cycle based assignment is enabled and + there are more than one non-isolated PMDs present and atleast one of + it polls more than one queue. +

+
+ +

+ The minimum time (in minutes) 2 consecutive PMD Auto Load Balancing + iterations. +

+

+ The defaul value is 1 min. If configured to 0 then it would be + converted to default value i.e. 1 min +

+

+ This option can be configured to avoid frequent trigger of auto load + balancing of PMDs. For e.g. set the value (in min) such that it occurs + once in few hours or a day or a week. +

+