From patchwork Thu Mar 16 11:07:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9627869 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 683616048C for ; Thu, 16 Mar 2017 11:16:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 609FB28573 for ; Thu, 16 Mar 2017 11:16:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55581285A1; Thu, 16 Mar 2017 11:16:06 +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 BF9AC28573 for ; Thu, 16 Mar 2017 11:16:04 +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 1coTLt-0004CA-0Y; Thu, 16 Mar 2017 11:13:53 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coTLr-0004BY-NV for xen-devel@lists.xenproject.org; Thu, 16 Mar 2017 11:13:51 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id D0/8B-08534-E637AC85; Thu, 16 Mar 2017 11:13:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLLMWRWlGSWpSXmKPExsVywNwkVjev+FS Ewbcpkhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0bHzNusBS0aFUuPP2FuYLwr18XIxcEicItJ 4vzSLUwgjpDANEaJy5dPsnUxcnJICPBKHFk2gxXC9pf42XaaDaKogVFi7Y3/7CAJNgF1icdfe 5hAbBEBJYl7qyaDTWIW2Mkkse70d2aQhLBAskTblVcsIDaLgKrEh++7wTbwCrhLLP95hBFig5 zEyWOTwbZxCnhIfGxvB7OFgGrebfjLPoGRbwEjwypGjeLUorLUIl1DE72kosz0jJLcxMwcXUM DY73c1OLixPTUnMSkYr3k/NxNjMBgYQCCHYwrtnseYpTkYFIS5S3/cSJCiC8pP6UyI7E4I76o NCe1+BCjDAeHkgTvEaWTEUKCRanpqRVpmTnAsIVJS3DwKInw5oKkeYsLEnOLM9MhUqcYFaXEe S+AJARAEhmleXBtsFi5xCgrJczLCHSIEE9BalFuZgmq/CtGcQ5GJWHezSBTeDLzSuCmvwJazA S0+O2HEyCLSxIRUlINjEteNx7RXp3lmzm/dnby2kdTOt47TupTm2sk0hheqtJ9pibXdtVuo9P XNu+Sn23WyCqf++pdtP/7qLWbPzNV3fxVxbL6QfnBijVSc43qz81b6RR83MeP415R8EGvHk+r F8v8d1Wa7L7kzSnR/y4naFGIV8LcQIGTS2tvFBuderHKWbRo+gz/w0osxRmJhlrMRcWJAJLOF CCQAgAA X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1489662818!78881615!5 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 6106 invoked from network); 16 Mar 2017 11:13:49 -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:13:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489662829; x=1521198829; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=4k0m00tohWkikiZutYchhYY/nVgMsVNfMw22hEkT35U=; b=BPLBgNFHDjduiEt17NN7sBqnONJGxyjw1tzGvmefPaSO222bTNZnQBkq F8YDlStaNNPocr+LFfgwnSlrUEVfKw==; 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:13:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,172,1486454400"; d="scan'208";a="944976392" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by orsmga003.jf.intel.com with ESMTP; 16 Mar 2017 04:13:46 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Thu, 16 Mar 2017 19:07:56 +0800 Message-Id: <1489662495-5375-7-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 06/25] x86: refactor psr: L3 CAT: 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. - When domain init, its psr resource should be allocated. - When domain free, its psr resource should be freed too. - When domain is scheduled, its COS ID on the socket should be set into ASSOC register to make corresponding COS MSR value work. Signed-off-by: Yi Sun Reviewed-by: Konrad Rzeszutek Wilk --- v9: - rename 'l3_cat_get_cos_max' to 'cat_get_cos_max' to cover all CAT/CDP features. (suggested by Roger Pau) - replace feature list handling to feature array handling. (suggested by Roger Pau) - implement 'psr_alloc_cos' to match 'psr_free_cos'. (suggested by Wei Liu) - use 'psr_alloc_feat_enabled'. (suggested by Wei Liu) - fix coding style issue. (suggested by Wei Liu) - remove 'inline'. (suggested by Jan Beulich) - modify patch title to indicate 'L3 CAT'. (suggested by Jan Beulich) - remove 'psr_cos_ids' check in 'psr_free_cos'. (suggested by Jan Beulich) v6: - change 'PSR_ASSOC_REG_POS' to 'PSR_ASSOC_REG_SHIFT'. (suggested by Konrad Rzeszutek Wilk) v5: - rename 'feat_tmp' to 'feat'. (suggested by Jan Beulich) - define 'PSR_ASSOC_REG_POS'. (suggested by Jan Beulich) v4: - create this patch to make codes easier to understand. (suggested by Jan Beulich) --- xen/arch/x86/psr.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 66a9ce8..a6a8081 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_SHIFT 32 + /* CAT features use 1 COS register in one access. */ #define CAT_COS_NUM 1 @@ -233,8 +235,14 @@ static void cat_init_feature(struct cpuid_leaf regs, return; } +static unsigned int cat_get_cos_max(const struct feat_node *feat) +{ + return feat->info.cat_info.cos_max; +} + /* L3 CAT ops */ static const struct feat_ops l3_cat_ops = { + .get_cos_max = cat_get_cos_max, }; static void __init parse_psr_bool(char *s, char *value, char *feature, @@ -378,11 +386,39 @@ void psr_free_rmid(struct domain *d) d->arch.psr_rmid = 0; } -static inline void psr_assoc_init(void) +static unsigned int get_max_cos_max(const struct psr_socket_info *info) +{ + const struct feat_node *feat; + unsigned int cos_max = 0, i; + + for ( i = 0; i < PSR_SOCKET_MAX_FEAT; i++ ) + { + feat = info->features[i]; + if ( !feat ) + continue; + + cos_max = max(feat->ops.get_cos_max(feat), cos_max); + } + + return cos_max; +} + +static void psr_assoc_init(void) { struct psr_assoc *psra = &this_cpu(psr_assoc); - if ( psr_cmt_enabled() ) + if ( psr_alloc_feat_enabled() ) + { + 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_SHIFT; + } + + if ( psr_cmt_enabled() || psra->cos_mask ) rdmsrl(MSR_IA32_PSR_ASSOC, psra->val); } @@ -391,6 +427,13 @@ static inline void psr_assoc_rmid(uint64_t *reg, unsigned int rmid) *reg = (*reg & ~rmid_mask) | (rmid & rmid_mask); } +static void psr_assoc_cos(uint64_t *reg, unsigned int cos, + uint64_t cos_mask) +{ + *reg = (*reg & ~cos_mask) | + (((uint64_t)cos << PSR_ASSOC_REG_SHIFT) & cos_mask); +} + void psr_ctxt_switch_to(struct domain *d) { struct psr_assoc *psra = &this_cpu(psr_assoc); @@ -399,6 +442,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); @@ -424,14 +472,37 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, return 0; } -int psr_domain_init(struct domain *d) +/* Called with domain lock held, no extra lock needed for 'psr_cos_ids' */ +static void psr_free_cos(struct domain *d) +{ + xfree(d->arch.psr_cos_ids); + d->arch.psr_cos_ids = NULL; +} + +static int psr_alloc_cos(struct domain *d) { + d->arch.psr_cos_ids = xzalloc_array(unsigned int, nr_sockets); + if ( !d->arch.psr_cos_ids ) + return -ENOMEM; + return 0; } +int psr_domain_init(struct domain *d) +{ + /* Init to success value */ + int ret = 0; + + if ( psr_alloc_feat_enabled() ) + ret = psr_alloc_cos(d); + + return ret; +} + void psr_domain_free(struct domain *d) { psr_free_rmid(d); + psr_free_cos(d); } static void __init init_psr(void)