From patchwork Wed Dec 14 04:07:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9474043 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 82BEC60823 for ; Wed, 14 Dec 2016 11:12:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A6082871B for ; Wed, 14 Dec 2016 11:12:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F4072871F; Wed, 14 Dec 2016 11:12:33 +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=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, 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 1995E2871B for ; Wed, 14 Dec 2016 11:12:33 +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 1cH7Rs-0005cz-8P; Wed, 14 Dec 2016 11:10:12 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH7Rr-0005b3-92 for xen-devel@lists.xenproject.org; Wed, 14 Dec 2016 11:10:11 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id E6/32-05787-29821585; Wed, 14 Dec 2016 11:10:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsXS1tYhoTtJIzD CYOIOHovvWyYzOTB6HP5whSWAMYo1My8pvyKBNeP5tR2sBbekK052PmJsYDws0sXIySEkUCFx q386O4gtIcArcWTZDFYI20/izK0JQHEuoJoGRokfS/eBJdgE1CUef+1hArFFBJQk7q2azARSx CzQzSSx8uFWFpCEsECgxPy3K8FsFgFViV1fn4E18Ap4SLxc8Rhqm5zEyWOTgYZycHACxf9tSY Q4yF3iYu879gmMvAsYGVYxahSnFpWlFukaGeslFWWmZ5TkJmbm6BoamOnlphYXJ6an5iQmFes l5+duYgSGAwMQ7GD8Mz/wEKMkB5OSKC/X1YAIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8s9QD I4QEi1LTUyvSMnOAgQmTluDgURLhDVIBSvMWFyTmFmemQ6ROMSpKifOuBOkTAElklObBtcGi4 RKjrJQwLyPQIUI8BalFuZklqPKvGMU5GJWEeTeATOHJzCuBm/4KaDET0GLRJf4gi0sSEVJSDY zCf8R/2K994fXmqRD7Du7ZkSc/P1T7FRMppCc16UTnLo3nyj4inrbB8+qe6194vPtWfKOlPT9 35v6WAIWDX83vpZsmCb04bDbFPIvzmU7s4s/Lb7z8n2Lr/WD1lyV3Xnev+pDncnfieWP/RQvO /PydM2djzoTZb7tPBMu9XCk3W6lzTQvL2tJjSizFGYmGWsxFxYkACtyXa4ECAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1481713769!48240089!13 X-Originating-IP: [134.134.136.24] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjQgPT4gMzkwOTcx\n X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22322 invoked from network); 14 Dec 2016 11:10:09 -0000 Received: from mga09.intel.com (HELO mga09.intel.com) (134.134.136.24) by server-12.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Dec 2016 11:10:09 -0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP; 14 Dec 2016 03:10:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,346,1477983600"; d="scan'208";a="39863303" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga004.jf.intel.com with ESMTP; 14 Dec 2016 03:10:07 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 14 Dec 2016 12:07:52 +0800 Message-Id: <1481688484-5093-13-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481688484-5093-1-git-send-email-yi.y.sun@linux.intel.com> References: <1481688484-5093-1-git-send-email-yi.y.sun@linux.intel.com> Cc: 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 Subject: [Xen-devel] [PATCH v4 12/24] x86: refactor psr: 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 with previous patches, we have got all features values and COS ID to set. Then, we write MSRs of all features except the setting value is same as original value. Till now, set value process is completed. Signed-off-by: Yi Sun --- xen/arch/x86/psr.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index ac98c39..ec757a2 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -186,6 +186,9 @@ struct feat_ops { unsigned int (*exceeds_cos_max)(const uint64_t val[], const struct feat_node *feat, unsigned int cos); + /* write_msr is used to write out feature MSR register. */ + int (*write_msr)(unsigned int cos, const uint64_t val[], + struct feat_node *feat); }; @@ -441,6 +444,22 @@ static unsigned int l3_cat_exceeds_cos_max(const uint64_t val[], return 1; } +static int l3_cat_write_msr(unsigned int cos, const uint64_t val[], + struct feat_node *feat) +{ + if ( cos > feat->info.l3_cat_info.cos_max ) + /* L3 CAT uses one COS. */ + return 1; + + if ( feat->cos_reg_val[cos] != val[0] ) + { + feat->cos_reg_val[cos] = val[0]; + wrmsrl(MSR_IA32_PSR_L3_MASK(cos), val[0]); + } + /* L3 CAT uses one COS. */ + return 1; +} + struct feat_ops l3_cat_ops = { .init_feature = l3_cat_init_feature, .get_max_cos_max = l3_cat_get_max_cos_max, @@ -452,6 +471,7 @@ struct feat_ops l3_cat_ops = { .get_cos_max_from_type = l3_cat_get_cos_max_from_type, .compare_val = l3_cat_compare_val, .exceeds_cos_max = l3_cat_exceeds_cos_max, + .write_msr = l3_cat_write_msr, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -889,9 +909,67 @@ static int alloc_new_cos(const struct psr_socket_info *info, return -ENOENT; } +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 list_head *feat_list; + const uint64_t *val; +}; + +static void do_write_psr_msr(void *data) +{ + struct cos_write_info *info = (struct cos_write_info *)data; + unsigned int cos = info->cos; + struct list_head *feat_list= info->feat_list; + const uint64_t *val = info->val; + struct feat_node *feat_tmp; + int ret; + + if ( !feat_list ) + return; + + /* We need set all features values into MSRs. */ + list_for_each_entry(feat_tmp, feat_list, list) + { + ret = feat_tmp->ops.write_msr(cos, val, feat_tmp); + if ( ret <= 0) + return; + + val += ret; + } +} + static int write_psr_msr(unsigned int socket, unsigned int cos, const uint64_t *val) { + struct psr_socket_info *info = get_socket_info(socket); + + struct cos_write_info data = + { + .cos = cos, + .feat_list = &info->feat_list, + .val = val, + }; + + 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; }