From patchwork Tue Jan 10 07:42:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9506651 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 B1F07606E1 for ; Tue, 10 Jan 2017 07:46:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A555728156 for ; Tue, 10 Jan 2017 07:46:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99BAC28485; Tue, 10 Jan 2017 07:46:05 +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 C71E628156 for ; Tue, 10 Jan 2017 07:46:04 +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 1cQr5y-00045z-Lh; Tue, 10 Jan 2017 07:43:50 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQr5x-000435-00 for xen-devel@lists.xenproject.org; Tue, 10 Jan 2017 07:43:49 +0000 Received: from [85.158.143.35] by server-5.bemta-6.messagelabs.com id CF/AC-11476-4B094785; Tue, 10 Jan 2017 07:43:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVywNykWHfzhJI Ig9vPlS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyXje/YC54WVKw4/pe1gfFxcBcjB4eQQKXE 8vWKXYycHBICvBJHls1ghbD9Jd4fm8vUxcgFVNLAKHFl+Xl2kASbgLrE4689TCC2iICSxL1Vk 8GKmAX2M0rMP36cGSQhLBAisXH3UrAiFgFViU+/2sFsXgEPia9vZrBAbJCTOHlsMtg2TqB4y9 V1jCC2kIC7RPPb+4wTGHkXMDKsYtQoTi0qSy3SNTTTSyrKTM8oyU3MzNE1NDDTy00tLk5MT81 JTCrWS87P3cQIDAcGINjBeH9jwCFGSQ4mJVHeFN2SCCG+pPyUyozE4oz4otKc1OJDjDIcHEoS vFX9QDnBotT01Iq0zBxgYMKkJTh4lER4WUDSvMUFibnFmekQqVOMuhzTni1+yiTEkpeflyolz hsIUiQAUpRRmgc3AhYllxhlpYR5GYGOEuIpSC3KzSxBlX/FKM7BqCTMuw9kCk9mXgncpldARz ABHRFpVwxyREkiQkqqgdGkJqGY/6uk57+L4gf/ikzhWt24L0NelWlpze/XEvOnWdgf9n5y943 doecOi0+J3WEJF41bfFPths/bTaYLHSo27ksWuy31ovG+5cX3BaYNZyYoJdarPLP09j9V/MzF 3m/13V+dBvXT7/mYf865kCddqCWiGRMUxp6xXkVkO/8tkx26nLJbApRYijMSDbWYi4oTAbZ7u XGNAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1484034223!45252429!2 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17728 invoked from network); 10 Jan 2017 07:43:47 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jan 2017 07:43:47 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 09 Jan 2017 23:43:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,343,1477983600"; d="scan'208";a="211583169" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 09 Jan 2017 23:43:40 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 10 Jan 2017 15:42:29 +0800 Message-Id: <1484034155-4521-11-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com> References: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com> Cc: wei.liu2@citrix.com, he.chen@linux.intel.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, Yi Sun , jbeulich@suse.com, chao.p.peng@linux.intel.com Subject: [Xen-devel] [RFC 10/16] tools: refactor codes to make get hw info interface be general. 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 changes some interfaces in tools/ to make get hw info be general but not only for CAT. Add 'LIBXL_HAVE_PSR_MBA' to indicate interface change. Signed-off-by: Yi Sun --- tools/libxc/include/xenctrl.h | 23 +++++++++++-- tools/libxc/xc_psr.c | 32 +++++++++++------- tools/libxl/libxl.h | 12 +++++-- tools/libxl/libxl_psr.c | 75 +++++++++++++++++++++++++++++++++++++++---- tools/libxl/libxl_types.idl | 15 +++++++++ tools/libxl/xl_cmdimpl.c | 45 ++++++++++++++------------ 6 files changed, 159 insertions(+), 43 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index a009625..fa62e2a 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2606,6 +2606,24 @@ 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, +}; +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; + } 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, @@ -2627,9 +2645,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 0098a4d..af648eb 100644 --- a/tools/libxc/xc_psr.c +++ b/tools/libxc/xc_psr.c @@ -323,35 +323,43 @@ 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 ) { - case 2: + switch ( type ) { + 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.l2_info.cos_max; - *cbm_len = sysctl.u.psr_alloc_op.u.l2_info.cbm_len; - *cdp_enabled = false; + hw_info->u.xc_cat_info.cos_max = + sysctl.u.psr_alloc_op.u.l2_info.cos_max; + hw_info->u.xc_cat_info.cbm_len = + sysctl.u.psr_alloc_op.u.l2_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.l3_info.cos_max; - *cbm_len = sysctl.u.psr_alloc_op.u.l3_info.cbm_len; - *cdp_enabled = sysctl.u.psr_alloc_op.u.l3_info.flags & - XEN_SYSCTL_PSR_CAT_L3_CDP; + hw_info->u.xc_cat_info.cos_max = + sysctl.u.psr_alloc_op.u.l3_info.cos_max; + hw_info->u.xc_cat_info.cbm_len = + sysctl.u.psr_alloc_op.u.l3_info.cbm_len; + hw_info->u.xc_cat_info.cdp_enabled = + sysctl.u.psr_alloc_op.u.l3_info.flags & + XEN_SYSCTL_PSR_CAT_L3_CDP; } break; default: diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 45a9978..7575ccd 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -911,6 +911,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); * If this is defined, the L2 Cache Allocation Technology feature is supported. */ #define LIBXL_HAVE_PSR_L2_CAT 1 + +/* + * LIBXL_HAVE_PSR_MBA + * + * If this is defined, the Memory Bandwidth Allocation feature is supported. + */ +#define LIBXL_HAVE_PSR_MBA 1 #endif /* @@ -2173,8 +2180,9 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid, * On success, the function returns an array of elements in 'info', * and the length in 'nr'. */ -int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info, - int *nr, unsigned int lvl); +int libxl_psr_get_hw_info(libxl_ctx *ctx, libxl_psr_hw_info **info, + int *nr, libxl_psr_feat_type type, int lvl); +void libxl_psr_hw_info_list_free(libxl_psr_hw_info *list, int nr); void libxl_psr_cat_info_list_free(libxl_psr_cat_info *list, int nr); #endif diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index d28ace0..2fe42b7 100644 --- a/tools/libxl/libxl_psr.c +++ b/tools/libxl/libxl_psr.c @@ -352,17 +352,64 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid, return rc; } -int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info, - int *nr, unsigned int lvl) +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; + 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; + 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) { GC_INIT(ctx); int rc; int i = 0, socketid, nr_sockets; libxl_bitmap socketmap; - libxl_psr_cat_info *ptr; + libxl_psr_hw_info *ptr; + xc_psr_feat_type xc_type; + xc_psr_hw_info hw_info; libxl_bitmap_init(&socketmap); + if ( 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"); @@ -376,17 +423,24 @@ int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info, goto out; } - ptr = libxl__malloc(NOGC, nr_sockets * sizeof(libxl_psr_cat_info)); + 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_cat_get_info(ctx->xch, socketid, lvl, &ptr[i].cos_max, - &ptr[i].cbm_len, &ptr[i].cdp_enabled)) { + if (xc_psr_get_hw_info(ctx->xch, socketid, xc_type, &hw_info)) { libxl__psr_cat_log_err_msg(gc, errno); 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++; } @@ -398,6 +452,15 @@ out: 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); +} + void libxl_psr_cat_info_list_free(libxl_psr_cat_info *list, int nr) { int i; diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 5a401b8..a15d9ef 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -908,3 +908,18 @@ libxl_psr_cat_info = Struct("psr_cat_info", [ ("cbm_len", uint32), ("cdp_enabled", bool), ]) + +libxl_psr_feat_type = Enumeration("psr_feat_type", [ + (1, "CAT_INFO"), + ]) + +libxl_psr_hw_info = Struct("psr_hw_info", [ + ("id", uint32), + ("u", KeyedUnion(None, libxl_psr_feat_type, "type", + [("cat_info", Struct(None, [ + ("cos_max", uint32), + ("cbm_len", uint32), + ("cdp_enabled", bool), + ])), + ])) + ]) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 58b4eef..5bf56e8 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -9337,11 +9337,12 @@ static int psr_l3_cat_hwinfo(void) int rc, nr; unsigned int i; uint32_t l3_cache_size; - libxl_psr_cat_info *info; + libxl_psr_hw_info *info; printf("Cache Allocation Technology (CAT): L3\n"); - rc = libxl_psr_cat_get_info(ctx, &info, &nr, 3); + rc = libxl_psr_get_hw_info(ctx, &info, &nr, + LIBXL_PSR_FEAT_TYPE_CAT_INFO, 3); if (rc) { fprintf(stderr, "Failed to get l3 cat info\n"); return rc; @@ -9357,15 +9358,15 @@ static int psr_l3_cat_hwinfo(void) printf("%-16s: %u\n", "Socket ID", info[i].id); printf("%-16s: %uKB\n", "L3 Cache", l3_cache_size); printf("%-16s: %s\n", "CDP Status", - info[i].cdp_enabled ? "Enabled" : "Disabled"); - printf("%-16s: %u\n", "Maximum COS", info[i].cos_max); - printf("%-16s: %u\n", "CBM length", info[i].cbm_len); + info[i].u.cat_info.cdp_enabled ? "Enabled" : "Disabled"); + printf("%-16s: %u\n", "Maximum COS", info[i].u.cat_info.cos_max); + printf("%-16s: %u\n", "CBM length", info[i].u.cat_info.cbm_len); printf("%-16s: %#llx\n", "Default CBM", - (1ull << info[i].cbm_len) - 1); + (1ull << info[i].u.cat_info.cbm_len) - 1); } out: - libxl_psr_cat_info_list_free(info, nr); + libxl_psr_hw_info_list_free(info, nr); return rc; } @@ -9436,7 +9437,7 @@ static int psr_cat_print_domain_cbm(uint32_t domid, uint32_t socketid, return 0; } -static int psr_cat_print_socket(uint32_t domid, libxl_psr_cat_info *info, +static int psr_cat_print_socket(uint32_t domid, libxl_psr_hw_info *info, unsigned int lvl) { int rc; @@ -9456,22 +9457,25 @@ static int psr_cat_print_socket(uint32_t domid, libxl_psr_cat_info *info, printf("%-16s: %uKB\n", "L3 Cache", l3_cache_size); } - printf("%-16s: %#llx\n", "Default CBM", (1ull << info->cbm_len) - 1); - if (info->cdp_enabled) + printf("%-16s: %#llx\n", "Default CBM", + (1ull << info->u.cat_info.cbm_len) - 1); + if (info->u.cat_info.cdp_enabled) printf("%5s%25s%16s%16s\n", "ID", "NAME", "CBM (code)", "CBM (data)"); else printf("%5s%25s%16s\n", "ID", "NAME", "CBM"); - return psr_cat_print_domain_cbm(domid, info->id, info->cdp_enabled, lvl); + return psr_cat_print_domain_cbm(domid, info->id, + info->u.cat_info.cdp_enabled, lvl); } static int psr_cat_show(uint32_t domid, unsigned int lvl) { int i, nr; int rc; - libxl_psr_cat_info *info; + libxl_psr_hw_info *info; - rc = libxl_psr_cat_get_info(ctx, &info, &nr, lvl); + rc = libxl_psr_get_hw_info(ctx, &info, &nr, + LIBXL_PSR_FEAT_TYPE_CAT_INFO, lvl); if (rc) { fprintf(stderr, "Failed to get %s cat info\n", (lvl == 3)?"L3":"L2"); return rc; @@ -9484,7 +9488,7 @@ static int psr_cat_show(uint32_t domid, unsigned int lvl) } out: - libxl_psr_cat_info_list_free(info, nr); + libxl_psr_hw_info_list_free(info, nr); return rc; } @@ -9493,11 +9497,12 @@ static int psr_l2_cat_hwinfo(void) int rc; unsigned int i; int nr; - libxl_psr_cat_info *info; + libxl_psr_hw_info *info; printf("Cache Allocation Technology (CAT): L2\n"); - rc = libxl_psr_cat_get_info(ctx, &info, &nr, 2); + rc = libxl_psr_get_hw_info(ctx, &info, &nr, + LIBXL_PSR_FEAT_TYPE_CAT_INFO, 2); if (rc) { fprintf(stderr, "Failed to get l2 cat info\n"); return rc; @@ -9506,13 +9511,13 @@ static int psr_l2_cat_hwinfo(void) for (i = 0; i < nr; i++) { /* There is no CMT on L2 cache so far. */ printf("%-16s: %u\n", "Socket ID", info[i].id); - printf("%-16s: %u\n", "Maximum COS", info[i].cos_max); - printf("%-16s: %u\n", "CBM length", info[i].cbm_len); + printf("%-16s: %u\n", "Maximum COS", info[i].u.cat_info.cos_max); + printf("%-16s: %u\n", "CBM length", info[i].u.cat_info.cbm_len); printf("%-16s: %#llx\n", "Default CBM", - (1ull << info[i].cbm_len) - 1); + (1ull << info[i].u.cat_info.cbm_len) - 1); } - libxl_psr_cat_info_list_free(info, nr); + libxl_psr_hw_info_list_free(info, nr); return rc; }