From patchwork Tue Jan 10 07:42:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9506621 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 DAFF1606E1 for ; Tue, 10 Jan 2017 07:45:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC6AE283F6 for ; Tue, 10 Jan 2017 07:45:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF12B28497; Tue, 10 Jan 2017 07:45:24 +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 A1BC428485 for ; Tue, 10 Jan 2017 07:45:23 +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 1cQr64-0004EN-TP; Tue, 10 Jan 2017 07:43:56 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQr63-0004CO-7t for xen-devel@lists.xenproject.org; Tue, 10 Jan 2017 07:43:55 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id A3/39-01684-AB094785; Tue, 10 Jan 2017 07:43:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsVywNykWHfXhJI Ig67JjBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bsGd4F3dYVb083MTUwbtftYuTgEBKolDg5 n62LkZNDQoBX4siyGawQtr/EskW7gOJcQCUNjBLHbu9kAUmwCahLPP7awwRiiwgoSdxbNZkJp IhZYD+jxPzjx5lBEsICNhK7Lv1lBVnAIqAqcf5zKEiYV8BDYtvqRqhlchInj00GW8YJFG+5uo 4RxBYScJdofnufcQIj7wJGhlWMGsWpRWWpRbrGBnpJRZnpGSW5iZk5uoYGxnq5qcXFiempOYl JxXrJ+bmbGIGhUM/AwLiDsfOE3yFGSQ4mJVHeFN2SCCG+pPyUyozE4oz4otKc1OJDjDIcHEoS vFX9QDnBotT01Iq0zBxgUMKkJTh4lER4WUDSvMUFibnFmekQqVOMilLivIEgCQGQREZpHlwbL BIuMcpKCfMyMjAwCPEUpBblZpagyr9iFOdgVBLmbQaZwpOZVwI3/RXQYiagxZF2xSCLSxIRUl INjK18DYGqU/0m7HfqZu+fw7i4xueCeMU8p+q6PeLLs/SkvSS9r/I6aqTtfPrjz9tb2Qv2TPb nu9OVxaVbIeJ2h3Gm+5SqXP11O79balg9SW37Xrp8Y4T31K29Bk1/GLcEnX2UuFPXfWP8jajZ q46LyjzOyzbKsvCuLX/t3/El8NWZe01q/79MUGIpzkg01GIuKk4EAMRsP1J/AgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1484034224!62972679!4 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 33638 invoked from network); 10 Jan 2017 07:43:53 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-12.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jan 2017 07:43:53 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 09 Jan 2017 23:43:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,343,1477983600"; d="scan'208";a="211583284" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 09 Jan 2017 23:43:51 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 10 Jan 2017 15:42:33 +0800 Message-Id: <1484034155-4521-15-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 14/16] tools: implemet get value flow for MBA. 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 get value flow in tools for MBA. Signed-off-by: Yi Sun --- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_psr.c | 3 ++ tools/libxl/libxl.h | 3 ++ tools/libxl/libxl_psr.c | 21 +++++++++ tools/libxl/libxl_types.idl | 1 + tools/libxl/xl.h | 3 ++ tools/libxl/xl_cmdimpl.c | 101 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 8 ++++ 8 files changed, 141 insertions(+) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index ffd0f63..29191d5 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2603,6 +2603,7 @@ enum xc_psr_val_type { XC_PSR_CAT_L3_CBM_CODE = 2, XC_PSR_CAT_L3_CBM_DATA = 3, XC_PSR_CAT_L2_CBM = 4, + XC_PSR_MBA_THRTL = 5, }; typedef enum xc_psr_val_type xc_psr_val_type; diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c index 381ef01..9348578 100644 --- a/tools/libxc/xc_psr.c +++ b/tools/libxc/xc_psr.c @@ -305,6 +305,9 @@ int xc_psr_get_domain_data(xc_interface *xch, uint32_t domid, case XC_PSR_CAT_L2_CBM: cmd = XEN_DOMCTL_PSR_CAT_OP_GET_L2_CBM; break; + case XC_PSR_MBA_THRTL: + cmd = XEN_DOMCTL_PSR_MBA_OP_GET_THRTL; + break; default: errno = EINVAL; return -1; diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 7575ccd..4c42c00 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -2175,6 +2175,9 @@ int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid, int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid, libxl_psr_cbm_type type, uint32_t target, uint64_t *cbm_r); +int libxl_psr_get_val(libxl_ctx *ctx, uint32_t domid, + libxl_psr_cbm_type type, uint32_t target, + uint64_t *val); /* * On success, the function returns an array of elements in 'info', diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c index 13d44b6..fac2617 100644 --- a/tools/libxl/libxl_psr.c +++ b/tools/libxl/libxl_psr.c @@ -88,6 +88,9 @@ static void libxl__psr_alloc_log_err_msg(libxl__gc *gc, case LIBXL_PSR_CBM_TYPE_L2_CBM: feat = "L2 CAT"; break; + case LIBXL_PSR_CBM_TYPE_MBA_THRTL: + feat = "MBA"; + break; default: LOGE(ERROR, "Input type %d is wrong!\n", type); libxl__psr_log_err_msg(gc, err); @@ -405,6 +408,24 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid, return rc; } +int libxl_psr_get_val(libxl_ctx *ctx, uint32_t domid, + libxl_psr_cbm_type type, uint32_t target, + uint64_t *val) +{ + GC_INIT(ctx); + int rc = 0; + xc_psr_val_type xc_type = libxl__psr_cbm_type_to_libxc_psr_val_type(type); + + if (xc_psr_get_domain_data(ctx->xch, domid, xc_type, + target, val)) { + libxl__psr_alloc_log_err_msg(gc, type, errno); + rc = ERROR_FAIL; + } + + GC_FREE; + return rc; +} + static inline xc_psr_feat_type libxl__psr_feat_type_to_libxc_psr_feat_type( libxl_psr_feat_type type, int lvl) { diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index bd8d2b8..579794a 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -900,6 +900,7 @@ libxl_psr_cbm_type = Enumeration("psr_cbm_type", [ (2, "L3_CBM_CODE"), (3, "L3_CBM_DATA"), (4, "L2_CBM"), + (5, "MBA_THRTL"), ]) libxl_psr_cat_info = Struct("psr_cat_info", [ diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h index 0a8c813..2d0e676 100644 --- a/tools/libxl/xl.h +++ b/tools/libxl/xl.h @@ -133,6 +133,9 @@ int main_psr_cmt_show(int argc, char **argv); int main_psr_cat_cbm_set(int argc, char **argv); int main_psr_cat_show(int argc, char **argv); #endif +#ifdef LIBXL_HAVE_PSR_MBA +int main_psr_mba_show(int argc, char **argv); +#endif int main_qemu_monitor_command(int argc, char **argv); void help(const char *command); diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 21ef2cf..2263635 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -9551,6 +9551,107 @@ static int psr_mba_hwinfo(void) libxl_psr_hw_info_list_free(info, nr); return rc; } + +static void psr_mba_print_one_domain_thrtl_type(uint32_t domid, + uint32_t socketid, + libxl_psr_cbm_type type) +{ + uint64_t thrtl; + + if (!libxl_psr_get_val(ctx, domid, type, socketid, &thrtl)) + printf("%#16"PRIx64, thrtl); + else + printf("%16s", "error"); +} + +static void psr_mba_print_one_domain_thrtl(uint32_t domid, uint32_t socketid) +{ + char *domain_name; + + domain_name = libxl_domid_to_name(ctx, domid); + printf("%5d%25s", domid, domain_name); + free(domain_name); + + psr_mba_print_one_domain_thrtl_type(domid, socketid, + LIBXL_PSR_CBM_TYPE_MBA_THRTL); + printf("\n"); +} + +static int psr_mba_print_domain_thrtl(uint32_t domid, uint32_t socketid) +{ + int i, nr_domains; + libxl_dominfo *list; + + if (domid != INVALID_DOMID) { + psr_mba_print_one_domain_thrtl(domid, socketid); + return 0; + } + + if (!(list = libxl_list_domain(ctx, &nr_domains))) { + fprintf(stderr, "Failed to get domain list for thrtl display\n"); + return -1; + } + + for (i = 0; i < nr_domains; i++) + psr_mba_print_one_domain_thrtl(list[i].domid, socketid); + libxl_dominfo_list_free(list, nr_domains); + + return 0; +} + +static int psr_mba_print_socket(uint32_t domid, libxl_psr_hw_info *info) +{ + printf("%-16s: %u\n", "Socket ID", info->id); + printf("%-16s: %u\n", "Default THRTL", 0); + printf("%5s%25s%16s\n", "ID", "NAME", "THRTL"); + + return psr_mba_print_domain_thrtl(domid, info->id); +} + +static int psr_mba_show(uint32_t domid) +{ + int i, nr; + int rc; + libxl_psr_hw_info *info; + + 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++) { + rc = psr_mba_print_socket(domid, info + i); + if (rc) + goto out; + } + +out: + libxl_psr_hw_info_list_free(info, nr); + return rc; +} + +int main_psr_mba_show(int argc, char **argv) +{ + int opt; + uint32_t domid; + + SWITCH_FOREACH_OPT(opt, "", NULL, "psr-mba-show", 0) { + /* No options */ + } + + if (optind >= argc) + domid = INVALID_DOMID; + else if (optind == argc - 1) + domid = find_domain(argv[optind]); + else { + help("psr-mba-show"); + return 2; + } + + return psr_mba_show(domid); +} #endif int main_psr_cat_cbm_set(int argc, char **argv) diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index 9e1ee6f..b7fc276 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -565,6 +565,14 @@ struct cmd_spec cmd_table[] = { }, #endif +#ifdef LIBXL_HAVE_PSR_MBA + { "psr-mba-show", + &main_psr_mba_show, 0, 1, + "Show Memory Bandwidth Allocation information", + "", + }, + +#endif { "usbctrl-attach", &main_usbctrl_attach, 0, 1, "Create a virtual USB controller for a domain",