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 11/16] tools: refactor codes to make get val be more general.
Date: Tue, 10 Jan 2017 15:42:30 +0800 [thread overview]
Message-ID: <1484034155-4521-12-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 refactors some codes in tools/ to make get value
be more general.
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
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@lists.xen.org
https://lists.xen.org/xen-devel
next prev 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 ` Yi Sun [this message]
2017-01-10 7:42 ` [RFC 12/16] tools: refactor codes to make set val be more general 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 ` [RFC 14/16] tools: implemet get value " Yi Sun
2017-01-10 7:42 ` [RFC 15/16] tools: implemet set " 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-12-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).