From patchwork Fri Jan 26 12:20:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Scheurich X-Patchwork-Id: 866283 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; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ericsson.com header.i=@ericsson.com header.b="WVmB1P8A"; 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 3zSdXR0D1Dz9s81 for ; Fri, 26 Jan 2018 23:30:15 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 30355FCF; Fri, 26 Jan 2018 12:29:03 +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 AC270F79 for ; Fri, 26 Jan 2018 12:28:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from sessmg23.ericsson.net (sessmg23.ericsson.net [193.180.251.45]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 09D2F34E for ; Fri, 26 Jan 2018 12:28:57 +0000 (UTC) X-AuditID: c1b4fb2d-b35ff70000007932-4c-5a6b1f08fc66 Received: from ESESSHC017.ericsson.se (Unknown_Domain [153.88.183.69]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id CD.9D.31026.80F1B6A5; Fri, 26 Jan 2018 13:28:56 +0100 (CET) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.69) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 26 Jan 2018 13:28:56 +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=NCqiY/6gI8KECEIB6Qw1miruHW4uguzncH3j4T06qI8=; b=WVmB1P8AKr7kUcbBbJnHqAtP4We1UZ33871ZQAMEIR65wv3U50l37Ts+J7bv6oeEwPEmeJB+mwzJnnFTYyvPFEJYvJztYR5nBiw5fw6s6ylS6EHzq+Pv1PHEN+PQBw78tjo8DXq4IFZMito2xGcviLCg/d4SqC08Sx7euDTM9HA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jan.scheurich@ericsson.com; Received: from ubuntu.eed.ericsson.se (129.192.10.2) by AM2PR07MB0644.eurprd07.prod.outlook.com (2a01:111:e400:840f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.5; Fri, 26 Jan 2018 12:28:54 +0000 From: Jan Scheurich To: Date: Fri, 26 Jan 2018 13:20:07 +0100 Message-ID: <1516969207-17326-4-git-send-email-jan.scheurich@ericsson.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516969207-17326-1-git-send-email-jan.scheurich@ericsson.com> References: <1516969207-17326-1-git-send-email-jan.scheurich@ericsson.com> MIME-Version: 1.0 X-Originating-IP: [129.192.10.2] X-ClientProxiedBy: VI1PR0102CA0009.eurprd01.prod.exchangelabs.com (2603:10a6:802::22) To AM2PR07MB0644.eurprd07.prod.outlook.com (2a01:111:e400:840f::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16b505b1-3daf-4afc-fc06-08d564b85d87 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:AM2PR07MB0644; X-Microsoft-Exchange-Diagnostics: 1; AM2PR07MB0644; 3:uGodOtSwnjinknuLSL682wj5Q34Y/NPJ34pCt78Wm+wMvyOSxOmGYOBlBHKdm3wZTfcgQuel7SNNHFnU+ZxWQF2E296eHrBbnhKHIWMXotxHMQcwhgz6YmZhWV5WmcKBVTiZElpP2eFg+p60jQYtArdsG7L/wYio3PajMSqazu/SWzqLmMGqOjsuuDSc7HNxEZLq6eD69jjiE+rvvmJjWPHOpqpzc8WYwC29uEv77VoXyqC0eek0tLxlC3WZPJG3; 25:vOB5Y1bBdfewQY4wElPgj0O2gxXlr15sI3zxXgC9oDv4dEQ/OOCBdM+SJWTFEGqYH3ziWGinX8uc/5oH3VxGgXV6KTNM960AViqK+hXq7WG34b6I0U5Gegi01QVMss4IaYFbkDzF9QGQtw2riICKROHFsoLy5wHBS0SvrZQn931y62bCqT6TPAnpYM6bd0+s0EDCewnzusXw/pNWVTZoflLXHiaavmdJsTRbnVZ3oZizuRqDp+5h/PWmqU1pCqzewr+PMK68x23KDrMef5FM9Aa7a6dwvvW7mxDZnwJAqel871MQVnLJeQZNJVvq/fJ8ZPqPp2s7qEKO/iueVrWRTQ==; 31:fLnxRFcpMRbmJIFsWGvADvN3azVGCScpLKaF0flqO27l970krEULqzzYWSmhFLSd/jYAD6qEQVQYlzbenrgwhDGb+gYhEurQSrUXx7s205qpuyYLDcMgAv8yDs9PIi5HnS6XwVk1N1NdgQEBK/3IXq30+CRB+jxMNLPGC33qxgeeiNl3bYPCyDbwrnMiNALmuqH3HsdZqAj7UM9nRtxwc3ele8W2XAX1I0atbWJUWjc= X-MS-TrafficTypeDiagnostic: AM2PR07MB0644: X-Microsoft-Exchange-Diagnostics: 1; AM2PR07MB0644; 20:q1OJiBSQanD2SzfloqX92LlB/K42CARhnIhRDPKezYvKml/S79PpmGvZNUYIDcwI/ZXFYJXuuQkl+uVKu239rU+2UHHBWzBFchE14zH3uFMiB0kDzngiZSBjzmaO8j7eCO8TCVWkEQ3yFjz3zlLDTluOW9Zs9dhZNz15y6TPgnRQ2QyIri49om+f3B9mnCiVuWgQplrc9g7h/SNwofqut+nSeg0YtXb8/ioWqw9ZivSxZzj/3N3a8vszai4z/o34d1K+Cbnsk5/ixv9YrJ1IZp4J1CvmWYczPjb4TxoKw2+WO/Ceb5nSjvy+Q3Ws1EzLVX1lYVJggSPuuLLxtiGmiyxF5pSWIcu9fsXUCLtM7phwA0gf1MymeyQMH/baV8lmPUex0yOj8jduuJIUeBb2OP9xrvHSOoCffo5Yomj6ruDsAXj1GXUiJNMcph5kg4+/jlRkXL+ANYD6PXX1qMLzc+eAPk00Nbb1LSWmuIZbEdXuxtK+wgZ6BDSXgfS6Vp/t; 4:pK3L1bHXgkTzJ8qYxVtYSMGzjFdkX3gSTOBpRqSVP/hxpdeleZs+pgAY0FI6dlvWJCT97FzLbQGCME8OXUbqYfVYIk9x1Bc6ApGtS/f3vK7MoohyyXE4vLOfyuDIykhGJ+kgXP13hhUPxUCS3EqjfQf79tMnNvDAIKq/S/zdrALgEcUpy08S2Ybdm6Lp3JrBVqc3Lbsbk1CW5AIEwtwFdVsLNyknBRxfl35yhKcYispOiWqRKMTqGXjmjLfqP2TNYzaA5faxAjDB5K0fCINeYUgDDTWnCZwDly6Ox0qPYaBxZKzXjUHIpXejfT3OpPznsOf/bk5CQwSXhweiEuiLzhi6N/2+YsDkE95GxDDGVao= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(37575265505322)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3231023)(2400081)(944501161)(93006095)(93001095)(3002001)(10201501046)(6041288)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM2PR07MB0644; BCL:0; PCL:0; RULEID:; SRVR:AM2PR07MB0644; X-Forefront-PRVS: 05641FD966 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(346002)(376002)(366004)(39380400002)(39860400002)(189003)(199004)(4326008)(6486002)(26005)(107886003)(97736004)(7736002)(16526019)(36756003)(25786009)(305945005)(2906002)(68736007)(105586002)(16586007)(59450400001)(316002)(47776003)(50226002)(2361001)(81156014)(8936002)(386003)(8676002)(6916009)(6506007)(2351001)(81166006)(2950100002)(6666003)(52116002)(6512007)(51416003)(53936002)(478600001)(86362001)(6116002)(50466002)(3846002)(76176011)(48376002)(66066001)(106356001)(5660300001)(186003)(21314002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR07MB0644; H:ubuntu.eed.ericsson.se; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; AM2PR07MB0644; 23:C9oMeqkP/Gi7VKV1YdzGz5XtoVicT5sTiTz8R39Ru?= KeMLiCMv2zWQiJLT/kOI7U461gGXiZ0GtYIaqf6PRD4tHm0l/ny55prU/av7Ht+53IlTXTBlTBvK9jNR4sAUCvjZnqqGRE3ykabGqHjn0cj2LjrLAFg5j8GHgDtjJfpBzqySAeAa37bh65jQBTM8YstfYDGsxi8LcJQez9bP2gFJ/CAexgPCxvLvekTViO9DGafoSFh5xM6OSYZju3y2adnpEofRbqPxIUoLpNBjmmisCEZZKwUCVyn0W3UlAUtRJmZsBEgEzGpUJ2mabh78dvTgTcf41QRWIWvv6iYNq27s7y0cVcoznQAQXlYcnpYQiN0RH2x8xuM3TrZ3wkiY4eJqEZZRoGUgc3FDJjFvz2LJ7i1UPs+4i318p7S/AqOq8mDDQjoganAyumo5rtz8s/jFbajHg4f1gc9yu4FR7Ea/lYG1Qpa1KT6GXiCG9SBK1+TWxqzNGnuhAbThyU/Gfljh9RIrikmSZdJWvSiB+HDjZCg/wRqA1V29UGtZYt7pveccJdzNaq3dhQxzmZefuYVl0TF31gPPcSsnlQeSLY+yrspvt4fa7MMCVDZs1VOC10QrZYNCnM9p3NtuOab36tDVXg5NHXHwjdCMagQhx+KRFHW+MchwxKSMP+hBb58r0FLpXIR+TbdeYWbBA7disVf7iJr0PsQHnnIaPcsKosJg87iQFn1RVSdHEKy1dWnmlrJ8bAYjSY3oDay7+z8Z9EBmr/70ftPSuT0aitWHY1FGvd4RFn1+1r54gVFSp874yeH5hZw2lKaUmIRLVacd7Gb+9OcXF9dE5TsA2cSLEXzH6FMGQmGAqP6UsAfu1a2W3KhYSl5LjkGnckCZsf/jLj+TgGrZSruvPVWR5lG3CfOShNWXQt9MBazemke5xfw0aEfifaUnwp6QTCnI+6vX1SYTZiPxR7qlJx99abe1ju2+JryDuo1I0i3YJaNP9t6v/MQEixKr3hhKdCJaNnXFJLFGcCct6RTdkn8LszTvcj3mmvdyMEJoSIG/Hjry2uzunEtLhdjHwI3tnhtIjJ5igyr+4cltDIkA918mVCo5YqHJnYXwRUjd8cADV5UKhEMTId0zsmVa6Wbn3wkAR4/U/QhW8FhEUlJAVTgSQFvhj3N/rFF23rzlSfpfod10Pn8QUMPFGwGKjtijWvb4o3fMEYR X-Microsoft-Exchange-Diagnostics: 1; AM2PR07MB0644; 6:NwOH/Bi7VKewOlIsDgPjO5GaajJVSzXKA1Yd6j8XOKf1dZW5R9qrawtfPtB2xDdyJ8OsV2bPBz8x5vBAqmqUYFnEFQ6MEJ1fYFy7tSr9aFne4ZaxhGMrY2nEE4C38mBC2gOTgdnqM55ZkkwPiVE77hp2BNtdrvxWbkbs+WsQnMH7OhNHCtBEjQXzfzO7UA2e1exPQW+C6umw7m11ogcpHOeIKm+xaRxe6bjbTcMdbu0xTuDEYgsW2cv77dxW0z+EZY+cVYXHEN41MQbADnCyFJs1+Wg3kc7k6XBCA8wXrwuiDjQIuoCJ3DaqZMQtrW6ftVCvq+sLLycf/odbFcSesr/Rn67g0sxwZvDG7uVsVAs=; 5:MzAx4szqp4T+k2zTnhkg+80sIx8sRst5U6WoOGjFB7jnFLs5tBp3ynMfQU2LQueyaiABV6us7j/g+fJKjyMMqczQHf0d0rDf4znhb5JkwvuHG/58U4SxN+M41IQIxOcicxZVFUU0794nWnXqgFdB5px2AuiJjhdO1sl5s+hSzwc=; 24:PVh0CYrD3sUom0lJCthe2oDxs2gays3oy6Tuz3XrGKkais0z5bQZTB3/DUOjCtWgLIJ0DbrLnPM4dIVv95hZROY4cnb35OKzOwhHyGfVPRY=; 7:OBvt2wdYeHGXIponOzyWJTQlP3AjKy3oMNr25iFVg8GUn8bmpbSqTObAGOAAxosqyon/V8A9XmpOFQFEpV1TD8u3P6gdg3R2xtNnWc5OZRpDT9EHyU9wo1AsV0wdkJcOR1kb6O0zG1GLJD5L+B5ujuSTKo393V9HLAW6mixu4dEj0e0FZNlIrOnifHxjIv4c7MFhonNPB2Pnf6EsIlCvwdZ7uGGqbn+ZTAlBA99au6/bloWA2r/9aIFaRQu3vLgJ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2018 12:28:54.4683 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16b505b1-3daf-4afc-fc06-08d564b85d87 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR07MB0644 X-OriginatorOrg: ericsson.com X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUhTURjGOfdju1uublPpteyDYQiSy2bIhD6MMlYWhP2hLCSX3lQ259hV yRJaKUmLSgjF2SzxI/IrUxeZDtPJpGVSYZbSH2qstGamxiyTZZt3gf8973l+zznvA4fCxUZy M5WlzWX0WpVGwhMSpuSn8ZHUdrUyatQRK+9sqUdy+6AVl78rWeLL2yaHSHmLbY4fRypqrV8x xZexFaT40TPCU9yyNKJThFK4L53RZOUz+t0HUoWZ9Q4TX/f4JrrQ0TaAGZDlvBEJKKD3wvjr WdyIhJSY7kfwcsJOcsMLBIbfY6sDQS9gYG79jHwRRKdA8ZMyjKNuYzDb5CSMiKJ4dBTc7Y7z MUF0CPyttfB8DE6XISiaWsR8RiCdBB7zo1VN0DuhZNhA+LSIPg4Nb5YQt9M2cAzcIX1aQCdA 0ycP7tNiL9PVcQPn+I3gMDlXszgN0Dc9jXPZHdBmMRG+h4GuQtBbMoFx4XDw2NwEB20F+5DZ r0/Ch2onyQWeezs3z2DcYODD98Fu/7UR8HNulMcZdXzwuNwYZ6hhZsrF47S3g8XqT1fgUOSp 8UOh0GBv9+tGEuofxHA7MWAZLeaVoojKNZ0q13SqRlgjCmYZls3OkEVLGX1WGsvmaKVaJrcd eX9In2U5shM1uQ7ZEE0hSYDo0ga1Ukyq8tmCbBsCCpcEiWIE3iNRuqrgIqPPOavP0zCsDW2h CMkmkeOYSCmmM1S5jJphdIz+v4tRgs0GFHCEbJ4K63DHLhYOL1jrAqXjI/OJzQljnXOng0PG B9LmXaG9Bcv3R64Mi9R5YtvR6q5douXDVa9Kw2VB7jDZPdSaoqkTVBS5y6n1xdJvB3X4/LnC a/EGlmT/PFun2x/dHfg+sceZ9Lb1cuHHlP7wwTPlV0/8qkmWXU9dmXzIM0sINlO1JwLXs6p/ AfukOR0DAAA= 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: i.maximets@samsung.com Subject: [ovs-dev] [PATCH v8 3/3] dpif-netdev: Detection and logging of suspicious PMD iterations 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 This patch enhances dpif-netdev-perf to detect iterations with suspicious statistics according to the following criteria: - iteration lasts longer than US_THR microseconds (default 250). This can be used to capture events where a PMD is blocked or interrupted for such a period of time that there is a risk for dropped packets on any of its Rx queues. - max vhost qlen exceeds a threshold Q_THR (default 128). This can be used to infer virtio queue overruns and dropped packets inside a VM, which are not visible in OVS otherwise. Such suspicious iterations can be logged together with their iteration statistics to be able to correlate them to packet drop or other events outside OVS. A new command is introduced to enable/disable logging at run-time and to adjust the above thresholds for suspicious iterations: ovs-appctl dpif-netdev/pmd-perf-log-set on | off [-b before] [-a after] [-e|-ne] [-us usec] [-q qlen] Turn logging on or off at run-time (on|off). -b before: The number of iterations before the suspicious iteration to be logged (default 5). -a after: The number of iterations after the suspicious iteration to be logged (default 5). -e: Extend logging interval if another suspicious iteration is detected before logging occurs. -ne: Do not extend logging interval (default). -q qlen: Suspicious vhost queue fill level threshold. Increase this to 512 if the Qemu supports 1024 virtio queue length. (default 128). -us usec: change the duration threshold for a suspicious iteration (default 250 us). Note: Logging of suspicious iterations itself consumes a considerable amount of processing cycles of a PMD which may be visible in the iteration history. In the worst case this can lead OVS to detect another suspicious iteration caused by logging. If more than 100 iterations around a suspicious iteration have been logged once, OVS falls back to the safe default values (-b 5/-a 5/-ne) to avoid that logging itself causes continuos further logging. Signed-off-by: Jan Scheurich Acked-by: Billy O'Mahony --- NEWS | 2 + lib/dpif-netdev-perf.c | 201 ++++++++++++++++++++++++++++++++++++++++++++ lib/dpif-netdev-perf.h | 42 +++++++++ lib/dpif-netdev-unixctl.man | 59 +++++++++++++ lib/dpif-netdev.c | 5 ++ 5 files changed, 309 insertions(+) diff --git a/NEWS b/NEWS index 587b036..615a630 100644 --- a/NEWS +++ b/NEWS @@ -59,6 +59,8 @@ v2.9.0 - xx xxx xxxx * Commands ovs-appctl dpif-netdev/pmd-*-show can now work on a single PMD * Detailed PMD performance metrics available with new command ovs-appctl dpif-netdev/pmd-perf-show + * Supervision of PMD performance metrics and logging of suspicious + iterations - vswitchd: * Datapath IDs may now be specified as 0x1 (etc.) instead of 16 digits. * Configuring a controller, or unconfiguring all controllers, now deletes diff --git a/lib/dpif-netdev-perf.c b/lib/dpif-netdev-perf.c index 43f537e..e6afd07 100644 --- a/lib/dpif-netdev-perf.c +++ b/lib/dpif-netdev-perf.c @@ -25,6 +25,24 @@ VLOG_DEFINE_THIS_MODULE(pmd_perf); +#define ITER_US_THRESHOLD 250 /* Warning threshold for iteration duration + in microseconds. */ +#define VHOST_QUEUE_FULL 128 /* Size of the virtio TX queue. */ +#define LOG_IT_BEFORE 5 /* Number of iterations to log before + suspicious iteration. */ +#define LOG_IT_AFTER 5 /* Number of iterations to log after + suspicious iteration. */ + +bool log_enabled = false; +bool log_extend = false; +static uint32_t log_it_before = LOG_IT_BEFORE; +static uint32_t log_it_after = LOG_IT_AFTER; +static uint32_t log_us_thr = ITER_US_THRESHOLD; +uint32_t log_q_thr = VHOST_QUEUE_FULL; +uint64_t iter_cycle_threshold; + +static struct vlog_rate_limit latency_rl = VLOG_RATE_LIMIT_INIT(600, 600); + #ifdef DPDK_NETDEV static uint64_t get_tsc_hz(void) @@ -127,6 +145,10 @@ pmd_perf_stats_init(struct pmd_perf_stats *s) histogram_walls_set_log(&s->cycles_per_upcall, 1000, 1000000); histogram_walls_set_log(&s->max_vhost_qfill, 0, 512); s->start_ms = time_msec(); + s->log_susp_it = UINT32_MAX; + s->log_begin_it = UINT32_MAX; + s->log_end_it = UINT32_MAX; + s->log_reason = NULL; } void @@ -382,6 +404,10 @@ pmd_perf_stats_clear_lock(struct pmd_perf_stats *s) history_init(&s->milliseconds); s->start_ms = time_msec(); s->milliseconds.sample[0].timestamp = s->start_ms; + s->log_susp_it = UINT32_MAX; + s->log_begin_it = UINT32_MAX; + s->log_end_it = UINT32_MAX; + s->log_reason = NULL; /* Clearing finished. */ s->clear = false; ovs_mutex_unlock(&s->clear_mutex); @@ -402,3 +428,178 @@ pmd_perf_stats_clear(struct pmd_perf_stats *s) s->clear = true; } } + +/* Delay logging of the suspicious iteration and the range of iterations + * around it until after the last iteration in the range to be logged. + * This avoids any distortion of the measurements through the cost of + * logging itself. */ + +void +pmd_perf_set_log_susp_iteration(struct pmd_perf_stats *s, + char *reason) +{ + if (s->log_susp_it == UINT32_MAX) { + /* No logging scheduled yet. */ + s->log_susp_it = s->iterations.idx; + s->log_reason = reason; + s->log_begin_it = history_sub(s->iterations.idx, log_it_before); + s->log_end_it = history_add(s->iterations.idx, log_it_after + 1); + } else if (log_extend) { + /* Logging was initiated earlier, we the previous suspicious iteration + * now and extend the logging interval, if possible. */ + struct iter_stats *susp = &s->iterations.sample[s->log_susp_it]; + uint32_t new_end_it, old_range, new_range; + + VLOG_WARN_RL(&latency_rl, + "Suspicious iteration (%s): tsc=%"PRIu64 + " duration=%"PRIu64" us\n", + s->log_reason, + susp->timestamp, + (1000000L * susp->cycles) / get_tsc_hz()); + + new_end_it = history_add(s->iterations.idx, log_it_after + 1); + new_range = history_sub(new_end_it, s->log_begin_it); + old_range = history_sub(s->log_end_it, s->log_begin_it); + if (new_range < old_range) { + /* Extended range exceeds history length. */ + new_end_it = s->log_begin_it; + } + s->log_susp_it = s->iterations.idx; + s->log_reason = reason; + s->log_end_it = new_end_it; + } +} + +void +pmd_perf_log_susp_iteration_neighborhood(struct pmd_perf_stats *s) +{ + ovs_assert(s->log_reason != NULL); + ovs_assert(s->log_susp_it != UINT32_MAX); + + struct ds log = DS_EMPTY_INITIALIZER; + struct iter_stats *susp = &s->iterations.sample[s->log_susp_it]; + uint32_t range = history_sub(s->log_end_it, s->log_begin_it); + + VLOG_WARN_RL(&latency_rl, + "Suspicious iteration (%s): tsc=%"PRIu64 + " duration=%"PRIu64" us\n", + s->log_reason, + susp->timestamp, + (1000000L * susp->cycles) / get_tsc_hz()); + + pmd_perf_format_iteration_history(&log, s, range); + VLOG_WARN_RL(&latency_rl, + "Neighborhood of suspicious iteration:\n" + "%s", ds_cstr(&log)); + ds_destroy(&log); + s->log_susp_it = s->log_end_it = s->log_begin_it = UINT32_MAX; + s->log_reason = NULL; + + if (range > 100) { + /* Reset to safe default values to avoid disturbance. */ + log_it_before = LOG_IT_BEFORE; + log_it_after = LOG_IT_AFTER; + log_extend = false; + } +} + +void +pmd_perf_log_set_cmd(struct unixctl_conn *conn, + int argc, const char *argv[], + void *aux OVS_UNUSED) +{ + unsigned int it_before, it_after, us_thr, q_thr; + bool on, extend; + bool usage = false; + + on = log_enabled; + extend = log_extend; + it_before = log_it_before; + it_after = log_it_after; + q_thr = log_q_thr; + us_thr = log_us_thr; + + while (argc > 1) { + if (!strcmp(argv[1], "on")) { + on = true; + argc--; + argv++; + } else if (!strcmp(argv[1], "off")) { + on = false; + argc--; + argv++; + } else if (!strcmp(argv[1], "-e")) { + extend = true; + argc--; + argv++; + } else if (!strcmp(argv[1], "-ne")) { + extend = false; + argc--; + argv++; + } else if (!strcmp(argv[1], "-a") && argc > 2) { + if (str_to_uint(argv[2], 10, &it_after)) { + if (it_after > HISTORY_LEN - 2) { + it_after = HISTORY_LEN - 2; + } + } else { + usage = true; + break; + } + argc -= 2; + argv += 2; + } else if (!strcmp(argv[1], "-b") && argc > 2) { + if (str_to_uint(argv[2], 10, &it_before)) { + if (it_before > HISTORY_LEN - 2) { + it_before = HISTORY_LEN - 2; + } + } else { + usage = true; + break; + } + argc -= 2; + argv += 2; + } else if (!strcmp(argv[1], "-q") && argc > 2) { + if (!str_to_uint(argv[2], 10, &q_thr)) { + usage = true; + break; + } + argc -= 2; + argv += 2; + } else if (!strcmp(argv[1], "-us") && argc > 2) { + if (!str_to_uint(argv[2], 10, &us_thr)) { + usage = true; + break; + } + argc -= 2; + argv += 2; + } else { + usage = true; + break; + } + } + if (it_before + it_after > HISTORY_LEN - 2) { + it_after = HISTORY_LEN - 2 - it_before; + } + + if (usage) { + unixctl_command_reply_error(conn, + "Usage: ovs-appctl dpif-netdev/pmd-perf-log-set " + "[on|off] [-b before] [-a after] [-e|-ne] " + "[-us usec] [-q qlen]"); + return; + } + + VLOG_INFO("pmd-perf-log-set: %s, before=%d, after=%d, extend=%s, " + "us_thr=%d, q_thr=%d\n", + on ? "on" : "off", it_before, it_after, + extend ? "true" : "false", us_thr, q_thr); + log_enabled = on; + log_extend = extend; + log_it_before = it_before; + log_it_after = it_after; + log_q_thr = q_thr; + log_us_thr = us_thr; + iter_cycle_threshold = (log_us_thr * get_tsc_hz()) / 1000000L; + + unixctl_command_reply(conn, ""); +} diff --git a/lib/dpif-netdev-perf.h b/lib/dpif-netdev-perf.h index b91cb30..334908f 100644 --- a/lib/dpif-netdev-perf.h +++ b/lib/dpif-netdev-perf.h @@ -171,6 +171,14 @@ struct pmd_perf_stats { struct history iterations; /* Millisecond history buffer. */ struct history milliseconds; + /* Suspicious iteration log. */ + uint32_t log_susp_it; + /* Start of iteration range to log. */ + uint32_t log_begin_it; + /* End of iteration range to log. */ + uint32_t log_end_it; + /* Reason for logging suspicious iteration. */ + char *log_reason; }; /* Support for accurate timing of PMD execution on TSC clock cycle level. @@ -341,6 +349,15 @@ history_store(struct history *h, struct iter_stats *is) return history_next(h); } +/* Data and function related to logging of suspicious iterations. */ + +extern bool log_enabled; +extern uint32_t log_q_thr; +extern uint64_t iter_cycle_threshold; + +void pmd_perf_set_log_susp_iteration(struct pmd_perf_stats *s, char *reason); +void pmd_perf_log_susp_iteration_neighborhood(struct pmd_perf_stats *s); + /* Functions recording PMD metrics per iteration. */ static inline void @@ -370,6 +387,7 @@ pmd_perf_end_iteration(struct pmd_perf_stats *s, int rx_packets, uint64_t now_tsc = cycles_counter_update(s); struct iter_stats *cum_ms; uint64_t cycles, cycles_per_pkt = 0; + char *reason = NULL; cycles = now_tsc - s->current.timestamp; s->current.cycles = cycles; @@ -421,6 +439,27 @@ pmd_perf_end_iteration(struct pmd_perf_stats *s, int rx_packets, /* Store in iteration history. This advances the iteration idx and * clears the next slot in the iteration history. */ history_store(&s->iterations, &s->current); + + if (log_enabled) { + /* Log suspicious iterations. */ + if (cycles > iter_cycle_threshold) { + reason = "Excessive total cycles"; + } else if (s->current.max_vhost_qfill >= log_q_thr) { + reason = "Vhost RX queue full"; + } + if (OVS_UNLIKELY(reason)) { + pmd_perf_set_log_susp_iteration(s, reason); + cycles_counter_update(s); + } + + /* Log iteration interval around suspicious iteration when reaching + * the end of the range to be logged. */ + if (OVS_UNLIKELY(s->log_end_it == s->iterations.idx)) { + pmd_perf_log_susp_iteration_neighborhood(s); + cycles_counter_update(s); + } + } + if (now_tsc > s->next_check_tsc) { /* Check if ms is completed and store in milliseconds history. */ uint64_t now = time_msec(); @@ -458,6 +497,9 @@ void pmd_perf_format_iteration_history(struct ds *str, int n_iter); void pmd_perf_format_ms_history(struct ds *str, struct pmd_perf_stats *s, int n_ms); +void pmd_perf_log_set_cmd(struct unixctl_conn *conn, + int argc, const char *argv[], + void *aux OVS_UNUSED); #ifdef __cplusplus } diff --git a/lib/dpif-netdev-unixctl.man b/lib/dpif-netdev-unixctl.man index 76c3e4e..ab8619e 100644 --- a/lib/dpif-netdev-unixctl.man +++ b/lib/dpif-netdev-unixctl.man @@ -149,6 +149,65 @@ reported by the \fBdpif-netdev/pmd-stats-show\fR command. To reset the counters and start a new measurement use \fBdpif-netdev/pmd-stats-clear\fR. . +.IP "\fBdpif-netdev/pmd-perf-log-set\fR \fBon\fR|\fBoff\fR \ +[\fB-b\fR \fIbefore\fR] [\fB-a\fR \fIafter\fR] [\fB-e\fR|\fB-ne\fR] \ +[\fB-us\fR \fIusec\fR] [\fB-q\fR \fIqlen\fR]" +. +The userspace "netdev" datapath is able to supervise the PMD performance +metrics and detect iterations with suspicious statistics according to the +following criteria: +.RS +.IP \(em +The iteration lasts longer than \fIusec\fR microseconds (default 250). +This can be used to capture events where a PMD is blocked or interrupted for +such a period of time that there is a risk for dropped packets on any of its Rx +queues. +.IP \(em +The max vhost qlen exceeds a threshold \fIqlen\fR (default 128). This can be +used to infer virtio queue overruns and dropped packets inside a VM, which are +not visible in OVS otherwise. +.RE +.IP +Such suspicious iterations can be logged together with their iteration +statistics in the \fBovs-vswitchd.log\fR to be able to correlate them to +packet drop or other events outside OVS. + +The above command enables (\fBon\fR) or disables (\fBoff\fR) supervision and +logging at run-time and can be used to adjust the above thresholds for +detecting suspicious iterations. By default supervision and logging is +disabled. + +The command options are: +.RS +.IP "\fB-b\fR \fIbefore\fR" +The number of iterations before the suspicious iteration to be logged +(default 5). +.IP "\fB-a\fR \fIafter\fR" +The number of iterations after the suspicious iteration to be logged +(default 5). +.IP "\fB-e\fR" +Extend logging interval if another suspicious iteration is detected +before logging occurs. +.IP "\fB-ne\fR" +Do not extend logging interval if another suspicious iteration is detected +before logging occurs (default). +.IP "\fB-q\fR \fIqlen\fR" +Suspicious vhost queue fill level threshold. Increase this to 512 if the Qemu +supports 1024 virtio queue length (default 128). +.IP "\fB-us\fR \fIusec\fR" +Change the duration threshold for a suspicious iteration (default 250 us). +.RE + +Note: Logging of suspicious iterations itself consumes a considerable amount +of processing cycles of a PMD which may be visible in the iteration history. +In the worst case this can lead OVS to detect another suspicious iteration +caused by logging. + +If more than 100 iterations around a suspicious iteration have been logged +once, OVS falls back to the safe default values (-b 5 -a 5 -ne) to avoid +that logging itself continuously causes logging of further suspicious +iterations. +. .IP "\fBdpif-netdev/pmd-rxq-show\fR [\fB-pmd\fR \fIcore\fR] [\fIdp\fR]" For one or all pmd threads of the datapath \fIdp\fR show the list of queue-ids with port names, which this thread polls. diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index dbd75e1..c2c114f 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1235,6 +1235,11 @@ dpif_netdev_init(void) unixctl_command_register("dpif-netdev/pmd-rxq-rebalance", "[dp]", 0, 1, dpif_netdev_pmd_rebalance, NULL); + unixctl_command_register("dpif-netdev/pmd-perf-log-set", + "on|off [-b before] [-a after] [-e|-ne] " + "[-us usec] [-q qlen]", + 0, 10, pmd_perf_log_set_cmd, + NULL); return 0; }