From patchwork Thu Mar 16 11:08:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9627871 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 E5E2F6048C for ; Thu, 16 Mar 2017 11:16:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDDF528573 for ; Thu, 16 Mar 2017 11:16:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2C76285B5; Thu, 16 Mar 2017 11:16:07 +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 713BF28573 for ; Thu, 16 Mar 2017 11:16:07 +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 1coTME-0004XI-06; Thu, 16 Mar 2017 11:14:14 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTMC-0004Vb-QF for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:14:12 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 1A/2F-20914-4837AC85; Thu, 16 Mar 2017 11:14:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVywNwkVre5+FS Ewa+/shbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aRG+YFv1QrlnS8YWtgXC7TxcjJwSJwi0ni /7XwLkYuDiGBaYwSj9fsYgdJSAjwShxZNoMVwvaX+LzoPlhcSKCBUeLiZhcQm01AXeLx1x4mE FtEQEni3qrJTCCDmAV2MkmsO/2dGSQhLBApsfvZfhaIbaoS3z+vBLI5OHgFPCRm3OaGmC8ncf LYZLBdnEDhj+3trBC73CXebfjLPoGRbwEjwypGjeLUorLUIl1DE72kosz0jJLcxMwcXUMDY73 c1OLixPTUnMSkYr3k/NxNjMAgYQCCHYwrtnseYpTkYFIS5S3/cSJCiC8pP6UyI7E4I76oNCe1 +BCjDAeHkgTvEaWTEUKCRanpqRVpmTnAcIVJS3DwKInw5oKkeYsLEnOLM9MhUqcYFaXEeS+AJ ARAEhmleXBtsBi5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHezSBTeDLzSuCmvwJazAS0+O 2HEyCLSxIRUlINjLKr7ugoOnx5xBnU+Th5eV+k1aZ1qh8Spl+1ersgzD33yZF/j6tXJ+x7WJ+ h66atznycv+Vpy6nQxKtcr0TPij0vuLk3aGPcXy9xvZiLZ+aqaBZXCM+/qdPVasp/7Lybbsyi 7KbDFuf2vbraM0MvfOILjktbj1k1f0oR3y7NKnInt6xgup/DAyWW4oxEQy3mouJEAE1fJ8eMA gAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1489662818!78881615!12 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 9843 invoked from network); 16 Mar 2017 11:14:10 -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:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489662850; x=1521198850; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=AiT5vVCOzd7j7Ia6zWoM7NeGtYR0txvuiBpVfREYNe0=; b=TIAPMqXs7gqoqiKjASE3r0u8vFw6spJRbR1zgvhyMcKPbmryAhOaWvbq D2AfRUWaJ6FcNYEXlVpzO59YaQsgyQ==; 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:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,172,1486454400"; d="scan'208";a="944976567" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2017 04:14:07 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 16 Mar 2017 19:08:03 +0800 Message-Id: <1489662495-5375-14-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 13/25] x86: refactor psr: L3 CAT: set value: implement write msr 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 id picking flow.' We have got the feature value and COS ID to set. Then, we write MSR of the designated feature. Till now, set value process is completed. Signed-off-by: Yi Sun --- v9: - replace feature list handling to feature array handling. (suggested by Roger Pau) - add 'array_len' in 'struct cos_write_info' and check if val array exceeds it. - modify 'write_psr_msr' flow only to set one value a time. No need to set whole feature array values. - modify patch title to indicate 'L3 CAT'. (suggested by Jan Beulich) - changes about 'uint64_t' to 'uint32_t'. (suggested by Jan Beulich) v8: - modify 'write_msr' callback function to 'void' because we have to set all features' cbm. When input cos exceeds some features' cos_max, just skip them but not break the iteration. v5: - modify commit message to provide exact patch name to continue from. (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) - correct code format. (suggested by Jan Beulich) v4: - create this patch to make codes easier understand. (suggested by Jan Beulich) --- xen/arch/x86/psr.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index d4db407..2bc7f3c 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -149,6 +149,10 @@ struct feat_node { bool (*fits_cos_max)(const uint32_t val[], const struct feat_node *feat, unsigned int cos); + + /* write_msr is used to write out feature MSR register. */ + void (*write_msr)(unsigned int cos, uint32_t val, + enum cbm_type type, struct feat_node *feat); } ops; /* Encapsulate feature specific HW info here. */ @@ -421,6 +425,18 @@ static bool cat_fits_cos_max(const uint32_t val[], } /* L3 CAT ops */ +static void l3_cat_write_msr(unsigned int cos, uint32_t val, + enum cbm_type type, struct feat_node *feat) +{ + if ( feat->cos_reg_val[cos] != val ) + { + feat->cos_reg_val[cos] = val; + wrmsrl(MSR_IA32_PSR_L3_MASK(cos), (uint64_t)val); + } + + return; +} + static const struct feat_ops l3_cat_ops = { .get_cos_max = cat_get_cos_max, .get_feat_info = cat_get_feat_info, @@ -429,6 +445,7 @@ static const struct feat_ops l3_cat_ops = { .set_new_val = cat_set_new_val, .compare_val = cat_compare_val, .fits_cos_max = cat_fits_cos_max, + .write_msr = l3_cat_write_msr, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -957,11 +974,62 @@ static int pick_avail_cos(const struct psr_socket_info *info, return -EOVERFLOW; } +static unsigned int get_socket_cpu(unsigned int socket) +{ + if ( likely(socket < nr_sockets) ) + return cpumask_any(socket_cpumask[socket]); + + return nr_cpu_ids; +} + +struct cos_write_info +{ + unsigned int cos; + struct feat_node *feature; + uint32_t val; + enum cbm_type type; +}; + +static void do_write_psr_msr(void *data) +{ + struct cos_write_info *info = (struct cos_write_info *)data; + unsigned int cos = info->cos; + struct feat_node *feat = info->feature; + + if ( !feat ) + return; + + if ( cos > feat->ops.get_cos_max(feat) ) + return; + + feat->ops.write_msr(cos, info->val, info->type, feat); +} + static int write_psr_msr(unsigned int socket, unsigned int cos, uint32_t val, enum cbm_type type, enum psr_feat_type feat_type) { - return -ENOENT; + struct psr_socket_info *info = get_socket_info(socket); + struct cos_write_info data = + { + .cos = cos, + .feature = info->features[feat_type], + .val = val, + .type = type, + }; + + if ( socket == cpu_to_socket(smp_processor_id()) ) + do_write_psr_msr(&data); + else + { + unsigned int cpu = get_socket_cpu(socket); + + if ( cpu >= nr_cpu_ids ) + return -ENOTSOCK; + on_selected_cpus(cpumask_of(cpu), do_write_psr_msr, &data, 1); + } + + return 0; } int psr_set_val(struct domain *d, unsigned int socket,