From patchwork Thu Mar 16 11:08:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9627883 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 7A8786048C for ; Thu, 16 Mar 2017 11:16:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71FB628573 for ; Thu, 16 Mar 2017 11:16:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6660A285A1; Thu, 16 Mar 2017 11:16:19 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 9F7D628573 for ; Thu, 16 Mar 2017 11:16:18 +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 1coTMf-000583-Il; Thu, 16 Mar 2017 11:14:41 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTMe-00055D-Mo for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:14:40 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 46/D0-20914-0A37AC85; Thu, 16 Mar 2017 11:14:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkkeJIrShJLcpLzFFi42I5YG4Sqzu/+FS Ewfapkhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bunSdYC7qyKrYvOcTYwNjg28XIxcEicItJ YvO0iewgjpDANEaJ4y+eMncxcnJICPBKHFk2gxXC9pfo6WtigyhqYJT4vXoeG0iCTUBd4vHXH iYQW0RASeLeqslMIEXMAjuZJNad/g42SVjAQ2LB1PWMIDaLgKrEugPXwBp4geItaycwQWyQkz h5bDLYNk6g+Mf2djBbSMBd4t2Gv+wTGPkWMDKsYtQoTi0qSy3SNTTRSyrKTM8oyU3MzNE1NDD Wy00tLk5MT81JTCrWS87P3cQIDBYGINjBuGK75yFGSQ4mJVHe8h8nIoT4kvJTKjMSizPii0pz UosPMcpwcChJ8B5ROhkhJFiUmp5akZaZAwxbmLQEB4+SCG8uSJq3uCAxtzgzHSJ1ilGXY87s3 W+YhFjy8vNSpcR5L4AUCYAUZZTmwY2AxdAlRlkpYV5GoKOEeApSi3IzS1DlXzGKczAqCfNuBp nCk5lXArfpFdARTEBHvP1wAuSIkkSElFQDI7/QUeeOtDvL5D/nBDJnGF2qaMrS9FRZprbFKej lji8le9Rr++5OVjit8M7liKxQ1fub3tlrxHTS3yZw/plzdkukpsTTvUJt/kWb8s/85ttt6r/9 8pHKKv6+13z3non4Wa451HxFpfccz+26u+v3rEy4359h4aqbrjBZLXx1T5v7+y8/HGyWKbEUZ yQaajEXFScCAE40s76cAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1489662818!78881615!21 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14912 invoked from network); 16 Mar 2017 11:14:38 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-2.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Mar 2017 11:14:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489662878; x=1521198878; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=UpD5+3WLiyBOZwzzXRXOux3MDAwHrYrFp9qMnBbyNYA=; b=b0p7xTnZGeckcuSgkVdyAe9o3ly2LNVR3OBWvy+gsi6Shje8Tz0kOyXZ KhvlI0wO0UoDqS+/i0JCL81Lzn6Ukg==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2017 04:14:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,172,1486454400"; d="scan'208";a="944976817" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2017 04:14:35 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 16 Mar 2017 19:08:12 +0800 Message-Id: <1489662495-5375-23-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489662495-5375-1-git-send-email-yi.y.sun@linux.intel.com> References: <1489662495-5375-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, he.chen@linux.intel.com, ian.jackson@eu.citrix.com, Yi Sun , mengxu@cis.upenn.edu, jbeulich@suse.com, chao.p.peng@linux.intel.com, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v9 22/25] tools: L2 CAT: support get HW info for L2 CAT. 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 xl/xc changes to support get HW info for L2 CAT. 'xl psr-hwinfo' is updated to show both L3 CAT and L2 CAT info. Example(on machine which only supports L2 CAT): Cache Monitoring Technology (CMT): Enabled : 0 Cache Allocation Technology (CAT): L2 Socket ID : 0 Maximum COS : 3 CBM length : 8 Default CBM : 0xff Signed-off-by: He Chen Signed-off-by: Yi Sun Acked-by: Wei Liu --- v9: - add some cases to handle return error no. - move xl_cmdimpl.c codes into xl/xl_psr.c. - change 'l3_info' to 'cat_info' to cover both L3 and L2 CAT. v6: - adjust '{' position for 'switch'. (suggested by Wei Liu) - modify commit message to remove error log. (suggested by Dario Faggioli) v5: - modify commit message to remove error log. (suggested by Wei Liu and Jan Beulich) - replace unnecessary 'return' to 'break'. (suggested by Wei Liu) - restore 'libxl_psr_cat_get_l3_info' to keep interface backward compatible but change codes in it to call new function to get hw info. (suggested by Wei Liu) - add 'L2_CBM' into 'psr_cbm_type' because it is interface change which should be in same patch with new 'LIBXL_HAVE_' macro. (suggested by Wei Liu) - addjust logs sentence to make unnecessary error logs not show. (suggested by Wei Liu and Jan Beulich) v4: - create this patch to help reviewers better understand the codes. --- tools/libxc/include/xenctrl.h | 6 ++--- tools/libxc/xc_psr.c | 39 +++++++++++++++++++++++--------- tools/libxl/libxl.h | 9 ++++++++ tools/libxl/libxl_psr.c | 28 ++++++++++++++++++----- tools/libxl/libxl_types.idl | 1 + tools/xl/xl_psr.c | 52 +++++++++++++++++++++++++++++++++---------- xen/arch/x86/sysctl.c | 18 +++++++-------- xen/include/public/sysctl.h | 2 +- 8 files changed, 114 insertions(+), 41 deletions(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index a48981a..99c6fa5 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2442,9 +2442,9 @@ 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_l3_info(xc_interface *xch, uint32_t socket, - uint32_t *cos_max, uint32_t *cbm_len, - bool *cdp_enabled); +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_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 43b3286..84a08c4 100644 --- a/tools/libxc/xc_psr.c +++ b/tools/libxc/xc_psr.c @@ -317,24 +317,41 @@ int xc_psr_cat_get_domain_data(xc_interface *xch, uint32_t domid, return rc; } -int xc_psr_cat_get_l3_info(xc_interface *xch, uint32_t socket, - uint32_t *cos_max, uint32_t *cbm_len, - bool *cdp_enabled) +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 rc; + int rc = -1; DECLARE_SYSCTL; sysctl.cmd = XEN_SYSCTL_psr_cat_op; - sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l3_info; sysctl.u.psr_cat_op.target = socket; - rc = xc_sysctl(xch, &sysctl); - if ( !rc ) + switch ( lvl ) { - *cos_max = sysctl.u.psr_cat_op.u.l3_info.cos_max; - *cbm_len = sysctl.u.psr_cat_op.u.l3_info.cbm_len; - *cdp_enabled = sysctl.u.psr_cat_op.u.l3_info.flags & - XEN_SYSCTL_PSR_CAT_L3_CDP; + case 2: + sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l2_info; + rc = xc_sysctl(xch, &sysctl); + if ( !rc ) + { + *cos_max = sysctl.u.psr_cat_op.u.cat_info.cos_max; + *cbm_len = sysctl.u.psr_cat_op.u.cat_info.cbm_len; + *cdp_enabled = false; + } + break; + case 3: + sysctl.u.psr_cat_op.cmd = XEN_SYSCTL_PSR_CAT_get_l3_info; + rc = xc_sysctl(xch, &sysctl); + if ( !rc ) + { + *cos_max = sysctl.u.psr_cat_op.u.cat_info.cos_max; + *cbm_len = sysctl.u.psr_cat_op.u.cat_info.cbm_len; + *cdp_enabled = sysctl.u.psr_cat_op.u.cat_info.flags & + XEN_SYSCTL_PSR_CAT_L3_CDP; + } + break; + default: + errno = EOPNOTSUPP; + break; } return rc; diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 92f1751..6c6fb01 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -904,6 +904,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src); * If this is defined, the Code and Data Prioritization feature is supported. */ #define LIBXL_HAVE_PSR_CDP 1 + +/* + * LIBXL_HAVE_PSR_L2_CAT + * + * If this is defined, the L2 Cache Allocation Technology feature is supported. + */ +#define LIBXL_HAVE_PSR_L2_CAT 1 #endif /* @@ -2172,6 +2179,8 @@ 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_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info, int *nr); void libxl_psr_cat_info_list_free(libxl_psr_cat_info *list, int nr); diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index ec5c79d..f55ba1e 100644 --- a/tools/libxl/libxl_psr.c +++ b/tools/libxl/libxl_psr.c @@ -91,6 +91,15 @@ static void libxl__psr_cat_log_err_msg(libxl__gc *gc, int err) case ENXIO: msg = "Unable to set code or data CBM when CDP is disabled"; break; + case EINVAL: + msg = "Invalid input or some internal values are not expected"; + break; + case ERANGE: + msg = "Socket number is wrong"; + break; + case ENOSPC: + msg = "Value array exceeds the range"; + break; default: libxl__psr_log_err_msg(gc, err); @@ -352,8 +361,8 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid, return rc; } -int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info, - int *nr) +int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info, + int *nr, unsigned int lvl) { GC_INIT(ctx); int rc; @@ -380,9 +389,8 @@ int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info, libxl_for_each_set_bit(socketid, socketmap) { ptr[i].id = socketid; - if (xc_psr_cat_get_l3_info(ctx->xch, socketid, &ptr[i].cos_max, - &ptr[i].cbm_len, &ptr[i].cdp_enabled)) { - libxl__psr_cat_log_err_msg(gc, errno); + if (xc_psr_cat_get_info(ctx->xch, socketid, lvl, &ptr[i].cos_max, + &ptr[i].cbm_len, &ptr[i].cdp_enabled)) { rc = ERROR_FAIL; free(ptr); goto out; @@ -398,6 +406,16 @@ out: return rc; } +int libxl_psr_cat_get_l3_info(libxl_ctx *ctx, libxl_psr_cat_info **info, + int *nr) +{ + int rc; + + rc = libxl_psr_cat_get_info(ctx, info, nr, 3); + + return rc; +} + 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 a612d1f..5a401b8 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -899,6 +899,7 @@ libxl_psr_cbm_type = Enumeration("psr_cbm_type", [ (1, "L3_CBM"), (2, "L3_CBM_CODE"), (3, "L3_CBM_DATA"), + (4, "L2_CBM"), ]) libxl_psr_cat_info = Struct("psr_cat_info", [ diff --git a/tools/xl/xl_psr.c b/tools/xl/xl_psr.c index c061b29..271b88f 100644 --- a/tools/xl/xl_psr.c +++ b/tools/xl/xl_psr.c @@ -294,21 +294,19 @@ int main_psr_cmt_show(int argc, char **argv) } #endif -#ifdef LIBXL_HAVE_PSR_CAT -static int psr_cat_hwinfo(void) +#if defined(LIBXL_HAVE_PSR_CAT) || defined(LIBXL_HAVE_PSR_L2_CAT) +static int psr_l3_cat_hwinfo(void) { - int rc; - int i, nr; + int rc, nr; + unsigned int i; uint32_t l3_cache_size; libxl_psr_cat_info *info; - printf("Cache Allocation Technology (CAT):\n"); - - rc = libxl_psr_cat_get_l3_info(ctx, &info, &nr); - if (rc) { - fprintf(stderr, "Failed to get cat info\n"); + rc = libxl_psr_cat_get_info(ctx, &info, &nr, 3); + if (rc) return rc; - } + + printf("Cache Allocation Technology (CAT):\n"); for (i = 0; i < nr; i++) { rc = libxl_psr_cmt_get_l3_cache_size(ctx, info[i].id, &l3_cache_size); @@ -417,7 +415,7 @@ static int psr_cat_show(uint32_t domid) int rc; libxl_psr_cat_info *info; - rc = libxl_psr_cat_get_l3_info(ctx, &info, &nr); + rc = libxl_psr_cat_get_info(ctx, &info, &nr, 3); if (rc) { fprintf(stderr, "Failed to get cat info\n"); return rc; @@ -434,6 +432,32 @@ out: return rc; } +static int psr_l2_cat_hwinfo(void) +{ + int rc; + unsigned int i; + int nr; + libxl_psr_cat_info *info; + + rc = libxl_psr_cat_get_info(ctx, &info, &nr, 2); + if (rc) + return rc; + + printf("Cache Allocation Technology (CAT): L2\n"); + + 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: %#llx\n", "Default CBM", + (1ull << info[i].cbm_len) - 1); + } + + libxl_psr_cat_info_list_free(info, nr); + return rc; +} + int main_psr_cat_cbm_set(int argc, char **argv) { uint32_t domid; @@ -551,7 +575,11 @@ int main_psr_hwinfo(int argc, char **argv) ret = psr_cmt_hwinfo(); if (!ret && (all || cat)) - ret = psr_cat_hwinfo(); + ret = psr_l3_cat_hwinfo(); + + /* L2 CAT is independent of CMT and L3 CAT */ + if (all || cat) + ret = psr_l2_cat_hwinfo(); return ret; } diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index f701910..c00c234 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -182,11 +182,11 @@ long arch_do_sysctl( PSR_CBM_TYPE_L3, data, ARRAY_SIZE(data)); if ( !ret ) { - sysctl->u.psr_cat_op.u.l3_info.cbm_len = + sysctl->u.psr_cat_op.u.cat_info.cbm_len = data[PSR_INFO_IDX_CBM_LEN]; - sysctl->u.psr_cat_op.u.l3_info.cos_max = + sysctl->u.psr_cat_op.u.cat_info.cos_max = data[PSR_INFO_IDX_COS_MAX]; - sysctl->u.psr_cat_op.u.l3_info.flags = + sysctl->u.psr_cat_op.u.cat_info.flags = data[PSR_INFO_IDX_FLAG]; } else @@ -202,11 +202,11 @@ long arch_do_sysctl( ARRAY_SIZE(data)); if ( !ret ) { - sysctl->u.psr_cat_op.u.l3_info.cbm_len = + sysctl->u.psr_cat_op.u.cat_info.cbm_len = data[PSR_INFO_IDX_CBM_LEN]; - sysctl->u.psr_cat_op.u.l3_info.cos_max = + sysctl->u.psr_cat_op.u.cat_info.cos_max = data[PSR_INFO_IDX_COS_MAX]; - sysctl->u.psr_cat_op.u.l3_info.flags = + sysctl->u.psr_cat_op.u.cat_info.flags = data[PSR_INFO_IDX_FLAG]; } } @@ -225,9 +225,9 @@ long arch_do_sysctl( if ( ret ) break; - sysctl->u.psr_cat_op.u.l3_info.cbm_len = data[PSR_INFO_IDX_CBM_LEN]; - sysctl->u.psr_cat_op.u.l3_info.cos_max = data[PSR_INFO_IDX_COS_MAX]; - sysctl->u.psr_cat_op.u.l3_info.flags = data[PSR_INFO_IDX_FLAG]; + sysctl->u.psr_cat_op.u.cat_info.cbm_len = data[PSR_INFO_IDX_CBM_LEN]; + sysctl->u.psr_cat_op.u.cat_info.cos_max = data[PSR_INFO_IDX_COS_MAX]; + sysctl->u.psr_cat_op.u.cat_info.flags = data[PSR_INFO_IDX_FLAG]; if ( !ret && __copy_field_to_guest(u_sysctl, sysctl, u.psr_cat_op) ) ret = -EFAULT; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 1fe8fe4..a3998c6 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -754,7 +754,7 @@ struct xen_sysctl_psr_cat_op { uint32_t cos_max; /* OUT: Maximum COS */ #define XEN_SYSCTL_PSR_CAT_L3_CDP (1u << 0) uint32_t flags; /* OUT: CAT flags */ - } l3_info; + } cat_info; } u; }; typedef struct xen_sysctl_psr_cat_op xen_sysctl_psr_cat_op_t;