From patchwork Thu Mar 16 11:08:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9627881 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 A68016048C for ; Thu, 16 Mar 2017 11:16:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EA3E28573 for ; Thu, 16 Mar 2017 11:16:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 934F1285A1; Thu, 16 Mar 2017 11:16:14 +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 084F128573 for ; Thu, 16 Mar 2017 11:16:14 +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 1coTM8-0004RW-Ew; Thu, 16 Mar 2017 11:14:08 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTM6-0004Pf-ST for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:14:06 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id CF/CE-20914-E737AC85; Thu, 16 Mar 2017 11:14:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVywNwkVre2+FS Ewbq7Shbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aty1UFm3Qr5v46zNrAuEi+i5GTg0XgFpPE vQP6XYxcHEIC0xglFvT+YwNJSAjwShxZNoMVwvaXaFjyGiwuJNDAKLHwQC6IzSagLvH4aw8Ti C0ioCRxb9VkJpBBzAI7mSTWnf7ODJIQFoiWOLVuDRvENlWJT+ufgQ3lFfCQ2NnwhQVigZzEyW OTweKcQPGP7e2sEMvcJd5t+Ms+gZFvASPDKkaN4tSistQiXUMTvaSizPSMktzEzBxdQwNjvdz U4uLE9NScxKRiveT83E2MwDBhAIIdjCu2ex5ilORgUhLlLf9xIkKILyk/pTIjsTgjvqg0J7X4 EKMMB4eSBO8RpZMRQoJFqempFWmZOcCAhUlLcPAoifDmgqR5iwsSc4sz0yFSpxgVpcR5L4AkB EASGaV5cG2wKLnEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYd7NIFN4MvNK4Ka/AlrMBLT47Y cTIItLEhFSUg2My961HOzbfPRBmJ+fyWvWNQmVRsxXPqYIaK5aXyUWuF/Fsv78t/vT1X9N9De Rzs4TK5T74no26IrD4hOeac9Eux66nH0nd+HQBkevmOLofq6jSU/NU8o4Z75tDG5erCwrtaPo /N21NokLQ6+WCElWcD96ZrK9IHP3xonfY3Z/zz/hcnztm83dSizFGYmGWsxFxYkAOBBXE40CA AA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1489662818!78881615!10 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 8863 invoked from network); 16 Mar 2017 11:14:05 -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:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489662845; x=1521198845; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=LuAPigSLta9tDzfM70jlwCkK8nsMVJ6hvg+ESbie6bE=; b=t29+4eYFd83z0PhaY5izrFG4schiseWfilXe0jwCDxJ/YbWkmUYTL2VO dHZnSrN5mYTUy8OG5F2eTNiH6ShyyQ==; 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:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,172,1486454400"; d="scan'208";a="944976518" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2017 04:14:01 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 16 Mar 2017 19:08:01 +0800 Message-Id: <1489662495-5375-12-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 11/25] x86: refactor psr: L3 CAT: set value: implement cos finding 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 patch: 'x86: refactor psr: L3 CAT: set value: assemble features value array' We can try to find if there is a COS ID on which all features' COS registers values are same as the array assembled before. Signed-off-by: Yi Sun --- v9: - modify comments of 'compare_val' to be same as current implementation. (suggested by Wei Liu) - fix indentation issue. (suggested by Wei Liu) - rename 'l3_cat_compare_val' to 'cat_compare_val' to cover all L3/L2 CAT features. (suggested by Roger Pau) - remove parameter 'found' from 'cat_compare_val' and modify the return values to let caller know if the id is found or not. (suggested by Roger Pau) - replace feature list handling to feature array handling. (suggested by Roger Pau) - replace 'get_cos_num' to 'feat->cos_num'. (suggested by Jan Beulich) - directly use 'cos_reg_val[0]' as default value. (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) - remove 'get_cos_max_from_type' because it can be replaced by 'get_cos_max'. - 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 comments according to changes of codes. (suggested by Jan Beulich) v4: - create this patch to make codes easier to understand. (suggested by Jan Beulich) --- xen/arch/x86/psr.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 18aad8e..f2c2614 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -123,6 +123,19 @@ struct feat_node { const struct feat_node *feat, enum cbm_type type, uint32_t new_val); + + /* + * compare_val is used in set value process to compare if the + * input value array can match all the features' COS registers values + * according to input cos id. + * + * The return value is: + * 1 - find the entry in value array. + * 0 - not find the entry in value array. + * negative - error. + */ + int (*compare_val)(const uint32_t val[], const struct feat_node *feat, + unsigned int cos); } ops; /* Encapsulate feature specific HW info here. */ @@ -352,6 +365,33 @@ static int cat_set_new_val(uint32_t val[], return 0; } +static int cat_compare_val(const uint32_t val[], + const struct feat_node *feat, + unsigned int cos) +{ + /* + * Different features' cos_max are different. If cos id of the feature + * being set exceeds other feature's cos_max, the val of other feature + * must be default value. HW supports such case. + */ + if ( cos > feat->info.cat_info.cos_max ) + { + /* cos_reg_val[0] is the default value. */ + if ( val[0] != feat->cos_reg_val[0] ) + return -EINVAL; + + /* Find */ + return 1; + } + + if ( val[0] == feat->cos_reg_val[cos] ) + /* Find */ + return 1; + + /* Not find */ + return 0; +} + /* L3 CAT ops */ static const struct feat_ops l3_cat_ops = { .get_cos_max = cat_get_cos_max, @@ -359,6 +399,7 @@ static const struct feat_ops l3_cat_ops = { .get_val = cat_get_val, .get_old_val = cat_get_old_val, .set_new_val = cat_set_new_val, + .compare_val = cat_compare_val, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -752,7 +793,61 @@ static int find_cos(const uint32_t val[], uint32_t array_len, enum psr_feat_type feat_type, const struct psr_socket_info *info) { + unsigned int cos, i; + const unsigned int *ref = info->cos_ref; + const struct feat_node *feat; + const uint32_t *val_array = val; + int find = 0; + unsigned int cos_max; + ASSERT(spin_is_locked((spinlock_t *)(&info->ref_lock))); + + /* 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); + + for ( cos = 0; cos <= cos_max; cos++ ) + { + if ( cos && !ref[cos] ) + continue; + + /* + * If fail to find cos in below loop, need find whole feature array + * again from beginning. + */ + val_array = val; + for ( i = 0; i < PSR_SOCKET_MAX_FEAT; i++ ) + { + if ( !info->features[i] ) + continue; + + feat = info->features[i]; + /* + * Compare value according to feature array order. + * We must follow this order because value array is assembled + * as this order. + */ + find = feat->ops.compare_val(val_array, feat, cos); + if ( find < 0 ) + return find; + + /* If fail to match, go to next cos to compare. */ + if ( !find ) + break; + + val_array += feat->cos_num; + if ( val_array - val > array_len ) + return -ENOSPC; + } + + /* For this COS ID all entries in the values array did match. Use it. */ + if ( find ) + return cos; + } + return -ENOENT; }