From patchwork Thu Mar 3 16:48:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 8493991 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C3B9B9F9A0 for ; Thu, 3 Mar 2016 16:51:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF01320364 for ; Thu, 3 Mar 2016 16:51:32 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 55C0B2037C for ; Thu, 3 Mar 2016 16:51:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abWR8-0005Sn-Sp; Thu, 03 Mar 2016 16:49:14 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1abWR8-0005Ms-4c for xen-devel@lists.xen.org; Thu, 03 Mar 2016 16:49:14 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 07/77-19343-40B68D65; Thu, 03 Mar 2016 16:49:08 +0000 X-Env-Sender: jgross@suse.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1457023748!26732184!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40900 invoked from network); 3 Mar 2016 16:49:08 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-5.tower-31.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 3 Mar 2016 16:49:08 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AC483ADDC; Thu, 3 Mar 2016 16:49:07 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xen.org Date: Thu, 3 Mar 2016 17:48:50 +0100 Message-Id: <1457023730-10997-7-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1457023730-10997-1-git-send-email-jgross@suse.com> References: <1457023730-10997-1-git-send-email-jgross@suse.com> Cc: Juergen Gross , Wei Liu , Ian Jackson , Stefano Stabellini Subject: [Xen-devel] [PATCH v3 6/6] libxl: add force option for xl vcpu-pin 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to be able to undo a vcpu pin override in case of a kernel driver error add a flag "-f" to the "xl vcpu-pin" command forcing the hypervisor to undo the override. Cc: Ian Jackson Cc: Stefano Stabellini Cc: Wei Liu Signed-off-by: Juergen Gross Reviewed-by: Dario Faggioli --- tools/libxl/libxl.c | 31 +++++++++++++++++++++++++------ tools/libxl/libxl.h | 4 ++++ tools/libxl/xl_cmdimpl.c | 27 +++++++++++++++++++++++---- tools/libxl/xl_cmdtable.c | 3 ++- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 4cdc169..53f0100 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5301,18 +5301,20 @@ err: return NULL; } -int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, - const libxl_bitmap *cpumap_hard, - const libxl_bitmap *cpumap_soft) +static int libxl__set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, + uint32_t vcpuid, + const libxl_bitmap *cpumap_hard, + const libxl_bitmap *cpumap_soft, + unsigned flags) { GC_INIT(ctx); libxl_bitmap hard, soft; - int rc, flags = 0; + int rc; libxl_bitmap_init(&hard); libxl_bitmap_init(&soft); - if (!cpumap_hard && !cpumap_soft) { + if (!cpumap_hard && !cpumap_soft && !flags) { rc = ERROR_INVAL; goto out; } @@ -5327,7 +5329,7 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, goto out; libxl__bitmap_copy_best_effort(gc, &hard, cpumap_hard); - flags = XEN_VCPUAFFINITY_HARD; + flags |= XEN_VCPUAFFINITY_HARD; } if (cpumap_soft) { rc = libxl_cpu_bitmap_alloc(ctx, &soft, 0); @@ -5378,6 +5380,23 @@ int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, return rc; } +int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, + const libxl_bitmap *cpumap_hard, + const libxl_bitmap *cpumap_soft) +{ + return libxl__set_vcpuaffinity(ctx, domid, vcpuid, cpumap_hard, + cpumap_soft, 0); +} + +int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid, + uint32_t vcpuid, + const libxl_bitmap *cpumap_hard, + const libxl_bitmap *cpumap_soft) +{ + return libxl__set_vcpuaffinity(ctx, domid, vcpuid, cpumap_hard, + cpumap_soft, XEN_VCPUAFFINITY_FORCE); +} + int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid, unsigned int max_vcpus, const libxl_bitmap *cpumap_hard, diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index f9e3ef5..19ec076 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1715,6 +1715,10 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo); int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, const libxl_bitmap *cpumap_hard, const libxl_bitmap *cpumap_soft); +int libxl_set_vcpuaffinity_force(libxl_ctx *ctx, uint32_t domid, + uint32_t vcpuid, + const libxl_bitmap *cpumap_hard, + const libxl_bitmap *cpumap_soft); int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid, unsigned int max_vcpus, const libxl_bitmap *cpumap_hard, diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 411473d..120f30b 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -5344,6 +5344,10 @@ int main_vcpulist(int argc, char **argv) int main_vcpupin(int argc, char **argv) { + static struct option opts[] = { + {"force", 0, 0, 'f'}, + COMMON_LONG_OPTS + }; libxl_vcpuinfo *vcpuinfo; libxl_bitmap cpumap_hard, cpumap_soft;; libxl_bitmap *soft = &cpumap_soft, *hard = &cpumap_hard; @@ -5355,13 +5359,17 @@ int main_vcpupin(int argc, char **argv) long vcpuid; const char *vcpu, *hard_str, *soft_str; char *endptr; - int opt, nb_cpu, nb_vcpu, rc = EXIT_FAILURE; + int opt, nb_cpu, nb_vcpu, force = 0, rc = EXIT_FAILURE; libxl_bitmap_init(&cpumap_hard); libxl_bitmap_init(&cpumap_soft); - SWITCH_FOREACH_OPT(opt, "", NULL, "vcpu-pin", 3) { - /* No options */ + SWITCH_FOREACH_OPT(opt, "f", opts, "vcpu-pin", 3) { + case 'f': + force = 1; + break; + default: + break; } domid = find_domain(argv[optind]); @@ -5376,6 +5384,10 @@ int main_vcpupin(int argc, char **argv) fprintf(stderr, "Error: Invalid argument %s as VCPU.\n", vcpu); goto out; } + if (force) { + fprintf(stderr, "Error: --force and 'all' as VCPU not allowed.\n"); + goto out; + } vcpuid = -1; } @@ -5437,7 +5449,14 @@ int main_vcpupin(int argc, char **argv) goto out; } - if (vcpuid != -1) { + if (force) { + if (libxl_set_vcpuaffinity_force(ctx, domid, vcpuid, hard, soft)) { + fprintf(stderr, "Could not set affinity for vcpu `%ld'.\n", + vcpuid); + goto out; + } + } + else if (vcpuid != -1) { if (libxl_set_vcpuaffinity(ctx, domid, vcpuid, hard, soft)) { fprintf(stderr, "Could not set affinity for vcpu `%ld'.\n", vcpuid); diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index fdc1ac6..7cc0401 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -222,7 +222,8 @@ struct cmd_spec cmd_table[] = { { "vcpu-pin", &main_vcpupin, 1, 1, "Set which CPUs a VCPU can use", - " ", + "[option] ", + "-f, --force undo an override pinning done by the kernel", }, { "vcpu-set", &main_vcpuset, 0, 1,