From patchwork Tue Oct 25 03:40:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Sun X-Patchwork-Id: 9393899 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 6F45560762 for ; Tue, 25 Oct 2016 02:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 628A52927B for ; Tue, 25 Oct 2016 02:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 561DB29282; Tue, 25 Oct 2016 02:36:19 +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 9524F2927B for ; Tue, 25 Oct 2016 02:36:18 +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 1byrYf-0004Gm-Rn; Tue, 25 Oct 2016 02:33:45 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byrYf-0004Gb-2G for xen-devel@lists.xenproject.org; Tue, 25 Oct 2016 02:33:45 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 04/B5-28857-884CE085; Tue, 25 Oct 2016 02:33:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrHLMWRWlGSWpSXmKPExsVywNykWLf9CF+ EweVrmhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8aUDzkFuwwrll/YwdrAeEq5i5GTQ0igQuJr z2ImEFtCgFfiyLIZrBB2gET/52nMXYxcQDUNjBKduyeCFbEJqEs8/toDZosIKEncWzWZCaSIW WA/o8Svl49ZQBLCArYSZ89+YAOxWQRUJVY23mUHsXkF3CUe3tzCArFBTuLksclg2zgFPCTu7D 3ODnGRu0RfQxPjBEbeBYwMqxg1ilOLylKLdA3N9ZKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpO K9ZLzczcxAsOBAQh2MN7eGHCIUZKDSUmUd+YmvgghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErzr DwPlBItS01Mr0jJzgIEJk5bg4FES4X0CkuYtLkjMLc5Mh0idYlSUEuddBJIQAElklObBtcGi4 RKjrJQwLyPQIUI8BalFuZklqPKvGMU5GJWEeV+ATOHJzCuBm/4KaDET0GLBeB6QxSWJCCmpBk bu6UEpvvsUWgo6eGbNy1GYZDYjuNAw48qReb/EWPV0JC0ct6g2fJKf8izsVeqy64rXXumfjFj w6tuO3WYO72+Vqocb/WlqqmXme/V7i9V6c8EZbT91Hp0R43Gy1xdrWHhf6twsd/Hw8ub7gSsu 95f/O5TSe1pgFvu/aUf17/up1RZEibkqyiqxFGckGmoxFxUnAgAUzB20gQIAAA== X-Env-Sender: yi.y.sun@linux.intel.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1477362814!54875270!3 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 49559 invoked from network); 25 Oct 2016 02:33:43 -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:43 -0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 24 Oct 2016 19:33:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.31,544,1473145200"; d="scan'208"; a="1049570072" Received: from vmmmba-s2600wft.bj.intel.com ([10.240.193.60]) by orsmga001.jf.intel.com with ESMTP; 24 Oct 2016 19:33:41 -0700 From: Yi Sun To: xen-devel@lists.xenproject.org Date: Tue, 25 Oct 2016 11:40:50 +0800 Message-Id: <1477366863-5246-3-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 02/15] x86: refactor psr: Split 'ref' out. 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 'ref' in 'struct psr_cat_cbm' is used as a reference count for one COS register. It doesn't relate to cbm. So, it can be splitted out. This patch removes 'ref' from 'struct psr_cat_cbm' and creates a 'cos_ref' array to manage reference counts of all COS registers. It also renames the 'cbm_lock' to 'ref_lock' because this lock is used to protect the reference count. Signed-off-by: Yi Sun --- xen/arch/x86/psr.c | 55 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 0b5073c..ee20389 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -23,6 +23,9 @@ #define PSR_CAT (1<<1) #define PSR_CDP (1<<2) +/* Per spec, the maximum COS register number is 128. */ +#define MAX_COS_REG_NUM 128 + struct psr_cat_cbm { union { uint64_t cbm; @@ -31,14 +34,19 @@ struct psr_cat_cbm { uint64_t data; }; }; - unsigned int ref; }; struct psr_cat_socket_info { unsigned int cbm_len; unsigned int cos_max; struct psr_cat_cbm *cos_to_cbm; - spinlock_t cbm_lock; + /* + * Every entry of cos_ref is the reference count of a COS register. + * One entry of cos_ref corresponds to one COS ID. + */ + unsigned int cos_ref[MAX_COS_REG_NUM]; + /* Protect cos_ref */ + spinlock_t ref_lock; }; struct psr_assoc { @@ -54,7 +62,7 @@ static unsigned long *__read_mostly cdp_socket_enable; static unsigned int opt_psr; static unsigned int __initdata opt_rmid_max = 255; -static unsigned int __read_mostly opt_cos_max = 255; +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); @@ -400,14 +408,15 @@ static int write_l3_cbm(unsigned int socket, unsigned int cos, return 0; } -static int find_cos(struct psr_cat_cbm *map, unsigned int cos_max, +static int find_cos(struct psr_cat_cbm *map, unsigned int *ref, + unsigned int cos_max, uint64_t cbm_code, uint64_t cbm_data, bool_t cdp_enabled) { unsigned int cos; for ( cos = 0; cos <= cos_max; cos++ ) { - if ( (map[cos].ref || cos == 0) && + if ( (ref[cos] || cos == 0) && ((!cdp_enabled && map[cos].cbm == cbm_code) || (cdp_enabled && map[cos].code == cbm_code && map[cos].data == cbm_data)) ) @@ -417,18 +426,18 @@ static int find_cos(struct psr_cat_cbm *map, unsigned int cos_max, return -ENOENT; } -static int pick_avail_cos(struct psr_cat_cbm *map, unsigned int cos_max, +static int pick_avail_cos(unsigned int *ref, unsigned int cos_max, unsigned int old_cos) { unsigned int cos; /* If old cos is referred only by the domain, then use it. */ - if ( map[old_cos].ref == 1 && old_cos != 0 ) + if ( ref[old_cos] == 1 && old_cos != 0 ) return old_cos; /* Find an unused one other than cos0. */ for ( cos = 1; cos <= cos_max; cos++ ) - if ( map[cos].ref == 0 ) + if ( ref[cos] == 0 ) return cos; return -ENOENT; @@ -443,6 +452,7 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, 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; if ( IS_ERR(info) ) return PTR_ERR(info); @@ -457,6 +467,7 @@ 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 ) { @@ -480,22 +491,22 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, return -EINVAL; } - spin_lock(&info->cbm_lock); - cos = find_cos(map, cos_max, cbm_code, cbm_data, cdp_enabled); + spin_lock(&info->ref_lock); + cos = find_cos(map, ref, cos_max, cbm_code, cbm_data, cdp_enabled); if ( cos >= 0 ) { if ( cos == old_cos ) { - spin_unlock(&info->cbm_lock); + spin_unlock(&info->ref_lock); return 0; } } else { - cos = pick_avail_cos(map, cos_max, old_cos); + cos = pick_avail_cos(ref, cos_max, old_cos); if ( cos < 0 ) { - spin_unlock(&info->cbm_lock); + spin_unlock(&info->ref_lock); return cos; } @@ -507,7 +518,7 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, ret = write_l3_cbm(socket, cos, cbm_code, cbm_data, cdp_enabled); if ( ret ) { - spin_unlock(&info->cbm_lock); + spin_unlock(&info->ref_lock); return ret; } map[cos].code = cbm_code; @@ -515,9 +526,9 @@ int psr_set_l3_cbm(struct domain *d, unsigned int socket, } } - map[cos].ref++; - map[old_cos].ref--; - spin_unlock(&info->cbm_lock); + ref[cos]++; + ref[old_cos]--; + spin_unlock(&info->ref_lock); d->arch.psr_cos_ids[socket] = cos; @@ -540,9 +551,9 @@ static void psr_free_cos(struct domain *d) continue; info = cat_socket_info + socket; - spin_lock(&info->cbm_lock); - info->cos_to_cbm[cos].ref--; - spin_unlock(&info->cbm_lock); + spin_lock(&info->ref_lock); + info->cos_ref[cos]--; + spin_unlock(&info->ref_lock); } xfree(d->arch.psr_cos_ids); @@ -574,7 +585,7 @@ static int cat_cpu_prepare(unsigned int cpu) if ( temp_cos_to_cbm == NULL && (temp_cos_to_cbm = xzalloc_array(struct psr_cat_cbm, - opt_cos_max + 1UL)) == NULL ) + MAX_COS_REG_NUM)) == NULL ) return -ENOMEM; return 0; @@ -609,7 +620,7 @@ static void cat_cpu_init(void) /* cos=0 is reserved as default cbm(all ones). */ info->cos_to_cbm[0].cbm = (1ull << info->cbm_len) - 1; - spin_lock_init(&info->cbm_lock); + spin_lock_init(&info->ref_lock); set_bit(socket, cat_socket_enable);