From patchwork Thu Mar 16 11:08:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9627875 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 214266048C for ; Thu, 16 Mar 2017 11:16:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 191B028573 for ; Thu, 16 Mar 2017 11:16:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D582285B5; Thu, 16 Mar 2017 11:16:13 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 70ABF28573 for ; Thu, 16 Mar 2017 11:16:12 +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 1coTMA-0004Tg-Nt; Thu, 16 Mar 2017 11:14:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTM9-0004Sc-N8 for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:14:09 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 11/15-05091-1837AC85; Thu, 16 Mar 2017 11:14:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsVywNwkVreh+FS EwbIT0hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bu+zdZCv4ZVKy7O4O1gXGxUhcjFweLwC0m iadbFjOBOEIC0xgl3m3uYOxi5OSQEOCVOLJsBiuE7S/xasZuFoiiBkaJxbeusYAk2ATUJR5/7 WECsUUElCTurZoMNolZYCeTxLrT35lBEsICcRLnT11nA7FZBFQlfr9YwA5i8wp4SMx50skCsU FO4uSxyWDbOIHiH9vbwWwhAXeJdxv+sk9g5FvAyLCKUaM4tagstUjX0EQvqSgzPaMkNzEzR9f QwFgvN7W4ODE9NScxqVgvOT93EyMwWBiAYAfjiu2ehxglOZiURHnLf5yIEOJLyk+pzEgszogv Ks1JLT7EKMPBoSTBe0TpZISQYFFqempFWmYOMGxh0hIcPEoivLkgad7igsTc4sx0iNQpRkUpc d4LIAkBkERGaR5cGyxWLjHKSgnzMgIdIsRTkFqUm1mCKv+KUZyDUUmYdzPIFJ7MvBK46a+AFj MBLX774QTI4pJEhJRUA6PymsygtItKPB9Udha81jQ6av97j+wJrT0/9Fba2m12SzcIuyC1POF 735l3t+N2XXnjWDpdRD3ZNr+g9niyl9eNSwoPbjVs/ckm7X16V3F/YqmIwsmX8Q1G9+YJTvhw U1X+fNSWOK2oTL7bwnJCC1Lrf5w8zip36aso749yrxvFq+9ZbE8LDFJiKc5INNRiLipOBADuP 85ekAIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1489662818!78881615!11 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9271 invoked from network); 16 Mar 2017 11:14:07 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-2.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Mar 2017 11:14:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489662847; x=1521198847; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=dKPhxWQQ6PYzQewDueXWvOpg3wWBfrxFzzGDh3NmfNo=; b=nWBpVZnlgRhtePu5JQk/au1GarWQIQ2IZ2QH4DJapSOBW2Xz6G6TEOOP nK73oFbC57og/DzUkdOqtcMremmpIw==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2017 04:14:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,172,1486454400"; d="scan'208";a="944976546" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2017 04:14:04 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 16 Mar 2017 19:08:02 +0800 Message-Id: <1489662495-5375-13-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489662495-5375-1-git-send-email-yi.y.sun@linux.intel.com> References: <1489662495-5375-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 v9 12/25] 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 --- 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 | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index f2c2614..d4db407 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -136,6 +136,19 @@ struct feat_node { */ int (*compare_val)(const uint32_t val[], const struct feat_node *feat, unsigned int cos); + + /* + * 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 uint32_t val[], + const struct feat_node *feat, + unsigned int cos); } ops; /* Encapsulate feature specific HW info here. */ @@ -392,6 +405,21 @@ static int cat_compare_val(const uint32_t val[], return 0; } +static bool cat_fits_cos_max(const uint32_t val[], + const struct feat_node *feat, + unsigned int cos) +{ + if ( cos > feat->info.cat_info.cos_max && + val[0] != feat->cos_reg_val[0] ) + /* + * Exceed cos_max and value to set is not default, + * return error. + */ + return false; + + return true; +} + /* L3 CAT ops */ static const struct feat_ops l3_cat_ops = { .get_cos_max = cat_get_cos_max, @@ -400,6 +428,7 @@ static const struct feat_ops l3_cat_ops = { .get_old_val = cat_get_old_val, .set_new_val = cat_set_new_val, .compare_val = cat_compare_val, + .fits_cos_max = cat_fits_cos_max, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -851,13 +880,81 @@ static int find_cos(const uint32_t val[], uint32_t 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 ret, i; + const struct feat_node *feat; + + for ( i = 0; i < PSR_SOCKET_MAX_FEAT; i++ ) + { + if ( !info->features[i] ) + continue; + + feat = info->features[i]; + + ret = feat->ops.fits_cos_max(val, feat, cos); + if ( !ret ) + return false; + + array_len -= feat->cos_num; + if ( array_len < 0 ) + return false; + + val += feat->cos_num; + } + + return true; +} + static int pick_avail_cos(const struct psr_socket_info *info, const uint32_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; + ASSERT(spin_is_locked((spinlock_t *)(&info->ref_lock))); - return -ENOENT; + + /* cos_max is the one of the feature which is being set. */ + feat = info->features[feat_type]; + if ( !feat ) + return -ENOENT; + + cos_max = feat->ops.get_cos_max(feat); + 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 -EOVERFLOW; + + return cos; + } + } + + return -EOVERFLOW; } static int write_psr_msr(unsigned int socket, unsigned int cos,