From patchwork Wed Dec 14 04:07:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9474001 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 73B8A60823 for ; Wed, 14 Dec 2016 11:12:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B0252871A for ; Wed, 14 Dec 2016 11:12:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E3BA28722; Wed, 14 Dec 2016 11:12:01 +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 078EB2871A for ; Wed, 14 Dec 2016 11:12:01 +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 1cH7RV-0004rw-Bg; Wed, 14 Dec 2016 11:09:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH7RU-0004r7-Ih for xen-devel@lists.xenproject.org; Wed, 14 Dec 2016 11:09:48 +0000 Received: from [85.158.143.35] by server-5.bemta-6.messagelabs.com id CD/5D-11476-B7821585; Wed, 14 Dec 2016 11:09:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsXS1tYhoVutERh h8KiL2+L7lslMDowehz9cYQlgjGLNzEvKr0hgzZh3vpO1YJdsRc/ciewNjCfEuhg5OYQEKiTe rdjGBGJLCPBKHFk2gxXC9pM407GerYuRC6imgVHi9P1msCI2AXWJx197wGwRASWJe6smM4EUM Qt0M0msfLiVBSQhLBAtceLgXHYQm0VAVeJJ52GwOK+Au8SzGR+ZITbISZw8NhloGwcHp4CHxL 8tiRAHuUtc7H3HPoGRdwEjwypGjeLUorLUIl0jY72kosz0jJLcxMwcXUMDM73c1OLixPTUnMS kYr3k/NxNjMBwYACCHYx/5gceYpTkYFIS5eW6GhAhxJeUn1KZkVicEV9UmpNafIhRhoNDSYJ3 lnpghJBgUWp6akVaZg4wMGHSEhw8SiK8QSpAad7igsTc4sx0iNQpRkUpcd6VIH0CIImM0jy4N lg0XGKUlRLmZQQ6RIinILUoN7MEVf4VozgHo5Iw7waQKTyZeSVw018BLWYCWiy6xB9kcUkiQk qqgdFzzpPd3r4FWWxbmkqfHpjwaeJFx+hGgUvc6TpMbAHGhv3/7/AzbyrtdCpNisrdd5L/+Yt nqnX7WqLca5+d/NFS+mNGp6OaJeN65rYD/wKCuKXuNex15lZ7IvVwprmelufLSvN7ce8e//u2 Vvqk972mI9eEbhRu/Za38E3//PKvvKZMD/8tTVBiKc5INNRiLipOBAA+Zz9WgQIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1481713769!48240089!6 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 15992 invoked from network); 14 Dec 2016 11:09:46 -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:09:46 -0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP; 14 Dec 2016 03:09:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,346,1477983600"; d="scan'208";a="39863190" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga004.jf.intel.com with ESMTP; 14 Dec 2016 03:09:43 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Wed, 14 Dec 2016 12:07:45 +0800 Message-Id: <1481688484-5093-6-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 05/24] x86: refactor psr: implement Domain init/free and schedule flows. 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 This patch implements the Domain init/free and schedule flows. Signed-off-by: Yi Sun --- xen/arch/x86/psr.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index fa9bc32..746c90e 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -113,6 +113,8 @@ struct feat_ops { unsigned int ecx, unsigned int edx, struct feat_node *feat, struct psr_socket_info *info); + /* get_max_cos_max is used to get feature's cos_max. */ + unsigned int (*get_max_cos_max)(const struct feat_node *feat); }; @@ -213,8 +215,14 @@ static void l3_cat_init_feature(unsigned int eax, unsigned int ebx, feat->info.l3_cat_info.cbm_len); } +static unsigned int l3_cat_get_max_cos_max(const struct feat_node *feat) +{ + return feat->info.l3_cat_info.cos_max; +} + struct feat_ops l3_cat_ops = { .init_feature = l3_cat_init_feature, + .get_max_cos_max = l3_cat_get_max_cos_max, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -358,11 +366,32 @@ void psr_free_rmid(struct domain *d) d->arch.psr_rmid = 0; } +static inline unsigned int get_max_cos_max(const struct psr_socket_info *info) +{ + const struct feat_node *feat_tmp; + unsigned int cos_max = 0; + + list_for_each_entry(feat_tmp, &info->feat_list, list) + cos_max = max(feat_tmp->ops.get_max_cos_max(feat_tmp), cos_max); + + return cos_max; +} + static inline void psr_assoc_init(void) { struct psr_assoc *psra = &this_cpu(psr_assoc); - if ( psr_cmt_enabled() ) + if ( socket_info ) + { + unsigned int socket = cpu_to_socket(smp_processor_id()); + const struct psr_socket_info *info = socket_info + socket; + unsigned int cos_max = get_max_cos_max(info); + + if ( info->feat_mask ) + psra->cos_mask = ((1ull << get_count_order(cos_max)) - 1) << 32; + } + + if ( psr_cmt_enabled() || psra->cos_mask ) rdmsrl(MSR_IA32_PSR_ASSOC, psra->val); } @@ -371,6 +400,12 @@ static inline void psr_assoc_rmid(uint64_t *reg, unsigned int rmid) *reg = (*reg & ~rmid_mask) | (rmid & rmid_mask); } +static inline void psr_assoc_cos(uint64_t *reg, unsigned int cos, + uint64_t cos_mask) +{ + *reg = (*reg & ~cos_mask) | (((uint64_t)cos << 32) & cos_mask); +} + void psr_ctxt_switch_to(struct domain *d) { struct psr_assoc *psra = &this_cpu(psr_assoc); @@ -379,6 +414,11 @@ void psr_ctxt_switch_to(struct domain *d) if ( psr_cmt_enabled() ) psr_assoc_rmid(®, d->arch.psr_rmid); + if ( psra->cos_mask ) + psr_assoc_cos(®, d->arch.psr_cos_ids ? + d->arch.psr_cos_ids[cpu_to_socket(smp_processor_id())] : + 0, psra->cos_mask); + if ( reg != psra->val ) { wrmsrl(MSR_IA32_PSR_ASSOC, reg); @@ -404,14 +444,32 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, return 0; } +/* Called with domain lock held, no extra lock needed for 'psr_cos_ids' */ +static void psr_free_cos(struct domain *d) +{ + if( !d->arch.psr_cos_ids ) + return; + + xfree(d->arch.psr_cos_ids); + d->arch.psr_cos_ids = NULL; +} + int psr_domain_init(struct domain *d) { + if ( socket_info ) + { + d->arch.psr_cos_ids = xzalloc_array(unsigned int, nr_sockets); + if ( !d->arch.psr_cos_ids ) + return -ENOMEM; + } + return 0; } void psr_domain_free(struct domain *d) { psr_free_rmid(d); + psr_free_cos(d); } static int cpu_prepare_work(unsigned int cpu)