Message ID | 1481688484-5093-6-git-send-email-yi.y.sun@linux.intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
>>> On 14.12.16 at 05:07, <yi.y.sun@linux.intel.com> wrote: > @@ -358,11 +366,32 @@ void psr_free_rmid(struct domain *d) > d->arch.psr_rmid = 0; > } > > +static inline unsigned int get_max_cos_max(const struct psr_socket_info *info) > +{ > + const struct feat_node *feat_tmp; Same remark as on the earlier patch regarding the _tmp suffix. Should this reoccur in later patches, I won't give the same comment again. > + unsigned int cos_max = 0; > + > + list_for_each_entry(feat_tmp, &info->feat_list, list) > + cos_max = max(feat_tmp->ops.get_max_cos_max(feat_tmp), cos_max); > + > + return cos_max; > +} > + > static inline void psr_assoc_init(void) > { > struct psr_assoc *psra = &this_cpu(psr_assoc); > > - if ( psr_cmt_enabled() ) > + if ( socket_info ) > + { > + unsigned int socket = cpu_to_socket(smp_processor_id()); > + const struct psr_socket_info *info = socket_info + socket; > + unsigned int cos_max = get_max_cos_max(info); > + > + if ( info->feat_mask ) > + psra->cos_mask = ((1ull << get_count_order(cos_max)) - 1) << 32; > + } > + > + if ( psr_cmt_enabled() || psra->cos_mask ) > rdmsrl(MSR_IA32_PSR_ASSOC, psra->val); > } > > @@ -371,6 +400,12 @@ static inline void psr_assoc_rmid(uint64_t *reg, unsigned int rmid) > *reg = (*reg & ~rmid_mask) | (rmid & rmid_mask); > } > > +static inline void psr_assoc_cos(uint64_t *reg, unsigned int cos, > + uint64_t cos_mask) > +{ > + *reg = (*reg & ~cos_mask) | (((uint64_t)cos << 32) & cos_mask); This recurring 32 would perhaps better become a #define, so they can be identified as the same entity (at least I think they are). Jan
On 17-01-10 06:34:50, Jan Beulich wrote: > >>> On 14.12.16 at 05:07, <yi.y.sun@linux.intel.com> wrote: > > @@ -358,11 +366,32 @@ void psr_free_rmid(struct domain *d) > > d->arch.psr_rmid = 0; > > } > > > > +static inline unsigned int get_max_cos_max(const struct psr_socket_info *info) > > +{ > > + const struct feat_node *feat_tmp; > > Same remark as on the earlier patch regarding the _tmp suffix. > Should this reoccur in later patches, I won't give the same > comment again. > Thank you! I will take care all of them. > > + unsigned int cos_max = 0; > > + > > + list_for_each_entry(feat_tmp, &info->feat_list, list) > > + cos_max = max(feat_tmp->ops.get_max_cos_max(feat_tmp), cos_max); > > + > > + return cos_max; > > +} > > + > > static inline void psr_assoc_init(void) > > { > > struct psr_assoc *psra = &this_cpu(psr_assoc); > > > > - if ( psr_cmt_enabled() ) > > + if ( socket_info ) > > + { > > + unsigned int socket = cpu_to_socket(smp_processor_id()); > > + const struct psr_socket_info *info = socket_info + socket; > > + unsigned int cos_max = get_max_cos_max(info); > > + > > + if ( info->feat_mask ) > > + psra->cos_mask = ((1ull << get_count_order(cos_max)) - 1) << 32; > > + } > > + > > + if ( psr_cmt_enabled() || psra->cos_mask ) > > rdmsrl(MSR_IA32_PSR_ASSOC, psra->val); > > } > > > > @@ -371,6 +400,12 @@ static inline void psr_assoc_rmid(uint64_t *reg, unsigned int rmid) > > *reg = (*reg & ~rmid_mask) | (rmid & rmid_mask); > > } > > > > +static inline void psr_assoc_cos(uint64_t *reg, unsigned int cos, > > + uint64_t cos_mask) > > +{ > > + *reg = (*reg & ~cos_mask) | (((uint64_t)cos << 32) & cos_mask); > > This recurring 32 would perhaps better become a #define, so they > can be identified as the same entity (at least I think they are). > Good suggestion, thanks! > Jan
diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index fa9bc32..746c90e 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -113,6 +113,8 @@ struct feat_ops { unsigned int ecx, unsigned int edx, struct feat_node *feat, struct psr_socket_info *info); + /* get_max_cos_max is used to get feature's cos_max. */ + unsigned int (*get_max_cos_max)(const struct feat_node *feat); }; @@ -213,8 +215,14 @@ static void l3_cat_init_feature(unsigned int eax, unsigned int ebx, feat->info.l3_cat_info.cbm_len); } +static unsigned int l3_cat_get_max_cos_max(const struct feat_node *feat) +{ + return feat->info.l3_cat_info.cos_max; +} + struct feat_ops l3_cat_ops = { .init_feature = l3_cat_init_feature, + .get_max_cos_max = l3_cat_get_max_cos_max, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -358,11 +366,32 @@ void psr_free_rmid(struct domain *d) d->arch.psr_rmid = 0; } +static inline unsigned int get_max_cos_max(const struct psr_socket_info *info) +{ + const struct feat_node *feat_tmp; + unsigned int cos_max = 0; + + list_for_each_entry(feat_tmp, &info->feat_list, list) + cos_max = max(feat_tmp->ops.get_max_cos_max(feat_tmp), cos_max); + + return cos_max; +} + static inline void psr_assoc_init(void) { struct psr_assoc *psra = &this_cpu(psr_assoc); - if ( psr_cmt_enabled() ) + if ( socket_info ) + { + unsigned int socket = cpu_to_socket(smp_processor_id()); + const struct psr_socket_info *info = socket_info + socket; + unsigned int cos_max = get_max_cos_max(info); + + if ( info->feat_mask ) + psra->cos_mask = ((1ull << get_count_order(cos_max)) - 1) << 32; + } + + if ( psr_cmt_enabled() || psra->cos_mask ) rdmsrl(MSR_IA32_PSR_ASSOC, psra->val); } @@ -371,6 +400,12 @@ static inline void psr_assoc_rmid(uint64_t *reg, unsigned int rmid) *reg = (*reg & ~rmid_mask) | (rmid & rmid_mask); } +static inline void psr_assoc_cos(uint64_t *reg, unsigned int cos, + uint64_t cos_mask) +{ + *reg = (*reg & ~cos_mask) | (((uint64_t)cos << 32) & cos_mask); +} + void psr_ctxt_switch_to(struct domain *d) { struct psr_assoc *psra = &this_cpu(psr_assoc); @@ -379,6 +414,11 @@ void psr_ctxt_switch_to(struct domain *d) if ( psr_cmt_enabled() ) psr_assoc_rmid(®, d->arch.psr_rmid); + if ( psra->cos_mask ) + psr_assoc_cos(®, d->arch.psr_cos_ids ? + d->arch.psr_cos_ids[cpu_to_socket(smp_processor_id())] : + 0, psra->cos_mask); + if ( reg != psra->val ) { wrmsrl(MSR_IA32_PSR_ASSOC, reg); @@ -404,14 +444,32 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, return 0; } +/* Called with domain lock held, no extra lock needed for 'psr_cos_ids' */ +static void psr_free_cos(struct domain *d) +{ + if( !d->arch.psr_cos_ids ) + return; + + xfree(d->arch.psr_cos_ids); + d->arch.psr_cos_ids = NULL; +} + int psr_domain_init(struct domain *d) { + if ( socket_info ) + { + d->arch.psr_cos_ids = xzalloc_array(unsigned int, nr_sockets); + if ( !d->arch.psr_cos_ids ) + return -ENOMEM; + } + return 0; } void psr_domain_free(struct domain *d) { psr_free_rmid(d); + psr_free_cos(d); } static int cpu_prepare_work(unsigned int cpu)
This patch implements the Domain init/free and schedule flows. Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com> --- xen/arch/x86/psr.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-)