From patchwork Thu Jan 19 06:01:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9525207 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 3A3B760437 for ; Thu, 19 Jan 2017 06:05:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2681728610 for ; Thu, 19 Jan 2017 06:05:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B6632863A; Thu, 19 Jan 2017 06:05:21 +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 ADBDB28610 for ; Thu, 19 Jan 2017 06:05:20 +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 1cU5oR-0006va-UR; Thu, 19 Jan 2017 06:03:07 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU5oR-0006un-J7 for xen-devel@lists.xenproject.org; Thu, 19 Jan 2017 06:03:07 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 90/7A-03637-A9650885; Thu, 19 Jan 2017 06:03:06 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNykWHdWWEO EwfUGDovvWyYzOTB6HP5whSWAMYo1My8pvyKBNaPz0xX2gsMqFX+f5TYwLpPsYuTiEBKYzigx 6dcpli5GTg4JAV6JI8tmsELY/hIrPu9mB7GFBBoYJdZvYgKx2QTUJR5/7QGzRQSUJO6tmswEM ohZoJtJYuXDrWCDhAWiJHZPnQRWxCKgKrH88SlmEJtXwEPi9vfTjBAL5CROHpsMtowTKH5l/g WoZe4SW1ZcYprAyLuAkWEVo0ZxalFZapGuobleUlFmekZJbmJmjq6hgbFebmpxcWJ6ak5iUrF ecn7uJkZgODAAwQ7Gl6c9DzFKcjApifLaWzZECPEl5adUZiQWZ8QXleakFh9ilOHgUJLgVQ0F ygkWpaanVqRl5gADEyYtwcGjJMLLDJLmLS5IzC3OTIdInWJUlBLnfRwClBAASWSU5sG1waLhE qOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5RUHG82TmlcBNfwW0mAlosZVyPcjikkSElFQDoz PvXeHcOV9tn50qPPbSYGpR2snt5v86ZQ4xSNwu2hDXxn1R7+7n20+NH22/apXIZHKneL5OQRK z2G5bz+PV8lbvmOYdf3vO/mWOeeM6n0aBrMR6cfu/u/vUfeanHJ5SeMLVcoOtTQZ/8eXGdRN/ Kh9P634Svvr903N9i6vP8GS87eq9qTs7UYmlOCPRUIu5qDgRAEDXI9qBAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1484805772!81354767!7 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33964 invoked from network); 19 Jan 2017 06:03:05 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-8.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Jan 2017 06:03:05 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jan 2017 22:03:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,252,1477983600"; d="scan'208";a="215119508" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 18 Jan 2017 22:03:02 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 19 Jan 2017 14:01:12 +0800 Message-Id: <1484805686-7249-11-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484805686-7249-1-git-send-email-yi.y.sun@linux.intel.com> References: <1484805686-7249-1-git-send-email-yi.y.sun@linux.intel.com> Cc: wei.liu2@citrix.com, konrad.wilk@oracle.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 Subject: [Xen-devel] [PATCH RESEND v5 10/24] x86: refactor psr: 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 with patch: 'x86: refactor psr: 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 --- v5: - modify commit message to provide exact patch name to continue from. - remove 'get_cos_max_from_type' because it can be replaced by 'get_cos_max'. - move type check out from callback functions to caller. - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'. - modify comments according to changes of codes. --- xen/arch/x86/psr.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 7c6f2bf..8832e08 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -141,6 +141,19 @@ struct feat_ops { const struct feat_node *feat, enum cbm_type type, uint64_t m); + /* + * 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 the amount of entries to skip in the value array + * or error. + * 1 - one entry in value array. + * 2 - two entries in value array, e.g. CDP uses two entries. + * negative - error. + */ + int (*compare_val)(const uint64_t val[], const struct feat_node *feat, + unsigned int cos, bool *found); }; /* @@ -347,6 +360,34 @@ static int l3_cat_set_new_val(uint64_t val[], return 0; } +static int l3_cat_compare_val(const uint64_t val[], + const struct feat_node *feat, + unsigned int cos, bool *found) +{ + uint64_t l3_def_cbm; + + l3_def_cbm = (1ull << feat->info.l3_cat_info.cbm_len) - 1; + + /* + * 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.l3_cat_info.cos_max ) + { + if ( val[0] != l3_def_cbm ) + { + *found = false; + return -ENOENT; + } + *found = true; + } + else + *found = (val[0] == feat->cos_reg_val[cos]); + + return 0; +} + static const struct feat_ops l3_cat_ops = { .get_cos_max = l3_cat_get_cos_max, .get_feat_info = l3_cat_get_feat_info, @@ -354,6 +395,7 @@ static const struct feat_ops l3_cat_ops = { .get_cos_num = l3_cat_get_cos_num, .get_old_val = l3_cat_get_old_val, .set_new_val = l3_cat_set_new_val, + .compare_val = l3_cat_compare_val, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -706,6 +748,57 @@ static int find_cos(const uint64_t *val, uint32_t array_len, enum psr_feat_type feat_type, const struct psr_socket_info *info) { + unsigned int cos; + const unsigned int *ref = info->cos_ref; + const struct feat_node *feat; + const uint64_t *val_tmp = val; + int ret; + bool found = false; + unsigned int cos_max = 0; + + /* cos_max is the one of the feature which is being set. */ + list_for_each_entry(feat, &info->feat_list, list) + { + if ( feat->feature != feat_type ) + continue; + + cos_max = feat->ops.get_cos_max(feat); + if ( cos_max > 0 ) + break; + } + + for ( cos = 0; cos <= cos_max; cos++ ) + { + if ( cos && !ref[cos] ) + continue; + + /* Not found, need find again from beginning. */ + val_tmp = val; + list_for_each_entry(feat, &info->feat_list, list) + { + /* + * Compare value according to feature list order. + * We must follow this order because value array is assembled + * as this order in get_old_set_new(). + */ + ret = feat->ops.compare_val(val_tmp, feat, cos, &found); + if ( ret < 0 ) + return ret; + + /* If fail to match, go to next cos to compare. */ + if ( !found ) + break; + + val_tmp += feat->ops.get_cos_num(feat); + if ( val_tmp - val > array_len ) + return -EINVAL; + } + + /* For this COS ID all entries in the values array did match. Use it. */ + if ( found ) + return cos; + } + return -ENOENT; }