From patchwork Thu Jul 6 01:53:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9827455 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 A5D98602BD for ; Thu, 6 Jul 2017 02:09:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95520285C7 for ; Thu, 6 Jul 2017 02:09:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A227285C9; Thu, 6 Jul 2017 02:09:27 +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 19936285C7 for ; Thu, 6 Jul 2017 02:09:27 +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 1dSwCL-0000te-8n; Thu, 06 Jul 2017 02:07:17 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSwCK-0000sK-2f for xen-devel@lists.xenproject.org; Thu, 06 Jul 2017 02:07:16 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 49/C1-01735-35B9D595; Thu, 06 Jul 2017 02:07:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXS1tYhrxs0Ozb S4MAXA4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPh4W6mgic6FYde72FuYNwt38XIySEkUCkx cekcRhBbQoBX4siyGawQdoDE393NQHEuoJoGRone+avYQRJsAuoSj7/2MIHYIgJKEvdWTWYCK WIWmM8k8fr8A2aQhLBAvMTDZRfAbBYBVYkNa96CNfAKeErsar0GtU1O4uSxyWDbOIHiR642s0 Nc5CGxsf010wRG3gWMDKsYNYpTi8pSi3SNLPWSijLTM0pyEzNzdA0NTPVyU4uLE9NTcxKTivW S83M3MQIDop6BgXEH4+UtfocYJTmYlER5/+jHRgrxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4J07 CygnWJSanlqRlpkDDE2YtAQHj5II72phoDRvcUFibnFmOkTqFKMux6sJ/78xCbHk5eelSonz2 oPMEAApyijNgxsBi5NLjLJSwryMDAwMQjwFqUW5mSWo8q8YxTkYlYR5g0Gm8GTmlcBtegV0BB PQEYqNMSBHlCQipKQaGJlbnR21LylZaFrtSY0uVnjL2St7ljn8ywN7xU3stg8XXjP5lffkf87 F3nZ1uTp5QelVzwOOJk7WKzvssSVv8vRLBbPs+u/1qZ/yXZtiezVuo+KZvU1hiVNORJ/l3ZTw ++0BrtbdlVNdy3ZKGxgJWv5+8MqFLWj6y7MyHXVfmS67SUx4W6dYrsRSnJFoqMVcVJwIAGNLL OOOAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1499306830!62773795!3 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6227 invoked from network); 6 Jul 2017 02:07:14 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-14.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Jul 2017 02:07:14 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 05 Jul 2017 19:07:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,314,1496127600"; d="scan'208"; a="1191048062" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.80]) by fmsmga002.fm.intel.com with ESMTP; 05 Jul 2017 19:07:02 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 6 Jul 2017 09:53:04 +0800 Message-Id: <1499305996-19029-12-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1499305996-19029-1-git-send-email-yi.y.sun@linux.intel.com> References: <1499305996-19029-1-git-send-email-yi.y.sun@linux.intel.com> Cc: kevin.tian@intel.com, wei.liu2@citrix.com, andrew.cooper3@citrix.com, dario.faggioli@citrix.com, ian.jackson@eu.citrix.com, Yi Sun , mengxu@cis.upenn.edu, jbeulich@suse.com, chao.p.peng@linux.intel.com, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v13 11/23] x86: refactor psr: L3 CAT: 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 from previous patch: 'x86: refactor psr: L3 CAT: 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 Reviewed-by: Jan Beulich --- v13: - remove unnecessary blank line. (suggested by Jan Beulich) - remove unnecessary comment and fix comment wording. (suggested by Jan Beulich) v12: - use 'ASSERT_UNREACHABLE()' to record bug and return error code if feat exists but props does not exist. (suggested by Jan Beulich) - declare same type vairables in one line. (suggested by Jan Beulich) - use 'ARRAY_SIZE' to calculate array boundary. (suggested by Jan Beulich) v11: - remove unnecessary variable initialization. (suggested by Jan Beulich) - changes about 'feat_props'. (suggested by Jan Beulich) - replace 'get_val' calling to generic codes. (suggested by Jan Beulich) v10: - remove 'fits_cos_max' hook and CAT implementation. Move the process into generic flow. (suggested by Jan Beulich) - changes about 'props'. (suggested by Jan Beulich) - adjust codes positions. (suggested by Jan Beulich) v9: - modify return value of 'pick_avail_cos' to make it more accurate. - rename 'l3_cat_fits_cos_max' to 'cat_fits_cos_max' to cover L3/L2 CAT features. (suggested by Roger Pau) - replace feature list handling to feature array handling. (suggested by Roger Pau) - fix comment. (suggested by Wei Liu) - directly use 'cos_reg_val[0]' as default value. (suggested by Jan Beulich) - replace 'get_cos_num' to 'feat->cos_num'. (suggested by Jan Beulich) - modify patch title to indicate 'L3 CAT'. (suggested by Jan Beulich) - changes about 'uint64_t' to 'uint32_t'. (suggested by Jan Beulich) v5: - modify commit message to provide exact patch name to continue from. (suggested by Jan Beulich) - change 'exceeds_cos_max' to 'fits_cos_max' to be accurate. (suggested by Jan Beulich) - modify comments according to changes of codes. (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) - modify code format. (suggested by Jan Beulich) v4: - create this patch to make codes easier to understand. (suggested by Jan Beulich) --- xen/arch/x86/psr.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 306b02b..cbe08ce 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -859,12 +859,91 @@ static int find_cos(const uint32_t val[], unsigned int array_len, return -ENOENT; } +static bool fits_cos_max(const uint32_t val[], + uint32_t array_len, + const struct psr_socket_info *info, + unsigned int cos) +{ + unsigned int i; + + for ( i = 0; i < ARRAY_SIZE(info->features); i++ ) + { + const struct feat_node *feat = info->features[i]; + const struct feat_props *props = feat_props[i]; + + if ( !feat ) + continue; + + if ( !props ) + { + ASSERT_UNREACHABLE(); + return false; + } + + if ( array_len < props->cos_num ) + return false; + + if ( cos > feat->cos_max ) + { + unsigned int j; + + for ( j = 0; j < props->cos_num; j++ ) + { + /* Get default value, the COS ID of which is zero. */ + uint32_t default_val = feat->cos_reg_val[j]; + + if ( val[j] != default_val ) + return false; + } + } + + array_len -= props->cos_num; + val += props->cos_num; + } + + return true; +} + static int pick_avail_cos(const struct psr_socket_info *info, const uint32_t val[], unsigned int array_len, unsigned int old_cos, enum psr_feat_type feat_type) { - return -ENOENT; + unsigned int cos, 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. */ + feat = info->features[feat_type]; + if ( !feat ) + return -ENOENT; + + cos_max = feat->cos_max; + if ( !cos_max ) + return -ENOENT; + + /* 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) ) + break; + + return cos; + } + } + + return -EOVERFLOW; } static int write_psr_msrs(unsigned int socket, unsigned int cos,