From patchwork Wed Aug 9 07:41:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9889795 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 257B9602D7 for ; Wed, 9 Aug 2017 08:01:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1782B285FC for ; Wed, 9 Aug 2017 08:01:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BD8A28A09; Wed, 9 Aug 2017 08:01:29 +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 F0B1328A49 for ; Wed, 9 Aug 2017 08:01:21 +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 1dfLso-0001uj-9Z; Wed, 09 Aug 2017 07:58:26 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfLsm-0001tD-RS for xen-devel@lists.xenproject.org; Wed, 09 Aug 2017 07:58:25 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id 03/56-09901-0A0CA895; Wed, 09 Aug 2017 07:58:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpkkeJIrShJLcpLzFFi42Jpa+uQ0J1/oCv SYN4sKYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPjwTnMBY8LKta++8HUwHghsIuRi0NIYBqj xKNpK1i7GDk5JAR4JY4smwFl+0u8OPmAGcQWEmhglDh7lgXEZhNQl3j8tYcJxBYRUJK4t2oyE 8ggZoFtTBLvL79gB0kICxRIzLp9CMxmEVCVWHj5OpjNK+Ah8f3tXBaIBXISJ49NBlvGCRTf3P GHDWKZu8S3Xd3sExh5FzAyrGLUKE4tKkst0jU21EsqykzPKMlNzMzRNTQw08tNLS5OTE/NSUw q1kvOz93ECAwIBiDYwdi0KPAQoyQHk5Io7ybtzkghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKEryX 9ndFCgkWpaanVqRl5gBDEyYtwcGjJMK7ESTNW1yQmFucmQ6ROsVozLFh9fovTByvJvz/xiTEk peflyolzrsfpFQApDSjNA9uECxmLjHKSgnzMgKdJsRTkFqUm1mCKv+KUZyDUUmY9zTIFJ7MvB K4fa+ATmECOiXCtxPklJJEhJRUA6Pe4xfiImpn5v+TVy5Ielfa/XhO+qmc3rebdZ7NK7j80mP jyWeLl6vL7jNaOn+16QM36QcVKmdFrC6Fc+xm78jxnnqm1IL9VUrXfrn7D/ZK1fYKvnv40l0p RmfOqu7gbcmreMQ4Yqf/0mT96ce3w7TQVieL/cMva7EN3keDU1a+TOoW9nyUL6/EUpyRaKjFX FScCABaCOrSlAIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-11.tower-27.messagelabs.com!1502265470!79168193!10 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 1681 invoked from network); 9 Aug 2017 07:58:22 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-11.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 9 Aug 2017 07:58:22 -0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Aug 2017 00:58:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,346,1498546800"; d="scan'208";a="117183097" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.80]) by orsmga004.jf.intel.com with ESMTP; 09 Aug 2017 00:58:19 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 9 Aug 2017 15:41:48 +0800 Message-Id: <1502264512-4648-10-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502264512-4648-1-git-send-email-yi.y.sun@linux.intel.com> References: <1502264512-4648-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] [PATCH v1 09/13] 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 --- v1: - remove the pointless initialization for 'xc_psr_feat_type'. (suggested by Wei Liu) - use 'libxl__' for internal functions. (suggested by Wei Liu) - change error value '-1' to 'ERROR_INVAL'. (suggested by Wei Liu) - remove an extraneous space. (suggested by Wei Liu) - replace some 'int' to 'unsigned int'. (suggested by Wei Liu) - remove test to macro 'LIBXL_HAVE_PSR_MBA'. (suggested by Wei Liu) - change 'mba_info.linear' to 'mba_info.flags'. (suggested by Chao Peng) - adjust print info only to show the MBA info after successfully getting HW info. --- tools/libxc/include/xenctrl.h | 30 +++++++- tools/libxc/xc_psr.c | 46 +++++++++---- tools/libxl/libxl_psr.c | 155 +++++++++++++++++++++++++++++++++++------- tools/xl/xl_cmdtable.c | 1 + tools/xl/xl_psr.c | 39 ++++++++++- 5 files changed, 230 insertions(+), 41 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index c7710b8..81a6f48 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2458,6 +2458,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, + XC_PSR_FEAT_CAT_L3, + XC_PSR_FEAT_CAT_L2, + XC_PSR_FEAT_MBA, +}; +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, @@ -2479,9 +2504,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..ba412e4 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.flags & + XEN_SYSCTL_PSR_MBA_LINEAR; } break; default: diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index cf368ba..cb928e7 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 ERROR_INVAL; + + 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"); + rc = libxl_psr_get_hw_info(ctx, &hw_info, (unsigned int *)nr, + LIBXL_PSR_FEAT_TYPE_CAT_INFO, lvl); + if (rc) 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 * sizeof(libxl_psr_cat_info)); - ptr = libxl__malloc(NOGC, nr_sockets * 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,15 +441,120 @@ int libxl_psr_get_val(libxl_ctx *ctx, uint32_t domid, return ERROR_FAIL; } +static inline xc_psr_feat_type libxl__psr_feat_type_to_libxc_psr_feat_type( + libxl_psr_feat_type type, unsigned 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 ERROR_INVAL; + } + + return 0; +} + int libxl_psr_get_hw_info(libxl_ctx *ctx, libxl_psr_hw_info **info, unsigned int *nr, libxl_psr_feat_type type, unsigned int lvl) { - return ERROR_FAIL; + GC_INIT(ctx); + int rc, nr_sockets; + unsigned int i = 0, socketid; + 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, unsigned int nr) { + unsigned 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..5ac8a7e 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -524,6 +524,7 @@ 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" + "-b, --mba Show Memory Bandwidth Allocation (MBA) hardware info\n" }, { "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..bf41762 100644 --- a/tools/xl/xl_psr.c +++ b/tools/xl/xl_psr.c @@ -479,6 +479,33 @@ static int psr_l2_cat_hwinfo(void) return rc; } +static int psr_mba_hwinfo(void) +{ + int rc; + unsigned int i, nr; + libxl_psr_hw_info *info; + + rc = libxl_psr_get_hw_info(ctx, &info, &nr, + LIBXL_PSR_FEAT_TYPE_MBA_INFO, 0); + if (rc) + return rc; + + printf("Memory Bandwidth Allocation (MBA):\n"); + + 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; +} + int main_psr_cat_cbm_set(int argc, char **argv) { uint32_t domid; @@ -597,20 +624,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 +654,10 @@ int main_psr_hwinfo(int argc, char **argv) if (all || cat) ret = psr_l2_cat_hwinfo(); + /* MBA is independent of CMT and CAT */ + if (all || mba) + ret = psr_mba_hwinfo(); + return ret; }