From patchwork Sat Jul 15 00:31:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9841845 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 A53E660212 for ; Sat, 15 Jul 2017 00:48:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95C47287AE for ; Sat, 15 Jul 2017 00:48:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A937287B3; Sat, 15 Jul 2017 00:48:44 +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 1DE9C28798 for ; Sat, 15 Jul 2017 00:48:44 +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 1dWBE0-0007Cu-Kc; Sat, 15 Jul 2017 00:46:24 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dWBDz-0007CD-DW for xen-devel@lists.xenproject.org; Sat, 15 Jul 2017 00:46:23 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id A4/03-02181-ED569695; Sat, 15 Jul 2017 00:46:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsVywNxEW/duama kwdQ5Fhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0bDywNsBU90Kl53vGFsYNwt38XIySEkUCHx dd80ZhBbQoBX4siyGawQtr/EnKadQHEuoJoGRonF7f0sIAk2AXWJx197mEBsEQEliXurJjOBF DELzGeSeH3+AVAHB4ewQLxEX1M5iMkioCrx8bo+SDmvgIdE79y7ULvkJE4emwy2ixMoPnVfGz tIuZCAu0TL7PIJjLwLGBlWMWoUpxaVpRbpGhvoJRVlpmeU5CZm5ugaGhjr5aYWFyemp+YkJhX rJefnbmIEhkI9AwPjDsbOE36HGCU5mJREed/dzogU4kvKT6nMSCzOiC8qzUktPsQow8GhJME7 NSUzUkiwKDU9tSItMwcYlDBpCQ4eJRHeWSBp3uKCxNzizHSI1ClGXY5XE/5/YxJiycvPS5US5 9UEKRIAKcoozYMbAYuQS4yyUsK8jAwMDEI8BalFuZklqPKvGMU5GJWEeeeDTOHJzCuB2/QK6A gmoCPasjJAjihJREhJNTAan1A5o+SWMOnSm/XTdGSenC382Oh5es3FezMLG5ZbX0nc5/pms0D q2lUeMeevhypHTIllfpQTvkRzVm5Y25zfDEUzXi2fwXelbKHsS4FgNvX/Z/cunHrprpeSb0jG ara/HN2O/J2rP7T/cmox/Xq68pncciFt4f5Z3B4J9jzFGw2092otu6KsxFKckWioxVxUnAgAL ElOeIsCAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1500079549!66978060!12 X-Originating-IP: [192.55.52.43] 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 35697 invoked from network); 15 Jul 2017 00:46:21 -0000 Received: from mga05.intel.com (HELO mga05.intel.com) (192.55.52.43) by server-6.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Jul 2017 00:46:21 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP; 14 Jul 2017 17:46:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,360,1496127600"; d="scan'208";a="111534874" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.80]) by orsmga002.jf.intel.com with ESMTP; 14 Jul 2017 17:46:18 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Sat, 15 Jul 2017 08:31:44 +0800 Message-Id: <1500078716-5928-12-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500078716-5928-1-git-send-email-yi.y.sun@linux.intel.com> References: <1500078716-5928-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 v14 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 ab070c2..e698872 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,