Skip to contentSkip to conversation

enable Cache QoS Monitoring (CQM) feature

PATCH Superseded Dongxiao Xu 2 participants 11 messages Feb 8, 2014 – Feb 18, 2014

v8 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v8 cover enable Cache QoS Monitoring (CQM) feature

Changes from v7:
- Address comments from Andrew Cooper, including:
* Check CQM capability before allocating cpumask memory.
* Move one function declaration into the correct patch.

Changes from v6:
- Address comments from Jan Beulich, including:
* Remove the unnecessary CPUID feature check.
* Remove the unnecessary socket_cpu_map.
* Spin_lock related changes, avoid spin_lock_irqsave().
* Use readonly mapping to pass cqm data between Xen/Userspace, to avoid data copying.
* Optimize RDMSR/WRMSR logic to avoid unnecessary calls.
* Misc fixes including __read_mostly prefix, return value, etc.

Changes from v5:
- Address comments from Dario Faggioli, including:
* Define a new libxl_cqminfo structure to avoid reference of xc structure in libxl functions.
* Use LOGE() instead of the LIBXL__LOG() functions.

Changes from v4:
- When comparing xl cqm parameter, use strcmp instead of strncmp, otherwise, "xl pqos-attach cqmabcd domid" will be considered as a valid command line.
- Address comments from Andrew Cooper, including:
* Adjust the pqos parameter parsing function.
* Modify the pqos related documentation.
* Add a check for opt_cqm_max_rmid in initialization code.
* Do not IPI CPU that is in same socket with current CPU.
- Address comments from Dario Faggioli, including:
* Fix an typo in export symbols.
* Return correct libxl error code for qos related functions.
* Abstract the error printing logic into a function.
- Address comment from Daniel De Graaf, including:
* Add return value in for pqos related check.
- Address comments from Konrad Rzeszutek Wilk, including:
* Modify the GPLv2 related file header, remove the address.

Changes from v3:
- Use structure to better organize CQM related global variables.
- Address comments from Andrew Cooper, including:
* Remove the domain creation flag for CQM RMID allocation.
* Adjust the boot parameter format, use custom_param().
* Add documentation for the new added boot parameter.
* Change QoS type flag to be uint64_t.
* Initialize the per socket cpu bitmap in system boot time.
* Remove get_cqm_avail() function.
* Misc of format changes.
- Address comment from Daniel De Graaf, including:
* Use avc_current_has_perm() for XEN2__PQOS_OP that belongs to SECCLASS_XEN2.

Changes from v2:
- Address comments from Andrew Cooper, including:
* Merging tools stack changes into one patch.
* Reduce the IPI number to one per socket.
* Change structures for CQM data exchange between tools and Xen.
* Misc of format/variable/function name changes.
- Address comments from Konrad Rzeszutek Wilk, including:
* Simplify the error printing logic.
* Add xsm check for the new added hypercalls.

Changes from v1:
- Address comments from Andrew Cooper, including:
* Change function names, e.g., alloc_cqm_rmid(), system_supports_cqm(), etc.
* Change some structure element order to save packing cost.
* Correct some function's return value.
* Some programming styles change.
* ...

Future generations of Intel Xeon processor may offer monitoring capability in each logical processor to measure specific quality-of-service metric, for example, the Cache QoS Monitoring to get L3 cache occupancy. Detailed information please refer to Intel SDM chapter 17.14.

Cache QoS Monitoring provides a layer of abstraction between applications and logical processors through the use of Resource Monitoring IDs (RMIDs). In Xen design, each guest in the system can be assigned an RMID independently, while RMID=0 is reserved for monitoring domains that doesn't enable CQM service. When any of the domain's vcpu is scheduled on a logical processor, the domain's RMID will be activated by programming the value into one specific MSR, and when the vcpu is scheduled out, a RMID=0 will be programmed into that MSR. The Cache QoS Hardware tracks cache utilization of memory accesses according to the RMIDs and reports monitored data via a counter register. With this solution, we can get the knowledge how much L3 cache is used by a certain guest.

To attach CQM service to a certain guest, two approaches are provided:
1) Create the guest with "pqos_cqm=1" set in configuration file.
2) Use "xl pqos-attach cqm domid" for a running guest.

To detached CQM service from a guest, users can:
1) Use "xl pqos-detach cqm domid" for a running guest.
2) Also destroying a guest will detach the CQM service.

To get the L3 cache usage, users can use the command of:

$ xl pqos-list cqm

The below data is just an example showing how the CQM related data is exposed to end user.

[root@localhost]# xl pqos-list cqm
Name               ID  SocketID        L3C_Usage       SocketID        L3C_Usage
Domain-0            0         0         20127744              1         25231360
ExampleHVMDomain    1         0          3211264              1         10551296

RMID count 56 RMID available 53

Dongxiao Xu (6):
x86: detect and initialize Cache QoS Monitoring feature
x86: dynamically attach/detach CQM service for a guest
x86: collect CQM information from all sockets
x86: enable CQM monitoring for each domain RMID
xsm: add platform QoS related xsm policies
tools: enable Cache QoS Monitoring feature for libxl/libxc

 docs/misc/xen-command-line.markdown          |    7 +
 tools/flask/policy/policy/modules/xen/xen.if |    2 +-
 tools/flask/policy/policy/modules/xen/xen.te |    5 +-
 tools/libxc/xc_domain.c                      |   37 ++++
 tools/libxc/xenctrl.h                        |   12 ++
 tools/libxl/Makefile                         |    3 +-
 tools/libxl/libxl.h                          |    4 +
 tools/libxl/libxl_pqos.c                     |  132 +++++++++++++
 tools/libxl/libxl_types.idl                  |    7 +
 tools/libxl/xl.h                             |    3 +
 tools/libxl/xl_cmdimpl.c                     |  111 +++++++++++
 tools/libxl/xl_cmdtable.c                    |   15 ++
 xen/arch/x86/Makefile                        |    1 +
 xen/arch/x86/domain.c                        |    8 +
 xen/arch/x86/domctl.c                        |   28 +++
 xen/arch/x86/pqos.c                          |  273 ++++++++++++++++++++++++++
 xen/arch/x86/setup.c                         |    3 +
 xen/arch/x86/sysctl.c                        |   58 ++++++
 xen/include/asm-x86/cpufeature.h             |    1 +
 xen/include/asm-x86/domain.h                 |    2 +
 xen/include/asm-x86/msr-index.h              |    5 +
 xen/include/asm-x86/pqos.h                   |   59 ++++++
 xen/include/public/domctl.h                  |   11 ++
 xen/include/public/sysctl.h                  |   11 ++
 xen/xsm/flask/hooks.c                        |    8 +
 xen/xsm/flask/policy/access_vectors          |   17 +-
 26 files changed, 817 insertions(+), 6 deletions(-)
 create mode 100644 tools/libxl/libxl_pqos.c
 create mode 100644 xen/arch/x86/pqos.c
 create mode 100644 xen/include/asm-x86/pqos.h
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v8 1/6 x86: detect and initialize Cache QoS Monitoring feature

Detect platform QoS feature status and enumerate the resource types, one of which is to monitor the L3 cache occupancy.

Also introduce a Xen grub command line parameter to control the QoS feature status.

---
 docs/misc/xen-command-line.markdown |    7 ++
 xen/arch/x86/Makefile               |    1 +
 xen/arch/x86/pqos.c                 |  156 +++++++++++++++++++++++++++++++++++
 xen/arch/x86/setup.c                |    3 +
 xen/include/asm-x86/cpufeature.h    |    1 +
 xen/include/asm-x86/pqos.h          |   43 ++++++++++
 6 files changed, 211 insertions(+)
 create mode 100644 xen/arch/x86/pqos.c
 create mode 100644 xen/include/asm-x86/pqos.h
docs/misc/xen-command-line.markdown +7 -0
index 15aa404..7751ffe 100644
@@ -770,6 +770,13 @@ This option can be specified more than once (up to 8 times at present).
 ### ple\_window
 > `= <integer>`
 
+### pqos (Intel)
+> `= List of ( <boolean> | cqm:<boolean> | cqm_max_rmid:<integer> )`
+
+> Default: `pqos=1,cqm:1,cqm_max_rmid:255`
+
+Configure platform QoS services.
+
 ### reboot
 > `= t[riple] | k[bd] | n[o] [, [w]arm | [c]old]`
 
xen/arch/x86/Makefile +1 -0
index d502bdf..54962e0 100644
@@ -58,6 +58,7 @@ obj-y += crash.o
 obj-y += tboot.o
 obj-y += hpet.o
 obj-y += xstate.o
+obj-y += pqos.o
 
 obj-$(crash_debug) += gdbstub.o
 
xen/arch/x86/pqos.c new file +156 -0

156 lines not on this page · raw message

xen/arch/x86/setup.c +3 -0
index b49256d..639528f 100644
@@ -48,6 +48,7 @@
 #include <asm/setup.h>
 #include <xen/cpu.h>
 #include <asm/nmi.h>
+#include <asm/pqos.h>
 
 /* opt_nosmp: If true, secondary processors are ignored. */
 static bool_t __initdata opt_nosmp;
@@ -1419,6 +1420,8 @@ void __init __start_xen(unsigned long mbi_p)
 
     domain_unpause_by_systemcontroller(dom0);
 
+    init_platform_qos();
+
     reset_stack_and_jump(init_done);
 }
 
xen/include/asm-x86/cpufeature.h +1 -0
index 1cfaf94..ca59668 100644
@@ -147,6 +147,7 @@
 #define X86_FEATURE_ERMS	(7*32+ 9) /* Enhanced REP MOVSB/STOSB */
 #define X86_FEATURE_INVPCID	(7*32+10) /* Invalidate Process Context ID */
 #define X86_FEATURE_RTM 	(7*32+11) /* Restricted Transactional Memory */
+#define X86_FEATURE_QOSM	(7*32+12) /* Platform QoS monitoring capability */
 #define X86_FEATURE_NO_FPU_SEL 	(7*32+13) /* FPU CS/DS stored as zero */
 #define X86_FEATURE_SMAP	(7*32+20) /* Supervisor Mode Access Prevention */
 
xen/include/asm-x86/pqos.h new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v8 2/6 x86: dynamically attach/detach CQM service for a guest

In reply to Dongxiao Xu

Add hypervisor side support for dynamically attach and detach CQM services for a certain guest.

When attach CQM service for a guest, system will allocate an RMID for it. When detach or guest is shutdown, the RMID will be retrieved back for future use.

---
 xen/arch/x86/domain.c        |    3 +++
 xen/arch/x86/domctl.c        |   28 ++++++++++++++++++++
 xen/arch/x86/pqos.c          |   60 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/domain.h |    2 ++
 xen/include/asm-x86/pqos.h   |   12 +++++++++
 xen/include/public/domctl.h  |   11 ++++++++
 6 files changed, 116 insertions(+)
xen/arch/x86/domain.c +3 -0
index 16f2b50..2656204 100644
@@ -60,6 +60,7 @@
 #include <xen/numa.h>
 #include <xen/iommu.h>
 #include <compat/vcpu.h>
+#include <asm/pqos.h>
 
 DEFINE_PER_CPU(struct vcpu *, curr_vcpu);
 DEFINE_PER_CPU(unsigned long, cr4);
@@ -612,6 +613,8 @@ void arch_domain_destroy(struct domain *d)
 
     free_xenheap_page(d->shared_info);
     cleanup_domain_irq_mapping(d);
+
+    free_cqm_rmid(d);
 }
 
 unsigned long pv_guest_cr4_fixup(const struct vcpu *v, unsigned long guest_cr4)
xen/arch/x86/domctl.c +28 -0
index ef6c140..7219011 100644
@@ -35,6 +35,7 @@
 #include <asm/mem_sharing.h>
 #include <asm/xstate.h>
 #include <asm/debugger.h>
+#include <asm/pqos.h>
 
 static int gdbsx_guest_mem_io(
     domid_t domid, struct xen_domctl_gdbsx_memio *iop)
@@ -1245,6 +1246,33 @@ long arch_do_domctl(
     }
     break;
 
+    case XEN_DOMCTL_attach_pqos:
+    {
+        if ( !(domctl->u.qos_type.flags & XEN_DOMCTL_pqos_cqm) )
+            ret = -EINVAL;
+        else if ( !system_supports_cqm() )
+            ret = -ENODEV;
+        else
+            ret = alloc_cqm_rmid(d);
+    }
+    break;
+
+    case XEN_DOMCTL_detach_pqos:
+    {
+        if ( !(domctl->u.qos_type.flags & XEN_DOMCTL_pqos_cqm) )
+            ret = -EINVAL;
+        else if ( !system_supports_cqm() )
+            ret = -ENODEV;
+        else if ( d->arch.pqos_cqm_rmid > 0 )
+        {
+            free_cqm_rmid(d);
+            ret = 0;
+        }
+        else
+            ret = -ENOENT;
+    }
+    break;
+
     default:
         ret = iommu_do_domctl(domctl, d, u_domctl);
         break;
xen/arch/x86/pqos.c +60 -0

72 lines not on this page · raw message

xen/include/asm-x86/domain.h +2 -0
index ea72db2..662714d 100644
@@ -313,6 +313,8 @@ struct arch_domain
     spinlock_t e820_lock;
     struct e820entry *e820;
     unsigned int nr_e820;
+
+    unsigned int pqos_cqm_rmid;       /* CQM RMID assigned to the domain */
 } __cacheline_aligned;
 
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))
xen/include/asm-x86/pqos.h +12 -0
index 0a8065c..f25037d 100644
@@ -16,6 +16,7 @@
  */
 #ifndef ASM_PQOS_H
 #define ASM_PQOS_H
+#include <xen/sched.h>
 
 #include <public/xen.h>
 #include <xen/spinlock.h>
@@ -38,6 +39,17 @@ struct pqos_cqm {
 };
 extern struct pqos_cqm *cqm;
 
+static inline bool_t system_supports_cqm(void)
+{
+    return !!cqm;
+}
+
+/* IA32_QM_CTR */
+#define IA32_QM_CTR_ERROR_MASK         (0x3ul << 62)
+
 void init_platform_qos(void);
 
+int alloc_cqm_rmid(struct domain *d);
+void free_cqm_rmid(struct domain *d);
+
 #endif
xen/include/public/domctl.h +11 -0
index 91f01fa..f8d9293 100644
@@ -885,6 +885,14 @@ struct xen_domctl_set_max_evtchn {
 typedef struct xen_domctl_set_max_evtchn xen_domctl_set_max_evtchn_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_set_max_evtchn_t);
 
+struct xen_domctl_qos_type {
+#define _XEN_DOMCTL_pqos_cqm      0
+#define XEN_DOMCTL_pqos_cqm       (1U<<_XEN_DOMCTL_pqos_cqm)
+    uint64_t flags;
+};
+typedef struct xen_domctl_qos_type xen_domctl_qos_type_t;
+DEFINE_XEN_GUEST_HANDLE(xen_domctl_qos_type_t);
+
 struct xen_domctl {
     uint32_t cmd;
 #define XEN_DOMCTL_createdomain                   1
@@ -954,6 +962,8 @@ struct xen_domctl {
 #define XEN_DOMCTL_setnodeaffinity               68
 #define XEN_DOMCTL_getnodeaffinity               69
 #define XEN_DOMCTL_set_max_evtchn                70
+#define XEN_DOMCTL_attach_pqos                   71
+#define XEN_DOMCTL_detach_pqos                   72
 #define XEN_DOMCTL_gdbsx_guestmemio            1000
 #define XEN_DOMCTL_gdbsx_pausevcpu             1001
 #define XEN_DOMCTL_gdbsx_unpausevcpu           1002
@@ -1014,6 +1024,7 @@ struct xen_domctl {
         struct xen_domctl_set_broken_page_p2m set_broken_page_p2m;
         struct xen_domctl_gdbsx_pauseunp_vcpu gdbsx_pauseunp_vcpu;
         struct xen_domctl_gdbsx_domstatus   gdbsx_domstatus;
+        struct xen_domctl_qos_type          qos_type;
         uint8_t                             pad[128];
     } u;
 };
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v8 3/6 x86: collect CQM information from all sockets

In reply to Dongxiao Xu

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.

---
 xen/arch/x86/pqos.c             |   43 +++++++++++++++++++++++++++++
 xen/arch/x86/sysctl.c           |   58 +++++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/msr-index.h |    4 +++
 xen/include/asm-x86/pqos.h      |    3 ++
 xen/include/public/sysctl.h     |   11 ++++++++
 5 files changed, 119 insertions(+)
xen/arch/x86/pqos.c +43 -0
index eb469ac..2cde56e 100644
@@ -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>
@@ -205,6 +206,48 @@ 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());
+    unsigned long i;
+
+    ASSERT(system_supports_cqm());
+
+    if ( socket < 0 )
+        return;
+
+    for ( rmid = cqm->min_rmid; rmid <= cqm->max_rmid; 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);
+
+        i = (unsigned long)(cqm->max_rmid + 1) * socket + rmid;
+        if ( !(cqm_data & IA32_QM_CTR_ERROR_MASK) )
+            cqm->buffer[i] = cqm_data * cqm->upscaling_factor;
+    }
+}
+
+void get_cqm_info(const cpumask_t *cpu_cqmdata_map)
+{
+    unsigned int nr_sockets = cpumask_weight(cpu_cqmdata_map) + 1;
+    unsigned int nr_rmids = cqm->max_rmid + 1;
+
+    /* 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);
+
+    /* Copy the rmid_to_dom info to the buffer */
+    memcpy(cqm->buffer + nr_sockets * nr_rmids, cqm->rmid_to_dom,
+           sizeof(domid_t) * (cqm->max_rmid + 1));
+
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/sysctl.c +58 -0

76 lines not on this page · raw message

xen/include/asm-x86/msr-index.h +4 -0
index fc9fbc6..e3ff10c 100644
@@ -489,4 +489,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 */
xen/include/asm-x86/pqos.h +3 -0
index f25037d..4372af6 100644
@@ -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>
@@ -51,5 +53,6 @@ void init_platform_qos(void);
 
 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
xen/include/public/sysctl.h +11 -0
index 8437d31..335b1d9 100644
@@ -632,6 +632,15 @@ 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 buffer_mfn;
+    uint32_t size;
+    uint32_t nr_rmids;
+    uint32_t nr_sockets;
+};
+typedef struct xen_sysctl_getcqminfo xen_sysctl_getcqminfo_t;
+DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getcqminfo_t);
+
 
 struct xen_sysctl {
     uint32_t cmd;
@@ -654,6 +663,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;
@@ -675,6 +685,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;
 };
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v8 4/6 x86: enable CQM monitoring for each domain RMID

In reply to Dongxiao Xu

If the CQM service is attached to a domain, its related RMID will be set to hardware for monitoring when the domain's vcpu is scheduled in. When the domain's vcpu is scheduled out, RMID 0 (system reserved) will be set for monitoring.

---
 xen/arch/x86/domain.c           |    5 +++++
 xen/arch/x86/pqos.c             |   14 ++++++++++++++
 xen/include/asm-x86/msr-index.h |    1 +
 xen/include/asm-x86/pqos.h      |    1 +
 4 files changed, 21 insertions(+)
xen/arch/x86/domain.c +5 -0
index 2656204..9eeedf0 100644
@@ -1372,6 +1372,8 @@ static void __context_switch(void)
     {
         memcpy(&p->arch.user_regs, stack_regs, CTXT_SWITCH_STACK_BYTES);
         vcpu_save_fpu(p);
+        if ( system_supports_cqm() && cqm->used_rmid )
+            cqm_assoc_rmid(0);
         p->arch.ctxt_switch_from(p);
     }
 
@@ -1396,6 +1398,9 @@ static void __context_switch(void)
         }
         vcpu_restore_fpu_eager(n);
         n->arch.ctxt_switch_to(n);
+
+        if ( system_supports_cqm() && n->domain->arch.pqos_cqm_rmid > 0 )
+            cqm_assoc_rmid(n->domain->arch.pqos_cqm_rmid);
     }
 
     gdt = !is_pv_32on64_vcpu(n) ? per_cpu(gdt_table, cpu) :
xen/arch/x86/pqos.c +14 -0
index 2cde56e..7369e10 100644
@@ -62,6 +62,7 @@ static void __init parse_pqos_param(char *s)
 custom_param("pqos", parse_pqos_param);
 
 struct pqos_cqm __read_mostly *cqm = NULL;
+static uint64_t __read_mostly rmid_mask;
 
 static void __init init_cqm(void)
 {
@@ -135,6 +136,8 @@ static void __init init_qos_monitor(void)
 
     cpuid_count(0xf, 0, &eax, &ebx, &ecx, &qm_features);
 
+    rmid_mask = ~(~0ull << get_count_order(ebx));
+
     if ( opt_cqm && (qm_features & QOS_MONITOR_TYPE_L3) )
         init_cqm();
 }
@@ -248,6 +251,17 @@ void get_cqm_info(const cpumask_t *cpu_cqmdata_map)
 
 }
 
+void cqm_assoc_rmid(unsigned int rmid)
+{
+    uint64_t val;
+    uint64_t new_val;
+
+    rdmsrl(MSR_IA32_PQR_ASSOC, val);
+    new_val = (val & ~rmid_mask) | (rmid & rmid_mask);
+    if ( val != new_val )
+        wrmsrl(MSR_IA32_PQR_ASSOC, new_val);
+}
+
 /*
  * Local variables:
  * mode: C
xen/include/asm-x86/msr-index.h +1 -0
index e3ff10c..13800e6 100644
@@ -492,5 +492,6 @@
 /* Platform QoS register */
 #define MSR_IA32_QOSEVTSEL             0x00000c8d
 #define MSR_IA32_QMC                   0x00000c8e
+#define MSR_IA32_PQR_ASSOC             0x00000c8f
 
 #endif /* __ASM_MSR_INDEX_H */
xen/include/asm-x86/pqos.h +1 -0
index 4372af6..87820d5 100644
@@ -54,5 +54,6 @@ void init_platform_qos(void);
 int alloc_cqm_rmid(struct domain *d);
 void free_cqm_rmid(struct domain *d);
 void get_cqm_info(const cpumask_t *cpu_cqmdata_map);
+void cqm_assoc_rmid(unsigned int rmid);
 
 #endif
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v8 5/6 xsm: add platform QoS related xsm policies

In reply to Dongxiao Xu

Add xsm policies for attach/detach pqos services and get CQM info hypercalls.

---
 tools/flask/policy/policy/modules/xen/xen.if |    2 +-
 tools/flask/policy/policy/modules/xen/xen.te |    5 ++++-
 xen/xsm/flask/hooks.c                        |    8 ++++++++
 xen/xsm/flask/policy/access_vectors          |   17 ++++++++++++++---
 4 files changed, 27 insertions(+), 5 deletions(-)
tools/flask/policy/policy/modules/xen/xen.if +1 -1
index dedc035..1f683af 100644
@@ -49,7 +49,7 @@ define(`create_domain_common', `
 			getdomaininfo hypercall setvcpucontext setextvcpucontext
 			getscheduler getvcpuinfo getvcpuextstate getaddrsize
 			getaffinity setaffinity };
-	allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim  set_max_evtchn };
+	allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim set_max_evtchn pqos_op };
 	allow $1 $2:security check_context;
 	allow $1 $2:shadow enable;
 	allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op };
tools/flask/policy/policy/modules/xen/xen.te +4 -1
index bb59fe8..115fcfe 100644
@@ -64,6 +64,9 @@ allow dom0_t xen_t:xen {
 	getidle debug getcpuinfo heap pm_op mca_op lockprof cpupool_op tmem_op
 	tmem_control getscheduler setscheduler
 };
+allow dom0_t xen_t:xen2 {
+	pqos_op
+};
 allow dom0_t xen_t:mmu memorymap;
 
 # Allow dom0 to use these domctls on itself. For domctls acting on other
@@ -76,7 +79,7 @@ allow dom0_t dom0_t:domain {
 	getpodtarget setpodtarget set_misc_info set_virq_handler
 };
 allow dom0_t dom0_t:domain2 {
-	set_cpuid gettsc settsc setscheduler set_max_evtchn
+	set_cpuid gettsc settsc setscheduler set_max_evtchn pqos_op
 };
 allow dom0_t dom0_t:resource { add remove };
 
xen/xsm/flask/hooks.c +8 -0
index 7cdef04..6ee7771 100644
@@ -730,6 +730,10 @@ static int flask_domctl(struct domain *d, int cmd)
     case XEN_DOMCTL_set_max_evtchn:
         return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__SET_MAX_EVTCHN);
 
+    case XEN_DOMCTL_attach_pqos:
+    case XEN_DOMCTL_detach_pqos:
+        return current_has_perm(d, SECCLASS_DOMAIN2, DOMAIN2__PQOS_OP);
+
     default:
         printk("flask_domctl: Unknown op %d\n", cmd);
         return -EPERM;
@@ -785,6 +789,10 @@ static int flask_sysctl(int cmd)
     case XEN_SYSCTL_numainfo:
         return domain_has_xen(current->domain, XEN__PHYSINFO);
 
+    case XEN_SYSCTL_getcqminfo:
+        return avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2,
+                                    XEN2__PQOS_OP, NULL);
+
     default:
         printk("flask_sysctl: Unknown op %d\n", cmd);
         return -EPERM;
xen/xsm/flask/policy/access_vectors +14 -3
index 1fbe241..91af8b2 100644
@@ -3,9 +3,9 @@
 #
 # class class_name { permission_name ... }
 
-# Class xen consists of dom0-only operations dealing with the hypervisor itself.
-# Unless otherwise specified, the source is the domain executing the hypercall,
-# and the target is the xen initial sid (type xen_t).
+# Class xen and xen2 consists of dom0-only operations dealing with the
+# hypervisor itself. Unless otherwise specified, the source is the domain
+# executing the hypercall, and the target is the xen initial sid (type xen_t).
 class xen
 {
 # XENPF_settime
@@ -75,6 +75,14 @@ class xen
     setscheduler
 }
 
+# This is a continuation of class xen, since only 32 permissions can be
+# defined per class
+class xen2
+{
+# XEN_SYSCTL_getcqminfo
+    pqos_op
+}
+
 # Classes domain and domain2 consist of operations that a domain performs on
 # another domain or on itself.  Unless otherwise specified, the source is the
 # domain executing the hypercall, and the target is the domain being operated on
@@ -196,6 +204,9 @@ class domain2
     setclaim
 # XEN_DOMCTL_set_max_evtchn
     set_max_evtchn
+# XEN_DOMCTL_attach_pqos
+# XEN_DOMCTL_detach_pqos
+    pqos_op
 }
 
 # Similar to class domain, but primarily contains domctls related to HVM domains
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v8 6/6 tools: enable Cache QoS Monitoring feature for libxl/libxc

In reply to Dongxiao Xu

Introduced two new xl commands to attach/detach CQM service for a guest

$ xl pqos-attach cqm domid
$ xl pqos-detach cqm domid

Introduce one new xl command to retrive guest CQM information

$ xl pqos-list cqm
---
 tools/libxc/xc_domain.c     |   37 ++++++++++++
 tools/libxc/xenctrl.h       |   12 ++++
 tools/libxl/Makefile        |    3 +-
 tools/libxl/libxl.h         |    4 ++
 tools/libxl/libxl_pqos.c    |  132 +++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_types.idl |    7 +++
 tools/libxl/xl.h            |    3 +
 tools/libxl/xl_cmdimpl.c    |  111 ++++++++++++++++++++++++++++++++++++
 tools/libxl/xl_cmdtable.c   |   15 +++++
 9 files changed, 323 insertions(+), 1 deletion(-)
 create mode 100644 tools/libxl/libxl_pqos.c
tools/libxc/xc_domain.c +37 -0
index c2fdd74..bcdffd2 100644
@@ -1776,6 +1776,43 @@ int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid,
     return do_domctl(xch, &domctl);
 }
 
+int xc_domain_pqos_attach(xc_interface *xch, uint32_t domid, uint64_t flags)
+{
+    DECLARE_DOMCTL;
+    domctl.cmd = XEN_DOMCTL_attach_pqos;
+    domctl.domain = (domid_t)domid;
+    domctl.u.qos_type.flags = flags;
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_pqos_detach(xc_interface *xch, uint32_t domid, uint64_t flags)
+{
+    DECLARE_DOMCTL;
+    domctl.cmd = XEN_DOMCTL_detach_pqos;
+    domctl.domain = (domid_t)domid;
+    domctl.u.qos_type.flags = flags;
+    return do_domctl(xch, &domctl);
+}
+
+int xc_domain_getcqminfo(xc_interface *xch, xc_cqminfo_t *info)
+{
+    int ret = 0;
+    DECLARE_SYSCTL;
+
+    sysctl.cmd = XEN_SYSCTL_getcqminfo;
+    if ( xc_sysctl(xch, &sysctl) < 0 )
+        ret = -1;
+    else
+    {
+        info->buffer_mfn = sysctl.u.getcqminfo.buffer_mfn;
+        info->size = sysctl.u.getcqminfo.size;
+        info->nr_rmids = sysctl.u.getcqminfo.nr_rmids;
+        info->nr_sockets = sysctl.u.getcqminfo.nr_sockets;
+    }
+
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxc/xenctrl.h +12 -0
index 13f816b..f4eb198 100644
@@ -2427,4 +2427,16 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch,
  */
 int xc_kexec_unload(xc_interface *xch, int type);
 
+struct xc_cqminfo
+{
+    uint64_aligned_t buffer_mfn;
+    uint32_t size;
+    uint32_t nr_rmids;
+    uint32_t nr_sockets;
+};
+typedef struct xc_cqminfo xc_cqminfo_t;
+
+int xc_domain_pqos_attach(xc_interface *xch, uint32_t domid, uint64_t flags);
+int xc_domain_pqos_detach(xc_interface *xch, uint32_t domid, uint64_t flags);
+int xc_domain_getcqminfo(xc_interface *xch, xc_cqminfo_t *info);
 #endif /* XENCTRL_H */
tools/libxl/Makefile +2 -1
index d8495bb..8beb7f8 100644
@@ -76,7 +76,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
 			libxl_internal.o libxl_utils.o libxl_uuid.o \
 			libxl_json.o libxl_aoutils.o libxl_numa.o \
 			libxl_save_callout.o _libxl_save_msgs_callout.o \
-			libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
+			libxl_qmp.o libxl_event.o libxl_fork.o libxl_pqos.o \
+			$(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 $(LIBXL_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h
tools/libxl/libxl.h +4 -0
index 12d6c31..f3d2202 100644
@@ -1105,6 +1105,10 @@ int libxl_flask_getenforce(libxl_ctx *ctx);
 int libxl_flask_setenforce(libxl_ctx *ctx, int mode);
 int libxl_flask_loadpolicy(libxl_ctx *ctx, void *policy, uint32_t size);
 
+int libxl_pqos_attach(libxl_ctx *ctx, uint32_t domid, const char * qos_type);
+int libxl_pqos_detach(libxl_ctx *ctx, uint32_t domid, const char * qos_type);
+void libxl_map_cqm_buffer(libxl_ctx *ctx, libxl_cqminfo *xlinfo);
+
 /* misc */
 
 /* Each of these sets or clears the flag according to whether the
tools/libxl/libxl_pqos.c new file +132 -0

132 lines not on this page · raw message

tools/libxl/libxl_types.idl +7 -0
index 649ce50..43c0f48 100644
@@ -596,3 +596,10 @@ libxl_event = Struct("event",[
                                  ])),
            ("domain_create_console_available", Struct(None, [])),
            ]))])
+
+libxl_cqminfo = Struct("cqminfo", [
+    ("buffer_virt",    uint64),
+    ("size",           uint32),
+    ("nr_rmids",       uint32),
+    ("nr_sockets",     uint32),
+    ])
tools/libxl/xl.h +3 -0
index c876a33..4362b96 100644
@@ -106,6 +106,9 @@ int main_setenforce(int argc, char **argv);
 int main_loadpolicy(int argc, char **argv);
 int main_remus(int argc, char **argv);
 int main_devd(int argc, char **argv);
+int main_pqosattach(int argc, char **argv);
+int main_pqosdetach(int argc, char **argv);
+int main_pqoslist(int argc, char **argv);
 
 void help(const char *command);
 
tools/libxl/xl_cmdimpl.c +111 -0

117 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +15 -0
index ebe0220..d4af4a9 100644
@@ -494,6 +494,21 @@ struct cmd_spec cmd_table[] = {
       "[options]",
       "-F                      Run in the foreground",
     },
+    { "pqos-attach",
+      &main_pqosattach, 0, 1,
+      "Allocate and map qos resource",
+      "<Resource> <Domain>",
+    },
+    { "pqos-detach",
+      &main_pqosdetach, 0, 1,
+      "Reliquish qos resource",
+      "<Resource> <Domain>",
+    },
+    { "pqos-list",
+      &main_pqoslist, 0, 0,
+      "List qos information for all domains",
+      "<Resource>",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v8 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc

Quoted 5 lines · Dongxiao Xu

Introduced two new xl commands to attach/detach CQM service for a guest

$ xl pqos-attach cqm domid
$ xl pqos-detach cqm domid

Introduce one new xl command to retrive guest CQM information

"retrieve"

Quoted 1 line
$ xl pqos-list cqm

Please patch the xl manpages to describe all these new commands.

I wonder though -- are these aimed at end users or are they really for developer use? I'm wondering if they should be exposed this way or whether they should be exposed by some lower level tool (similar to how xenpm is separate). I don't know what the correct answer is here.

tools/libxc/xc_domain.c int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid, · line 1804

Quoted 8 lines
tools/libxc/xc_domain.c +8 -0
+int xc_domain_getcqminfo(xc_interface *xch, xc_cqminfo_t *info)
+{
+    int ret = 0;
+    DECLARE_SYSCTL;
+
+    sysctl.cmd = XEN_SYSCTL_getcqminfo;
+    if ( xc_sysctl(xch, &sysctl) < 0 )
+        ret = -1;

xc_sysctl returns -1 on error AFAICT. So:

	ret = xc_sysctl(...);
	if (ret >= 0)
	{
		info->etc
	}
	return ret;

tools/libxl/libxl_types.idl libxl_event = Struct("event",[ · line 600

Quoted 10 lines
tools/libxl/libxl_types.idl +2 -0
index 649ce50..43c0f48 100644
@@ -596,3 +596,10 @@ libxl_event = Struct("event",[
                                  ])),
            ("domain_create_console_available", Struct(None, [])),
            ]))])
+
+libxl_cqminfo = Struct("cqminfo", [

You need to also patch libxl.h to add a suitable LIBXL_HAVE_FOO define, see the existing examples in that header.

Ian.

#8 lore raw

Re: [PATCH v8 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc

Quoted 10 lines

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: Monday, February 10, 2014 6:16 PM
To: Xu, Dongxiao
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v8 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc

Quoted 8 lines
Quoted 5 lines · Dongxiao Xu

Introduced two new xl commands to attach/detach CQM service for a guest

$ xl pqos-attach cqm domid
$ xl pqos-detach cqm domid

Introduce one new xl command to retrive guest CQM information

"retrieve"

Thanks.

Quoted 4 lines
Quoted 2 lines
$ xl pqos-list cqm

Please patch the xl manpages to describe all these new commands.

OK.

Quoted 5 lines

I wonder though -- are these aimed at end users or are they really for developer use? I'm wondering if they should be exposed this way or whether they should be exposed by some lower level tool (similar to how xenpm is separate). I don't know what the correct answer is here.

I think one target should be the sys admins, who needs to watch the system cache usages and determine how to balance the resource.

Quoted 11 lines

tools/libxc/xc_domain.c int xc_domain_set_max_evtchn(xc_interface *xch, uint32_t domid, · line 1804

Quoted 9 lines
tools/libxc/xc_domain.c +8 -0
+int xc_domain_getcqminfo(xc_interface *xch, xc_cqminfo_t *info)
+{
+    int ret = 0;
+    DECLARE_SYSCTL;
+
+    sysctl.cmd = XEN_SYSCTL_getcqminfo;
+    if ( xc_sysctl(xch, &sysctl) < 0 )
+        ret = -1;

xc_sysctl returns -1 on error AFAICT. So:

Quoted 6 lines
	ret = xc_sysctl(...);
	if (ret >= 0)
	{
		info->etc
	}
	return ret;

OK.

Quoted 14 lines

tools/libxl/libxl_types.idl libxl_event = Struct("event",[ · line 600

Quoted 11 lines
tools/libxl/libxl_types.idl +2 -0
index 649ce50..43c0f48 100644
@@ -596,3 +596,10 @@ libxl_event = Struct("event",[
                                  ])),
            ("domain_create_console_available", Struct(None, [])),
            ]))])
+
+libxl_cqminfo = Struct("cqminfo", [

You need to also patch libxl.h to add a suitable LIBXL_HAVE_FOO define, see the existing examples in that header.

OK.

Thanks,
Dongxiao

Quoted 2 lines

Ian.

#9 lore raw

Re: [PATCH v8 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc

In reply to Ian Campbell
Quoted 24 lines

-----Original Message-----
From: Xu, Dongxiao
Sent: Monday, February 10, 2014 7:19 PM
To: Ian Campbell
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v8 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc

Quoted 5 lines
Quoted 5 lines
tools/libxl/libxl_types.idl +0 -0
index 649ce50..43c0f48 100644
@@ -596,3 +596,10 @@ libxl_event = Struct("event",[
Quoted 8 lines

tools/libxl/libxl_types.idl libxl_event = Struct("event",[ · line 600

Quoted 5 lines
tools/libxl/libxl_types.idl +2 -0
                                  ])),
            ("domain_create_console_available", Struct(None, [])),
            ]))])
+
+libxl_cqminfo = Struct("cqminfo", [

You need to also patch libxl.h to add a suitable LIBXL_HAVE_FOO define, see the existing examples in that header.

Quoted 1 line

OK.

Hi Ian,

Just had another look at the comments:

* In the event that a change is required which cannot be made
* backwards compatible in this manner a #define of the form
* LIBXL_HAVE_<interface> will always be added in order to make it
* possible to write applciations which build against any version of
* libxl. Such changes are expected to be exceptional and used as a
* last resort. The barrier for backporting such a change to a stable
* branch will be very high.

LIBXL_HAVE_<interface> is to address the back compatibility issue, and mostly it is used in cases like "adding a new field to the existing data structure".

In this patch, the libxl_cqminfo is a new added data structure, and it seems that there is no such compatibility issue. Do we really need to add the LIBXL_HAVE_<interface> macro?

Thanks,
Dongxiao

Quoted 6 lines

Thanks,
Dongxiao

Quoted 2 lines

Ian.

#10 lore raw

Re: [PATCH v8 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc

Quoted 38 lines · Dongxiao
Quoted 24 lines

-----Original Message-----
From: Xu, Dongxiao
Sent: Monday, February 10, 2014 7:19 PM
To: Ian Campbell
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v8 6/6] tools: enable Cache QoS Monitoring feature for libxl/libxc

Quoted 5 lines
Quoted 5 lines
tools/libxl/libxl_types.idl +0 -0
index 649ce50..43c0f48 100644
@@ -596,3 +596,10 @@ libxl_event = Struct("event",[
Quoted 8 lines

tools/libxl/libxl_types.idl libxl_event = Struct("event",[ · line 600

Quoted 5 lines
tools/libxl/libxl_types.idl +2 -0
                                  ])),
            ("domain_create_console_available", Struct(None, [])),
            ]))])
+
+libxl_cqminfo = Struct("cqminfo", [

You need to also patch libxl.h to add a suitable LIBXL_HAVE_FOO define, see the existing examples in that header.

Quoted 1 line

OK.

Hi Ian,

Just had another look at the comments:

* In the event that a change is required which cannot be made
* backwards compatible in this manner a #define of the form
* LIBXL_HAVE_<interface> will always be added in order to make it
* possible to write applciations which build against any version of
* libxl. Such changes are expected to be exceptional and used as a
* last resort. The barrier for backporting such a change to a stable
* branch will be very high.

Quoted 7 lines

LIBXL_HAVE_<interface> is to address the back compatibility issue, and mostly it is used in cases like "adding a new field to the existing data structure".

In this patch, the libxl_cqminfo is a new added data structure, and it seems that there is no such compatibility issue. Do we really need to add the LIBXL_HAVE_<interface> macro?

I think so -- so that consumers of the libxl API know that it is available to be used. The fact that it is an entire struct rather than a new field doesn't make a difference here I think.

Ian.