From patchwork Mon Feb 22 21:02:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 8383351 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 D49419F7C9 for ; Mon, 22 Feb 2016 21:05:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6D30205CA for ; Mon, 22 Feb 2016 21:05:38 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C978D205D3 for ; Mon, 22 Feb 2016 21:05:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aXxdE-00016J-3I; Mon, 22 Feb 2016 21:03:00 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aXxdC-00015u-6k for xen-devel@lists.xen.org; Mon, 22 Feb 2016 21:02:58 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 64/05-03800-1877BC65; Mon, 22 Feb 2016 21:02:57 +0000 X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1456174975!24159266!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 38626 invoked from network); 22 Feb 2016 21:02:56 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-10.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Feb 2016 21:02:56 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1ML2px4008812 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Feb 2016 21:02:51 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u1ML2nDl010755 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 22 Feb 2016 21:02:49 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u1ML2mQF018329; Mon, 22 Feb 2016 21:02:49 GMT Received: from localhost.localdomain (/89.181.88.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Feb 2016 13:02:48 -0800 From: Joao Martins To: xen-devel@lists.xen.org Date: Mon, 22 Feb 2016 21:02:11 +0000 Message-Id: <1456174934-22973-6-git-send-email-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456174934-22973-1-git-send-email-joao.m.martins@oracle.com> References: <1456174934-22973-1-git-send-email-joao.m.martins@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: Wei Liu , Joao Martins , Ian Jackson , Ian Campbell , Stefano Stabellini Subject: [Xen-devel] [PATCH RFC 5/8] libxl: introduce smt field X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 By setting it to true, it enables the vcpus set by the guest to be seen as a SMT-enabled topology. It uses then libxl__cpuid_set_topology() to change the cpuid accordingly. This setting is made *before* the cpuid is set so that any changes could be overwritten. The number of SMT threads are the ones supported by the host. And for that it adds another helper routine libxl__count_threads_per_core to fetch it. This feature is useful in HT-enabled hosts so that hard pinned domains can see the right topology (i.e. SMT cores exposed as SMT cores) which in return would lead guest scheduler making better decisions. Signed-off-by: Joao Martins --- CC: Ian Jackson CC: Stefano Stabellini CC: Ian Campbell CC: Wei Liu --- tools/libxl/libxl_create.c | 2 ++ tools/libxl/libxl_dom.c | 10 ++++++++++ tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 1 + tools/libxl/libxl_utils.c | 17 +++++++++++++++++ 5 files changed, 31 insertions(+) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index de5d27f..dac15d5 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -195,6 +195,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, b_info->num_vcpu_hard_affinity = b_info->max_vcpus; } + libxl_defbool_setdefault(&b_info->smt, false); + libxl_defbool_setdefault(&b_info->numa_placement, true); if (b_info->max_memkb == LIBXL_MEMKB_DEFAULT) diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 2269998..ff9356d 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -507,6 +507,16 @@ int libxl__build_post(libxl__gc *gc, uint32_t domid, } libxl_cpuid_apply_policy(ctx, domid); + if (info->type == LIBXL_DOMAIN_TYPE_HVM + && libxl_defbool_val(info->smt)) { + + uint32_t threads = 0; + + if (!libxl__count_threads_per_core(gc, &threads)) + libxl__cpuid_set_topology(ctx, domid, + info->max_vcpus / threads, threads); + } + if (info->cpuid != NULL) libxl_cpuid_set(ctx, domid, info->cpuid); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 903ad7b..7cc4de7 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -4033,6 +4033,7 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr, const libxl_bitmap *sptr); int libxl__count_physical_sockets(libxl__gc *gc, int *sockets); +int libxl__count_threads_per_core(libxl__gc *gc, uint32_t *threads); #define LIBXL_QEMU_USER_PREFIX "xen-qemuuser" diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index f04279e..fa4725a 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -421,6 +421,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("nodemap", libxl_bitmap), ("vcpu_hard_affinity", Array(libxl_bitmap, "num_vcpu_hard_affinity")), ("vcpu_soft_affinity", Array(libxl_bitmap, "num_vcpu_soft_affinity")), + ("smt", libxl_defbool), ("numa_placement", libxl_defbool), ("tsc_mode", libxl_tsc_mode), ("max_memkb", MemKB), diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index e42422a..dd063c8 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -861,6 +861,23 @@ int libxl__count_physical_sockets(libxl__gc *gc, int *sockets) return 0; } +int libxl__count_threads_per_core(libxl__gc *gc, uint32_t *threads) +{ + int rc; + libxl_physinfo info; + + libxl_physinfo_init(&info); + + rc = libxl_get_physinfo(CTX, &info); + if (rc) + return rc; + + *threads = info.threads_per_core; + + libxl_physinfo_dispose(&info); + return 0; +} + int libxl_socket_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *socketmap, int max_sockets) {