From patchwork Tue Oct 25 03:40:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9393891 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 9733460762 for ; Tue, 25 Oct 2016 02:36:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8946128B39 for ; Tue, 25 Oct 2016 02:36:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D7B22927D; Tue, 25 Oct 2016 02:36:13 +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 DA61828B39 for ; Tue, 25 Oct 2016 02:36:12 +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 1byrYk-0004H9-2o; Tue, 25 Oct 2016 02:33:50 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byrYi-0004H3-AA for xen-devel@lists.xenproject.org; Tue, 25 Oct 2016 02:33:48 +0000 Received: from [193.109.254.147] by server-1.bemta-6.messagelabs.com id A0/EF-01767-B84CE085; Tue, 25 Oct 2016 02:33:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVywNykWLfrCF+ EwaEzuhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b0EykFH50rPm9dxt7A+NOgi5GTQ0igQuLG 9j5GEFtCgFfiyLIZrBB2gMT/t7+B4lxANQ2MEhv/r2ACSbAJqEs8/toDZosIKEncWzWZCaSIW WA/o8Svl49ZQBLCAp4SUw98YwaxWQRUJSYcus4GYvMKuEtM/vgPapucxMljk8G2cQp4SNzZe5 wd4iJ3ib6GJsYJjLwLGBlWMWoUpxaVpRbpGprrJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhX rJefnbmIEhgMDEOxgvL0x4BCjJAeTkijvzE18EUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeNcf BsoJFqWmp1akZeYAAxMmLcHBoyTC+wQkzVtckJhbnJkOkTrFqMuxZcGNtUxCLHn5ealS4ryLQ IoEQIoySvPgRsCi5BKjrJQwLyPQUUI8BalFuZklqPKvGMU5GJWEeV+ATOHJzCuB2/QK6AgmoC ME43lAjihJREhJNTAqXHS+wpnFks92YmtMs12b7P0dfv8exsaosrK0ud37uHr3Oo+rNh7zNzV ldJaZcrQumDd5TmBGhpewVyDv3c5fIWzX9V8z/nbuOcrM/af1k8GCCSf1ZxkVvdjX4/3B7m3M RKs1bzm8drm+llQ5qLl91zWHjUdLvpuJyyxcVsR17n72l0mXDYqUWIozEg21mIuKEwFBpXUOj QIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1477362814!54875270!4 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 49699 invoked from network); 25 Oct 2016 02:33:46 -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:46 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 24 Oct 2016 19:33:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,544,1473145200"; d="scan'208"; a="1049570090" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.60]) by orsmga001.jf.intel.com with ESMTP; 24 Oct 2016 19:33:44 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 25 Oct 2016 11:40:51 +0800 Message-Id: <1477366863-5246-4-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 03/15] x86: refactor psr: Remove 'struct psr_cat_cbm'. 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 'struct psr_cat_cbm' is defined for L3 CAT only. It is not appropriate for other features. This patch replaces it with a generic array, 'uint64_t cos_reg_val[MAX_COS_REG_NUM]', to save values of COS registers. So 'temp_cos_to_cbm' is not useful anymore, remove it. Signed-off-by: Yi Sun --- xen/arch/x86/psr.c | 93 ++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index ee20389..a0342ce 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -26,20 +26,15 @@ /* Per spec, the maximum COS register number is 128. */ #define MAX_COS_REG_NUM 128 -struct psr_cat_cbm { - union { - uint64_t cbm; - struct { - uint64_t code; - uint64_t data; - }; - }; -}; - struct psr_cat_socket_info { unsigned int cbm_len; unsigned int cos_max; - struct psr_cat_cbm *cos_to_cbm; + /* + * Store the values of COS registers: + * CAT uses 1 entry for one COS ID; + * CDP uses 2 entries for one COS ID and DATA is the first one. + */ + uint64_t cos_reg_val[MAX_COS_REG_NUM]; /* * Every entry of cos_ref is the reference count of a COS register. * One entry of cos_ref corresponds to one COS ID. @@ -49,6 +44,21 @@ struct psr_cat_socket_info { spinlock_t ref_lock; }; +/* + * get_data - get DATA COS register value from input COS ID. + * @info: the struct psr_cat_socket_info pointer. + * @cos: the COS ID. + */ +#define get_cdp_data(info, cos) \ + info->cos_reg_val[cos * 2] +/* + * get_cdp_code - get CODE COS register value from input COS ID. + * @info: the struct psr_cat_socket_info pointer. + * @cos: the COS ID. + */ +#define get_cdp_code(info, cos) \ + info->cos_reg_val[cos * 2 + 1] + struct psr_assoc { uint64_t val; uint64_t cos_mask; @@ -66,8 +76,6 @@ static unsigned int __read_mostly opt_cos_max = MAX_COS_REG_NUM - 1; static uint64_t rmid_mask; static DEFINE_PER_CPU(struct psr_assoc, psr_assoc); -static struct psr_cat_cbm *temp_cos_to_cbm; - static unsigned int get_socket_cpu(unsigned int socket) { if ( likely(socket < nr_sockets) ) @@ -306,6 +314,7 @@ int psr_get_l3_cbm(struct domain *d, unsigned int socket, { struct psr_cat_socket_info *info = get_cat_socket_info(socket); bool_t cdp_enabled = cdp_is_enabled(socket); + unsigned int cos = d->arch.psr_cos_ids[socket]; if ( IS_ERR(info) ) return PTR_ERR(info); @@ -315,21 +324,21 @@ int psr_get_l3_cbm(struct domain *d, unsigned int socket, case PSR_CBM_TYPE_L3: if ( cdp_enabled ) return -EXDEV; - *cbm = info->cos_to_cbm[d->arch.psr_cos_ids[socket]].cbm; + *cbm = info->cos_reg_val[cos]; break; case PSR_CBM_TYPE_L3_CODE: if ( !cdp_enabled ) - *cbm = info->cos_to_cbm[d->arch.psr_cos_ids[socket]].cbm; + *cbm = info->cos_reg_val[cos]; else - *cbm = info->cos_to_cbm[d->arch.psr_cos_ids[socket]].code; + *cbm = get_cdp_code(info, cos); break; case PSR_CBM_TYPE_L3_DATA: if ( !cdp_enabled ) - *cbm = info->cos_to_cbm[d->arch.psr_cos_ids[socket]].cbm; + *cbm = info->cos_reg_val[cos]; else - *cbm = info->cos_to_cbm[d->arch.psr_cos_ids[socket]].data; + *cbm = get_cdp_data(info, cos); break; default: @@ -408,7 +417,7 @@ static int write_l3_cbm(unsigned int socket, unsigned int cos, return 0; } -static int find_cos(struct psr_cat_cbm *map, unsigned int *ref, +static int find_cos(struct psr_cat_socket_info *info, unsigned int *ref, unsigned int cos_max, uint64_t cbm_code, uint64_t cbm_data, bool_t cdp_enabled) { @@ -417,9 +426,9 @@ static int find_cos(struct psr_cat_cbm *map, unsigned int *ref, for ( cos = 0; cos <= cos_max; cos++ ) { if ( (ref[cos] || cos == 0) && - ((!cdp_enabled && map[cos].cbm == cbm_code) || - (cdp_enabled && map[cos].code == cbm_code && - map[cos].data == cbm_data)) ) + ((!cdp_enabled && info->cos_reg_val[cos] == cbm_code) || + (cdp_enabled && get_cdp_code(info, cos) == cbm_code && + get_cdp_data(info, cos) == cbm_data)) ) return cos; } @@ -450,7 +459,6 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, int cos, ret; uint64_t cbm_data, cbm_code; bool_t cdp_enabled = cdp_is_enabled(socket); - struct psr_cat_cbm *map; struct psr_cat_socket_info *info = get_cat_socket_info(socket); unsigned int *ref; @@ -466,7 +474,6 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, cos_max = info->cos_max; old_cos = d->arch.psr_cos_ids[socket]; - map = info->cos_to_cbm; ref = info->cos_ref; switch ( type ) @@ -478,11 +485,11 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, case PSR_CBM_TYPE_L3_CODE: cbm_code = cbm; - cbm_data = map[old_cos].data; + cbm_data = get_cdp_data(info, old_cos); break; case PSR_CBM_TYPE_L3_DATA: - cbm_code = map[old_cos].code; + cbm_code = get_cdp_code(info, old_cos); cbm_data = cbm; break; @@ -492,7 +499,7 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, } spin_lock(&info->ref_lock); - cos = find_cos(map, ref, cos_max, cbm_code, cbm_data, cdp_enabled); + cos = find_cos(info, ref, cos_max, cbm_code, cbm_data, cdp_enabled); if ( cos >= 0 ) { if ( cos == old_cos ) @@ -512,8 +519,9 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, /* We try to avoid writing MSR. */ if ( (cdp_enabled && - (map[cos].code != cbm_code || map[cos].data != cbm_data)) || - (!cdp_enabled && map[cos].cbm != cbm_code) ) + (get_cdp_code(info, cos) != cbm_code || + get_cdp_data(info, cos) != cbm_data)) || + (!cdp_enabled && info->cos_reg_val[cos] != cbm_code) ) { ret = write_l3_cbm(socket, cos, cbm_code, cbm_data, cdp_enabled); if ( ret ) @@ -521,8 +529,8 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, spin_unlock(&info->ref_lock); return ret; } - map[cos].code = cbm_code; - map[cos].data = cbm_data; + get_cdp_code(info, cos) = cbm_code; + get_cdp_data(info, cos) = cbm_data; } } @@ -583,10 +591,7 @@ static int cat_cpu_prepare(unsigned int cpu) if ( !cat_socket_info ) return 0; - if ( temp_cos_to_cbm == NULL && - (temp_cos_to_cbm = xzalloc_array(struct psr_cat_cbm, - MAX_COS_REG_NUM)) == NULL ) - return -ENOMEM; + /* Keep this function for future usage. */ return 0; } @@ -615,10 +620,8 @@ static void cat_cpu_init(void) info->cbm_len = (eax & 0x1f) + 1; info->cos_max = min(opt_cos_max, edx & 0xffff); - info->cos_to_cbm = temp_cos_to_cbm; - temp_cos_to_cbm = NULL; /* cos=0 is reserved as default cbm(all ones). */ - info->cos_to_cbm[0].cbm = (1ull << info->cbm_len) - 1; + info->cos_reg_val[0] = (1ull << info->cbm_len) - 1; spin_lock_init(&info->ref_lock); @@ -627,8 +630,10 @@ static void cat_cpu_init(void) if ( (ecx & PSR_CAT_CDP_CAPABILITY) && (opt_psr & PSR_CDP) && cdp_socket_enable && !test_bit(socket, cdp_socket_enable) ) { - info->cos_to_cbm[0].code = (1ull << info->cbm_len) - 1; - info->cos_to_cbm[0].data = (1ull << info->cbm_len) - 1; + /* CODE */ + get_cdp_code(info, 0) = (1ull << info->cbm_len) - 1; + /* DATA */ + get_cdp_data(info, 0) = (1ull << info->cbm_len) - 1; /* We only write mask1 since mask0 is always all ones by default. */ wrmsrl(MSR_IA32_PSR_L3_MASK(1), (1ull << info->cbm_len) - 1); @@ -653,14 +658,6 @@ static void cat_cpu_fini(unsigned int cpu) if ( !socket_cpumask[socket] || cpumask_empty(socket_cpumask[socket]) ) { - struct psr_cat_socket_info *info = cat_socket_info + socket; - - if ( info->cos_to_cbm ) - { - xfree(info->cos_to_cbm); - info->cos_to_cbm = NULL; - } - if ( cdp_is_enabled(socket) ) clear_bit(socket, cdp_socket_enable);