From patchwork Tue Oct 25 03:40:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9393881 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 7A35B60762 for ; Tue, 25 Oct 2016 02:36:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C91028A62 for ; Tue, 25 Oct 2016 02:36:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 605072927B; Tue, 25 Oct 2016 02:36:07 +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 46A0A28A62 for ; Tue, 25 Oct 2016 02:36:05 +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 1byrYo-0004Jn-IU; Tue, 25 Oct 2016 02:33:54 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byrYo-0004HN-09 for xen-devel@lists.xenproject.org; Tue, 25 Oct 2016 02:33:54 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id CD/DF-08293-194CE085; Tue, 25 Oct 2016 02:33:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsVywNykWHfiEb4 Ig+cT+Sy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozefU4FE3Qquo/cZmxgnKzUxcjJISRQIXFj 3isWEFtCgFfiyLIZrBB2gMSXxktANhdQTQOjxN8Fz5lAEmwC6hKPv/aA2SICShL3Vk1mAiliF tjPKPHr5WOwScIC4RLNj2eydTFycLAIqEpM6nIBCfMKuEvM/tLLBrFATuLksclgyzgFPCTu7D 3ODnGQu0RfQxPjBEbeBYwMqxg1ilOLylKLdA3N9ZKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpO K9ZLzczcxAoOBAQh2MN7eGHCIUZKDSUmUd+YmvgghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErzr DwPlBItS01Mr0jJzgGEJk5bg4FES4X0CkuYtLkjMLc5Mh0idYlSUEuddBJIQAElklObBtcFi4 RKjrJQwLyPQIUI8BalFuZklqPKvGMU5GJWEeV+ATOHJzCuBm/4KaDET0GLBeB6QxSWJCCmpBk aVwEsPDF8yS8pxO2YWJvhmrJ2xY53JccvIyesTGydt+Dj3bM0Dxr7qsIcbd+3pqC/X/LHtl+S 2tfudUhNCVm2++ET06FvGlPpwxlOrp/r13uxLWr74fsT+4t8bMu02XyjX5T2Z2jE/ynXWFdd3 0p12hbfyo+LPbPSW2fl9yz1Z4eklGTvtDxQrsRRnJBpqMRcVJwIA6nWGUoACAAA= X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1477362814!54875270!6 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49901 invoked from network); 25 Oct 2016 02:33:52 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-14.tower-27.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 25 Oct 2016 02:33:52 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 24 Oct 2016 19:33:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,544,1473145200"; d="scan'208"; a="1049570123" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.60]) by orsmga001.jf.intel.com with ESMTP; 24 Oct 2016 19:33:50 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 25 Oct 2016 11:40:53 +0800 Message-Id: <1477366863-5246-6-git-send-email-yi.y.sun@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477366863-5246-1-git-send-email-yi.y.sun@linux.intel.com> References: <1477366863-5246-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] [PATCH v3 05/15] x86: refactor psr: Use 'feat_mask' to record featues enabled. 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 'cdp_socket_enable' and 'cat_socket_enable' are used to mask if CDP/CAT are enabled on socket. But they are specific for CAT and CDP. So, replace them with 'feat_mask' which is a general mask. Signed-off-by: Yi Sun --- xen/arch/x86/psr.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 97f1c33..aa902d2 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -26,6 +26,9 @@ /* Per spec, the maximum COS register number is 128. */ #define MAX_COS_REG_NUM 128 +#define PSR_SOCKET_L3_CAT 0 +#define PSR_SOCKET_L3_CDP 1 + /* CAT/CDP HW info data structure. */ struct psr_cat_hw_info { unsigned int cbm_len; @@ -33,6 +36,8 @@ struct psr_cat_hw_info { }; struct psr_cat_socket_info { + /* bit 1~0: [01]->L3 CAT-only, [10]->L3 CDP */ + unsigned int feat_mask; struct psr_cat_hw_info l3_info; /* * Store the values of COS registers: @@ -71,9 +76,7 @@ struct psr_assoc { struct psr_cmt *__read_mostly psr_cmt; -static unsigned long *__read_mostly cat_socket_enable; static struct psr_cat_socket_info *__read_mostly cat_socket_info; -static unsigned long *__read_mostly cdp_socket_enable; static unsigned int opt_psr; static unsigned int __initdata opt_rmid_max = 255; @@ -238,7 +241,7 @@ static inline void psr_assoc_init(void) { unsigned int socket = cpu_to_socket(smp_processor_id()); - if ( test_bit(socket, cat_socket_enable) ) + if ( cat_socket_info[socket].feat_mask ) psra->cos_mask = ((1ull << get_count_order( cat_socket_info[socket].l3_info.cos_max)) - 1) << 32; } @@ -285,7 +288,7 @@ static struct psr_cat_socket_info *get_cat_socket_info(unsigned int socket) if ( socket >= nr_sockets ) return ERR_PTR(-ENOTSOCK); - if ( !test_bit(socket, cat_socket_enable) ) + if ( !cat_socket_info[socket].feat_mask ) return ERR_PTR(-ENOENT); return cat_socket_info + socket; @@ -293,7 +296,7 @@ static struct psr_cat_socket_info *get_cat_socket_info(unsigned int socket) static inline bool_t cdp_is_enabled(unsigned int socket) { - return cdp_socket_enable && test_bit(socket, cdp_socket_enable); + return test_bit(PSR_SOCKET_L3_CDP, &cat_socket_info[socket].feat_mask); } int psr_get_cat_l3_info(unsigned int socket, uint32_t *cbm_len, @@ -558,7 +561,7 @@ static void psr_free_cos(struct domain *d) if( !d->arch.psr_cos_ids ) return; - for_each_set_bit(socket, cat_socket_enable, nr_sockets) + for( socket = 0; socket < nr_sockets; socket++ ) { if ( (cos = d->arch.psr_cos_ids[socket]) == 0 ) continue; @@ -614,14 +617,14 @@ static void cat_cpu_init(void) return; socket = cpu_to_socket(cpu); - if ( test_bit(socket, cat_socket_enable) ) + info = cat_socket_info + socket; + if ( info->feat_mask ) return; cpuid_count(PSR_CPUID_LEVEL_CAT, 0, &eax, &ebx, &ecx, &edx); if ( ebx & PSR_RESOURCE_TYPE_L3 ) { cpuid_count(PSR_CPUID_LEVEL_CAT, 1, &eax, &ebx, &ecx, &edx); - info = cat_socket_info + socket; info->l3_info.cbm_len = (eax & 0x1f) + 1; info->l3_info.cos_max = min(opt_cos_max, edx & 0xffff); @@ -630,10 +633,8 @@ static void cat_cpu_init(void) spin_lock_init(&info->ref_lock); - set_bit(socket, cat_socket_enable); - if ( (ecx & PSR_CAT_CDP_CAPABILITY) && (opt_psr & PSR_CDP) && - cdp_socket_enable && !test_bit(socket, cdp_socket_enable) ) + !test_bit(PSR_SOCKET_L3_CDP, &info->feat_mask) ) { /* CODE */ get_cdp_code(info, 0) = (1ull << info->l3_info.cbm_len) - 1; @@ -649,8 +650,11 @@ static void cat_cpu_init(void) /* Cut half of cos_max when CDP is enabled. */ info->l3_info.cos_max >>= 1; - set_bit(socket, cdp_socket_enable); + __set_bit(PSR_SOCKET_L3_CDP, &info->feat_mask); } + else + __set_bit(PSR_SOCKET_L3_CAT, &info->feat_mask); + printk(XENLOG_INFO "CAT: enabled on socket %u, cos_max:%u, cbm_len:%u, CDP:%s\n", socket, info->l3_info.cos_max, info->l3_info.cbm_len, cdp_is_enabled(socket) ? "on" : "off"); @@ -663,17 +667,17 @@ static void cat_cpu_fini(unsigned int cpu) if ( !socket_cpumask[socket] || cpumask_empty(socket_cpumask[socket]) ) { - if ( cdp_is_enabled(socket) ) - clear_bit(socket, cdp_socket_enable); + struct psr_cat_socket_info *info = cat_socket_info + socket; - clear_bit(socket, cat_socket_enable); + if ( cdp_is_enabled(socket) ) + clear_bit(PSR_SOCKET_L3_CDP, &info->feat_mask); + else + clear_bit(PSR_SOCKET_L3_CAT, &info->feat_mask); } } static void __init psr_cat_free(void) { - xfree(cat_socket_enable); - cat_socket_enable = NULL; xfree(cat_socket_info); cat_socket_info = NULL; } @@ -686,12 +690,10 @@ static void __init init_psr_cat(void) return; } - cat_socket_enable = xzalloc_array(unsigned long, BITS_TO_LONGS(nr_sockets)); cat_socket_info = xzalloc_array(struct psr_cat_socket_info, nr_sockets); - cdp_socket_enable = xzalloc_array(unsigned long, BITS_TO_LONGS(nr_sockets)); - if ( !cat_socket_enable || !cat_socket_info ) - psr_cat_free(); + if ( !cat_socket_info ) + printk(XENLOG_INFO "Fail to alloc socket_info!\n"); } static int psr_cpu_prepare(unsigned int cpu)