From patchwork Sat Apr 1 13:53:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9657953 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 57B3960349 for ; Sat, 1 Apr 2017 13:56:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E4D2285C2 for ; Sat, 1 Apr 2017 13:56:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42F4F28610; Sat, 1 Apr 2017 13:56: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 D503F28613 for ; Sat, 1 Apr 2017 13:56:13 +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 1cuJTo-0005qi-P5; Sat, 01 Apr 2017 13:54:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuJTm-0005oy-OA for xen-devel@lists.xenproject.org; Sat, 01 Apr 2017 13:54:10 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 24/D0-23854-201BFD85; Sat, 01 Apr 2017 13:54:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsXS1tYhosuw8X6 EwZUec4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNePJpclsBfNVK65u+cbcwLhGqouRi4NF4BaT ROvF5awgjpDANEaJZQ1/gRxODgkBXokjy2ZA2f4Se06+Y+xi5AAqqpc4sU0UJMwmoC7x+GsPE 4gtIqAkcW/VZCaQOcwCO5kk1p3+zgxSLywQL/FruQ5IDYuAqsTtW1PZQcK8Ap4Sb5bKQUyXkz h5bDLYJk6g8JUX+1hAbCEBD4lVky4xT2DkW8DIsIpRozi1qCy1SNfQQi+pKDM9oyQ3MTNH19D AWC83tbg4MT01JzGpWC85P3cTIzBI6hkYGHcw/j7teYhRkoNJSZT3e/G9CCG+pPyUyozE4oz4 otKc1OJDjDIcHEoSvAob7kcICRalpqdWpGXmAMMVJi3BwaMkwntsPVCat7ggMbc4Mx0idYpRU Uqc9xlIQgAkkVGaB9cGi5FLjLJSwryMDAwMQjwFqUW5mSWo8q8YxTkYlYR55UGm8GTmlcBNfw W0mAloscXXuyCLSxIRUlINjN4trhzGT+deltnjd/HpL4mSl0f1zz478fV0jHftNJcYVzHf+GT N1TX3b6vx/Fu08kWaefL32fqr1HPuKC8wcX102/72x1gO/5fMl8/qpbxnX+T44tmhddum/3t4 w6frb8/fngXRa28Gawf9/nckfPNiDUVLt/fyKsxW/A5nS6V8T9lOjH/wPV2JpTgj0VCLuag4E QAchiITjAIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1491054811!37933881!13 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.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52747 invoked from network); 1 Apr 2017 13:54:08 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-9.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Apr 2017 13:54:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491054848; x=1522590848; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Q5unaH2yfahgpEarHzkevxm0kAecfS/TQFpJNHGh2MU=; b=i+QULfbSmP7UTR2fdSVvlNxKts6tIcC5kk+VNw1tnwJFqpRygAbs/LbW 6ksMr1IucAn89IneaTQpaqr3B5ESgw==; Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Apr 2017 06:54:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,258,1486454400"; d="scan'208";a="950544879" Received: from yisun1-ubuntu.bj.intel.com ([10.238.156.112]) by orsmga003.jf.intel.com with ESMTP; 01 Apr 2017 06:54:05 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Sat, 1 Apr 2017 21:53:43 +0800 Message-Id: <1491054836-30488-13-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491054836-30488-1-git-send-email-yi.y.sun@linux.intel.com> References: <1491054836-30488-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 v10 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 --- 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 | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index a6c6f18..44c9313 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -800,15 +800,82 @@ 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 < PSR_SOCKET_MAX_FEAT; i++ ) + { + uint32_t default_val = 0; + const struct feat_node *feat = info->features[i]; + if ( !feat ) + continue; + + if ( array_len < feat->props->cos_num ) + return false; + + if ( cos > feat->props->cos_max ) + { + feat->props->get_val(feat, 0, &default_val); + if ( val[0] != default_val ) + return false; + } + + array_len -= feat->props->cos_num; + + val += feat->props->cos_num; + } + + return true; +} + static int pick_avail_cos(const struct psr_socket_info *info, spinlock_t *ref_lock, const uint32_t val[], unsigned int 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(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->props->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_msr(unsigned int socket, unsigned int cos,