From patchwork Sat Apr 1 13:53:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9657959 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 F22E360349 for ; Sat, 1 Apr 2017 13:56:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E952A285C2 for ; Sat, 1 Apr 2017 13:56:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE2A428613; Sat, 1 Apr 2017 13:56:19 +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 503EE285C2 for ; Sat, 1 Apr 2017 13:56:19 +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 1cuJTk-0005nJ-H0; Sat, 01 Apr 2017 13:54: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 1cuJTj-0005mL-9L for xen-devel@lists.xenproject.org; Sat, 01 Apr 2017 13:54:07 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 9A/DD-14551-EF0BFD85; Sat, 01 Apr 2017 13:54:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsXS1tYhovtvw/0 Ig3tvuSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ow3U+8zFjSqV0y+s5mlgXGlVBcjFweLwC0m iYNzTjCBOEIC0xglJu1cwtrFyMkhIcArcWTZDCjbX2LrwqmMILaQQL3EnkVTweJsAuoSj7/2M IHYIgJKEvdWTQYbxCywk0li3envzCAJYYEYiQm/PoLZLAKqEvcn3wVr5hXwlJh7+R8LxAI5iZ PHJoPFOYHiV17sY4FY5iGxatIl5gmMfAsYGVYxahSnFpWlFukaWuglFWWmZ5TkJmbm6BoaGOv lphYXJ6an5iQmFesl5+duYgSGSj0DA+MOxt+nPQ8xSnIwKYnyfi++FyHEl5SfUpmRWJwRX1Sa k1p8iFGGg0NJglcBGHpCgkWp6akVaZk5wKCFSUtw8CiJ8B5bD5TmLS5IzC3OTIdInWJUlBLnf QaSEABJZJTmwbXBIuUSo6yUMC8jAwODEE9BalFuZgmq/CtGcQ5GJWFeeZApPJl5JXDTXwEtZg JabPH1LsjikkSElFQDo0VkrxlHxWp7taMJk9KFFv94KqXXuMr6fLba4qxT7fuXyq3pSU7Jzg9 tdnJ+4zGRuVc+5AXPPhuJdQfV49o2rfu2Yavwq6ea/LPeHr89I6BcbN48xcVcBgFHn2t8jvLk eyFwrGnDsSM1zAo/1O48P6rzfcO8DwtTRMOuf9HYsZFpkpxA8QqtBUosxRmJhlrMRcWJABXGB rGPAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1491054811!37933881!12 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 52493 invoked from network); 1 Apr 2017 13:54:05 -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:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491054845; x=1522590845; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=rtUme5EEkAXs0MnGKCAvn1Rvj3AYQbzrWZNPf4ani1U=; b=i8AnDN51zTC/o1a649miL+aKNfnZ6/4MMDSMtZYnyebDzHbmwYT5BQSu L/jAnVpA2n5SwzVw2OI8g7Jl5W6NLQ==; 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:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,258,1486454400"; d="scan'208";a="950544837" Received: from yisun1-ubuntu.bj.intel.com ([10.238.156.112]) by orsmga003.jf.intel.com with ESMTP; 01 Apr 2017 06:54:01 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Sat, 1 Apr 2017 21:53:42 +0800 Message-Id: <1491054836-30488-12-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 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 --- v10: - remove 'compare_val' hook and its CAT implementation. Make its functionality be generic in 'find_cos' flow. (suggested by Jan Beulich) - changes related to 'props'. (suggested by Jan Beulich) - rename 'val_array' to 'val_ptr'. (suggested by Jan Beulich) - rename 'find' to 'found'. (suggested by Jan Beulich) - move some variables declaration and initialization into loop. (suggested by Jan Beulich) - adjust codes positions. (suggested by Jan Beulich) 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 | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index c912478..a6c6f18 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -720,8 +720,83 @@ static int find_cos(const uint32_t val[], unsigned int array_len, const struct psr_socket_info *info, spinlock_t *ref_lock) { + unsigned int cos, i; + const unsigned int *ref = info->cos_ref; + const struct feat_node *feat; + unsigned int cos_max; + ASSERT(spin_is_locked(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->props->cos_max; + + for ( cos = 0; cos <= cos_max; cos++ ) + { + const uint32_t *val_ptr = val; + bool found = false; + + if ( cos && !ref[cos] ) + continue; + + /* + * If fail to find cos in below loop, need find whole feature array + * again from beginning. + */ + for ( i = 0; i < PSR_SOCKET_MAX_FEAT; i++ ) + { + uint32_t default_val = 0; + + feat = info->features[i]; + if ( !feat ) + continue; + + /* + * COS ID 0 always stores the default value so input 0 to get + * default value. + */ + feat->props->get_val(feat, 0, &default_val); + + /* + * Compare value according to feature array order. + * We must follow this order because value array is assembled + * as this order. + */ + if ( cos > feat->props->cos_max ) + { + /* + * If cos is bigger than feature's cos_max, the val should be + * default value. Otherwise, it fails to find a COS ID. So we + * have to exit find flow. + */ + if ( val[0] != default_val ) + return -EINVAL; + + found = true; + } + else + { + if ( val[0] == feat->cos_reg_val[cos] ) + found = true; + } + + /* If fail to match, go to next cos to compare. */ + if ( !found ) + break; + + val_ptr += feat->props->cos_num; + if ( val_ptr - val > array_len ) + return -ENOSPC; + } + + /* For this COS ID all entries in the values array do match. Use it. */ + if ( found ) + return cos; + } + return -ENOENT; }