[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v9 17/25] x86: refactor psr: CDP: implement set value callback functions.
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@xxxxxxxxxxxxxxx> --- 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(+) 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, -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |