From: Yi Sun <yi.y.sun@linux.intel.com>
To: xen-devel@lists.xenproject.org
Cc: wei.liu2@citrix.com, he.chen@linux.intel.com,
andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com,
Yi Sun <yi.y.sun@linux.intel.com>,
jbeulich@suse.com, chao.p.peng@linux.intel.com
Subject: [RFC 06/16] x86: implement init flow for MBA.
Date: Tue, 10 Jan 2017 15:42:25 +0800 [thread overview]
Message-ID: <1484034155-4521-7-git-send-email-yi.y.sun@linux.intel.com> (raw)
In-Reply-To: <1484034155-4521-1-git-send-email-yi.y.sun@linux.intel.com>
This patch implements init flow for MBA including its callback
functions.
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
---
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
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-01-10 7:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 7:42 [RFC 00/16] Enable Memory Bandwidth Allocation in Xen Yi Sun
2017-01-10 7:42 ` [RFC 01/16] docs: create Memory Bandwidth Allocation (MBA) feature document Yi Sun
2017-02-23 20:46 ` Meng Xu
2017-02-24 5:07 ` Yi Sun
2017-02-24 15:53 ` Meng Xu
2017-02-27 4:39 ` Yi Sun
2017-01-10 7:42 ` [RFC 02/16] Rename sysctl/domctl interface and xsm policy to make them general Yi Sun
2017-01-10 7:42 ` [RFC 03/16] x86: change 'cbm_type' to 'psr_val_type' to make it general Yi Sun
2017-01-10 7:42 ` [RFC 04/16] x86: implement data structure of MBA Yi Sun
2017-01-10 7:42 ` [RFC 05/16] x86: parse config parameters for MBA Yi Sun
2017-01-10 7:42 ` Yi Sun [this message]
2017-01-10 7:42 ` [RFC 07/16] x86: implement get hw info flow " Yi Sun
2017-01-10 7:42 ` [RFC 08/16] x86: implement get value " Yi Sun
2017-01-10 7:42 ` [RFC 09/16] x86: implement set " Yi Sun
2017-01-10 7:42 ` [RFC 10/16] tools: refactor codes to make get hw info interface be general Yi Sun
2017-01-10 7:42 ` [RFC 11/16] tools: refactor codes to make get val be more general Yi Sun
2017-01-10 7:42 ` [RFC 12/16] tools: refactor codes to make set " Yi Sun
2017-01-10 7:42 ` [RFC 13/16] tools: implemet get hw info flow for MBA Yi Sun
2017-01-10 7:42 ` [RFC 14/16] tools: implemet get value " Yi Sun
2017-01-10 7:42 ` [RFC 15/16] tools: implemet set " Yi Sun
2017-01-10 7:42 ` [RFC 16/16] docs: add MBA description in docs Yi Sun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1484034155-4521-7-git-send-email-yi.y.sun@linux.intel.com \
--to=yi.y.sun@linux.intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=chao.p.peng@linux.intel.com \
--cc=he.chen@linux.intel.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).