diff mbox

[v9,17/25] x86: refactor psr: CDP: implement set value callback functions.

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

Commit Message

Yi Sun March 16, 2017, 11:08 a.m. UTC
This patch implements L3 CDP set value related callback functions.

With this patch, 'psr-cat-cbm-set' command can work for L3 CDP.

Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
v9:
    - add comment to explain why CDP uses 2 COSs.
      (suggested by Wei Liu)
    - use 'cat_default_val'.
      (suggested by Wei Liu)
    - remove 'l3_cdp_get_cos_num' because we can directly get cos_num from
      feat_node now.
      (suggested by Jan Beulich)
    - remove cos checking because it has been moved to common function.
      (suggested by Jan Beulich)
    - l3_cdp_set_new_val parameter 'm' is changed to 'new_val'.
      (suggested by Jan Beulich)
    - directly use get_cdp_data(feat, 0) and get_cdp_code(feat, 0) to get
      default value.
      (suggested by Jan Beulich)
    - modify 'l3_cdp_write_msr' flow to write value into register according
      to input type.
    - changes about 'uint64_t' to 'uint32_t'.
      (suggested by Jan Beulich)
v8:
    - modify 'l3_cdp_write_msr' type to 'void'.
v5:
    - remove type check in callback function.
      (suggested by Jan Beulich)
    - modify return value of callback functions because we do not need them
      to return number of entries the feature uses. In caller, we call
      'get_cos_num' to get the number of entries the feature uses.
      (suggested by Jan Beulich)
    - remove 'l3_cdp_get_cos_max_from_type'.
    - rename 'l3_cdp_exceeds_cos_max' to 'l3_cdp_fits_cos_max'.
      (suggested by Jan Beulich)
v4:
    - create this patch to make codes easier to understand.
      (suggested by Jan Beulich)
---
 xen/arch/x86/psr.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

Comments

Jan Beulich March 27, 2017, 2:17 p.m. UTC | #1
>>> On 16.03.17 at 12:08, <yi.y.sun@linux.intel.com> wrote:
> +static bool l3_cdp_fits_cos_max(const uint32_t val[],
> +                                const struct feat_node *feat,
> +                                unsigned int cos)
> +{
> +    if ( cos > feat->info.cat_info.cos_max &&
> +         (val[0] != get_cdp_data(feat, 0) || val[1] != get_cdp_code(feat, 0)) )
> +            /*
> +             * Exceed cos_max and value to set is not default,
> +             * return error.
> +             */
> +            return false;

Indentation. But presumably this function will go away anyway.

Jan
Yi Sun March 28, 2017, 5:14 a.m. UTC | #2
On 17-03-27 08:17:04, Jan Beulich wrote:
> >>> On 16.03.17 at 12:08, <yi.y.sun@linux.intel.com> wrote:
> > +static bool l3_cdp_fits_cos_max(const uint32_t val[],
> > +                                const struct feat_node *feat,
> > +                                unsigned int cos)
> > +{
> > +    if ( cos > feat->info.cat_info.cos_max &&
> > +         (val[0] != get_cdp_data(feat, 0) || val[1] != get_cdp_code(feat, 0)) )
> > +            /*
> > +             * Exceed cos_max and value to set is not default,
> > +             * return error.
> > +             */
> > +            return false;
> 
> Indentation. But presumably this function will go away anyway.
> 
As explanation in previous patch, this CDP callback function is different
with CAT. So, I am afraid we have to keep it.

> Jan
diff mbox

Patch

diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c
index 0ce8a6b..7ede8a1 100644
--- a/xen/arch/x86/psr.c
+++ b/xen/arch/x86/psr.c
@@ -530,10 +530,101 @@  static void l3_cdp_get_val(const struct feat_node *feat, unsigned int cos,
         *val = get_cdp_code(feat, cos);
 }
 
+static void l3_cdp_get_old_val(uint32_t val[],
+                               const struct feat_node *feat,
+                               unsigned int old_cos)
+{
+    /* Data */
+    val[0] = get_cdp_data(feat, old_cos);
+    /* Code */
+    val[1] = get_cdp_code(feat, old_cos);
+}
+
+static int l3_cdp_set_new_val(uint32_t val[],
+                              const struct feat_node *feat,
+                              enum cbm_type type,
+                              uint32_t new_val)
+{
+    if ( !psr_check_cbm(feat->info.cat_info.cbm_len, new_val) )
+        return -EINVAL;
+
+    if ( type == PSR_CBM_TYPE_L3_DATA )
+        val[0] = new_val;
+    else
+        val[1] = new_val;
+
+    return 0;
+}
+
+static int l3_cdp_compare_val(const uint32_t val[],
+                              const struct feat_node *feat,
+                              unsigned int cos)
+{
+    /*
+     * Different features' cos_max are different. If cos id of the feature
+     * being set exceeds other feature's cos_max, the val of other feature
+     * must be default value. HW supports such case.
+    */
+    if ( cos > feat->info.cat_info.cos_max )
+    {
+        if ( val[0] != get_cdp_data(feat, 0) ||
+             val[1] != get_cdp_code(feat, 0) )
+            return -EINVAL;
+
+        /* Find */
+        return 1;
+    }
+
+    if ( val[0] == get_cdp_data(feat, cos) &&
+         val[1] == get_cdp_code(feat, cos) )
+        /* Find */
+        return 1;
+
+    /* Not find */
+    return 0;
+}
+
+static bool l3_cdp_fits_cos_max(const uint32_t val[],
+                                const struct feat_node *feat,
+                                unsigned int cos)
+{
+    if ( cos > feat->info.cat_info.cos_max &&
+         (val[0] != get_cdp_data(feat, 0) || val[1] != get_cdp_code(feat, 0)) )
+            /*
+             * Exceed cos_max and value to set is not default,
+             * return error.
+             */
+            return false;
+
+    return true;
+}
+
+static void l3_cdp_write_msr(unsigned int cos, uint32_t val,
+                             enum cbm_type type, struct feat_node *feat)
+{
+    /* Data */
+    if ( type == PSR_CBM_TYPE_L3_DATA && get_cdp_data(feat, cos) != val )
+    {
+        get_cdp_data(feat, cos) = val;
+        wrmsrl(MSR_IA32_PSR_L3_MASK_DATA(cos), (uint64_t)val);
+    }
+    /* Code */
+    if ( type == PSR_CBM_TYPE_L3_CODE && get_cdp_code(feat, cos) != val )
+    {
+        get_cdp_code(feat, cos) = val;
+        wrmsrl(MSR_IA32_PSR_L3_MASK_CODE(cos), (uint64_t)val);
+    }
+}
+
 struct feat_ops l3_cdp_ops = {
     .get_cos_max = cat_get_cos_max,
     .get_feat_info = l3_cdp_get_feat_info,
     .get_val = l3_cdp_get_val,
+    .get_old_val = l3_cdp_get_old_val,
+    .set_new_val = l3_cdp_set_new_val,
+    .compare_val = l3_cdp_compare_val,
+    .fits_cos_max = l3_cdp_fits_cos_max,
+    .write_msr = l3_cdp_write_msr,
 };
 
 static void __init parse_psr_bool(char *s, char *value, char *feature,