From patchwork Thu Jul 20 08:49:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9854319 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 C433660388 for ; Thu, 20 Jul 2017 09:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8EE028782 for ; Thu, 20 Jul 2017 09:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD9CA28785; Thu, 20 Jul 2017 09:06:30 +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 D6CB828782 for ; Thu, 20 Jul 2017 09:06:29 +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 1dY7Na-0007Zy-0D; Thu, 20 Jul 2017 09:04:18 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dY7NY-0007Y3-Qr for xen-devel@lists.xenproject.org; Thu, 20 Jul 2017 09:04:17 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 3F/91-03406-01270795; Thu, 20 Jul 2017 09:04:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42Jpa+uQ1+UqKog 0uLJF0uL7lslMDowehz9cYQlgjGLNzEvKr0hgzTjQFFOwJafi8O1rTA2MW/26GDk5hAQqJBbd ncMGYksI8EocWTaDFcIOkLh4cyJ7FyMXUE0Do8TzLVcYQRJsAuoSj7/2MIHYIgJKEvdWTWYCK WIW2MYk8f7yC3aQhLBAvsSVPffAJrEIqEpsufKHBcTmFfCU6Drwkwlig5zEyWOTwWo4geLPuz ezQ1zkIXFv5V/mCYy8CxgZVjFqFKcWlaUW6Roa6yUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCY V6yXn525iBIYDAxDsYPyyLOAQoyQHk5IoL0tgQaQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd6H BUA5waLU9NSKtMwcYGDCpCU4eJREINK8xQWJucWZ6RCpU4zGHBtWr//CxPFqwv9vTEIsefl5q VLivEtBSgVASjNK8+AGwSLmEqOslDAvI9BpQjwFqUW5mSWo8q8YxTkYlYR5n4NM4cnMK4Hb9w roFCagUx65gZ1SkoiQkmpgLLx3/+2vF68rGqZ3+9w5yNmR8fQU38p52T90uVduf9a8Mfz/oZX Lt+ZcWOpmZPn+o/rprsK/po1K1qfOiZhOs39nPyXn6PTsro9yyQVtd29cM9J4vjZt78biU51p aiqzXnxWCtoxqaB/vds6h4cPjrowFx/ZaXtuc8sMdf5jdp+umAS+vfR7U6ISS3FGoqEWc1FxI gDT+Z+DkwIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1500541426!108131258!9 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64286 invoked from network); 20 Jul 2017 09:04:09 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-9.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Jul 2017 09:04:09 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP; 20 Jul 2017 02:04:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,383,1496127600"; d="scan'208"; a="1153387090" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.80]) by orsmga001.jf.intel.com with ESMTP; 20 Jul 2017 02:04:06 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 20 Jul 2017 16:49:10 +0800 Message-Id: <1500540553-29199-10-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500540553-29199-1-git-send-email-yi.y.sun@linux.intel.com> References: <1500540553-29199-1-git-send-email-yi.y.sun@linux.intel.com> Cc: kevin.tian@intel.com, wei.liu2@citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, Yi Sun , julien.grall@arm.com, mengxu@cis.upenn.edu, jbeulich@suse.com, chao.p.peng@linux.intel.com, roger.pau@citrix.com Subject: [Xen-devel] [RFC v2 09/12] tools: implement the new get hw info interface suitable to all psr allocation features. 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-Virus-Scanned: ClamAV using ClamSMTP This patch implements a new get hw info interface suitable for all psr allocation features and the whole flow. It also enables MBA support in tools to get MBA HW info. Signed-off-by: Yi Sun --- tools/libxc/include/xenctrl.h | 30 +++++++- tools/libxc/xc_psr.c | 46 +++++++++---- tools/libxl/libxl_psr.c | 155 +++++++++++++++++++++++++++++++++++------- tools/xl/xl_cmdtable.c | 3 + tools/xl/xl_psr.c | 45 +++++++++++- 5 files changed, 238 insertions(+), 41 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 2248900..0b0ec31 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2460,6 +2460,31 @@ enum xc_psr_cat_type { }; typedef enum xc_psr_cat_type xc_psr_cat_type; +enum xc_psr_feat_type { + XC_PSR_FEAT_UNKNOWN = 0, + XC_PSR_FEAT_CAT_L3 = 1, + XC_PSR_FEAT_CAT_L2 = 2, + XC_PSR_FEAT_MBA = 3, +}; +typedef enum xc_psr_feat_type xc_psr_feat_type; + +struct xc_psr_hw_info { + union { + struct { + uint32_t cos_max; + uint32_t cbm_len; + bool cdp_enabled; + } xc_cat_info; + + struct { + uint32_t cos_max; + uint32_t thrtl_max; + bool linear; + } xc_mba_info; + } u; +}; +typedef struct xc_psr_hw_info xc_psr_hw_info; + int xc_psr_cmt_attach(xc_interface *xch, uint32_t domid); int xc_psr_cmt_detach(xc_interface *xch, uint32_t domid); int xc_psr_cmt_get_domain_rmid(xc_interface *xch, uint32_t domid, @@ -2481,9 +2506,8 @@ int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid, int xc_psr_cat_get_domain_data(xc_interface *xch, uint32_t domid, xc_psr_cat_type type, uint32_t target, uint64_t *data); -int xc_psr_cat_get_info(xc_interface *xch, uint32_t socket, unsigned int lvl, - uint32_t *cos_max, uint32_t *cbm_len, - bool *cdp_enabled); +int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket, + xc_psr_feat_type type, xc_psr_hw_info *hw_info); int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps); int xc_get_cpu_featureset(xc_interface *xch, uint32_t index, diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c index 73d05f2..494d1f0 100644 --- a/tools/libxc/xc_psr.c +++ b/tools/libxc/xc_psr.c @@ -323,36 +323,58 @@ int xc_psr_cat_get_domain_data(xc_interface *xch, uint32_t domid, return rc; } -int xc_psr_cat_get_info(xc_interface *xch, uint32_t socket, unsigned int lvl, - uint32_t *cos_max, uint32_t *cbm_len, bool *cdp_enabled) +int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket, + xc_psr_feat_type type, xc_psr_hw_info *hw_info) { int rc = -1; DECLARE_SYSCTL; + if ( !hw_info ) + return rc; + sysctl.cmd = XEN_SYSCTL_psr_alloc_op; sysctl.u.psr_alloc_op.target = socket; - switch ( lvl ) + switch ( type ) { - case 2: + case XC_PSR_FEAT_CAT_L2: sysctl.u.psr_alloc_op.cmd = XEN_SYSCTL_PSR_CAT_get_l2_info; rc = xc_sysctl(xch, &sysctl); if ( !rc ) { - *cos_max = sysctl.u.psr_alloc_op.u.cat_info.cos_max; - *cbm_len = sysctl.u.psr_alloc_op.u.cat_info.cbm_len; - *cdp_enabled = false; + hw_info->u.xc_cat_info.cos_max = + sysctl.u.psr_alloc_op.u.cat_info.cos_max; + hw_info->u.xc_cat_info.cbm_len = + sysctl.u.psr_alloc_op.u.cat_info.cbm_len; + hw_info->u.xc_cat_info.cdp_enabled = false; } break; - case 3: + case XC_PSR_FEAT_CAT_L3: sysctl.u.psr_alloc_op.cmd = XEN_SYSCTL_PSR_CAT_get_l3_info; rc = xc_sysctl(xch, &sysctl); if ( !rc ) { - *cos_max = sysctl.u.psr_alloc_op.u.cat_info.cos_max; - *cbm_len = sysctl.u.psr_alloc_op.u.cat_info.cbm_len; - *cdp_enabled = sysctl.u.psr_alloc_op.u.cat_info.flags & - XEN_SYSCTL_PSR_CAT_L3_CDP; + hw_info->u.xc_cat_info.cos_max = + sysctl.u.psr_alloc_op.u.cat_info.cos_max; + hw_info->u.xc_cat_info.cbm_len = + sysctl.u.psr_alloc_op.u.cat_info.cbm_len; + hw_info->u.xc_cat_info.cdp_enabled = + sysctl.u.psr_alloc_op.u.cat_info.flags & + XEN_SYSCTL_PSR_CAT_L3_CDP; + } + break; + case XC_PSR_FEAT_MBA: + sysctl.u.psr_alloc_op.cmd = XEN_SYSCTL_PSR_MBA_get_info; + rc = xc_sysctl(xch, &sysctl); + if ( !rc ) + { + hw_info->u.xc_mba_info.cos_max = + sysctl.u.psr_alloc_op.u.mba_info.cos_max; + hw_info->u.xc_mba_info.thrtl_max = + sysctl.u.psr_alloc_op.u.mba_info.thrtl_max; + hw_info->u.xc_mba_info.linear = + sysctl.u.psr_alloc_op.u.mba_info.linear & + XEN_SYSCTL_PSR_MBA_LINEAR; } break; default: diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index 8319301..43b84b6 100644 --- a/tools/libxl/libxl_psr.c +++ b/tools/libxl/libxl_psr.c @@ -361,47 +361,49 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid, return rc; } +static inline int libxl_psr_hw_info_to_libxl_psr_cat_info( + libxl_psr_feat_type type, libxl_psr_hw_info *hw_info, + libxl_psr_cat_info *cat_info) +{ + if (type != LIBXL_PSR_FEAT_TYPE_CAT_INFO) + return -1; + + cat_info->id = hw_info->id; + cat_info->cos_max = hw_info->u.cat_info.cos_max; + cat_info->cbm_len = hw_info->u.cat_info.cbm_len; + cat_info->cdp_enabled = hw_info->u.cat_info.cdp_enabled; + + return 0; +} + int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info, int *nr, unsigned int lvl) { GC_INIT(ctx); int rc; - int i = 0, socketid, nr_sockets; - libxl_bitmap socketmap; + unsigned int i; + libxl_psr_hw_info *hw_info; libxl_psr_cat_info *ptr; - libxl_bitmap_init(&socketmap); - - rc = libxl__count_physical_sockets(gc, &nr_sockets); - if (rc) { - LOGE(ERROR, "failed to get system socket count"); - goto out; - } - - libxl_socket_bitmap_alloc(ctx, &socketmap, nr_sockets); - rc = libxl_get_online_socketmap(ctx, &socketmap); - if (rc < 0) { - LOGE(ERROR, "failed to get available sockets"); + rc = libxl_psr_get_hw_info(ctx, &hw_info, nr, + LIBXL_PSR_FEAT_TYPE_CAT_INFO, lvl); + if (rc) goto out; - } - ptr = libxl__malloc(NOGC, nr_sockets * sizeof(libxl_psr_cat_info)); + ptr = libxl__malloc(NOGC, *nr * sizeof(libxl_psr_cat_info)); - libxl_for_each_set_bit(socketid, socketmap) { - ptr[i].id = socketid; - if (xc_psr_cat_get_info(ctx->xch, socketid, lvl, &ptr[i].cos_max, - &ptr[i].cbm_len, &ptr[i].cdp_enabled)) { + for (i = 0; i < *nr; i++) { + if (libxl_psr_hw_info_to_libxl_psr_cat_info( + LIBXL_PSR_FEAT_TYPE_CAT_INFO, + &hw_info[i], &ptr[i])) { rc = ERROR_FAIL; free(ptr); goto out; } - i++; } *info = ptr; - *nr = i; out: - libxl_bitmap_dispose(&socketmap); GC_FREE; return rc; } @@ -439,14 +441,119 @@ int libxl_psr_get_val(libxl_ctx *ctx, uint32_t domid, return EXIT_FAILURE; } +static inline xc_psr_feat_type libxl__psr_feat_type_to_libxc_psr_feat_type( + libxl_psr_feat_type type, int lvl) +{ + xc_psr_feat_type xc_type = XC_PSR_FEAT_UNKNOWN; + + switch (type) { + case LIBXL_PSR_FEAT_TYPE_CAT_INFO: + if (lvl == 3) + xc_type = XC_PSR_FEAT_CAT_L3; + if (lvl == 2) + xc_type = XC_PSR_FEAT_CAT_L2; + break; + case LIBXL_PSR_FEAT_TYPE_MBA_INFO: + xc_type = XC_PSR_FEAT_MBA; + default: + break; + } + + return xc_type; +} + +static inline int libxc__psr_hw_info_to_libxl_psr_hw_info( + libxl_psr_feat_type type, xc_psr_hw_info *xc_hw_info, + libxl_psr_hw_info *xl_hw_info) +{ + switch (type) { + case LIBXL_PSR_FEAT_TYPE_CAT_INFO: + xl_hw_info->u.cat_info.cos_max = xc_hw_info->u.xc_cat_info.cos_max; + xl_hw_info->u.cat_info.cbm_len = xc_hw_info->u.xc_cat_info.cbm_len; + xl_hw_info->u.cat_info.cdp_enabled = + xc_hw_info->u.xc_cat_info.cdp_enabled; + break; + case LIBXL_PSR_FEAT_TYPE_MBA_INFO: + xl_hw_info->u.mba_info.cos_max = xc_hw_info->u.xc_mba_info.cos_max; + xl_hw_info->u.mba_info.thrtl_max = xc_hw_info->u.xc_mba_info.thrtl_max; + xl_hw_info->u.mba_info.linear = xc_hw_info->u.xc_mba_info.linear; + break; + default: + return -1; + } + + return 0; +} + int libxl_psr_get_hw_info(libxl_ctx *ctx, libxl_psr_hw_info **info, int *nr, libxl_psr_feat_type type, int lvl) { - return EXIT_FAILURE; + GC_INIT(ctx); + int rc; + int i = 0, socketid, nr_sockets; + libxl_bitmap socketmap; + libxl_psr_hw_info *ptr; + xc_psr_feat_type xc_type; + xc_psr_hw_info hw_info; + + libxl_bitmap_init(&socketmap); + + if ( type == LIBXL_PSR_FEAT_TYPE_CAT_INFO && lvl != 3 && lvl != 2) { + LOGE(ERROR, "input lvl %d is wrong!\n", lvl); + rc = ERROR_FAIL; + goto out; + } + + xc_type = libxl__psr_feat_type_to_libxc_psr_feat_type(type, lvl); + + rc = libxl__count_physical_sockets(gc, &nr_sockets); + if (rc) { + LOGE(ERROR, "failed to get system socket count"); + goto out; + } + + libxl_socket_bitmap_alloc(ctx, &socketmap, nr_sockets); + rc = libxl_get_online_socketmap(ctx, &socketmap); + if (rc < 0) { + LOGE(ERROR, "failed to get available sockets"); + goto out; + } + + ptr = libxl__malloc(NOGC, nr_sockets * sizeof(libxl_psr_hw_info)); + + libxl_for_each_set_bit(socketid, socketmap) { + ptr[i].id = socketid; + if (xc_psr_get_hw_info(ctx->xch, socketid, xc_type, &hw_info)) { + rc = ERROR_FAIL; + free(ptr); + goto out; + } + + if (libxc__psr_hw_info_to_libxl_psr_hw_info(type, &hw_info, &ptr[i])) { + LOGE(ERROR, "Input type %d is wrong!\n", type); + rc = ERROR_FAIL; + free(ptr); + goto out; + } + + i++; + } + + *info = ptr; + *nr = i; +out: + libxl_bitmap_dispose(&socketmap); + GC_FREE; + return rc; } void libxl_psr_hw_info_list_free(libxl_psr_hw_info *list, int nr) { + int i; + + for (i = 0; i < nr; i++) + libxl_psr_hw_info_dispose(&list[i]); + free(list); } /* diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 2c71a9f..14a02d4 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -524,6 +524,9 @@ struct cmd_spec cmd_table[] = { "[options]", "-m, --cmt Show Cache Monitoring Technology (CMT) hardware info\n" "-a, --cat Show Cache Allocation Technology (CAT) hardware info\n" +#ifdef LIBXL_HAVE_PSR_MBA + "-b, --mba Show Memory Bandwidth Allocation (MBA) hardware info\n" +#endif }, { "psr-cmt-attach", &main_psr_cmt_attach, 0, 1, diff --git a/tools/xl/xl_psr.c b/tools/xl/xl_psr.c index 7309d4f..037eab3 100644 --- a/tools/xl/xl_psr.c +++ b/tools/xl/xl_psr.c @@ -479,6 +479,37 @@ static int psr_l2_cat_hwinfo(void) return rc; } +#ifdef LIBXL_HAVE_PSR_MBA +static int psr_mba_hwinfo(void) +{ + int rc; + int i, nr; + libxl_psr_hw_info *info; + + printf("Memory Bandwidth Allocation (MBA):\n"); + + rc = libxl_psr_get_hw_info(ctx, &info, &nr, + LIBXL_PSR_FEAT_TYPE_MBA_INFO, 0); + if (rc) { + fprintf(stderr, "Failed to get mba info\n"); + return rc; + } + + for (i = 0; i < nr; i++) { + printf("%-16s: %u\n", "Socket ID", info[i].id); + printf("%-16s: %s\n", "Linear Mode", + info[i].u.mba_info.linear ? "Enabled" : "Disabled"); + printf("%-16s: %u\n", "Maximum COS", info[i].u.mba_info.cos_max); + printf("%-16s: %u\n", "Maximum Throttling Value", + info[i].u.mba_info.thrtl_max); + printf("%-16s: %u\n", "Default Throttling Value", 0); + } + + libxl_psr_hw_info_list_free(info, nr); + return rc; +} +#endif + int main_psr_cat_cbm_set(int argc, char **argv) { uint32_t domid; @@ -597,20 +628,24 @@ int main_psr_cat_show(int argc, char **argv) int main_psr_hwinfo(int argc, char **argv) { int opt, ret = 0; - bool all = true, cmt = false, cat = false; + bool all = true, cmt = false, cat = false, mba = false; static struct option opts[] = { {"cmt", 0, 0, 'm'}, {"cat", 0, 0, 'a'}, + {"mba", 0, 0, 'b'}, COMMON_LONG_OPTS }; - SWITCH_FOREACH_OPT(opt, "ma", opts, "psr-hwinfo", 0) { + SWITCH_FOREACH_OPT(opt, "mab", opts, "psr-hwinfo", 0) { case 'm': all = false; cmt = true; break; case 'a': all = false; cat = true; break; + case 'b': + all = false; mba = true; + break; } if (!ret && (all || cmt)) @@ -623,6 +658,12 @@ int main_psr_hwinfo(int argc, char **argv) if (all || cat) ret = psr_l2_cat_hwinfo(); +#ifdef LIBXL_HAVE_PSR_MBA + /* MBA is independent of CMT and CAT */ + if (all || mba) + ret = psr_mba_hwinfo(); +#endif + return ret; }