From patchwork Thu Jan 19 06:01:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9525227 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 7843D60437 for ; Thu, 19 Jan 2017 06:05:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 650652860C for ; Thu, 19 Jan 2017 06:05:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59AD62862A; Thu, 19 Jan 2017 06:05: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=-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 0199E2860C for ; Thu, 19 Jan 2017 06:05: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 1cU5oI-0006py-LV; Thu, 19 Jan 2017 06:02:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cU5oH-0006pY-9x for xen-devel@lists.xenproject.org; Thu, 19 Jan 2017 06:02:57 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 43/AF-19998-09650885; Thu, 19 Jan 2017 06:02:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPLMWRWlGSWpSXmKPExsVywNykWHdCWEO EwYGFzBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aM8yeYCr7LVvy40svWwDhZvIuRi0NIYDqj xIz5n5m7GDk5JAR4JY4sm8HaxcgBZPtLfD3mDVHTwChx4MMhJpAaNgF1icdfe8BsEQEliXurJ jOBFDELdDNJrHy4lQUkISyQJDGvfS/YUBYBVYnf86aDNfAKuEvM2f+OEWKZnMTJY5NZQWxOAQ +JK/MvsIPYQkA1W1ZcYprAyLuAkWEVo0ZxalFZapGuobleUlFmekZJbmJmjq6hgbFebmpxcWJ 6ak5iUrFecn7uJkZgQDAAwQ7Gl6c9DzFKcjApifLaWzZECPEl5adUZiQWZ8QXleakFh9ilOHg UJLgVQ0FygkWpaanVqRl5gBDEyYtwcGjJMLLDJLmLS5IzC3OTIdInWJUlBLnfRwClBAASWSU5 sG1weLhEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5RUHG82TmlcBNfwW0mAlosZVyPcjikk SElFQDo1jqufn3JGX/Bi+1fM1+N5ljzZyN7pWspwz8OGb1dMwO3H21wvZuleqvD3u+i/ptdL6 YmTL7mndMg1/Zmi/Tpl52TVNfonUn4dsUp2tarc/12vc0iWw9pl5qOvfonOiFF84k39+18ZrP dW2FQ7Mt4vIeJd/bHDm5ueuO7bn3buuUN/cJ3Y+J9VRiKc5INNRiLipOBABc40T3ggIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1484805772!81354767!2 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 32761 invoked from network); 19 Jan 2017 06:02:55 -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:02:55 -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:02:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,252,1477983600"; d="scan'208";a="215119463" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 18 Jan 2017 22:02:51 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 19 Jan 2017 14:01:07 +0800 Message-Id: <1484805686-7249-6-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 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 --- v5: - define macro 'PSR_ASSOC_REG_POS' to replace integer 32. - rename 'l3_cat_get_max_cos_max' to 'l3_cat_get_cos_max'. - modify variables names to make them better, e.g. 'feat_tmp' to 'feat'. --- xen/arch/x86/psr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index e9dc07a..7f06235 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -50,6 +50,8 @@ */ #define MAX_COS_REG_CNT 128 +#define PSR_ASSOC_REG_POS 32 + /* * PSR features are managed per socket. Below structure defines the members * used to manage these features. @@ -211,7 +213,13 @@ static void l3_cat_init_feature(struct cpuid_leaf_regs regs, feat->info.l3_cat_info.cbm_len); } +static unsigned int l3_cat_get_cos_max(const struct feat_node *feat) +{ + return feat->info.l3_cat_info.cos_max; +} + static const struct feat_ops l3_cat_ops = { + .get_cos_max = l3_cat_get_cos_max, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -355,11 +363,33 @@ 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; + unsigned int cos_max = 0; + + list_for_each_entry(feat, &info->feat_list, list) + cos_max = max(feat->ops.get_cos_max(feat), 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) << + PSR_ASSOC_REG_POS; + } + + if ( psr_cmt_enabled() || psra->cos_mask ) rdmsrl(MSR_IA32_PSR_ASSOC, psra->val); } @@ -368,6 +398,13 @@ 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 << PSR_ASSOC_REG_POS) & cos_mask); +} + void psr_ctxt_switch_to(struct domain *d) { struct psr_assoc *psra = &this_cpu(psr_assoc); @@ -376,6 +413,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); @@ -401,14 +443,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 void cpu_init_work(void)