From patchwork Mon Feb 22 21:02:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 8383341 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5761EC0554 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 6A4D9205B5 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 19897205CD 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 1aXxd6-00014H-Gw; Mon, 22 Feb 2016 21:02:52 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aXxd4-00012R-VH for xen-devel@lists.xen.org; Mon, 22 Feb 2016 21:02:51 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 49/71-19343-A777BC65; Mon, 22 Feb 2016 21:02:50 +0000 X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1456174968!24209008!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 58282 invoked from network); 22 Feb 2016 21:02:49 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-10.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Feb 2016 21:02:49 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u1ML2kvU008718 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Feb 2016 21:02:46 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id u1ML2kuf015012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 22 Feb 2016 21:02:46 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 u1ML2j8I018312; Mon, 22 Feb 2016 21:02:45 GMT Received: from localhost.localdomain (/89.181.88.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Feb 2016 13:02:45 -0800 From: Joao Martins To: xen-devel@lists.xen.org Date: Mon, 22 Feb 2016 21:02:10 +0000 Message-Id: <1456174934-22973-5-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: aserv0022.oracle.com [141.146.126.234] Cc: Wei Liu , Joao Martins , Ian Jackson , Ian Campbell , Stefano Stabellini Subject: [Xen-devel] [PATCH RFC 4/8] libxl: cpuid: add guest topology support 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 Introduce internal cpuid routine for setting the topology as seen by the guest. The topology is made based on leaf 1 and leaf 4 for Intel, more specifically setting: Number of logical processors: proccount (CPUID.1:EBX[16:24]) Number of physical cores - 1: procpkg (CPUID.(4,0):EBX[26:32]) cache core count - 1: proccountX (CPUID.(4,Y):EBX[14:26]) given that X is l1d, l1i, l2 or l3 and Y the correspondent subleave [0-3] Signed-off-by: Joao Martins --- CC: Ian Jackson CC: Stefano Stabellini CC: Ian Campbell CC: Wei Liu --- tools/libxl/libxl_cpuid.c | 38 ++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c index deb81d2..e220566 100644 --- a/tools/libxl/libxl_cpuid.c +++ b/tools/libxl/libxl_cpuid.c @@ -352,6 +352,44 @@ void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid, (const char**)(cpuid[i].policy), cpuid_res); } +static int libxl_cpuid_parse_list(libxl_cpuid_policy_list *topo, + char **keys, int *vals, size_t sz) +{ + int i, ret = -1; + + for (i = 0; i < sz; i++) { + char *str = NULL; + + asprintf(&str, "%s=%d", keys[i], vals[i]); + + ret = libxl_cpuid_parse_config(topo, str); + free(str); + + if (ret) + break; + } + + return ret; +} + +void libxl__cpuid_set_topology(libxl_ctx *ctx, uint32_t domid, + uint32_t cores, uint32_t threads) +{ + libxl_cpuid_policy_list topo; + char *keys[] = { + "htt", "proccount", "procpkg", + "proccountl1d", "proccountl1i", "proccountl2", "proccountl3" + }; + int vals[] = { + 1, cores * threads, --cores, + --threads, threads, threads, cores + }; + + memset(&topo, 0, sizeof(topo)); + if (!libxl_cpuid_parse_list(&topo, keys, vals, ARRAY_SIZE(keys))) + libxl_cpuid_set(ctx, domid, topo); +} + static const char *input_names[2] = { "leaf", "subleaf" }; static const char *policy_names[4] = { "eax", "ebx", "ecx", "edx" }; /* diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 650a958..903ad7b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3919,6 +3919,8 @@ static inline int libxl__key_value_list_is_empty(libxl_key_value_list *pkvl) } int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl); +void libxl__cpuid_set_topology(libxl_ctx *ctx, uint32_t domid, + uint32_t max_vcpus, uint32_t threads); /* Portability note: a proper flock(2) implementation is required */ typedef struct {