diff mbox

[RFC,v2,09/12] tools: implement the new get hw info interface suitable to all psr allocation features.

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

Commit Message

Yi Sun July 20, 2017, 8:49 a.m. UTC
This patch implements a new get hw info interface suitable for all psr allocation
features and the whole flow. It also enables MBA support in tools to get MBA
HW info.

Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
 tools/libxc/include/xenctrl.h |  30 +++++++-
 tools/libxc/xc_psr.c          |  46 +++++++++----
 tools/libxl/libxl_psr.c       | 155 +++++++++++++++++++++++++++++++++++-------
 tools/xl/xl_cmdtable.c        |   3 +
 tools/xl/xl_psr.c             |  45 +++++++++++-
 5 files changed, 238 insertions(+), 41 deletions(-)

Comments

Wei Liu July 31, 2017, 2:30 p.m. UTC | #1
On Thu, Jul 20, 2017 at 04:49:10PM +0800, Yi Sun wrote:
> This patch implements a new get hw info interface suitable for all psr allocation
> features and the whole flow. It also enables MBA support in tools to get MBA
> HW info.
> 
> Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
> ---
>  tools/libxc/include/xenctrl.h |  30 +++++++-
>  tools/libxc/xc_psr.c          |  46 +++++++++----
>  tools/libxl/libxl_psr.c       | 155 +++++++++++++++++++++++++++++++++++-------
>  tools/xl/xl_cmdtable.c        |   3 +
>  tools/xl/xl_psr.c             |  45 +++++++++++-
>  5 files changed, 238 insertions(+), 41 deletions(-)
> 
> diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
> index 2248900..0b0ec31 100644
> --- a/tools/libxc/include/xenctrl.h
> +++ b/tools/libxc/include/xenctrl.h
> @@ -2460,6 +2460,31 @@ 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,
> +    XC_PSR_FEAT_MBA        = 3,

Pointless initialisers.

> +};
> +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;
> +
> +        struct {
> +            uint32_t cos_max;
> +            uint32_t thrtl_max;
> +            bool     linear;
> +        } xc_mba_info;
> +    } u;
> +};
> +typedef struct xc_psr_hw_info xc_psr_hw_info;
[...]
> index 8319301..43b84b6 100644
> --- a/tools/libxl/libxl_psr.c
> +++ b/tools/libxl/libxl_psr.c
> @@ -361,47 +361,49 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
>      return rc;
>  }
>  
> +static inline int libxl_psr_hw_info_to_libxl_psr_cat_info(

libxl__ -> two underscores for internal functions.

> +                      libxl_psr_feat_type type, libxl_psr_hw_info *hw_info,
> +                      libxl_psr_cat_info *cat_info)
> +{
> +    if (type != LIBXL_PSR_FEAT_TYPE_CAT_INFO)
> +        return -1;

ERROR_INVAL;

> +
> +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;
> +    case LIBXL_PSR_FEAT_TYPE_MBA_INFO:
> +        xl_hw_info->u.mba_info.cos_max = xc_hw_info->u.xc_mba_info.cos_max;
> +        xl_hw_info->u.mba_info.thrtl_max = xc_hw_info->u.xc_mba_info.thrtl_max;
> +        xl_hw_info->u.mba_info.linear = xc_hw_info->u.xc_mba_info.linear;
> +        break;
> +    default:
> +        return -1;

ERROR_INVAL

> +    }
> +
> +    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)
>  {
> -    return EXIT_FAILURE;
> +    GC_INIT(ctx);
> +    int rc;
> +    int i = 0, socketid, nr_sockets;
> +    libxl_bitmap socketmap;
> +    libxl_psr_hw_info *ptr;
> +    xc_psr_feat_type xc_type;
> +    xc_psr_hw_info hw_info;
> +
> +    libxl_bitmap_init(&socketmap);
> +
> +    if ( type == LIBXL_PSR_FEAT_TYPE_CAT_INFO && lvl != 3 && lvl != 2) {

Extraneous space.

>  
>  void libxl_psr_hw_info_list_free(libxl_psr_hw_info *list, int nr)
>  {
> +    int i;

unsigned int

> +
> +    for (i = 0; i < nr; i++)
> +        libxl_psr_hw_info_dispose(&list[i]);
> +    free(list);
>  }
>  
>  /*
> diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
> index 2c71a9f..14a02d4 100644
> --- a/tools/xl/xl_cmdtable.c
> +++ b/tools/xl/xl_cmdtable.c
> @@ -524,6 +524,9 @@ struct cmd_spec cmd_table[] = {
>        "[options]",
>        "-m, --cmt       Show Cache Monitoring Technology (CMT) hardware info\n"
>        "-a, --cat       Show Cache Allocation Technology (CAT) hardware info\n"
> +#ifdef LIBXL_HAVE_PSR_MBA
> +      "-b, --mba       Show Memory Bandwidth Allocation (MBA) hardware info\n"
> +#endif

You don't need to test the macro. xl always has all features available.

Same comment applies to the rest of this patch.
diff mbox

Patch

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 2248900..0b0ec31 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2460,6 +2460,31 @@  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,
+    XC_PSR_FEAT_MBA        = 3,
+};
+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;
+
+        struct {
+            uint32_t cos_max;
+            uint32_t thrtl_max;
+            bool     linear;
+        } xc_mba_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,
@@ -2481,9 +2506,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 73d05f2..494d1f0 100644
--- a/tools/libxc/xc_psr.c
+++ b/tools/libxc/xc_psr.c
@@ -323,36 +323,58 @@  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 )
+    switch ( type )
     {
-    case 2:
+    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.cat_info.cos_max;
-            *cbm_len = sysctl.u.psr_alloc_op.u.cat_info.cbm_len;
-            *cdp_enabled = false;
+            hw_info->u.xc_cat_info.cos_max =
+                        sysctl.u.psr_alloc_op.u.cat_info.cos_max;
+            hw_info->u.xc_cat_info.cbm_len =
+                        sysctl.u.psr_alloc_op.u.cat_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.cat_info.cos_max;
-            *cbm_len = sysctl.u.psr_alloc_op.u.cat_info.cbm_len;
-            *cdp_enabled = sysctl.u.psr_alloc_op.u.cat_info.flags &
-                           XEN_SYSCTL_PSR_CAT_L3_CDP;
+            hw_info->u.xc_cat_info.cos_max =
+                        sysctl.u.psr_alloc_op.u.cat_info.cos_max;
+            hw_info->u.xc_cat_info.cbm_len =
+                        sysctl.u.psr_alloc_op.u.cat_info.cbm_len;
+            hw_info->u.xc_cat_info.cdp_enabled =
+                        sysctl.u.psr_alloc_op.u.cat_info.flags &
+                        XEN_SYSCTL_PSR_CAT_L3_CDP;
+        }
+        break;
+    case XC_PSR_FEAT_MBA:
+        sysctl.u.psr_alloc_op.cmd = XEN_SYSCTL_PSR_MBA_get_info;
+        rc = xc_sysctl(xch, &sysctl);
+        if ( !rc )
+        {
+            hw_info->u.xc_mba_info.cos_max =
+                        sysctl.u.psr_alloc_op.u.mba_info.cos_max;
+            hw_info->u.xc_mba_info.thrtl_max =
+                        sysctl.u.psr_alloc_op.u.mba_info.thrtl_max;
+            hw_info->u.xc_mba_info.linear =
+                        sysctl.u.psr_alloc_op.u.mba_info.linear &
+                        XEN_SYSCTL_PSR_MBA_LINEAR;
         }
         break;
     default:
diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c
index 8319301..43b84b6 100644
--- a/tools/libxl/libxl_psr.c
+++ b/tools/libxl/libxl_psr.c
@@ -361,47 +361,49 @@  int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
     return rc;
 }
 
+static inline int libxl_psr_hw_info_to_libxl_psr_cat_info(
+                      libxl_psr_feat_type type, libxl_psr_hw_info *hw_info,
+                      libxl_psr_cat_info *cat_info)
+{
+    if (type != LIBXL_PSR_FEAT_TYPE_CAT_INFO)
+        return -1;
+
+    cat_info->id = hw_info->id;
+    cat_info->cos_max = hw_info->u.cat_info.cos_max;
+    cat_info->cbm_len = hw_info->u.cat_info.cbm_len;
+    cat_info->cdp_enabled = hw_info->u.cat_info.cdp_enabled;
+
+    return 0;
+}
+
 int libxl_psr_cat_get_info(libxl_ctx *ctx, libxl_psr_cat_info **info,
                            int *nr, unsigned int lvl)
 {
     GC_INIT(ctx);
     int rc;
-    int i = 0, socketid, nr_sockets;
-    libxl_bitmap socketmap;
+    unsigned int i;
+    libxl_psr_hw_info *hw_info;
     libxl_psr_cat_info *ptr;
 
-    libxl_bitmap_init(&socketmap);
-
-    rc = libxl__count_physical_sockets(gc, &nr_sockets);
-    if (rc) {
-        LOGE(ERROR, "failed to get system socket count");
-        goto out;
-    }
-
-    libxl_socket_bitmap_alloc(ctx, &socketmap, nr_sockets);
-    rc = libxl_get_online_socketmap(ctx, &socketmap);
-    if (rc < 0) {
-        LOGE(ERROR, "failed to get available sockets");
+    rc = libxl_psr_get_hw_info(ctx, &hw_info, nr,
+                               LIBXL_PSR_FEAT_TYPE_CAT_INFO, lvl);
+    if (rc)
         goto out;
-    }
 
-    ptr = libxl__malloc(NOGC, nr_sockets * sizeof(libxl_psr_cat_info));
+    ptr = libxl__malloc(NOGC, *nr * sizeof(libxl_psr_cat_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)) {
+    for (i = 0; i < *nr; i++) {
+        if (libxl_psr_hw_info_to_libxl_psr_cat_info(
+                    LIBXL_PSR_FEAT_TYPE_CAT_INFO,
+                    &hw_info[i], &ptr[i])) {
             rc = ERROR_FAIL;
             free(ptr);
             goto out;
         }
-        i++;
     }
 
     *info = ptr;
-    *nr = i;
 out:
-    libxl_bitmap_dispose(&socketmap);
     GC_FREE;
     return rc;
 }
@@ -439,14 +441,119 @@  int libxl_psr_get_val(libxl_ctx *ctx, uint32_t domid,
     return EXIT_FAILURE;
 }
 
+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;
+    case LIBXL_PSR_FEAT_TYPE_MBA_INFO:
+        xc_type = XC_PSR_FEAT_MBA;
+    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;
+    case LIBXL_PSR_FEAT_TYPE_MBA_INFO:
+        xl_hw_info->u.mba_info.cos_max = xc_hw_info->u.xc_mba_info.cos_max;
+        xl_hw_info->u.mba_info.thrtl_max = xc_hw_info->u.xc_mba_info.thrtl_max;
+        xl_hw_info->u.mba_info.linear = xc_hw_info->u.xc_mba_info.linear;
+        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)
 {
-    return EXIT_FAILURE;
+    GC_INIT(ctx);
+    int rc;
+    int i = 0, socketid, nr_sockets;
+    libxl_bitmap socketmap;
+    libxl_psr_hw_info *ptr;
+    xc_psr_feat_type xc_type;
+    xc_psr_hw_info hw_info;
+
+    libxl_bitmap_init(&socketmap);
+
+    if ( type == LIBXL_PSR_FEAT_TYPE_CAT_INFO && 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");
+        goto out;
+    }
+
+    libxl_socket_bitmap_alloc(ctx, &socketmap, nr_sockets);
+    rc = libxl_get_online_socketmap(ctx, &socketmap);
+    if (rc < 0) {
+        LOGE(ERROR, "failed to get available sockets");
+        goto out;
+    }
+
+    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_get_hw_info(ctx->xch, socketid, xc_type, &hw_info)) {
+            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++;
+    }
+
+    *info = ptr;
+    *nr = i;
+out:
+    libxl_bitmap_dispose(&socketmap);
+    GC_FREE;
+    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);
 }
 
 /*
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 2c71a9f..14a02d4 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -524,6 +524,9 @@  struct cmd_spec cmd_table[] = {
       "[options]",
       "-m, --cmt       Show Cache Monitoring Technology (CMT) hardware info\n"
       "-a, --cat       Show Cache Allocation Technology (CAT) hardware info\n"
+#ifdef LIBXL_HAVE_PSR_MBA
+      "-b, --mba       Show Memory Bandwidth Allocation (MBA) hardware info\n"
+#endif
     },
     { "psr-cmt-attach",
       &main_psr_cmt_attach, 0, 1,
diff --git a/tools/xl/xl_psr.c b/tools/xl/xl_psr.c
index 7309d4f..037eab3 100644
--- a/tools/xl/xl_psr.c
+++ b/tools/xl/xl_psr.c
@@ -479,6 +479,37 @@  static int psr_l2_cat_hwinfo(void)
     return rc;
 }
 
+#ifdef LIBXL_HAVE_PSR_MBA
+static int psr_mba_hwinfo(void)
+{
+    int rc;
+    int i, nr;
+    libxl_psr_hw_info *info;
+
+    printf("Memory Bandwidth Allocation (MBA):\n");
+
+    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++) {
+        printf("%-16s: %u\n", "Socket ID", info[i].id);
+        printf("%-16s: %s\n", "Linear Mode",
+               info[i].u.mba_info.linear ? "Enabled" : "Disabled");
+        printf("%-16s: %u\n", "Maximum COS", info[i].u.mba_info.cos_max);
+        printf("%-16s: %u\n", "Maximum Throttling Value",
+               info[i].u.mba_info.thrtl_max);
+        printf("%-16s: %u\n", "Default Throttling Value", 0);
+    }
+
+    libxl_psr_hw_info_list_free(info, nr);
+    return rc;
+}
+#endif
+
 int main_psr_cat_cbm_set(int argc, char **argv)
 {
     uint32_t domid;
@@ -597,20 +628,24 @@  int main_psr_cat_show(int argc, char **argv)
 int main_psr_hwinfo(int argc, char **argv)
 {
     int opt, ret = 0;
-    bool all = true, cmt = false, cat = false;
+    bool all = true, cmt = false, cat = false, mba = false;
     static struct option opts[] = {
         {"cmt", 0, 0, 'm'},
         {"cat", 0, 0, 'a'},
+        {"mba", 0, 0, 'b'},
         COMMON_LONG_OPTS
     };
 
-    SWITCH_FOREACH_OPT(opt, "ma", opts, "psr-hwinfo", 0) {
+    SWITCH_FOREACH_OPT(opt, "mab", opts, "psr-hwinfo", 0) {
     case 'm':
         all = false; cmt = true;
         break;
     case 'a':
         all = false; cat = true;
         break;
+    case 'b':
+        all = false; mba = true;
+        break;
     }
 
     if (!ret && (all || cmt))
@@ -623,6 +658,12 @@  int main_psr_hwinfo(int argc, char **argv)
     if (all || cat)
         ret = psr_l2_cat_hwinfo();
 
+#ifdef LIBXL_HAVE_PSR_MBA
+    /* MBA is independent of CMT and CAT */
+    if (all || mba)
+        ret = psr_mba_hwinfo();
+#endif
+
     return ret;
 }