From: Dongxiao Xu <dongxiao.xu@intel.com>
To: xen-devel@lists.xen.org
Cc: keir@xen.org, Ian.Campbell@citrix.com,
stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com,
Ian.Jackson@eu.citrix.com, JBeulich@suse.com,
dgdegra@tycho.nsa.gov
Subject: [PATCH v10 3/6] x86: collect CQM information from all sockets
Date: Wed, 26 Mar 2014 14:35:19 +0800 [thread overview]
Message-ID: <1395815722-143165-4-git-send-email-dongxiao.xu@intel.com> (raw)
In-Reply-To: <1395815722-143165-1-git-send-email-dongxiao.xu@intel.com>
Collect CQM information (L3 cache occupancy) from all sockets.
Upper layer application can parse the data structure to get the
information of guest's L3 cache occupancy on certain sockets.
Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
Signed-off-by: Jiongxi Li <jiongxi.li@intel.com>
---
xen/arch/x86/pqos/cqm.c | 33 ++++++++++++++++++
xen/arch/x86/sysctl.c | 70 +++++++++++++++++++++++++++++++++++++++
xen/include/asm-x86/msr-index.h | 4 +++
xen/include/asm-x86/pqos.h | 6 ++++
xen/include/public/sysctl.h | 12 +++++++
5 files changed, 125 insertions(+)
diff --git a/xen/arch/x86/pqos/cqm.c b/xen/arch/x86/pqos/cqm.c
index 0f492a4..4913975 100644
--- a/xen/arch/x86/pqos/cqm.c
+++ b/xen/arch/x86/pqos/cqm.c
@@ -15,6 +15,7 @@
* more details.
*/
#include <asm/processor.h>
+#include <asm/msr.h>
#include <xen/init.h>
#include <xen/mm.h>
#include <xen/spinlock.h>
@@ -227,6 +228,38 @@ out:
spin_unlock(&cqm->cqm_lock);
}
+static void read_cqm_data(void *arg)
+{
+ uint64_t cqm_data;
+ unsigned int rmid;
+ int socket = cpu_to_socket(smp_processor_id());
+
+ ASSERT(system_supports_cqm());
+
+ if ( socket < 0 )
+ return;
+
+ for ( rmid = cqm->rmid_min; rmid <= cqm->rmid_max; rmid++ )
+ {
+ if ( cqm->rmid_to_dom[rmid] == DOMID_INVALID )
+ continue;
+
+ wrmsr(MSR_IA32_QOSEVTSEL, QOS_MONITOR_EVTID_L3, rmid);
+ rdmsrl(MSR_IA32_QMC, cqm_data);
+
+ if ( !(cqm_data & IA32_QM_CTR_ERROR_MASK) )
+ cqm->l3c[socket][rmid] = cqm_data * cqm->upscaling_factor;
+ }
+}
+
+void get_cqm_info(const cpumask_t *cpu_cqmdata_map)
+{
+ /* Read CQM data in current CPU */
+ read_cqm_data(NULL);
+ /* Issue IPI to other CPUs to read CQM data */
+ on_selected_cpus(cpu_cqmdata_map, read_cqm_data, NULL, 1);
+}
+
/*
* Local variables:
* mode: C
diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
index 15d4b91..30dcde3 100644
--- a/xen/arch/x86/sysctl.c
+++ b/xen/arch/x86/sysctl.c
@@ -28,6 +28,7 @@
#include <xen/nodemask.h>
#include <xen/cpu.h>
#include <xsm/xsm.h>
+#include <asm/pqos.h>
#define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)
@@ -66,6 +67,36 @@ void arch_do_physinfo(xen_sysctl_physinfo_t *pi)
pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm_directio;
}
+/* Select one random CPU for each socket. Current CPU's socket is excluded */
+static int select_socket_cpu(cpumask_t *cpu_bitmap)
+{
+ int i;
+ unsigned int cpu;
+ int socket, socket_curr = cpu_to_socket(smp_processor_id());
+ cpumask_var_t sockets;
+
+ if ( !zalloc_cpumask_var(&sockets) )
+ return -ENOMEM;
+
+ if ( socket_curr >= 0 )
+ set_bit(socket_curr, sockets);
+
+ cpumask_clear(cpu_bitmap);
+ for ( i = 0; i < NR_CPUS; i++ )
+ {
+ socket = cpu_to_socket(i);
+ if ( socket < 0 || test_and_set_bit(socket, sockets) )
+ continue;
+ cpu = cpumask_any(per_cpu(cpu_core_mask, i));
+ if ( cpu < nr_cpu_ids )
+ cpumask_set_cpu(cpu, cpu_bitmap);
+ }
+
+ free_cpumask_var(sockets);
+
+ return 0;
+}
+
long arch_do_sysctl(
struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
{
@@ -101,6 +132,45 @@ long arch_do_sysctl(
}
break;
+ case XEN_SYSCTL_getcqminfo:
+ {
+ struct cpuinfo_x86 *c = &boot_cpu_data;
+ cpumask_var_t cpu_cqmdata_map;
+
+ if ( !system_supports_cqm() )
+ {
+ ret = -ENODEV;
+ break;
+ }
+
+ if ( !zalloc_cpumask_var(&cpu_cqmdata_map) )
+ {
+ ret = -ENOMEM;
+ break;
+ }
+
+ ret = select_socket_cpu(cpu_cqmdata_map);
+ if ( ret < 0 )
+ {
+ free_cpumask_var(cpu_cqmdata_map);
+ break;
+ }
+
+ get_cqm_info(cpu_cqmdata_map);
+
+ sysctl->u.getcqminfo.socket_l3c_mfn = virt_to_mfn(cqm->socket_l3c_mfn);
+ sysctl->u.getcqminfo.rmid_dom_mfn = virt_to_mfn(cqm->rmid_to_dom);
+ sysctl->u.getcqminfo.nr_rmids = cqm->rmid_max + 1;
+ sysctl->u.getcqminfo.nr_sockets = cpumask_weight(cpu_cqmdata_map) + 1;
+ sysctl->u.getcqminfo.l3c_total = c->x86_cache_size;
+
+ if ( __copy_to_guest(u_sysctl, sysctl, 1) )
+ ret = -EFAULT;
+
+ free_cpumask_var(cpu_cqmdata_map);
+ }
+ break;
+
default:
ret = -ENOSYS;
break;
diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h
index ff86ed9..847aeb9 100644
--- a/xen/include/asm-x86/msr-index.h
+++ b/xen/include/asm-x86/msr-index.h
@@ -482,4 +482,8 @@
/* Geode defined MSRs */
#define MSR_GEODE_BUSCONT_CONF0 0x00001900
+/* Platform QoS register */
+#define MSR_IA32_QOSEVTSEL 0x00000c8d
+#define MSR_IA32_QMC 0x00000c8e
+
#endif /* __ASM_MSR_INDEX_H */
diff --git a/xen/include/asm-x86/pqos.h b/xen/include/asm-x86/pqos.h
index 01fa7f2..55b5187 100644
--- a/xen/include/asm-x86/pqos.h
+++ b/xen/include/asm-x86/pqos.h
@@ -17,6 +17,8 @@
#ifndef ASM_PQOS_H
#define ASM_PQOS_H
#include <xen/sched.h>
+#include <xen/cpumask.h>
+#include <public/domctl.h>
#include <public/xen.h>
#include <xen/spinlock.h>
@@ -27,6 +29,9 @@
/* QoS Monitoring Event ID */
#define QOS_MONITOR_EVTID_L3 0x1
+/* IA32_QM_CTR */
+#define IA32_QM_CTR_ERROR_MASK (0x3ul << 62)
+
struct pqos_cqm {
unsigned long rmid_mask;
unsigned int rmid_min;
@@ -52,5 +57,6 @@ void __init init_cqm(unsigned int rmid_max, unsigned long rmid_mask);
int alloc_cqm_rmid(struct domain *d);
void free_cqm_rmid(struct domain *d);
+void get_cqm_info(const cpumask_t *cpu_cqmdata_map);
#endif
diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
index 8ae6870..d2d9a64 100644
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -629,6 +629,16 @@ struct xen_sysctl_coverage_op {
typedef struct xen_sysctl_coverage_op xen_sysctl_coverage_op_t;
DEFINE_XEN_GUEST_HANDLE(xen_sysctl_coverage_op_t);
+struct xen_sysctl_getcqminfo {
+ uint64_aligned_t socket_l3c_mfn;
+ uint64_aligned_t rmid_dom_mfn;
+ uint32_t nr_rmids;
+ uint32_t nr_sockets;
+ uint32_t l3c_total;
+};
+typedef struct xen_sysctl_getcqminfo xen_sysctl_getcqminfo_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getcqminfo_t);
+
struct xen_sysctl {
uint32_t cmd;
@@ -651,6 +661,7 @@ struct xen_sysctl {
#define XEN_SYSCTL_cpupool_op 18
#define XEN_SYSCTL_scheduler_op 19
#define XEN_SYSCTL_coverage_op 20
+#define XEN_SYSCTL_getcqminfo 21
uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
union {
struct xen_sysctl_readconsole readconsole;
@@ -672,6 +683,7 @@ struct xen_sysctl {
struct xen_sysctl_cpupool_op cpupool_op;
struct xen_sysctl_scheduler_op scheduler_op;
struct xen_sysctl_coverage_op coverage_op;
+ struct xen_sysctl_getcqminfo getcqminfo;
uint8_t pad[128];
} u;
};
--
1.7.9.5
next prev parent reply other threads:[~2014-03-26 6:35 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-26 6:35 [PATCH v10 0/6] enable Cache QoS Monitoring (CQM) feature Dongxiao Xu
2014-03-26 6:35 ` [PATCH v10 1/6] x86: detect and initialize Cache QoS Monitoring feature Dongxiao Xu
2014-03-31 14:21 ` Jan Beulich
2014-03-31 15:33 ` Xu, Dongxiao
2014-03-31 15:42 ` Jan Beulich
2014-04-02 2:17 ` Xu, Dongxiao
2014-04-02 8:36 ` Jan Beulich
2014-04-02 12:40 ` Xu, Dongxiao
2014-04-02 14:48 ` Jan Beulich
2014-04-03 3:54 ` Xu, Dongxiao
2014-04-03 8:18 ` Jan Beulich
2014-04-03 8:27 ` Xu, Dongxiao
2014-04-03 8:46 ` Jan Beulich
2014-04-03 11:04 ` Xu, Dongxiao
2014-03-26 6:35 ` [PATCH v10 2/6] x86: dynamically attach/detach CQM service for a guest Dongxiao Xu
2014-04-02 15:24 ` Jan Beulich
2014-04-03 4:49 ` Xu, Dongxiao
2014-03-26 6:35 ` Dongxiao Xu [this message]
2014-04-02 15:35 ` [PATCH v10 3/6] x86: collect CQM information from all sockets Jan Beulich
2014-03-26 6:35 ` [PATCH v10 4/6] x86: enable CQM monitoring for each domain RMID Dongxiao Xu
2014-03-26 6:35 ` [PATCH v10 5/6] xsm: add platform QoS related xsm policies Dongxiao Xu
2014-03-26 6:35 ` [PATCH v10 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc Dongxiao Xu
2014-03-27 15:13 ` Ian Campbell
2014-03-28 0:53 ` Xu, Dongxiao
2014-03-28 9:43 ` Ian Campbell
2014-04-03 11:31 ` Xu, Dongxiao
2014-04-03 12:52 ` Ian Campbell
-- strict thread matches above, loose matches on Subject: below --
2014-04-03 11:21 [PATCH v10 3/6] x86: collect CQM information from all sockets Xu, Dongxiao
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=1395815722-143165-4-git-send-email-dongxiao.xu@intel.com \
--to=dongxiao.xu@intel.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=dgdegra@tycho.nsa.gov \
--cc=keir@xen.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.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).