From patchwork Mon Dec 12 16:18:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9470923 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 5517B60573 for ; Mon, 12 Dec 2016 16:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C3E3284D4 for ; Mon, 12 Dec 2016 16:24:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 414F5284D9; Mon, 12 Dec 2016 16:24:25 +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 B767D284D4 for ; Mon, 12 Dec 2016 16:24:24 +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 1cGTMh-0002Iv-O1; Mon, 12 Dec 2016 16:22:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGTMf-0002Di-IM for xen-devel@lists.xen.org; Mon, 12 Dec 2016 16:22:09 +0000 Received: from [85.158.137.68] by server-1.bemta-3.messagelabs.com id 12/2F-14854-0BECE485; Mon, 12 Dec 2016 16:22:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrrBXnfDOb8 Ig4f7xCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1owtvdOZCu6qVbT/KWxg/C7VxcjBISHgL/Hj ZH4XIycHm4CBxK1L35lBbBEBWYnVXXPYuxi5OJgFVjBK3Pu+kwWkXljAReLjJ2WQGhYBVYn+/ Q/ZQWxeAU+Jb1//sYHYEgJyEjfPdYLN4RTwkri9pR2sRgioZlnnJ1YIW03i7fIzLBC9ghInZz 4Bs5kFJCQOvnjBPIGRdxaS1CwkqQWMTKsYNYpTi8pSi3SNjPWSijLTM0pyEzNzdA0NjPVyU4u LE9NTcxKTivWS83M3MQIDp56BgXEHY99ev0OMkhxMSqK8Xw74RQjxJeWnVGYkFmfEF5XmpBYf YpTh4FCS4A05C5QTLEpNT61Iy8wBhjBMWoKDR0mEdyZImre4IDG3ODMdInWKUVFKnNcFJCEAk sgozYNrg8XNJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvAkgU3gy80rgpr8CWswEtPj5Pm +QxSWJCCmpBsZZE1R+ztaYWFJ4TFMp10PwxUuG9WJh4bm23pvOWvaIuJrtWtvaJ25uw3NHVKt o/2FXZ6eyj4131t9W+n3IUL56vlWA31q7JT4zDUK3XAmYVMer2Revu9co/YldgrqsqB334r85 7eEy1zzq+l5s+7DGTfT/X9OV6woOHtwxf/2fv+tL/B77ciqxFGckGmoxFxUnAgBKaaxXlgIAA A== X-Env-Sender: prvs=147044df7=ross.lagerwall@citrix.com X-Msg-Ref: server-15.tower-31.messagelabs.com!1481559726!71705635!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49340 invoked from network); 12 Dec 2016 16:22:07 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-15.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 12 Dec 2016 16:22:07 -0000 X-IronPort-AV: E=Sophos;i="5.33,337,1477958400"; d="scan'208";a="403136620" From: Ross Lagerwall To: Date: Mon, 12 Dec 2016 16:18:08 +0000 Message-ID: <1481559490-13844-6-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481559490-13844-1-git-send-email-ross.lagerwall@citrix.com> References: <1481559490-13844-1-git-send-email-ross.lagerwall@citrix.com> MIME-Version: 1.0 Cc: Ross Lagerwall , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v1 5/7] 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 --- 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 afd8c48..d683860 100644 --- a/tools/misc/xen-livepatch.c +++ b/tools/misc/xen-livepatch.c @@ -7,6 +7,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 30000000 /* in ns */ +#define DELAY (2 * HYPERVISOR_TIMEOUT) + +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); 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;