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 09/16] x86: implement set value flow for MBA.
Date: Tue, 10 Jan 2017 15:42:28 +0800	[thread overview]
Message-ID: <1484034155-4521-10-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 set value flow for MBA including its callback
function and domctl interface.

Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
 xen/arch/x86/domctl.c           |   6 ++
 xen/arch/x86/psr.c              | 152 +++++++++++++++++++++++++++++++++++++---
 xen/include/asm-x86/msr-index.h |   1 +
 xen/include/public/domctl.h     |   1 +
 4 files changed, 149 insertions(+), 11 deletions(-)

diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index 6145cf4..a7cf690 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -1393,6 +1393,12 @@ long arch_do_domctl(
                               PSR_VAL_TYPE_L2);
             break;
 
+        case XEN_DOMCTL_PSR_MBA_OP_SET_THRTL:
+            ret = psr_set_val(d, domctl->u.psr_alloc_op.target,
+                              domctl->u.psr_alloc_op.data,
+                              PSR_VAL_TYPE_MBA);
+            break;
+
         case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CBM:
             ret = psr_get_val(d, domctl->u.psr_alloc_op.target,
                               &domctl->u.psr_alloc_op.data,
diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c
index fd95a6d..965ed17 100644
--- a/xen/arch/x86/psr.c
+++ b/xen/arch/x86/psr.c
@@ -332,6 +332,14 @@ static bool_t psr_check_cbm(unsigned int cbm_len, uint64_t cbm)
     return 1;
 }
 
+static bool_t psr_check_thrtl(unsigned int thrtl_max, uint64_t thrtl)
+{
+    if ( thrtl > thrtl_max )
+        return 0;
+
+    return 1;
+}
+
 /* L3 CAT callback functions implementation. */
 static void l3_cat_init_feature(unsigned int eax, unsigned int ebx,
                                 unsigned int ecx, unsigned int edx,
@@ -1012,11 +1020,121 @@ static bool mba_get_val(const struct feat_node *feat, unsigned int cos,
     return true;
 }
 
+static unsigned int mba_get_cos_num(const struct feat_node *feat)
+{
+    /* MBA uses one COS. */
+    return 1;
+}
+
+static int mba_get_old_val(uint64_t val[],
+                           const struct feat_node *feat,
+                           unsigned int old_cos)
+{
+    if ( old_cos > feat->info.mba_info.cos_max )
+        /* Use default value. */
+        old_cos = 0;
+
+    val[0] = feat->cos_reg_val[old_cos];
+
+    /* MBA uses one COS. */
+    return 1;
+}
+
+static int mba_set_new_val(uint64_t val[],
+                           const struct feat_node *feat,
+                           unsigned int old_cos,
+                           enum psr_val_type type,
+                           uint64_t m)
+{
+    if ( type != PSR_VAL_TYPE_MBA )
+        return 1;
+
+    if ( !psr_check_thrtl(feat->info.mba_info.thrtl_max, m) )
+        return -EINVAL;
+
+    val[0] = m;
+
+    /* MBA uses one COS. */
+    return 1;
+}
+
+static unsigned int mba_get_cos_max_from_type(const struct feat_node *feat,
+                                              enum psr_val_type type)
+{
+    if ( type != PSR_VAL_TYPE_MBA )
+        return 0;
+
+    return feat->info.mba_info.cos_max;
+}
+
+static int mba_compare_val(const uint64_t val[],
+                           const struct feat_node *feat,
+                           unsigned int cos, bool *found)
+{
+    uint64_t mba_def = 0;
+
+    if ( cos > feat->info.mba_info.cos_max )
+    {
+        if ( val[0] != mba_def )
+        {
+            *found = false;
+            return -ENOENT;
+        }
+        *found = true;
+    }
+    else
+        *found = (val[0] == feat->cos_reg_val[cos]);
+
+    /* MBA uses one COS. */
+    return 1;
+}
+
+static unsigned int mba_exceeds_cos_max(const uint64_t val[],
+                                        const struct feat_node *feat,
+                                        unsigned int cos)
+{
+    uint64_t mba_def = 0;
+
+    if ( cos > feat->info.mba_info.cos_max &&
+         val[0] != mba_def )
+            /*
+             * Exceed cos_max and value to set is not default,
+             * return error.
+             */
+            return 0;
+
+    /* MBA uses one COS. */
+    return 1;
+}
+
+static int mba_write_msr(unsigned int cos, const uint64_t val[],
+                         struct feat_node *feat)
+{
+    if ( cos > feat->info.mba_info.cos_max )
+        return 1;
+
+    if ( feat->cos_reg_val[cos] != val[0] )
+    {
+        wrmsrl(MSR_IA32_PSR_MBA_MASK(cos), val[0]);
+        feat->cos_reg_val[cos] = val[0];
+    }
+
+    /* MBA uses one COS. */
+    return 1;
+}
+
 struct feat_ops mba_ops = {
     .init_feature = mba_init_feature,
     .get_max_cos_max = mba_get_max_cos_max,
     .get_feat_info = mba_get_feat_info,
     .get_val = mba_get_val,
+    .get_cos_num = mba_get_cos_num,
+    .get_old_val = mba_get_old_val,
+    .set_new_val = mba_set_new_val,
+    .get_cos_max_from_type = mba_get_cos_max_from_type,
+    .compare_val = mba_compare_val,
+    .exceeds_cos_max = mba_exceeds_cos_max,
+    .write_msr = mba_write_msr,
 };
 
 static void __init parse_psr_bool(char *s, char *value, char *feature,
@@ -1519,20 +1637,10 @@ static int write_psr_msr(unsigned int socket, unsigned int cos,
     return 0;
 }
 
-int psr_set_val(struct domain *d, unsigned int socket,
-                uint64_t val, enum psr_val_type type)
+static uint32_t psr_val_type_to_feat_flag(enum psr_val_type type)
 {
-    unsigned int old_cos;
-    int cos, ret;
-    unsigned int *ref;
-    uint64_t *val_array;
-    struct psr_socket_info *info = get_socket_info(socket);
-    uint32_t array_len;
     uint32_t flag;
 
-    if ( IS_ERR(info) )
-        return PTR_ERR(info);
-
     /* Judge if feature is enabled. */
     switch ( type ) {
     case PSR_VAL_TYPE_L3:
@@ -1545,10 +1653,32 @@ int psr_set_val(struct domain *d, unsigned int socket,
     case PSR_VAL_TYPE_L2:
         flag = PSR_SOCKET_L2_CAT;
         break;
+    case PSR_VAL_TYPE_MBA:
+        flag = PSR_SOCKET_MBA;
+        break;
     default:
         flag = 0xFFFF;
         break;
     }
+
+    return flag;
+}
+
+int psr_set_val(struct domain *d, unsigned int socket,
+                uint64_t val, enum psr_val_type type)
+{
+    unsigned int old_cos;
+    int cos, ret;
+    unsigned int *ref;
+    uint64_t *val_array;
+    struct psr_socket_info *info = get_socket_info(socket);
+    uint32_t array_len;
+    uint32_t flag;
+
+    if ( IS_ERR(info) )
+        return PTR_ERR(info);
+
+    flag = psr_val_type_to_feat_flag(type);
     if ( !test_bit(flag, &info->feat_mask) )
         return -ENODEV;
 
diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h
index a41e63a..2e97c6c 100644
--- a/xen/include/asm-x86/msr-index.h
+++ b/xen/include/asm-x86/msr-index.h
@@ -344,6 +344,7 @@
 #define MSR_IA32_PSR_L3_MASK_CODE(n)	(0x00000c90 + (n) * 2 + 1)
 #define MSR_IA32_PSR_L3_MASK_DATA(n)	(0x00000c90 + (n) * 2)
 #define MSR_IA32_PSR_L2_MASK(n)		(0x00000d10 + (n))
+#define MSR_IA32_PSR_MBA_MASK(n)	(0x00000d50 + (n))
 
 /* Intel Model 6 */
 #define MSR_P6_PERFCTR(n)		(0x000000c1 + (n))
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 2de7214..11609bc 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -1140,6 +1140,7 @@ struct xen_domctl_psr_alloc_op {
 #define XEN_DOMCTL_PSR_CAT_OP_GET_L3_DATA    5
 #define XEN_DOMCTL_PSR_CAT_OP_SET_L2_CBM     6
 #define XEN_DOMCTL_PSR_CAT_OP_GET_L2_CBM     7
+#define XEN_DOMCTL_PSR_MBA_OP_SET_THRTL      8
 #define XEN_DOMCTL_PSR_MBA_OP_GET_THRTL      9
     uint32_t cmd;       /* IN: XEN_DOMCTL_PSR_*_OP_* */
     uint32_t target;    /* IN */
-- 
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 ` Yi Sun [this message]
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 ` [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-10-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).