From patchwork Wed Dec 14 07:51:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9473769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CB24F60571 for ; Wed, 14 Dec 2016 07:54:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEBCF28681 for ; Wed, 14 Dec 2016 07:54:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2C25286D5; Wed, 14 Dec 2016 07:54:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2AB59286D2 for ; Wed, 14 Dec 2016 07:54:40 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH4MI-0001Zg-3Z; Wed, 14 Dec 2016 07:52:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH4MG-0001ZQ-I8 for xen-devel@lists.xen.org; Wed, 14 Dec 2016 07:52:12 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 03/80-27678-B2AF0585; Wed, 14 Dec 2016 07:52:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42JxWrohUlf7V0C Ewae1vBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0bD5znMBQ/UKvZeeMvWwPhHqouRk0NCwF/i UMciZhCbTcBA4tal72C2iICsxOquOexdjFwczAIrGCXufd/JApIQFnCReLa4nx3EZhFQlXj/5 xcriM0r4Cmx4NptFoihchI3z3WCDeIU8JJofnSPDcQWAqo5v3wPK4StJvF2+RkWiF5BiZMzn4 DZzAISEgdfvGCewMg7C0lqFpLUAkamVYwaxalFZalFukaGeklFmekZJbmJmTm6hgZmermpxcW J6ak5iUnFesn5uZsYgeHDAAQ7GP8sCzjEKMnBpCTKy3U1IEKILyk/pTIjsTgjvqg0J7X4EKMM B4eSBK/JT6CcYFFqempFWmYOMJBh0hIcPEoivF0gad7igsTc4sx0iNQpRkUpcV4DkIQASCKjN A+uDRY9lxhlpYR5GYEOEeIpSC3KzSxBlX/FKM7BqCTMOx1kCk9mXgnc9FdAi5mAFosu8QdZXJ KIkJJqYBS8ru2w2c1x8RFu9+bnl5cocD6rM5/ipOqx9CJPVGaxyPJ1Gmq3X9k4OD6yfP3cTE6 906uMdU912n/ZF+fi75QUep9gafSNMuHfX8Gfoq+bqSFrHZ654ffSHTcjC5UkbPi5F76eU68n lnLz2K/9E5qXfmPleOmS+U/vwP8daid3b3b+rL+rSYmlOCPRUIu5qDgRABoTYIuZAgAA X-Env-Sender: prvs=149da8861=ross.lagerwall@citrix.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1481701927!25115382!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 39720 invoked from network); 14 Dec 2016 07:52:10 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 14 Dec 2016 07:52:10 -0000 X-IronPort-AV: E=Sophos;i="5.33,345,1477958400"; d="scan'208";a="394683833" From: Ross Lagerwall To: Date: Wed, 14 Dec 2016 07:51:57 +0000 Message-ID: <1481701920-13758-6-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481701920-13758-1-git-send-email-ross.lagerwall@citrix.com> References: <1481701920-13758-1-git-send-email-ross.lagerwall@citrix.com> MIME-Version: 1.0 Cc: Ross Lagerwall , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v2 5/8] tools/livepatch: Remove pointless retry loop X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The default timeout in the hypervisor for a livepatch operation is 30 ms, but xen-livepatch currently waits for up to 30 seconds for the operation to complete. Instead, remove the retry loop and simply wait for 2 * 30 ms for the operation to complete. The extra period is to account for the time to actually start the operation. Furthermore, have xen-livepatch set the hypervisor timeout rather than relying on the hypervisor default since the tool doesn't know how long it will be. Use nanosleep rather than usleep since usleep has been removed from POSIX.1-2008. Signed-off-by: Ross Lagerwall Acked-by: Wei Liu --- tools/misc/xen-livepatch.c | 102 ++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c index 6e3fcf2..4ebe95e 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -265,17 +266,31 @@ struct { }, }; -/* Go around 300 * 0.1 seconds = 30 seconds. */ -#define RETRIES 300 -/* aka 0.1 second */ -#define DELAY 100000 +/* The hypervisor timeout for the live patching operation is 30 msec, + * but it could take some time for the operation to start, so wait twice + * that period. */ +#define HYPERVISOR_TIMEOUT_NS 30000000 +#define DELAY (2 * HYPERVISOR_TIMEOUT_NS) + +static void nanosleep_retry(long ns) +{ + struct timespec req, rem; + int rc; + + rem.tv_sec = 0; + rem.tv_nsec = ns; + + do { + req = rem; + rc = nanosleep(&req, &rem); + } while ( rc == -1 && errno == EINTR ); +} int action_func(int argc, char *argv[], unsigned int idx) { char name[XEN_LIVEPATCH_NAME_SIZE]; - int rc, original_state; + int rc; xen_livepatch_status_t status; - unsigned int retry = 0; if ( argc != 1 ) { @@ -315,11 +330,11 @@ int action_func(int argc, char *argv[], unsigned int idx) /* Perform action. */ if ( action_options[idx].allow & status.state ) { - printf("%s %s:", action_options[idx].verb, name); - rc = action_options[idx].function(xch, name, 0); + printf("%s %s... ", action_options[idx].verb, name); + rc = action_options[idx].function(xch, name, HYPERVISOR_TIMEOUT_NS); if ( rc ) { - printf(" failed\n"); + printf("failed\n"); fprintf(stderr, "Error %d: %s\n", errno, strerror(errno)); return -1; } @@ -334,56 +349,41 @@ int action_func(int argc, char *argv[], unsigned int idx) return -1; } - original_state = status.state; - do { - rc = xc_livepatch_get(xch, name, &status); - if ( rc ) - { - rc = -errno; - break; - } + nanosleep_retry(DELAY); + rc = xc_livepatch_get(xch, name, &status); - if ( status.state != original_state ) - break; - if ( status.rc && status.rc != -XEN_EAGAIN ) - { - rc = status.rc; - break; - } + if ( rc ) + rc = -errno; + else if ( status.rc ) + rc = status.rc; - printf("."); - usleep(DELAY); - } while ( ++retry < RETRIES ); + if ( rc == -XEN_EAGAIN ) + { + printf("failed\n"); + fprintf(stderr, "Operation didn't complete.\n"); + return -1; + } + + if ( rc == 0 ) + rc = status.state; - if ( retry >= RETRIES ) + if ( action_options[idx].expected == rc ) + printf("completed\n"); + else if ( rc < 0 ) { - printf(" failed\n"); - fprintf(stderr, "Operation didn't complete after 30 seconds.\n"); + printf("failed\n"); + fprintf(stderr, "Error %d: %s\n", -rc, strerror(-rc)); return -1; } else { - if ( rc == 0 ) - rc = status.state; - - if ( action_options[idx].expected == rc ) - printf(" completed\n"); - else if ( rc < 0 ) - { - printf(" failed\n"); - fprintf(stderr, "Error %d: %s\n", -rc, strerror(-rc)); - return -1; - } - else - { - printf(" failed\n"); - fprintf(stderr, "%s is in the wrong state.\n" - "Current state: %s\n" - "Expected state: %s\n", - name, state2str(rc), - state2str(action_options[idx].expected)); - return -1; - } + printf("failed\n"); + fprintf(stderr, "%s is in the wrong state.\n" + "Current state: %s\n" + "Expected state: %s\n", + name, state2str(rc), + state2str(action_options[idx].expected)); + return -1; } return 0;