From patchwork Tue Aug 1 08:48:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9873905 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 1E3BC60365 for ; Tue, 1 Aug 2017 09:07:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24F8A2582C for ; Tue, 1 Aug 2017 09:07:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19D3728670; Tue, 1 Aug 2017 09:07:16 +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 9DAA52582C for ; Tue, 1 Aug 2017 09:07:15 +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 1dcT6X-0005CK-F0; Tue, 01 Aug 2017 09:04:41 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcT6W-0005Az-B5 for xen-devel@lists.xenproject.org; Tue, 01 Aug 2017 09:04:40 +0000 Received: from [85.158.139.211] by server-16.bemta-5.messagelabs.com id B9/8A-01712-72440895; Tue, 01 Aug 2017 09:04:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsXS1tYhoqvu0hB psPwWo8X3LZOZHBg9Dn+4whLAGMWamZeUX5HAmvF69Wb2gic6FSv+LWNvYNwt38XIxSEkMI1R Yv7GmYxdjJwcEgK8EkeWzWCFsP0lZt59ywZiCwk0MErc36cLYrMJqEs8/trDBGKLCChJ3Fs1m QlkELPAfCaJ1+cfMIMkhAXiJXrWgwzl4GARUJV4M5cLJMwr4CHx5ekiZoj5chInj00G28UJFN 9x8wYzSLmQgLvEzpmJExh5FzAyrGJUL04tKkst0jXVSyrKTM8oyU3MzNE1NDDVy00tLk5MT81 JTCrWS87P3cQIDAUGINjB+KXf+RCjJAeTkiivYk99pBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ XgnnhkghwaLU9NSKtMwcYFDCpCU4eJREeC84AaV5iwsSc4sz0yFSpxh1OV5N+P+NSYglLz8vV Uqc9yJIkQBIUUZpHtwIWIRcYpSVEuZlBDpKiKcgtSg3swRV/hWjOAejkjDvfZApPJl5JXCbXg EdwQR0hGRpLcgRJYkIKakGRo+V0/ZoK2xMnCx9IGDRE9c17XMXT/7ln//ZY7ssz/zfIt9umee JKsvcW2XeypjP1eDGyRofxJnLobuhRXX+n8BofiWe0MyWWZlfN0mGrzy55lrGLKcdPlPsH81Z vsv1/dGQsr3rNVqfZasvy2DaLnGwmLnPI5yX5QNv/8LofSlW+79PrzHdrsRSnJFoqMVcVJwIA Jk678OLAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1501578248!89431283!12 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51066 invoked from network); 1 Aug 2017 09:04:38 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-16.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Aug 2017 09:04:38 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Aug 2017 02:04:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,305,1498546800"; d="scan'208";a="118061599" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.80]) by orsmga002.jf.intel.com with ESMTP; 01 Aug 2017 02:04:35 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 1 Aug 2017 16:48:42 +0800 Message-Id: <1501577334-7431-12-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1501577334-7431-1-git-send-email-yi.y.sun@linux.intel.com> References: <1501577334-7431-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 v15 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 7bfeafb..b553112 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -860,12 +860,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,