diff mbox

[RFC,14/16] tools: implemet get value flow for MBA.

Message ID 1484034155-4521-15-git-send-email-yi.y.sun@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yi Sun Jan. 10, 2017, 7:42 a.m. UTC
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 mbox

Patch

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",