xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Yi Sun <yi.y.sun@linux.intel.com>
To: xen-devel@lists.xenproject.org
Cc: wei.liu2@citrix.com, he.chen@linux.intel.com,
	andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com,
	Yi Sun <yi.y.sun@linux.intel.com>,
	jbeulich@suse.com, chao.p.peng@linux.intel.com
Subject: [RFC 14/16] tools: implemet get value flow for MBA.
Date: Tue, 10 Jan 2017 15:42:33 +0800	[thread overview]
Message-ID: <1484034155-4521-15-git-send-email-yi.y.sun@linux.intel.com> (raw)
In-Reply-To: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com>

This patch implements get value flow in tools for MBA.

Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
 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",
+      "<Domain>",
+    },
+
+#endif
     { "usbctrl-attach",
       &main_usbctrl_attach, 0, 1,
       "Create a virtual USB controller for a domain",
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-01-10  7:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10  7:42 [RFC 00/16] Enable Memory Bandwidth Allocation in Xen Yi Sun
2017-01-10  7:42 ` [RFC 01/16] docs: create Memory Bandwidth Allocation (MBA) feature document Yi Sun
2017-02-23 20:46   ` Meng Xu
2017-02-24  5:07     ` Yi Sun
2017-02-24 15:53       ` Meng Xu
2017-02-27  4:39         ` Yi Sun
2017-01-10  7:42 ` [RFC 02/16] Rename sysctl/domctl interface and xsm policy to make them general Yi Sun
2017-01-10  7:42 ` [RFC 03/16] x86: change 'cbm_type' to 'psr_val_type' to make it general Yi Sun
2017-01-10  7:42 ` [RFC 04/16] x86: implement data structure of MBA Yi Sun
2017-01-10  7:42 ` [RFC 05/16] x86: parse config parameters for MBA Yi Sun
2017-01-10  7:42 ` [RFC 06/16] x86: implement init flow " Yi Sun
2017-01-10  7:42 ` [RFC 07/16] x86: implement get hw info " Yi Sun
2017-01-10  7:42 ` [RFC 08/16] x86: implement get value " Yi Sun
2017-01-10  7:42 ` [RFC 09/16] x86: implement set " Yi Sun
2017-01-10  7:42 ` [RFC 10/16] tools: refactor codes to make get hw info interface be general Yi Sun
2017-01-10  7:42 ` [RFC 11/16] tools: refactor codes to make get val be more general Yi Sun
2017-01-10  7:42 ` [RFC 12/16] tools: refactor codes to make set " Yi Sun
2017-01-10  7:42 ` [RFC 13/16] tools: implemet get hw info flow for MBA Yi Sun
2017-01-10  7:42 ` Yi Sun [this message]
2017-01-10  7:42 ` [RFC 15/16] tools: implemet set value " Yi Sun
2017-01-10  7:42 ` [RFC 16/16] docs: add MBA description in docs Yi Sun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484034155-4521-15-git-send-email-yi.y.sun@linux.intel.com \
    --to=yi.y.sun@linux.intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=he.chen@linux.intel.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).