From patchwork Wed Jun 14 01:12: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: 9785131 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 53A4160384 for ; Wed, 14 Jun 2017 01:27:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4592B26E75 for ; Wed, 14 Jun 2017 01:27:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A3EB28472; Wed, 14 Jun 2017 01:27:58 +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 B9A8C26E75 for ; Wed, 14 Jun 2017 01:27:57 +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 1dKx4B-0007b9-5o; Wed, 14 Jun 2017 01:25:51 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dKx4A-0007Zv-6O for xen-devel@lists.xenproject.org; Wed, 14 Jun 2017 01:25:50 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 72/0D-02183-D9090495; Wed, 14 Jun 2017 01:25:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNykWHfmBId Ig+OTTC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oz9dx6wFFzVqXi6uZW5gfGjXBcjF4eQwDRG iXVrvrB0MXJySAjwShxZNoMVwvaT2PX3FiOILSTQAFS0zwzEZhNQl3j8tYcJxBYRUJK4t2oyE 8ggZoGdTBLrTn9nBkkIC8RLLJt/CMxmEVCVuHDiI9ggXgFPibNf10Atk5M4eWwy2DJOoHj362 dMEMs8JH5emco0gZF3ASPDKkaN4tSistQiXSNDvaSizPSMktzEzBxdQwNTvdzU4uLE9NScxKR iveT83E2MwICoZ2Bg3MF4d7LfIUZJDiYlUd4ldg6RQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR4 3/QB5QSLUtNTK9Iyc4ChCZOW4OBREuGtbQNK8xYXJOYWZ6ZDpE4xKkqJ854C6RMASWSU5sG1w eLhEqOslDAvIwMDgxBPQWpRbmYJqvwrRnEORiVh3uP9QFN4MvNK4Ka/AlrMBLT4+hUbkMUliQ gpqQZGE5PWiRxzgmsOMf0Q7a1k6dQveZGcuKiXvfXN5W6OV6eWOK57Hnqic7KN9vta1uAWzZl Xfj985XD1aVJ7SEvxLNN+7+Vq86deu6KSvNl8d4fixg+dN1luMcTIuZXWlU8/YqO5xYTP/Zv+ fb/bYYWt79dZNTwLer55glPepwuGp5qusFoITS1WYinOSDTUYi4qTgQAjYD3g4ICAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1497403511!87398197!12 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49007 invoked from network); 14 Jun 2017 01:25:45 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-16.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Jun 2017 01:25:45 -0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jun 2017 18:25:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,340,1493708400"; d="scan'208";a="99173913" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.64]) by orsmga002.jf.intel.com with ESMTP; 13 Jun 2017 18:25:40 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 14 Jun 2017 09:12:44 +0800 Message-Id: <1497402776-22348-12-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497402776-22348-1-git-send-email-yi.y.sun@linux.intel.com> References: <1497402776-22348-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, 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, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v12 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 --- 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 | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 942ae63..5cbc389 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -845,12 +845,97 @@ 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 which cos id is 0. + * For CDP: + * - DATA default value stored in cos_reg_val[0]; + * - CODE default value stored in cos_reg_val[1]. + */ + 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,