[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [RFC 11/16] tools: refactor codes to make get val be more general.



This patch refactors some codes in tools/ to make get value
be more general.

Signed-off-by: Yi Sun <yi.y.sun@xxxxxxxxxxxxxxx>
---
 tools/libxc/include/xenctrl.h | 12 +++----
 tools/libxc/xc_psr.c          |  8 ++---
 tools/libxl/libxl_psr.c       | 80 +++++++++++++++++++++++++++++++++++--------
 3 files changed, 75 insertions(+), 25 deletions(-)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index fa62e2a..69f9343 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2598,13 +2598,13 @@ enum xc_psr_cmt_type {
 };
 typedef enum xc_psr_cmt_type xc_psr_cmt_type;
 
-enum xc_psr_cat_type {
+enum xc_psr_val_type {
     XC_PSR_CAT_L3_CBM      = 1,
     XC_PSR_CAT_L3_CBM_CODE = 2,
     XC_PSR_CAT_L3_CBM_DATA = 3,
     XC_PSR_CAT_L2_CBM      = 4,
 };
-typedef enum xc_psr_cat_type xc_psr_cat_type;
+typedef enum xc_psr_val_type xc_psr_val_type;
 
 enum xc_psr_feat_type {
     XC_PSR_FEAT_UNKNOWN    = 0,
@@ -2640,11 +2640,11 @@ int xc_psr_cmt_get_data(xc_interface *xch, uint32_t 
rmid, uint32_t cpu,
 int xc_psr_cmt_enabled(xc_interface *xch);
 
 int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid,
-                               xc_psr_cat_type type, uint32_t target,
+                               xc_psr_val_type type, uint32_t target,
                                uint64_t data);
-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_get_domain_data(xc_interface *xch, uint32_t domid,
+                           xc_psr_val_type type, uint32_t target,
+                           uint64_t *data);
 int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket,
                        xc_psr_feat_type type, xc_psr_hw_info *hw_info);
 
diff --git a/tools/libxc/xc_psr.c b/tools/libxc/xc_psr.c
index af648eb..4dbb7c6 100644
--- a/tools/libxc/xc_psr.c
+++ b/tools/libxc/xc_psr.c
@@ -249,7 +249,7 @@ int xc_psr_cmt_enabled(xc_interface *xch)
     return 0;
 }
 int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t domid,
-                               xc_psr_cat_type type, uint32_t target,
+                               xc_psr_val_type type, uint32_t target,
                                uint64_t data)
 {
     DECLARE_DOMCTL;
@@ -283,9 +283,9 @@ int xc_psr_cat_set_domain_data(xc_interface *xch, uint32_t 
domid,
     return do_domctl(xch, &domctl);
 }
 
-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_get_domain_data(xc_interface *xch, uint32_t domid,
+                           xc_psr_val_type type, uint32_t target,
+                           uint64_t *data)
 {
     int rc;
     DECLARE_DOMCTL;
diff --git a/tools/libxl/libxl_psr.c b/tools/libxl/libxl_psr.c
index 2fe42b7..07c4bc4 100644
--- a/tools/libxl/libxl_psr.c
+++ b/tools/libxl/libxl_psr.c
@@ -71,16 +71,35 @@ static void libxl__psr_cmt_log_err_msg(libxl__gc *gc, int 
err)
     LOGE(ERROR, "%s", msg);
 }
 
-static void libxl__psr_cat_log_err_msg(libxl__gc *gc, int err)
+static void libxl__psr_alloc_log_err_msg(libxl__gc *gc,
+                                         libxl_psr_cbm_type type, int err)
 {
     char *msg;
+    char *feat;
+
+    switch (type) {
+    case LIBXL_PSR_CBM_TYPE_L3_CBM:
+        feat = "L3 CAT";
+        break;
+    case LIBXL_PSR_CBM_TYPE_L3_CBM_CODE:
+    case LIBXL_PSR_CBM_TYPE_L3_CBM_DATA:
+        feat = "L3 CDP";
+        break;
+    case LIBXL_PSR_CBM_TYPE_L2_CBM:
+        feat = "L2 CAT";
+        break;
+    default:
+        LOGE(ERROR, "Input type %d is wrong!\n", type);
+        libxl__psr_log_err_msg(gc, err);
+        return;
+    }
 
     switch (err) {
     case ENODEV:
-        msg = "CAT is not supported in this system";
+        msg = "is not supported in this system";
         break;
     case ENOENT:
-        msg = "CAT is not enabled on the socket";
+        msg = "is not enabled on the socket";
         break;
     case EOVERFLOW:
         msg = "no free COS available";
@@ -97,7 +116,38 @@ static void libxl__psr_cat_log_err_msg(libxl__gc *gc, int 
err)
         return;
     }
 
-    LOGE(ERROR, "%s", msg);
+    LOGE(ERROR, "%s: %s", feat, msg);
+}
+
+static void libxl__psr_hw_info_log_err_msg(libxl__gc *gc, int lvl,
+                                          libxl_psr_feat_type type, int err)
+{
+    char *msg;
+    char *feat;
+
+    switch (type) {
+    case LIBXL_PSR_FEAT_TYPE_CAT_INFO:
+        if (lvl == 3)
+            feat = "L3 CAT";
+        else
+            feat = "L2 CAT";
+        break;
+    default:
+        LOGE(ERROR, "Input type %d is wrong!\n", type);
+        libxl__psr_log_err_msg(gc, err);
+        return;
+    }
+
+    switch (err) {
+    case ENOENT:
+        msg = "is not enabled on the socket";
+        break;
+    default:
+        libxl__psr_log_err_msg(gc, err);
+        return;
+    }
+
+    LOGE(ERROR, "%s: %s", feat, msg);
 }
 
 static int libxl__pick_socket_cpu(libxl__gc *gc, uint32_t socketid)
@@ -294,11 +344,11 @@ out:
     return rc;
 }
 
-static inline xc_psr_cat_type libxl__psr_cbm_type_to_libxc_psr_cat_type(
+static inline xc_psr_val_type libxl__psr_cbm_type_to_libxc_psr_val_type(
     libxl_psr_cbm_type type)
 {
-    BUILD_BUG_ON(sizeof(libxl_psr_cbm_type) != sizeof(xc_psr_cat_type));
-    return (xc_psr_cat_type)type;
+    BUILD_BUG_ON(sizeof(libxl_psr_cbm_type) != sizeof(xc_psr_val_type));
+    return (xc_psr_val_type)type;
 }
 
 int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid,
@@ -316,15 +366,15 @@ int libxl_psr_cat_set_cbm(libxl_ctx *ctx, uint32_t domid,
     }
 
     libxl_for_each_set_bit(socketid, *target_map) {
-        xc_psr_cat_type xc_type;
+        xc_psr_val_type xc_type;
 
         if (socketid >= nr_sockets)
             break;
 
-        xc_type = libxl__psr_cbm_type_to_libxc_psr_cat_type(type);
+        xc_type = libxl__psr_cbm_type_to_libxc_psr_val_type(type);
         if (xc_psr_cat_set_domain_data(ctx->xch, domid, xc_type,
                                        socketid, cbm)) {
-            libxl__psr_cat_log_err_msg(gc, errno);
+            libxl__psr_alloc_log_err_msg(gc, type, errno);
             rc = ERROR_FAIL;
         }
     }
@@ -340,11 +390,11 @@ int libxl_psr_cat_get_cbm(libxl_ctx *ctx, uint32_t domid,
 {
     GC_INIT(ctx);
     int rc = 0;
-    xc_psr_cat_type xc_type = libxl__psr_cbm_type_to_libxc_psr_cat_type(type);
+    xc_psr_val_type xc_type = libxl__psr_cbm_type_to_libxc_psr_val_type(type);
 
-    if (xc_psr_cat_get_domain_data(ctx->xch, domid, xc_type,
-                                   target, cbm_r)) {
-        libxl__psr_cat_log_err_msg(gc, errno);
+    if (xc_psr_get_domain_data(ctx->xch, domid, xc_type,
+                               target, cbm_r)) {
+        libxl__psr_alloc_log_err_msg(gc, type, errno);
         rc = ERROR_FAIL;
     }
 
@@ -428,7 +478,7 @@ int libxl_psr_get_hw_info(libxl_ctx *ctx, libxl_psr_hw_info 
**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)) {
-            libxl__psr_cat_log_err_msg(gc, errno);
+            libxl__psr_hw_info_log_err_msg(gc, lvl, type, errno);
             rc = ERROR_FAIL;
             free(ptr);
             goto out;
-- 
1.9.1


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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.