diff mbox

[v9,13/25] x86: refactor psr: L3 CAT: set value: implement write msr flow.

Message ID 1489662495-5375-14-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
Continue from previous patch:
'x86: refactor psr: L3 CAT: set value: implement cos id picking flow.'

We have got the feature value and COS ID to set. Then, we write MSR of the
designated feature.

Till now, set value process is completed.

Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
v9:
    - replace feature list handling to feature array handling.
      (suggested by Roger Pau)
    - add 'array_len' in 'struct cos_write_info' and check if val array
      exceeds it.
    - modify 'write_psr_msr' flow only to set one value a time. No need to
      set whole feature array values.
    - modify patch title to indicate 'L3 CAT'.
      (suggested by Jan Beulich)
    - changes about 'uint64_t' to 'uint32_t'.
      (suggested by Jan Beulich)
v8:
    - modify 'write_msr' callback function to 'void' because we have to set
      all features' cbm. When input cos exceeds some features' cos_max, just
      skip them but not break the iteration.
v5:
    - modify commit message to provide exact patch name to continue from.
      (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)
    - move type check out from callback functions to caller.
      (suggested by Jan Beulich)
    - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'.
      (suggested by Jan Beulich)
    - correct code format.
      (suggested by Jan Beulich)
v4:
    - create this patch to make codes easier understand.
      (suggested by Jan Beulich)
---
 xen/arch/x86/psr.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 69 insertions(+), 1 deletion(-)

Comments

Jan Beulich March 27, 2017, 10:46 a.m. UTC | #1
>>> On 16.03.17 at 12:08, <yi.y.sun@linux.intel.com> wrote:
> @@ -421,6 +425,18 @@ static bool cat_fits_cos_max(const uint32_t val[],
>  }
>  
>  /* L3 CAT ops */
> +static void l3_cat_write_msr(unsigned int cos, uint32_t val,
> +                             enum cbm_type type, struct feat_node *feat)

"type" is an unused parameter. Please remove it from the hook
and this function.

> +{
> +    if ( feat->cos_reg_val[cos] != val )
> +    {
> +        feat->cos_reg_val[cos] = val;
> +        wrmsrl(MSR_IA32_PSR_L3_MASK(cos), (uint64_t)val);

I don't see the need for the cast.

> +    }
> +
> +    return;
> +}

Stray "return".

> +struct cos_write_info
> +{
> +    unsigned int cos;
> +    struct feat_node *feature;
> +    uint32_t val;
> +    enum cbm_type type;

With the "type" parameter removed above, this looks to be an
unused field then too. After the removal of it, please re-order
fields to leave no holes.

> +static void do_write_psr_msr(void *data)
> +{
> +    struct cos_write_info *info = (struct cos_write_info *)data;

Unnecessary cast again.

> +    unsigned int cos            = info->cos;
> +    struct feat_node *feat      = info->feature;
> +
> +    if ( !feat )
> +        return;

You shouldn't even call this function when !feat.

> +    if ( cos > feat->ops.get_cos_max(feat) )
> +        return;
> +
> +    feat->ops.write_msr(cos, info->val, info->type, feat);
> +}
> +
>  static int write_psr_msr(unsigned int socket, unsigned int cos,
>                           uint32_t val, enum cbm_type type,

"type", according to the above comments, should then go away
here too as it seems.

Jan
Yi Sun March 28, 2017, 5:06 a.m. UTC | #2
On 17-03-27 04:46:01, Jan Beulich wrote:
> >>> On 16.03.17 at 12:08, <yi.y.sun@linux.intel.com> wrote:
> > @@ -421,6 +425,18 @@ static bool cat_fits_cos_max(const uint32_t val[],
> >  }
> >  
> >  /* L3 CAT ops */
> > +static void l3_cat_write_msr(unsigned int cos, uint32_t val,
> > +                             enum cbm_type type, struct feat_node *feat)
> 
> "type" is an unused parameter. Please remove it from the hook
> and this function.
> 
This is used by CDP callback function. We need it to decide whether CODE
or DATA is written.

[...]
> > +struct cos_write_info
> > +{
> > +    unsigned int cos;
> > +    struct feat_node *feature;
> > +    uint32_t val;
> > +    enum cbm_type type;
> 
> With the "type" parameter removed above, this looks to be an
> unused field then too. After the removal of it, please re-order
> fields to leave no holes.
> 
Per above comment, 'type' is needed.

> > +static void do_write_psr_msr(void *data)
> > +{
> > +    struct cos_write_info *info = (struct cos_write_info *)data;
> 
> Unnecessary cast again.
> 
Thanks!

> > +    unsigned int cos            = info->cos;
> > +    struct feat_node *feat      = info->feature;
> > +
> > +    if ( !feat )
> > +        return;
> 
> You shouldn't even call this function when !feat.
> 
Ok, may I move the check to the 'write_psr_msr'?

> > +    if ( cos > feat->ops.get_cos_max(feat) )
> > +        return;
> > +
> > +    feat->ops.write_msr(cos, info->val, info->type, feat);
> > +}
> > +
> >  static int write_psr_msr(unsigned int socket, unsigned int cos,
> >                           uint32_t val, enum cbm_type type,
> 
> "type", according to the above comments, should then go away
> here too as it seems.
> 
Please check above comments.

> Jan
Jan Beulich March 28, 2017, 8:48 a.m. UTC | #3
>>> On 28.03.17 at 07:06, <yi.y.sun@linux.intel.com> wrote:
> On 17-03-27 04:46:01, Jan Beulich wrote:
>> >>> On 16.03.17 at 12:08, <yi.y.sun@linux.intel.com> wrote:
>> > @@ -421,6 +425,18 @@ static bool cat_fits_cos_max(const uint32_t val[],
>> >  }
>> >  
>> >  /* L3 CAT ops */
>> > +static void l3_cat_write_msr(unsigned int cos, uint32_t val,
>> > +                             enum cbm_type type, struct feat_node *feat)
>> 
>> "type" is an unused parameter. Please remove it from the hook
>> and this function.
>> 
> This is used by CDP callback function. We need it to decide whether CODE
> or DATA is written.

Strictly speaking you should then introduce it there - that'll also
allow better judgment as whether it's actually needed there, or
whether there are alternatives without.

>> > +    unsigned int cos            = info->cos;
>> > +    struct feat_node *feat      = info->feature;
>> > +
>> > +    if ( !feat )
>> > +        return;
>> 
>> You shouldn't even call this function when !feat.
>> 
> Ok, may I move the check to the 'write_psr_msr'?

Perhaps that's the right place, but it may also be that it would
better move even higher up. The question really is where it is
useful/needed.

Jan
Yi Sun March 28, 2017, 10:20 a.m. UTC | #4
On 17-03-28 02:48:53, Jan Beulich wrote:
> >>> On 28.03.17 at 07:06, <yi.y.sun@linux.intel.com> wrote:
> > On 17-03-27 04:46:01, Jan Beulich wrote:
> >> >>> On 16.03.17 at 12:08, <yi.y.sun@linux.intel.com> wrote:
> >> > @@ -421,6 +425,18 @@ static bool cat_fits_cos_max(const uint32_t val[],
> >> >  }
> >> >  
> >> >  /* L3 CAT ops */
> >> > +static void l3_cat_write_msr(unsigned int cos, uint32_t val,
> >> > +                             enum cbm_type type, struct feat_node *feat)
> >> 
> >> "type" is an unused parameter. Please remove it from the hook
> >> and this function.
> >> 
> > This is used by CDP callback function. We need it to decide whether CODE
> > or DATA is written.
> 
> Strictly speaking you should then introduce it there - that'll also
> allow better judgment as whether it's actually needed there, or
> whether there are alternatives without.
> 
Ok, I will introduce 'type' in CDP implementation.

> >> > +    unsigned int cos            = info->cos;
> >> > +    struct feat_node *feat      = info->feature;
> >> > +
> >> > +    if ( !feat )
> >> > +        return;
> >> 
> >> You shouldn't even call this function when !feat.
> >> 
> > Ok, may I move the check to the 'write_psr_msr'?
> 
> Perhaps that's the right place, but it may also be that it would
> better move even higher up. The question really is where it is
> useful/needed.
> 
Will consider the place to check it.
diff mbox

Patch

diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c
index d4db407..2bc7f3c 100644
--- a/xen/arch/x86/psr.c
+++ b/xen/arch/x86/psr.c
@@ -149,6 +149,10 @@  struct feat_node {
         bool (*fits_cos_max)(const uint32_t val[],
                              const struct feat_node *feat,
                              unsigned int cos);
+
+        /* write_msr is used to write out feature MSR register. */
+        void (*write_msr)(unsigned int cos, uint32_t val,
+                          enum cbm_type type, struct feat_node *feat);
     } ops;
 
     /* Encapsulate feature specific HW info here. */
@@ -421,6 +425,18 @@  static bool cat_fits_cos_max(const uint32_t val[],
 }
 
 /* L3 CAT ops */
+static void l3_cat_write_msr(unsigned int cos, uint32_t val,
+                             enum cbm_type type, struct feat_node *feat)
+{
+    if ( feat->cos_reg_val[cos] != val )
+    {
+        feat->cos_reg_val[cos] = val;
+        wrmsrl(MSR_IA32_PSR_L3_MASK(cos), (uint64_t)val);
+    }
+
+    return;
+}
+
 static const struct feat_ops l3_cat_ops = {
     .get_cos_max = cat_get_cos_max,
     .get_feat_info = cat_get_feat_info,
@@ -429,6 +445,7 @@  static const struct feat_ops l3_cat_ops = {
     .set_new_val = cat_set_new_val,
     .compare_val = cat_compare_val,
     .fits_cos_max = cat_fits_cos_max,
+    .write_msr = l3_cat_write_msr,
 };
 
 static void __init parse_psr_bool(char *s, char *value, char *feature,
@@ -957,11 +974,62 @@  static int pick_avail_cos(const struct psr_socket_info *info,
     return -EOVERFLOW;
 }
 
+static unsigned int get_socket_cpu(unsigned int socket)
+{
+    if ( likely(socket < nr_sockets) )
+        return cpumask_any(socket_cpumask[socket]);
+
+    return nr_cpu_ids;
+}
+
+struct cos_write_info
+{
+    unsigned int cos;
+    struct feat_node *feature;
+    uint32_t val;
+    enum cbm_type type;
+};
+
+static void do_write_psr_msr(void *data)
+{
+    struct cos_write_info *info = (struct cos_write_info *)data;
+    unsigned int cos            = info->cos;
+    struct feat_node *feat      = info->feature;
+
+    if ( !feat )
+        return;
+
+    if ( cos > feat->ops.get_cos_max(feat) )
+        return;
+
+    feat->ops.write_msr(cos, info->val, info->type, feat);
+}
+
 static int write_psr_msr(unsigned int socket, unsigned int cos,
                          uint32_t val, enum cbm_type type,
                          enum psr_feat_type feat_type)
 {
-    return -ENOENT;
+    struct psr_socket_info *info = get_socket_info(socket);
+    struct cos_write_info data =
+    {
+        .cos = cos,
+        .feature = info->features[feat_type],
+        .val = val,
+        .type = type,
+    };
+
+    if ( socket == cpu_to_socket(smp_processor_id()) )
+        do_write_psr_msr(&data);
+    else
+    {
+        unsigned int cpu = get_socket_cpu(socket);
+
+        if ( cpu >= nr_cpu_ids )
+            return -ENOTSOCK;
+        on_selected_cpus(cpumask_of(cpu), do_write_psr_msr, &data, 1);
+    }
+
+    return 0;
 }
 
 int psr_set_val(struct domain *d, unsigned int socket,