From patchwork Tue Jan 10 07:42:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9506643 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 C49EC606E1 for ; Tue, 10 Jan 2017 07:45:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8A1328485 for ; Tue, 10 Jan 2017 07:45:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD780284B0; Tue, 10 Jan 2017 07:45:52 +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 4D20728485 for ; Tue, 10 Jan 2017 07:45:52 +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 1cQr5w-00043d-V0; Tue, 10 Jan 2017 07:43:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQr5v-00041w-Nk for xen-devel@lists.xenproject.org; Tue, 10 Jan 2017 07:43:47 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 7A/77-25093-2B094785; Tue, 10 Jan 2017 07:43:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNykWHfThJI Ig75nfBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8as2+dYCk6rVMzY85e1gfGNdBcjJ4eQQKXE 9O3nGEFsCQFeiSPLZrBC2P4SC389ZIWoaWCUeLysGMRmE1CXePy1hwnEFhFQkri3ajKQzcXBL LCfUWL+8ePMIAlhATOJ3nmX2UBsFgFViXsH74It4BVwl7i45DMTxAI5iZPHJoMt4BTwkGi5uo 4RYpm7RPPb+4wTGHkXMDKsYtQoTi0qSy3SNTTTSyrKTM8oyU3MzNE1NDDTy00tLk5MT81JTCr WS87P3cQIDAcGINjBeH9jwCFGSQ4mJVHeFN2SCCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvFX9 QDnBotT01Iq0zBxgYMKkJTh4lER4WUDSvMUFibnFmekQqVOMilLivIEgCQGQREZpHlwbLBouM cpKCfMyAh0ixFOQWpSbWYIq/4pRnINRSZh3H8gUnsy8Erjpr4AWMwEtjrQrBllckoiQkmpg7F 3R1dv35Xf2p4cp2iVyHziqawWPnj9xUNXpzMr9/dF/HZTV9hSlGkTXTglZb6+0Qt9wxmupqqT ys6LzpxyxuqCxMMjV/+4z+eDu426/PVm+ZwcILp8feXth5uHKviTviCknPuYsm2LxvuTYn77v Fw+sEi+OZLzSXC+8inF35VmeMpESJ42jSizFGYmGWsxFxYkAYgBzZ4ECAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1484034223!45252429!1 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17544 invoked from network); 10 Jan 2017 07:43:45 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 10 Jan 2017 07:43:45 -0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP; 09 Jan 2017 23:43:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,343,1477983600"; d="scan'208";a="211583051" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.63]) by fmsmga004.fm.intel.com with ESMTP; 09 Jan 2017 23:43:29 -0800 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 10 Jan 2017 15:42:25 +0800 Message-Id: <1484034155-4521-7-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com> References: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com> Cc: wei.liu2@citrix.com, he.chen@linux.intel.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, Yi Sun , jbeulich@suse.com, chao.p.peng@linux.intel.com Subject: [Xen-devel] [RFC 06/16] x86: implement init flow for MBA. 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 init flow for MBA including its callback functions. Signed-off-by: Yi Sun --- xen/arch/x86/psr.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++- xen/include/asm-x86/psr.h | 1 + 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index eca9c43..e2ca6fb 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -41,6 +41,7 @@ #define CAT_CBM_LEN_MASK 0x1f #define CAT_COS_MAX_MASK 0xffff +#define MBA_THRTL_MAX_MASK 0xfff /* Linear bit. */ #define MBA_LINEAR (1<<2) @@ -265,6 +266,7 @@ static DEFINE_PER_CPU(struct psr_assoc, psr_assoc); static struct feat_node *feat_l3_cat; static struct feat_node *feat_l3_cdp; static struct feat_node *feat_l2_cat; +static struct feat_node *feat_mba; /* Common functions. */ static void free_feature(struct psr_socket_info *info) @@ -299,6 +301,12 @@ static void free_feature(struct psr_socket_info *info) xfree(feat_l2_cat); feat_l2_cat = NULL; } + + if ( feat_mba ) + { + xfree(feat_mba); + feat_mba = NULL; + } } static bool_t psr_check_cbm(unsigned int cbm_len, uint64_t cbm) @@ -934,6 +942,53 @@ struct feat_ops l2_cat_ops = { .write_msr = l2_cat_write_msr, }; +/* MBA callback functions implementation. */ +static void mba_init_feature(unsigned int eax, unsigned int ebx, + unsigned int ecx, unsigned int edx, + struct feat_node *feat, + struct psr_socket_info *info) +{ + struct psr_mba_hw_info mba_info; + unsigned int socket; + + /* No valid values so do not enable the feature. */ + if ( !eax || !edx ) + return; + + mba_info.thrtl_max = (eax & 0xfff) + 1; + mba_info.cos_max = min(opt_cos_max, edx & CAT_COS_MAX_MASK); + if ( ecx & MBA_LINEAR ) + mba_info.linear = 1; + + /* cos=0 is reserved as default thrtl(0), the max bandwidth. */ + feat->cos_reg_val[0] = 0; + + feat->feature = PSR_SOCKET_MBA; + __set_bit(PSR_SOCKET_MBA, &info->feat_mask); + + feat->info.mba_info = mba_info; + + info->nr_feat++; + + /* Add this feature into list. */ + list_add_tail(&feat->list, &info->feat_list); + + socket = cpu_to_socket(smp_processor_id()); + printk(XENLOG_INFO "MBA: enabled on socket %u, cos_max:%u, thrtl_max:%u, linear:%u.\n", + socket, feat->info.mba_info.cos_max, + feat->info.mba_info.thrtl_max, feat->info.mba_info.linear); +} + +static unsigned int mba_get_max_cos_max(const struct feat_node *feat) +{ + return feat->info.mba_info.cos_max; +} + +struct feat_ops mba_ops = { + .init_feature = mba_init_feature, + .get_max_cos_max = mba_get_max_cos_max, +}; + static void __init parse_psr_bool(char *s, char *value, char *feature, unsigned int mask) { @@ -1659,6 +1714,20 @@ static int cpu_prepare_work(unsigned int cpu) return -ENOMEM; } + if ( feat_mba == NULL && + (feat_mba = xzalloc(struct feat_node)) == NULL ) + { + xfree(feat_l3_cat); + feat_l3_cat = NULL; + + xfree(feat_l3_cdp); + feat_l3_cdp = NULL; + + xfree(feat_l2_cat); + feat_l2_cat = NULL; + return -ENOMEM; + } + return 0; } @@ -1712,6 +1781,18 @@ static void cpu_init_work(void) feat_tmp->ops = l2_cat_ops; feat_tmp->ops.init_feature(eax, ebx, ecx, edx, feat_tmp, info); } + + cpuid_count(PSR_CPUID_LEVEL_CAT, 0, &eax, &ebx, &ecx, &edx); + if ( ebx & PSR_RESOURCE_TYPE_MBA ) + { + feat_tmp = feat_mba; + feat_mba = NULL; + + /* Initialize MBA according to CPUID. */ + cpuid_count(PSR_CPUID_LEVEL_CAT, 3, &eax, &ebx, &ecx, &edx); + feat_tmp->ops = mba_ops; + feat_tmp->ops.init_feature(eax, ebx, ecx, edx, feat_tmp, info); + } } static void cpu_fini_work(unsigned int cpu) @@ -1817,7 +1898,7 @@ static int __init psr_presmp_init(void) if ( (opt_psr & PSR_CMT) && opt_rmid_max ) init_psr_cmt(opt_rmid_max); - if ( opt_psr & PSR_CAT ) + if ( opt_psr & (PSR_CAT | PSR_MBA) ) init_psr(); if ( psr_cpu_prepare(0) ) diff --git a/xen/include/asm-x86/psr.h b/xen/include/asm-x86/psr.h index 4d52918..9dd7782 100644 --- a/xen/include/asm-x86/psr.h +++ b/xen/include/asm-x86/psr.h @@ -24,6 +24,7 @@ /* Resource Type Enumeration */ #define PSR_RESOURCE_TYPE_L3 0x2 #define PSR_RESOURCE_TYPE_L2 0x4 +#define PSR_RESOURCE_TYPE_MBA 0x8 /* L3 Monitoring Features */ #define PSR_CMT_L3_OCCUPANCY 0x1