From patchwork Thu Jan 19 06:01:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9525229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D9A6E60437 for ; Thu, 19 Jan 2017 06:05:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C66ED2860C for ; Thu, 19 Jan 2017 06:05:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB0FE2862A; Thu, 19 Jan 2017 06:05:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E5422860C for ; Thu, 19 Jan 2017 06:05:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU5oV-0006yT-AE; Thu, 19 Jan 2017 06:03:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU5oT-0006xE-PK for xen-devel@lists.xenproject.org; Thu, 19 Jan 2017 06:03:09 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id C4/53-16730-D9650885; Thu, 19 Jan 2017 06:03:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsVywNykWHdOWEO EwexX0hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8a7nifMBXM1Ks6tFmlgnCjTxcjFISQwnVGi fc105i5GTg4JAV6JI8tmsHYxcgDZ/hIHr+WDhIUEGhglPr9yA7HZBNQlHn/tYQKxRQSUJO6tm swEModZoJtJYuXDrSwgCWGBWImp63rBbBYBVYlfy/+A2bwCHhJHTz5gg9glJ3Hy2GRWEJsTKH 5l/gV2iGXuEltWXGKawMi7gJFhFaNGcWpRWWqRrqG5XlJRZnpGSW5iZo6uoYGxXm5qcXFiemp OYlKxXnJ+7iZGYDAwAMEOxpenPQ8xSnIwKYny2ls2RAjxJeWnVGYkFmfEF5XmpBYfYpTh4FCS 4FUNBcoJFqWmp1akZeYAwxImLcHBoyTCywyS5i0uSMwtzkyHSJ1iVJQS530cApQQAElklObBt cFi4RKjrJQwLyPQIUI8BalFuZklqPKvGMU5GJWEeUVBxvNk5pXATX8FtJgJaLGVcj3I4pJEhJ RUA6OYcfNHNtvt87TSFJW3H9XLYrryvtZ0ywtWljsNK4Nn7GLaKnYufgHLY78rh/rDbvXV2S3 k7irckOGadElfr7vePfVbXu+U4FMzD+kzXi6Tr111SGv2x6hJWnkx/cpt178ufNI2M9NG/qTl 5e2XpivUO3yxu6a16JzBRHOVmQo8Xrz88eXzu5VYijMSDbWYi4oTARMY+eCAAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1484805772!81354767!8 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34048 invoked from network); 19 Jan 2017 06:03:07 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-8.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Jan 2017 06:03:07 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2017 22:03:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,252,1477983600"; d="scan'208";a="215119521" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 18 Jan 2017 22:03:05 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 19 Jan 2017 14:01:13 +0800 Message-Id: <1484805686-7249-12-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484805686-7249-1-git-send-email-yi.y.sun@linux.intel.com> References: <1484805686-7249-1-git-send-email-yi.y.sun@linux.intel.com> Cc: wei.liu2@citrix.com, konrad.wilk@oracle.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, he.chen@linux.intel.com, ian.jackson@eu.citrix.com, Yi Sun , mengxu@cis.upenn.edu, jbeulich@suse.com, chao.p.peng@linux.intel.com Subject: [Xen-devel] [PATCH RESEND v5 11/24] x86: refactor psr: set value: implement cos id picking flow. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Continue with previous patch: 'x86: refactor psr: set value: implement cos finding flow.' If fail to find a COS ID, we need pick a new COS ID for domain. Only COS ID that ref[COS_ID] is 1 or 0 can be picked to input a new set feature values. Signed-off-by: Yi Sun --- v5: - modify commit message to provide exact patch name to continue from. - change 'exceeds_cos_max' to 'fits_cos_max' to be accurate. - modify comments according to changes of codes. - 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. - move type check out from callback functions to caller. - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'. --- xen/arch/x86/psr.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 8832e08..c3e25bf 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -154,6 +154,17 @@ struct feat_ops { */ int (*compare_val)(const uint64_t val[], const struct feat_node *feat, unsigned int cos, bool *found); + /* + * fits_cos_max is used to check if the input cos id exceeds the + * feature's cos_max and if the input value is not the default one. + * Even if the associated cos exceeds the cos_max, HW can work with default + * value. That is the reason we need check if input value is default one. + * If both criteria are fulfilled, that means the input exceeds the range. + * If not, that means the input fits the requirements. + */ + bool (*fits_cos_max)(const uint64_t val[], + const struct feat_node *feat, + unsigned int cos); }; /* @@ -388,6 +399,25 @@ static int l3_cat_compare_val(const uint64_t val[], return 0; } +static bool l3_cat_fits_cos_max(const uint64_t val[], + const struct feat_node *feat, + unsigned int cos) +{ + uint64_t l3_def_cbm; + + l3_def_cbm = (1ull << feat->info.l3_cat_info.cbm_len) - 1; + + if ( cos > feat->info.l3_cat_info.cos_max && + val[0] != l3_def_cbm ) + /* + * Exceed cos_max and value to set is not default, + * return error. + */ + return false; + + return true; +} + static const struct feat_ops l3_cat_ops = { .get_cos_max = l3_cat_get_cos_max, .get_feat_info = l3_cat_get_feat_info, @@ -396,6 +426,7 @@ static const struct feat_ops l3_cat_ops = { .get_old_val = l3_cat_get_old_val, .set_new_val = l3_cat_set_new_val, .compare_val = l3_cat_compare_val, + .fits_cos_max = l3_cat_fits_cos_max, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -802,11 +833,79 @@ static int find_cos(const uint64_t *val, uint32_t array_len, return -ENOENT; } +static bool fits_cos_max(const uint64_t *val, + uint32_t array_len, + const struct psr_socket_info *info, + unsigned int cos) +{ + unsigned int ret; + const uint64_t *val_tmp = val; + const struct feat_node *feat; + + list_for_each_entry(feat, &info->feat_list, list) + { + ret = feat->ops.fits_cos_max(val_tmp, feat, cos); + if ( !ret ) + return false; + + val_tmp += feat->ops.get_cos_num(feat); + if ( val_tmp - val > array_len ) + return false; + } + + return true; +} + static int pick_avail_cos(const struct psr_socket_info *info, const uint64_t *val, uint32_t array_len, unsigned int old_cos, enum psr_feat_type feat_type) { + unsigned int cos; + unsigned int cos_max = 0; + const struct feat_node *feat; + const unsigned int *ref = info->cos_ref; + + /* + * cos_max is the one of the feature which is being set. + */ + list_for_each_entry(feat, &info->feat_list, list) + { + if ( feat->feature != feat_type ) + continue; + + cos_max = feat->ops.get_cos_max(feat); + if ( cos_max > 0 ) + break; + } + + if ( !cos_max ) + return -ENOENT; + + /* + * If old cos is referred only by the domain, then use it. And, we cannot + * use id 0 because it stores the default values. + */ + if ( old_cos && ref[old_cos] == 1 && + fits_cos_max(val, array_len, info, old_cos) ) + return old_cos; + + /* Find an unused one other than cos0. */ + for ( cos = 1; cos <= cos_max; cos++ ) + { + /* + * ref is 0 means this COS is not used by other domain and + * can be used for current setting. + */ + if ( !ref[cos] ) + { + if ( !fits_cos_max(val, array_len, info, cos) ) + return -ENOENT; + + return cos; + } + } + return -ENOENT; }