Dongxiao Xu
2013-Dec-03 08:47 UTC
[PATCH v4 0/7] enable Cache QoS Monitoring (CQM) feature
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 (domid) 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 (7): x86: detect and initialize Cache QoS Monitoring feature x86: dynamically attach/detach CQM service for a guest x86: initialize per socket cpu map 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 | 8 + tools/flask/policy/policy/modules/xen/xen.if | 2 +- tools/flask/policy/policy/modules/xen/xen.te | 5 +- tools/libxc/xc_domain.c | 47 ++++++ tools/libxc/xenctrl.h | 11 ++ tools/libxl/Makefile | 3 +- tools/libxl/libxl.h | 5 + tools/libxl/libxl_pqos.c | 108 ++++++++++++ tools/libxl/xl.h | 3 + tools/libxl/xl_cmdimpl.c | 146 ++++++++++++++++ tools/libxl/xl_cmdtable.c | 15 ++ xen/arch/x86/Makefile | 1 + xen/arch/x86/cpu/intel.c | 6 + xen/arch/x86/domain.c | 8 + xen/arch/x86/domctl.c | 40 +++++ xen/arch/x86/pqos.c | 234 ++++++++++++++++++++++++++ xen/arch/x86/setup.c | 3 + xen/arch/x86/smp.c | 7 +- xen/arch/x86/smpboot.c | 19 ++- xen/arch/x86/sysctl.c | 62 +++++++ 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 | 55 ++++++ xen/include/asm-x86/smp.h | 2 + xen/include/public/domctl.h | 20 +++ xen/include/public/sysctl.h | 10 ++ xen/include/xen/cpumask.h | 1 + xen/xsm/flask/hooks.c | 7 + xen/xsm/flask/policy/access_vectors | 17 +- 30 files changed, 844 insertions(+), 9 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 -- 1.7.9.5
Dongxiao Xu
2013-Dec-03 08:47 UTC
[PATCH v4 1/7] 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. Signed-off-by: Jiongxi Li <jiongxi.li@intel.com> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> --- docs/misc/xen-command-line.markdown | 8 +++ xen/arch/x86/Makefile | 1 + xen/arch/x86/cpu/intel.c | 6 ++ xen/arch/x86/pqos.c | 125 +++++++++++++++++++++++++++++++++++ xen/arch/x86/setup.c | 3 + xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/pqos.h | 42 ++++++++++++ 7 files changed, 186 insertions(+) create mode 100644 xen/arch/x86/pqos.c create mode 100644 xen/include/asm-x86/pqos.h diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown index 15aa404..bdb5f44 100644 --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -1037,3 +1037,11 @@ Use the x2apic physical apic driver. The alternative is the x2apic cluster driv > Default: `true` Permit use of the `xsave/xrstor` instructions. + +### pqos +> `= <boolean>` + +> Default: `true` + +Configure platform QoS services. +For CQM feature, the default parameter is: pqos=1,cqm=1,cqm_max_rmid=255. diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index d502bdf..54962e0 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -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 diff --git a/xen/arch/x86/cpu/intel.c b/xen/arch/x86/cpu/intel.c index 27fe762..f0d83ea 100644 --- a/xen/arch/x86/cpu/intel.c +++ b/xen/arch/x86/cpu/intel.c @@ -230,6 +230,12 @@ static void __devinit init_intel(struct cpuinfo_x86 *c) ( c->cpuid_level >= 0x00000006 ) && ( cpuid_eax(0x00000006) & (1u<<2) ) ) set_bit(X86_FEATURE_ARAT, c->x86_capability); + + /* Check platform QoS monitoring capability */ + if ((c->cpuid_level >= 0x00000007) && + (cpuid_ebx(0x00000007) & (1u<<12))) + set_bit(X86_FEATURE_QOSM, c->x86_capability); + } static struct cpu_dev intel_cpu_dev __cpuinitdata = { diff --git a/xen/arch/x86/pqos.c b/xen/arch/x86/pqos.c new file mode 100644 index 0000000..b786ec2 --- /dev/null +++ b/xen/arch/x86/pqos.c @@ -0,0 +1,125 @@ +/* + * pqos.c: Platform QoS related service for guest. + * + * Copyright (c) 2013, Intel Corporation + * Author: Jiongxi Li <jiongxi.li@intel.com> + * Author: Dongxiao Xu <dongxiao.xu@intel.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. + */ +#include <asm/processor.h> +#include <xen/init.h> +#include <asm/pqos.h> + +static bool_t __initdata opt_pqos = 1; +static bool_t __initdata opt_cqm = 1; +static unsigned int __initdata opt_cqm_max_rmid = 255; + +static void __init parse_pqos_param(char *s) +{ + char *ss; + char *val_str; + unsigned long val; + + do { + ss = strchr(s, '',''); + if ( ss ) + *ss = ''\0''; + + val_str = strchr(s, ''=''); + if ( !val_str ) + val_str = s; + else + val_str += 1; + + if ( !parse_bool(s) ) + opt_pqos = 0; + else if ( !strncmp(s, "cqm=", 4) && !parse_bool(val_str) ) + opt_cqm = 0; + else if ( !strncmp(s, "cqm_max_rmid=", 13) && + (val = simple_strtoul(val_str, NULL, 0)) ) + opt_cqm_max_rmid = val; + + s = ss + 1; + } while ( ss ); +} +custom_param("pqos", parse_pqos_param); + +struct pqos_cqm *cqm; + +static void __init init_cqm(void) +{ + unsigned int rmid; + unsigned int eax, edx; + + cqm = xzalloc(struct pqos_cqm); + if ( !cqm ) + return; + + cpuid_count(0xf, 1, &eax, &cqm->upscaling_factor, &cqm->max_rmid, &edx); + if ( !(edx & QOS_MONITOR_EVTID_L3) ) + { + xfree(cqm); + return; + } + + cqm->min_rmid = 1; + cqm->max_rmid = min(opt_cqm_max_rmid, cqm->max_rmid); + + cqm->rmid_to_dom = xmalloc_array(domid_t, cqm->max_rmid + 1); + if ( !cqm->rmid_to_dom ) + { + xfree(cqm); + return; + } + + /* Reserve RMID 0 for all domains not being monitored */ + cqm->rmid_to_dom[0] = DOMID_XEN; + for ( rmid = cqm->min_rmid; rmid <= cqm->max_rmid; rmid++ ) + cqm->rmid_to_dom[rmid] = DOMID_INVALID; + + printk(XENLOG_INFO "Cache QoS Monitoring Enabled.\n"); +} + +static void __init init_qos_monitor(void) +{ + unsigned int qm_features; + unsigned int eax, ebx, ecx; + + if ( !(boot_cpu_has(X86_FEATURE_QOSM)) ) + return; + + cpuid_count(0xf, 0, &eax, &ebx, &ecx, &qm_features); + + if ( opt_cqm && (qm_features & QOS_MONITOR_TYPE_L3) ) + init_cqm(); +} + +void __init init_platform_qos(void) +{ + if ( !opt_pqos ) + return; + + init_qos_monitor(); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 5bf4ee0..95418e4 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -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; @@ -1402,6 +1403,8 @@ void __init __start_xen(unsigned long mbi_p) domain_unpause_by_systemcontroller(dom0); + init_platform_qos(); + reset_stack_and_jump(init_done); } diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeature.h index 1cfaf94..ca59668 100644 --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -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 */ diff --git a/xen/include/asm-x86/pqos.h b/xen/include/asm-x86/pqos.h new file mode 100644 index 0000000..94d4f6e --- /dev/null +++ b/xen/include/asm-x86/pqos.h @@ -0,0 +1,42 @@ +/* + * pqos.h: Platform QoS related service for guest. + * + * Copyright (c) 2013, Intel Corporation + * Author: Jiongxi Li <jiongxi.li@intel.com> + * Author: Dongxiao Xu <dongxiao.xu@intel.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef ASM_PQOS_H +#define ASM_PQOS_H + +#include <public/xen.h> + +/* QoS Resource Type Enumeration */ +#define QOS_MONITOR_TYPE_L3 0x2 + +/* QoS Monitoring Event ID */ +#define QOS_MONITOR_EVTID_L3 0x1 + +struct pqos_cqm { + unsigned int min_rmid; + unsigned int max_rmid; + unsigned int upscaling_factor; + domid_t *rmid_to_dom; +}; +extern struct pqos_cqm *cqm; + +void init_platform_qos(void); + +#endif -- 1.7.9.5
Dongxiao Xu
2013-Dec-03 08:47 UTC
[PATCH v4 2/7] x86: dynamically attach/detach CQM service for a guest
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. Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Jiongxi Li <jiongxi.li@intel.com> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> --- xen/arch/x86/domain.c | 3 +++ xen/arch/x86/domctl.c | 40 +++++++++++++++++++++++++++++++++ xen/arch/x86/pqos.c | 51 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 2 ++ xen/include/asm-x86/pqos.h | 5 +++++ xen/include/public/domctl.h | 11 +++++++++ 6 files changed, 112 insertions(+) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index a3868f9..90e52a2 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -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) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index f7e4586..7007990 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -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) @@ -1223,6 +1224,45 @@ long arch_do_domctl( } break; + case XEN_DOMCTL_attach_pqos: + { + if ( domctl->u.qos_type.flags & XEN_DOMCTL_pqos_cqm ) + { + if ( !system_supports_cqm() ) + ret = -ENODEV; + else if ( d->arch.pqos_cqm_rmid > 0 ) + ret = -EEXIST; + else + { + ret = alloc_cqm_rmid(d); + if ( ret < 0 ) + ret = -EUSERS; + } + } + else + ret = -EINVAL; + } + break; + + case XEN_DOMCTL_detach_pqos: + { + if ( domctl->u.qos_type.flags & XEN_DOMCTL_pqos_cqm ) + { + if ( !system_supports_cqm() ) + ret = -ENODEV; + else if ( d->arch.pqos_cqm_rmid > 0 ) + { + free_cqm_rmid(d); + ret = 0; + } + else + ret = -ENOENT; + } + else + ret = -EINVAL; + } + break; + default: ret = iommu_do_domctl(domctl, d, u_domctl); break; diff --git a/xen/arch/x86/pqos.c b/xen/arch/x86/pqos.c index b786ec2..dd22cae 100644 --- a/xen/arch/x86/pqos.c +++ b/xen/arch/x86/pqos.c @@ -20,6 +20,7 @@ */ #include <asm/processor.h> #include <xen/init.h> +#include <xen/spinlock.h> #include <asm/pqos.h> static bool_t __initdata opt_pqos = 1; @@ -57,6 +58,7 @@ static void __init parse_pqos_param(char *s) custom_param("pqos", parse_pqos_param); struct pqos_cqm *cqm; +static DEFINE_SPINLOCK(cqm_lock); static void __init init_cqm(void) { @@ -114,6 +116,55 @@ void __init init_platform_qos(void) init_qos_monitor(); } +bool_t system_supports_cqm(void) +{ + return !!cqm; +} + +int alloc_cqm_rmid(struct domain *d) +{ + int rc = 0; + unsigned int rmid; + unsigned long flags; + + ASSERT(system_supports_cqm()); + + spin_lock_irqsave(&cqm_lock, flags); + for ( rmid = cqm->min_rmid; rmid <= cqm->max_rmid; rmid++ ) + { + if ( cqm->rmid_to_dom[rmid] != DOMID_INVALID) + continue; + + cqm->rmid_to_dom[rmid] = d->domain_id; + break; + } + spin_unlock_irqrestore(&cqm_lock, flags); + + /* No CQM RMID available, assign RMID=0 by default */ + if ( rmid > cqm->max_rmid ) + { + rmid = 0; + rc = -1; + } + + d->arch.pqos_cqm_rmid = rmid; + + return rc; +} + +void free_cqm_rmid(struct domain *d) +{ + unsigned int rmid = d->arch.pqos_cqm_rmid; + + /* We do not free system reserved "RMID=0" */ + if ( rmid == 0 ) + return; + + cqm->rmid_to_dom[rmid] = DOMID_INVALID; + + d->arch.pqos_cqm_rmid = 0; +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h index 9d39061..9487251 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -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)) diff --git a/xen/include/asm-x86/pqos.h b/xen/include/asm-x86/pqos.h index 94d4f6e..9807485 100644 --- a/xen/include/asm-x86/pqos.h +++ b/xen/include/asm-x86/pqos.h @@ -20,6 +20,7 @@ */ #ifndef ASM_PQOS_H #define ASM_PQOS_H +#include <xen/sched.h> #include <public/xen.h> @@ -39,4 +40,8 @@ extern struct pqos_cqm *cqm; void init_platform_qos(void); +bool_t system_supports_cqm(void); +int alloc_cqm_rmid(struct domain *d); +void free_cqm_rmid(struct domain *d); + #endif diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 01a3652..d53e216 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -869,6 +869,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 @@ -938,6 +946,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 @@ -998,6 +1008,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; }; -- 1.7.9.5
For each socket in the system, we create a separate bitmap to tag its related CPUs. This per socket bitmap will be initialized on system start up, and adjusted when CPU is dynamically online/offline. Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> --- xen/arch/x86/smp.c | 7 ++++++- xen/arch/x86/smpboot.c | 19 +++++++++++++++++-- xen/include/asm-x86/smp.h | 2 ++ xen/include/xen/cpumask.h | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/smp.c b/xen/arch/x86/smp.c index 0433f30..7959447 100644 --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -283,6 +283,9 @@ void smp_send_call_function_mask(const cpumask_t *mask) void __stop_this_cpu(void) { + int cpu = smp_processor_id(); + int socket = cpu_to_socket(cpu); + ASSERT(!local_irq_is_enabled()); disable_local_APIC(); @@ -296,7 +299,9 @@ void __stop_this_cpu(void) clts(); asm volatile ( "fninit" ); - cpumask_clear_cpu(smp_processor_id(), &cpu_online_map); + cpumask_clear_cpu(cpu, &cpu_online_map); + if ( socket >= 0 ) + cpumask_clear_cpu(cpu, &socket_cpu_map[socket]); } static void stop_this_cpu(void *dummy) diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 9f81c7b..c421464 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -59,6 +59,9 @@ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask); cpumask_t cpu_online_map __read_mostly; EXPORT_SYMBOL(cpu_online_map); +cpumask_t socket_cpu_map[MAX_NUM_SOCKETS] __read_mostly; +EXPORT_SYMBOL(socket_random_cpu_map); + struct cpuinfo_x86 cpu_data[NR_CPUS]; u32 x86_cpu_to_apicid[NR_CPUS] __read_mostly @@ -319,6 +322,7 @@ void start_secondary(void *unused) * want to limit the things done here to the most necessary things. */ unsigned int cpu = booting_cpu; + int socket; set_processor_id(cpu); set_current(idle_vcpu[cpu]); @@ -381,6 +385,9 @@ void start_secondary(void *unused) cpumask_set_cpu(cpu, &cpu_online_map); unlock_vector_lock(); + if ( (socket = cpu_to_socket(cpu)) >= 0 ) + cpumask_set_cpu(cpu, &socket_cpu_map[socket]); + init_percpu_time(); /* We can take interrupts now: we''re officially "up". */ @@ -788,8 +795,13 @@ void __init smp_prepare_cpus(unsigned int max_cpus) void __init smp_prepare_boot_cpu(void) { - cpumask_set_cpu(smp_processor_id(), &cpu_online_map); - cpumask_set_cpu(smp_processor_id(), &cpu_present_map); + int cpu = smp_processor_id(); + int socket = cpu_to_socket(cpu); + + cpumask_set_cpu(cpu, &cpu_online_map); + cpumask_set_cpu(cpu, &cpu_present_map); + if ( socket >= 0 ) + cpumask_set_cpu(cpu, &socket_cpu_map[socket]); } static void @@ -819,6 +831,7 @@ remove_siblinginfo(int cpu) void __cpu_disable(void) { int cpu = smp_processor_id(); + int socket = cpu_to_socket(cpu); set_cpu_state(CPU_STATE_DYING); @@ -836,6 +849,8 @@ void __cpu_disable(void) /* It''s now safe to remove this processor from the online map */ cpumask_clear_cpu(cpu, cpupool0->cpu_valid); cpumask_clear_cpu(cpu, &cpu_online_map); + if ( socket >= 0 ) + cpumask_clear_cpu(cpu, &socket_cpu_map[socket]); fixup_irqs(); if ( cpu_disable_scheduler(cpu) ) diff --git a/xen/include/asm-x86/smp.h b/xen/include/asm-x86/smp.h index 81f8610..f47fa1b 100644 --- a/xen/include/asm-x86/smp.h +++ b/xen/include/asm-x86/smp.h @@ -57,6 +57,8 @@ int hard_smp_processor_id(void); void __stop_this_cpu(void); +#define MAX_NUM_SOCKETS 256 + #endif /* !__ASSEMBLY__ */ #endif diff --git a/xen/include/xen/cpumask.h b/xen/include/xen/cpumask.h index 850b4a2..883a52a 100644 --- a/xen/include/xen/cpumask.h +++ b/xen/include/xen/cpumask.h @@ -419,6 +419,7 @@ static inline void free_cpumask_var(cpumask_var_t mask) extern cpumask_t cpu_possible_map; extern cpumask_t cpu_online_map; extern cpumask_t cpu_present_map; +extern cpumask_t socket_cpu_map[]; #if NR_CPUS > 1 #define num_online_cpus() cpumask_weight(&cpu_online_map) -- 1.7.9.5
Dongxiao Xu
2013-Dec-03 08:47 UTC
[PATCH v4 4/7] x86: collect CQM information from all sockets
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: Jiongxi Li <jiongxi.li@intel.com> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> --- xen/arch/x86/pqos.c | 46 +++++++++++++++++++++++++++++ xen/arch/x86/sysctl.c | 62 +++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/msr-index.h | 4 +++ xen/include/asm-x86/pqos.h | 7 +++++ xen/include/public/domctl.h | 9 ++++++ xen/include/public/sysctl.h | 10 +++++++ 6 files changed, 138 insertions(+) diff --git a/xen/arch/x86/pqos.c b/xen/arch/x86/pqos.c index dd22cae..dc0f0fc 100644 --- a/xen/arch/x86/pqos.c +++ b/xen/arch/x86/pqos.c @@ -19,6 +19,7 @@ * Place - Suite 330, Boston, MA 02111-1307 USA. */ #include <asm/processor.h> +#include <asm/msr.h> #include <xen/init.h> #include <xen/spinlock.h> #include <asm/pqos.h> @@ -121,6 +122,12 @@ bool_t system_supports_cqm(void) return !!cqm; } +unsigned int get_cqm_count(void) +{ + ASSERT(system_supports_cqm()); + return cqm->max_rmid + 1; +} + int alloc_cqm_rmid(struct domain *d) { int rc = 0; @@ -165,6 +172,45 @@ void free_cqm_rmid(struct domain *d) d->arch.pqos_cqm_rmid = 0; } +static void read_cqm_data(void *arg) +{ + uint64_t cqm_data; + unsigned int rmid; + int socket = cpu_to_socket(smp_processor_id()); + struct xen_socket_cqmdata *data = arg; + unsigned long flags, i; + + ASSERT(system_supports_cqm()); + + if ( socket < 0 ) + return; + + spin_lock_irqsave(&cqm_lock, flags); + 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 = socket * (cqm->max_rmid + 1) + rmid; + data[i].valid = !(cqm_data & IA32_QM_CTR_ERROR_MASK); + if ( data[i].valid ) + { + data[i].l3c_occupancy = cqm_data * cqm->upscaling_factor; + data[i].socket = socket; + data[i].domid = cqm->rmid_to_dom[rmid]; + } + } + spin_unlock_irqrestore(&cqm_lock, flags); +} + +void get_cqm_info(cpumask_t *cpu_cqmdata_map, struct xen_socket_cqmdata *data) +{ + on_selected_cpus(cpu_cqmdata_map, read_cqm_data, data, 1); +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index 15d4b91..3977e7d 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,21 @@ void arch_do_physinfo(xen_sysctl_physinfo_t *pi) pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm_directio; } +/* Select one random CPU for each socket */ +static void select_socket_cpu(cpumask_t *cpu_bitmap) +{ + int i; + unsigned int cpu; + + cpumask_clear(cpu_bitmap); + for ( i = 0; i < MAX_NUM_SOCKETS; i++ ) + { + cpu = cpumask_any(&socket_cpu_map[i]); + if ( cpu < nr_cpu_ids ) + cpumask_set_cpu(cpu, cpu_bitmap); + } +} + long arch_do_sysctl( struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { @@ -101,6 +117,52 @@ long arch_do_sysctl( } break; + case XEN_SYSCTL_getcqminfo: + { + struct xen_socket_cqmdata *info; + uint32_t num_sockets; + uint32_t num_rmid; + cpumask_t cpu_cqmdata_map; + + if ( !system_supports_cqm() ) + { + ret = -ENODEV; + break; + } + + select_socket_cpu(&cpu_cqmdata_map); + + num_sockets = min((unsigned int)cpumask_weight(&cpu_cqmdata_map), + sysctl->u.getcqminfo.num_sockets); + num_rmid = get_cqm_count(); + info = xzalloc_array(struct xen_socket_cqmdata, + num_rmid * num_sockets); + if ( !info ) + { + ret = -ENOMEM; + break; + } + + get_cqm_info(&cpu_cqmdata_map, info); + + if ( copy_to_guest_offset(sysctl->u.getcqminfo.buffer, + 0, info, num_rmid * num_sockets) ) + { + ret = -EFAULT; + xfree(info); + break; + } + + sysctl->u.getcqminfo.num_rmid = num_rmid; + sysctl->u.getcqminfo.num_sockets = num_sockets; + + if ( copy_to_guest(u_sysctl, sysctl, 1) ) + ret = -EFAULT; + + xfree(info); + } + break; + default: ret = -ENOSYS; break; diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h index e597a28..46ef165 100644 --- a/xen/include/asm-x86/msr-index.h +++ b/xen/include/asm-x86/msr-index.h @@ -488,4 +488,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 9807485..49f2302 100644 --- a/xen/include/asm-x86/pqos.h +++ b/xen/include/asm-x86/pqos.h @@ -21,6 +21,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> @@ -38,10 +40,15 @@ struct pqos_cqm { }; extern struct pqos_cqm *cqm; +/* IA32_QM_CTR */ +#define IA32_QM_CTR_ERROR_MASK (0x3ul << 62) + void init_platform_qos(void); bool_t system_supports_cqm(void); int alloc_cqm_rmid(struct domain *d); void free_cqm_rmid(struct domain *d); +unsigned int get_cqm_count(void); +void get_cqm_info(cpumask_t *cpu_cqmdata_map, struct xen_socket_cqmdata *data); #endif diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index d53e216..563aeaf 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -877,6 +877,15 @@ struct xen_domctl_qos_type { typedef struct xen_domctl_qos_type xen_domctl_qos_type_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_qos_type_t); +struct xen_socket_cqmdata { + uint64_t l3c_occupancy; + uint32_t socket; + domid_t domid; + uint8_t valid; +}; +typedef struct xen_socket_cqmdata xen_socket_cqmdata_t; +DEFINE_XEN_GUEST_HANDLE(xen_socket_cqmdata_t); + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 8437d31..8b2844e 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -632,6 +632,14 @@ 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); +/* XEN_SYSCTL_getcqminfo */ +struct xen_sysctl_getcqminfo { + XEN_GUEST_HANDLE_64(xen_socket_cqmdata_t) buffer; /* OUT */ + uint32_t num_sockets; /* IN/OUT */ + uint32_t num_rmid; /* OUT */ +}; +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 +662,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 +684,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
Dongxiao Xu
2013-Dec-03 08:47 UTC
[PATCH v4 5/7] x86: enable CQM monitoring for each domain RMID
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. Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Jiongxi Li <jiongxi.li@intel.com> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> --- xen/arch/x86/domain.c | 5 +++++ xen/arch/x86/pqos.c | 12 ++++++++++++ xen/include/asm-x86/msr-index.h | 1 + xen/include/asm-x86/pqos.h | 1 + 4 files changed, 19 insertions(+) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 90e52a2..79bc83c 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1366,6 +1366,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_assoc_rmid(0); p->arch.ctxt_switch_from(p); } @@ -1390,6 +1392,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) : diff --git a/xen/arch/x86/pqos.c b/xen/arch/x86/pqos.c index dc0f0fc..c510bba 100644 --- a/xen/arch/x86/pqos.c +++ b/xen/arch/x86/pqos.c @@ -58,6 +58,8 @@ static void __init parse_pqos_param(char *s) } custom_param("pqos", parse_pqos_param); +static uint64_t rmid_mask; + struct pqos_cqm *cqm; static DEFINE_SPINLOCK(cqm_lock); @@ -105,6 +107,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(); } @@ -211,6 +215,14 @@ void get_cqm_info(cpumask_t *cpu_cqmdata_map, struct xen_socket_cqmdata *data) on_selected_cpus(cpu_cqmdata_map, read_cqm_data, data, 1); } +void cqm_assoc_rmid(unsigned int rmid) +{ + uint64_t val; + + rdmsrl(MSR_IA32_PQR_ASSOC, val); + wrmsrl(MSR_IA32_PQR_ASSOC, (val & ~(rmid_mask)) | (rmid & rmid_mask)); +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h index 46ef165..45f4918 100644 --- a/xen/include/asm-x86/msr-index.h +++ b/xen/include/asm-x86/msr-index.h @@ -491,5 +491,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 */ diff --git a/xen/include/asm-x86/pqos.h b/xen/include/asm-x86/pqos.h index 49f2302..04dcdee 100644 --- a/xen/include/asm-x86/pqos.h +++ b/xen/include/asm-x86/pqos.h @@ -50,5 +50,6 @@ int alloc_cqm_rmid(struct domain *d); void free_cqm_rmid(struct domain *d); unsigned int get_cqm_count(void); void get_cqm_info(cpumask_t *cpu_cqmdata_map, struct xen_socket_cqmdata *data); +void cqm_assoc_rmid(unsigned int rmid); #endif -- 1.7.9.5
Dongxiao Xu
2013-Dec-03 08:47 UTC
[PATCH v4 6/7] xsm: add platform QoS related xsm policies
Add xsm policies for attach/detach pqos services and get CQM info hypercalls. Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> --- tools/flask/policy/policy/modules/xen/xen.if | 2 +- tools/flask/policy/policy/modules/xen/xen.te | 5 ++++- xen/xsm/flask/hooks.c | 7 +++++++ xen/xsm/flask/policy/access_vectors | 17 ++++++++++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/flask/policy/policy/modules/xen/xen.if b/tools/flask/policy/policy/modules/xen/xen.if index dedc035..1f683af 100644 --- a/tools/flask/policy/policy/modules/xen/xen.if +++ b/tools/flask/policy/policy/modules/xen/xen.if @@ -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 }; diff --git a/tools/flask/policy/policy/modules/xen/xen.te b/tools/flask/policy/policy/modules/xen/xen.te index bb59fe8..115fcfe 100644 --- a/tools/flask/policy/policy/modules/xen/xen.te +++ b/tools/flask/policy/policy/modules/xen/xen.te @@ -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 }; diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index b1e2593..6f9f355 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -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,9 @@ static int flask_sysctl(int cmd) case XEN_SYSCTL_numainfo: return domain_has_xen(current->domain, XEN__PHYSINFO); + case XEN_SYSCTL_getcqminfo: + avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2, XEN2__PQOS_OP, NULL); + default: printk("flask_sysctl: Unknown op %d\n", cmd); return -EPERM; diff --git a/xen/xsm/flask/policy/access_vectors b/xen/xsm/flask/policy/access_vectors index 1fbe241..91af8b2 100644 --- a/xen/xsm/flask/policy/access_vectors +++ b/xen/xsm/flask/policy/access_vectors @@ -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 -- 1.7.9.5
Dongxiao Xu
2013-Dec-03 08:47 UTC
[PATCH v4 7/7] tools: enable Cache QoS Monitoring feature for libxl/libxc
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 (domid) Signed-off-by: Jiongxi Li <jiongxi.li@intel.com> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> --- tools/libxc/xc_domain.c | 47 +++++++++++++++ tools/libxc/xenctrl.h | 11 ++++ tools/libxl/Makefile | 3 +- tools/libxl/libxl.h | 5 ++ tools/libxl/libxl_pqos.c | 108 +++++++++++++++++++++++++++++++++ tools/libxl/xl.h | 3 + tools/libxl/xl_cmdimpl.c | 146 +++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 15 +++++ 8 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_pqos.c diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 1ccafc5..1250cbb 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -1776,6 +1776,53 @@ 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, uint32_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, uint32_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_getcqminfolist(xc_interface *xch, sysctl_cqminfo_t *info) +{ + int ret = 0; + xen_socket_cqmdata_t *data = info->cqmdata; + DECLARE_SYSCTL; + + DECLARE_HYPERCALL_BOUNCE(data, + info->num_rmid * info->num_sockets * sizeof(*data), + XC_HYPERCALL_BUFFER_BOUNCE_OUT); + + if ( xc_hypercall_bounce_pre(xch, data) ) + return -1; + + sysctl.cmd = XEN_SYSCTL_getcqminfo; + set_xen_guest_handle(sysctl.u.getcqminfo.buffer, data); + + if ( xc_sysctl(xch, &sysctl) < 0 ) + ret = -1; + else + { + info->num_sockets = sysctl.u.getcqminfo.num_sockets; + info->num_rmid = sysctl.u.getcqminfo.num_rmid; + } + + xc_hypercall_bounce_post(xch, data); + + return ret; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 4ac6b8a..4d221e0 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2395,4 +2395,15 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch, */ int xc_kexec_unload(xc_interface *xch, int type); +struct xc_sysctl_getcqminfo +{ + uint32_t num_rmid; + uint32_t num_sockets; + xen_socket_cqmdata_t *cqmdata; +}; +typedef struct xc_sysctl_getcqminfo sysctl_cqminfo_t; + +int xc_domain_pqos_attach(xc_interface *xch, uint32_t domid, uint32_t flags); +int xc_domain_pqos_detach(xc_interface *xch, uint32_t domid, uint32_t flags); +int xc_domain_getcqminfolist(xc_interface *xch, sysctl_cqminfo_t *info); #endif /* XENCTRL_H */ diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index cf214bb..35f0b97 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -74,7 +74,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 diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index c7dceda..fdca92d 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -285,6 +285,7 @@ #include <libxl_uuid.h> #include <_libxl_list.h> +#include <xenctrl.h> /* API compatibility. */ #ifdef LIBXL_API_VERSION @@ -1051,6 +1052,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); +int libxl_get_cqm_info(libxl_ctx *ctx, sysctl_cqminfo_t *info); + /* misc */ /* Each of these sets or clears the flag according to whether the diff --git a/tools/libxl/libxl_pqos.c b/tools/libxl/libxl_pqos.c new file mode 100644 index 0000000..bf7593a --- /dev/null +++ b/tools/libxl/libxl_pqos.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2013 Intel Corporation + * Author Jiongxi Li <jiongxi.li@intel.com> + * Author Dongxiao Xu <dongxiao.xu@intel.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" /* must come before any other headers */ +#include "libxl_internal.h" + +static const char * const msg[] = { + [EINVAL] = "invalid QoS resource type! Supported types: \"cqm\"", + [ENODEV] = "CQM is not supported in this system.", + [EEXIST] = "CQM is already attached to this domain.", + [ENOENT] = "CQM is not attached to this domain.", + [EUSERS] = "there is no free CQM RMID available.", + [ESRCH] = "is this Domain ID valid?", +}; + +int libxl_pqos_attach(libxl_ctx *ctx, uint32_t domid, const char * qos_type) +{ + int rc; + uint32_t flags = 0; + + if (!strncmp(qos_type, "cqm", 3)) + flags |= XEN_DOMCTL_pqos_cqm; + else { + rc = -EINVAL; + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[EINVAL]); + return rc; + } + + rc = xc_domain_pqos_attach(ctx->xch, domid, flags); + if (rc < 0) { + switch(errno) { + case EINVAL: + case ENODEV: + case EEXIST: + case EUSERS: + case ESRCH: + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[errno]); + break; + default: + LIBXL__LOG(ctx, XTL_ERROR, "errno: %d", errno); + } + } + + return rc; +} + +int libxl_pqos_detach(libxl_ctx *ctx, uint32_t domid, const char * qos_type) +{ + int rc; + uint32_t flags = 0; + + if (!strncmp(qos_type, "cqm", 3)) + flags |= XEN_DOMCTL_pqos_cqm; + else { + rc = -EINVAL; + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[EINVAL]); + return rc; + } + + rc = xc_domain_pqos_detach(ctx->xch, domid, flags); + if (rc < 0) { + switch(errno) { + case EINVAL: + case ENODEV: + case ENOENT: + case ESRCH: + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[errno]); + break; + default: + LIBXL__LOG(ctx, XTL_ERROR, "errno: %d", errno); + } + } + + return rc; +} + +int libxl_get_cqm_info(libxl_ctx *ctx, + sysctl_cqminfo_t *info) +{ + int ret; + + ret = xc_domain_getcqminfolist(ctx->xch, info); + if (ret < 0) + return -EINVAL; + + return ret; +} + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h index e005c39..994d3be 100644 --- a/tools/libxl/xl.h +++ b/tools/libxl/xl.h @@ -105,6 +105,9 @@ int main_getenforce(int argc, char **argv); int main_setenforce(int argc, char **argv); int main_loadpolicy(int argc, char **argv); int main_remus(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); diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 8690ec7..5ff8f44 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -7193,6 +7193,152 @@ int main_remus(int argc, char **argv) return -ERROR_FAIL; } +int main_pqosattach(int argc, char **argv) +{ + uint32_t domid; + int opt, rc; + const char *qos_type = NULL; + + SWITCH_FOREACH_OPT(opt, "", NULL, "pqos-attach", 2) { + /* No options */ + } + + qos_type = argv[optind]; + domid = find_domain(argv[optind + 1]); + + rc = libxl_pqos_attach(ctx, domid, qos_type); + + return rc; +} + +int main_pqosdetach(int argc, char **argv) +{ + uint32_t domid; + int opt, rc; + const char *qos_type = NULL; + + SWITCH_FOREACH_OPT(opt, "", NULL, "pqos-detach", 2) { + /* No options */ + } + + qos_type = argv[optind]; + domid = find_domain(argv[optind + 1]); + + rc = libxl_pqos_detach(ctx, domid, qos_type); + + return rc; +} + +static void print_cqm_info(const sysctl_cqminfo_t *info, uint32_t first_domain, + unsigned int num_domains) +{ + unsigned long i, j, k; + xen_socket_cqmdata_t *cqmdata; + char *domname; + int print_header; + int print_newdom; + int cqm_domains = 0; + + if (info->num_rmid == 0) + printf("System doesn''t support CQM.\n"); + else { + print_header = 1; + for (i = first_domain; i < (first_domain + num_domains); i++) { + print_newdom = 1; + for (j = 0; j < (info->num_rmid * info->num_sockets); j++) { + cqmdata = info->cqmdata + j; + if (!cqmdata->valid || cqmdata->domid != i) + continue; + + if (print_header) { + printf("Name ID"); + for (k = 0; k < info->num_sockets; k++) + printf("\tSocketID\tL3C_Usage"); + print_header = 0; + } + + if (print_newdom) { + domname = libxl_domid_to_name(ctx, cqmdata->domid); + printf("\n%-40s %5d", domname, cqmdata->domid); + free(domname); + print_newdom = 0; + cqm_domains++; + } + printf("%10u %16lu ", cqmdata->socket, cqmdata->l3c_occupancy); + } + } + if (!cqm_domains) + printf("No RMID is assigned to domains.\n"); + else + printf("\n"); + printf("\nRMID count %5d\tRMID available %5d\n", + info->num_rmid, info->num_rmid - cqm_domains - 1); + } +} + +int main_pqoslist(int argc, char **argv) +{ + int opt; + const char *qos_type = NULL; + uint32_t first_domain; + unsigned int num_domains; + int rc = 0; + sysctl_cqminfo_t info; + + SWITCH_FOREACH_OPT(opt, "", NULL, "pqos-list", 1) { + /* No options */ + } + + qos_type = argv[optind]; + + if (!strncmp(qos_type, "cqm", 3)) { + if (optind + 1 >= argc) { + first_domain = 0; + num_domains = 1024; + } else if (optind + 1 == argc - 1) { + first_domain = find_domain(argv[optind + 1]); + num_domains = 1; + if (!libxl_domid_to_name(ctx, first_domain)) + { + fprintf(stderr, "Invalid domain id: %d.\n", first_domain); + return 1; + } + } else { + help("pqos-list"); + return 2; + } + + info.num_rmid= 256; + info.num_sockets = 128; + info.cqmdata = calloc(info.num_rmid * info.num_sockets, + sizeof(xen_socket_cqmdata_t)); + if (!info.cqmdata) { + fprintf(stderr, "Allocating domain cqminfo failed.\n"); + return ERROR_FAIL; + } + + rc = libxl_get_cqm_info(ctx, &info); + + if (rc < 0) { + fprintf(stderr, "Failed to get domain CQM info, " + "check whether CQM feature is supported.\n"); + if (info.cqmdata) + free(info.cqmdata); + return 1; + } + print_cqm_info(&info, first_domain, num_domains); + + if (info.cqmdata) + free(info.cqmdata); + } else { + fprintf(stderr, "QoS resource type supported is: cqm.\n"); + help("pqos-list"); + return 2; + } + + return 0; +} + /* * Local variables: * mode: C diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index 326a660..6ced416 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -488,6 +488,21 @@ struct cmd_spec cmd_table[] = { " of the domain." }, + { "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 about all/some domains", + "<Resource> [Domain]", + }, }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec); -- 1.7.9.5
Dario Faggioli
2013-Dec-03 09:56 UTC
Re: [PATCH v4 3/7] x86: initialize per socket cpu map
On mar, 2013-12-03 at 16:47 +0800, Dongxiao Xu wrote:> diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c > index 9f81c7b..c421464 100644 > --- a/xen/arch/x86/smpboot.c > +++ b/xen/arch/x86/smpboot.c > @@ -59,6 +59,9 @@ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask); > cpumask_t cpu_online_map __read_mostly; > EXPORT_SYMBOL(cpu_online_map); > > +cpumask_t socket_cpu_map[MAX_NUM_SOCKETS] __read_mostly; > +EXPORT_SYMBOL(socket_random_cpu_map); > +^_random_ ? Regards, Dario -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Andrew Cooper
2013-Dec-03 11:46 UTC
Re: [PATCH v4 1/7] x86: detect and initialize Cache QoS Monitoring feature
On 03/12/13 08:47, Dongxiao Xu wrote:> 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. > > Signed-off-by: Jiongxi Li <jiongxi.li@intel.com> > Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> > --- > docs/misc/xen-command-line.markdown | 8 +++ > xen/arch/x86/Makefile | 1 + > xen/arch/x86/cpu/intel.c | 6 ++ > xen/arch/x86/pqos.c | 125 +++++++++++++++++++++++++++++++++++ > xen/arch/x86/setup.c | 3 + > xen/include/asm-x86/cpufeature.h | 1 + > xen/include/asm-x86/pqos.h | 42 ++++++++++++ > 7 files changed, 186 insertions(+) > create mode 100644 xen/arch/x86/pqos.c > create mode 100644 xen/include/asm-x86/pqos.h > > diff --git a/docs/misc/xen-command-line.markdown b/docs/misc/xen-command-line.markdown > index 15aa404..bdb5f44 100644 > --- a/docs/misc/xen-command-line.markdown > +++ b/docs/misc/xen-command-line.markdown > @@ -1037,3 +1037,11 @@ Use the x2apic physical apic driver. The alternative is the x2apic cluster driv > > Default: `true` > > Permit use of the `xsave/xrstor` instructions. > + > +### pqos > +> `= <boolean>` > + > +> Default: `true` > + > +Configure platform QoS services. > +For CQM feature, the default parameter is: pqos=1,cqm=1,cqm_max_rmid=255.This should be in its correct alphabetic position. It should also have "(Intel)" in the title, and enumerate the options. There isn''t really a good example to follow. Perhaps something like +> `= List of ( <boolean> | cqm=<boolean> | cqm_max_rmid=<integer> )`> diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile > index d502bdf..54962e0 100644 > --- a/xen/arch/x86/Makefile > +++ b/xen/arch/x86/Makefile > @@ -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 > > diff --git a/xen/arch/x86/cpu/intel.c b/xen/arch/x86/cpu/intel.c > index 27fe762..f0d83ea 100644 > --- a/xen/arch/x86/cpu/intel.c > +++ b/xen/arch/x86/cpu/intel.c > @@ -230,6 +230,12 @@ static void __devinit init_intel(struct cpuinfo_x86 *c) > ( c->cpuid_level >= 0x00000006 ) && > ( cpuid_eax(0x00000006) & (1u<<2) ) ) > set_bit(X86_FEATURE_ARAT, c->x86_capability); > + > + /* Check platform QoS monitoring capability */ > + if ((c->cpuid_level >= 0x00000007) && > + (cpuid_ebx(0x00000007) & (1u<<12))) > + set_bit(X86_FEATURE_QOSM, c->x86_capability); > + > } > > static struct cpu_dev intel_cpu_dev __cpuinitdata = { > diff --git a/xen/arch/x86/pqos.c b/xen/arch/x86/pqos.c > new file mode 100644 > index 0000000..b786ec2 > --- /dev/null > +++ b/xen/arch/x86/pqos.c > @@ -0,0 +1,125 @@ > +/* > + * pqos.c: Platform QoS related service for guest. > + * > + * Copyright (c) 2013, Intel Corporation > + * Author: Jiongxi Li <jiongxi.li@intel.com> > + * Author: Dongxiao Xu <dongxiao.xu@intel.com> > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms and conditions of the GNU General Public License, > + * version 2, as published by the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * You should have received a copy of the GNU General Public License along with > + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple > + * Place - Suite 330, Boston, MA 02111-1307 USA. > + */ > +#include <asm/processor.h> > +#include <xen/init.h> > +#include <asm/pqos.h> > + > +static bool_t __initdata opt_pqos = 1; > +static bool_t __initdata opt_cqm = 1; > +static unsigned int __initdata opt_cqm_max_rmid = 255; > + > +static void __init parse_pqos_param(char *s) > +{ > + char *ss; > + char *val_str; > + unsigned long val; > + > + do { > + ss = strchr(s, '',''); > + if ( ss ) > + *ss = ''\0''; > + > + val_str = strchr(s, ''=''); > + if ( !val_str ) > + val_str = s; > + else > + val_str += 1; > + > + if ( !parse_bool(s) ) > + opt_pqos = 0; > + else if ( !strncmp(s, "cqm=", 4) && !parse_bool(val_str) ) > + opt_cqm = 0; > + else if ( !strncmp(s, "cqm_max_rmid=", 13) && > + (val = simple_strtoul(val_str, NULL, 0)) ) > + opt_cqm_max_rmid = val; > + > + s = ss + 1; > + } while ( ss ); > +} > +custom_param("pqos", parse_pqos_param);This currently won''t do what you expect, and to get regular Xen boolean behaviour, you need tobe a little more cunning. Here is some completely untested code... static void __init parse_pqos_param(char *s) { char *ss; char *val_str; int val; do { val = !!strncmp(s, "no-", 3); if ( !val ) s += 3; ss = strchr(s, '',''); if ( ss ) *ss = ''\0''; val_str = strchr(s, ''=''); if ( !parse_bool(s) ) opt_pqos = 0; else if ( !strcmp(s, "cqm") ) { if ( val_str && !parse_bool(val_str) ) val = !val; opt_cqm = val; } else if ( val_str && !strcmp(s, "cqm_max_rmid") ) opt_cqm_max_rmid = simple_strtoul(val_str, NULL, 0); s = ss + 1; } while ( ss ); } Which should allow things like "pqos=no-cqm" to work as expected.> + > +struct pqos_cqm *cqm; > + > +static void __init init_cqm(void) > +{ > + unsigned int rmid; > + unsigned int eax, edx;You have to deal with the case that opt_cqm_max_rmid is 0 if the user has provided junk on the command line. I would return early here in this case. ~Andrew> + > + cqm = xzalloc(struct pqos_cqm); > + if ( !cqm ) > + return; > + > + cpuid_count(0xf, 1, &eax, &cqm->upscaling_factor, &cqm->max_rmid, &edx); > + if ( !(edx & QOS_MONITOR_EVTID_L3) ) > + { > + xfree(cqm); > + return; > + } > + > + cqm->min_rmid = 1; > + cqm->max_rmid = min(opt_cqm_max_rmid, cqm->max_rmid); > + > + cqm->rmid_to_dom = xmalloc_array(domid_t, cqm->max_rmid + 1); > + if ( !cqm->rmid_to_dom ) > + { > + xfree(cqm); > + return; > + } > + > + /* Reserve RMID 0 for all domains not being monitored */ > + cqm->rmid_to_dom[0] = DOMID_XEN; > + for ( rmid = cqm->min_rmid; rmid <= cqm->max_rmid; rmid++ ) > + cqm->rmid_to_dom[rmid] = DOMID_INVALID; > + > + printk(XENLOG_INFO "Cache QoS Monitoring Enabled.\n"); > +} > + > +static void __init init_qos_monitor(void) > +{ > + unsigned int qm_features; > + unsigned int eax, ebx, ecx; > + > + if ( !(boot_cpu_has(X86_FEATURE_QOSM)) ) > + return; > + > + cpuid_count(0xf, 0, &eax, &ebx, &ecx, &qm_features); > + > + if ( opt_cqm && (qm_features & QOS_MONITOR_TYPE_L3) ) > + init_cqm(); > +} > + > +void __init init_platform_qos(void) > +{ > + if ( !opt_pqos ) > + return; > + > + init_qos_monitor(); > +} > + > +/* > + * Local variables: > + * mode: C > + * c-file-style: "BSD" > + * c-basic-offset: 4 > + * tab-width: 4 > + * indent-tabs-mode: nil > + * End: > + */ > diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c > index 5bf4ee0..95418e4 100644 > --- a/xen/arch/x86/setup.c > +++ b/xen/arch/x86/setup.c > @@ -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; > @@ -1402,6 +1403,8 @@ void __init __start_xen(unsigned long mbi_p) > > domain_unpause_by_systemcontroller(dom0); > > + init_platform_qos(); > + > reset_stack_and_jump(init_done); > } > > diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeature.h > index 1cfaf94..ca59668 100644 > --- a/xen/include/asm-x86/cpufeature.h > +++ b/xen/include/asm-x86/cpufeature.h > @@ -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 */ > > diff --git a/xen/include/asm-x86/pqos.h b/xen/include/asm-x86/pqos.h > new file mode 100644 > index 0000000..94d4f6e > --- /dev/null > +++ b/xen/include/asm-x86/pqos.h > @@ -0,0 +1,42 @@ > +/* > + * pqos.h: Platform QoS related service for guest. > + * > + * Copyright (c) 2013, Intel Corporation > + * Author: Jiongxi Li <jiongxi.li@intel.com> > + * Author: Dongxiao Xu <dongxiao.xu@intel.com> > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms and conditions of the GNU General Public License, > + * version 2, as published by the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * You should have received a copy of the GNU General Public License along with > + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple > + * Place - Suite 330, Boston, MA 02111-1307 USA. > + */ > +#ifndef ASM_PQOS_H > +#define ASM_PQOS_H > + > +#include <public/xen.h> > + > +/* QoS Resource Type Enumeration */ > +#define QOS_MONITOR_TYPE_L3 0x2 > + > +/* QoS Monitoring Event ID */ > +#define QOS_MONITOR_EVTID_L3 0x1 > + > +struct pqos_cqm { > + unsigned int min_rmid; > + unsigned int max_rmid; > + unsigned int upscaling_factor; > + domid_t *rmid_to_dom; > +}; > +extern struct pqos_cqm *cqm; > + > +void init_platform_qos(void); > + > +#endif
Andrew Cooper
2013-Dec-03 11:52 UTC
Re: [PATCH v4 4/7] x86: collect CQM information from all sockets
On 03/12/13 08:47, Dongxiao Xu wrote:> 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: Jiongxi Li <jiongxi.li@intel.com> > Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> > --- > xen/arch/x86/pqos.c | 46 +++++++++++++++++++++++++++++ > xen/arch/x86/sysctl.c | 62 +++++++++++++++++++++++++++++++++++++++ > xen/include/asm-x86/msr-index.h | 4 +++ > xen/include/asm-x86/pqos.h | 7 +++++ > xen/include/public/domctl.h | 9 ++++++ > xen/include/public/sysctl.h | 10 +++++++ > 6 files changed, 138 insertions(+) > > diff --git a/xen/arch/x86/pqos.c b/xen/arch/x86/pqos.c > index dd22cae..dc0f0fc 100644 > --- a/xen/arch/x86/pqos.c > +++ b/xen/arch/x86/pqos.c > @@ -19,6 +19,7 @@ > * Place - Suite 330, Boston, MA 02111-1307 USA. > */ > #include <asm/processor.h> > +#include <asm/msr.h> > #include <xen/init.h> > #include <xen/spinlock.h> > #include <asm/pqos.h> > @@ -121,6 +122,12 @@ bool_t system_supports_cqm(void) > return !!cqm; > } > > +unsigned int get_cqm_count(void) > +{ > + ASSERT(system_supports_cqm()); > + return cqm->max_rmid + 1; > +} > + > int alloc_cqm_rmid(struct domain *d) > { > int rc = 0; > @@ -165,6 +172,45 @@ void free_cqm_rmid(struct domain *d) > d->arch.pqos_cqm_rmid = 0; > } > > +static void read_cqm_data(void *arg) > +{ > + uint64_t cqm_data; > + unsigned int rmid; > + int socket = cpu_to_socket(smp_processor_id()); > + struct xen_socket_cqmdata *data = arg; > + unsigned long flags, i; > + > + ASSERT(system_supports_cqm()); > + > + if ( socket < 0 ) > + return; > + > + spin_lock_irqsave(&cqm_lock, flags); > + 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 = socket * (cqm->max_rmid + 1) + rmid; > + data[i].valid = !(cqm_data & IA32_QM_CTR_ERROR_MASK); > + if ( data[i].valid ) > + { > + data[i].l3c_occupancy = cqm_data * cqm->upscaling_factor; > + data[i].socket = socket; > + data[i].domid = cqm->rmid_to_dom[rmid]; > + } > + } > + spin_unlock_irqrestore(&cqm_lock, flags); > +} > + > +void get_cqm_info(cpumask_t *cpu_cqmdata_map, struct xen_socket_cqmdata *data) > +{ > + on_selected_cpus(cpu_cqmdata_map, read_cqm_data, data, 1); > +} > + > /* > * Local variables: > * mode: C > diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c > index 15d4b91..3977e7d 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,21 @@ void arch_do_physinfo(xen_sysctl_physinfo_t *pi) > pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm_directio; > } > > +/* Select one random CPU for each socket */ > +static void select_socket_cpu(cpumask_t *cpu_bitmap) > +{ > + int i; > + unsigned int cpu; > + > + cpumask_clear(cpu_bitmap); > + for ( i = 0; i < MAX_NUM_SOCKETS; i++ ) > + { > + cpu = cpumask_any(&socket_cpu_map[i]); > + if ( cpu < nr_cpu_ids ) > + cpumask_set_cpu(cpu, cpu_bitmap); > + } > +} > + > long arch_do_sysctl( > struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) > { > @@ -101,6 +117,52 @@ long arch_do_sysctl( > } > break; > > + case XEN_SYSCTL_getcqminfo: > + { > + struct xen_socket_cqmdata *info; > + uint32_t num_sockets; > + uint32_t num_rmid; > + cpumask_t cpu_cqmdata_map; > + > + if ( !system_supports_cqm() ) > + { > + ret = -ENODEV; > + break; > + } > + > + select_socket_cpu(&cpu_cqmdata_map);This should exclude the current socket. There is no point IPI''ing a different cpu on the same socket for an action this cpu can perform. ~Andrew> + > + num_sockets = min((unsigned int)cpumask_weight(&cpu_cqmdata_map), > + sysctl->u.getcqminfo.num_sockets); > + num_rmid = get_cqm_count(); > + info = xzalloc_array(struct xen_socket_cqmdata, > + num_rmid * num_sockets); > + if ( !info ) > + { > + ret = -ENOMEM; > + break; > + } > + > + get_cqm_info(&cpu_cqmdata_map, info); > + > + if ( copy_to_guest_offset(sysctl->u.getcqminfo.buffer, > + 0, info, num_rmid * num_sockets) ) > + { > + ret = -EFAULT; > + xfree(info); > + break; > + } > + > + sysctl->u.getcqminfo.num_rmid = num_rmid; > + sysctl->u.getcqminfo.num_sockets = num_sockets; > + > + if ( copy_to_guest(u_sysctl, sysctl, 1) ) > + ret = -EFAULT; > + > + xfree(info); > + } > + break; > + > default: > ret = -ENOSYS; > break; > diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-index.h > index e597a28..46ef165 100644 > --- a/xen/include/asm-x86/msr-index.h > +++ b/xen/include/asm-x86/msr-index.h > @@ -488,4 +488,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 9807485..49f2302 100644 > --- a/xen/include/asm-x86/pqos.h > +++ b/xen/include/asm-x86/pqos.h > @@ -21,6 +21,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> > > @@ -38,10 +40,15 @@ struct pqos_cqm { > }; > extern struct pqos_cqm *cqm; > > +/* IA32_QM_CTR */ > +#define IA32_QM_CTR_ERROR_MASK (0x3ul << 62) > + > void init_platform_qos(void); > > bool_t system_supports_cqm(void); > int alloc_cqm_rmid(struct domain *d); > void free_cqm_rmid(struct domain *d); > +unsigned int get_cqm_count(void); > +void get_cqm_info(cpumask_t *cpu_cqmdata_map, struct xen_socket_cqmdata *data); > > #endif > diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h > index d53e216..563aeaf 100644 > --- a/xen/include/public/domctl.h > +++ b/xen/include/public/domctl.h > @@ -877,6 +877,15 @@ struct xen_domctl_qos_type { > typedef struct xen_domctl_qos_type xen_domctl_qos_type_t; > DEFINE_XEN_GUEST_HANDLE(xen_domctl_qos_type_t); > > +struct xen_socket_cqmdata { > + uint64_t l3c_occupancy; > + uint32_t socket; > + domid_t domid; > + uint8_t valid; > +}; > +typedef struct xen_socket_cqmdata xen_socket_cqmdata_t; > +DEFINE_XEN_GUEST_HANDLE(xen_socket_cqmdata_t); > + > struct xen_domctl { > uint32_t cmd; > #define XEN_DOMCTL_createdomain 1 > diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h > index 8437d31..8b2844e 100644 > --- a/xen/include/public/sysctl.h > +++ b/xen/include/public/sysctl.h > @@ -632,6 +632,14 @@ 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); > > +/* XEN_SYSCTL_getcqminfo */ > +struct xen_sysctl_getcqminfo { > + XEN_GUEST_HANDLE_64(xen_socket_cqmdata_t) buffer; /* OUT */ > + uint32_t num_sockets; /* IN/OUT */ > + uint32_t num_rmid; /* OUT */ > +}; > +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 +662,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 +684,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; > };
Dario Faggioli
2013-Dec-03 12:17 UTC
Re: [PATCH v4 7/7] tools: enable Cache QoS Monitoring feature for libxl/libxc
On mar, 2013-12-03 at 16:47 +0800, Dongxiao Xu wrote:> 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 (domid) > > Signed-off-by: Jiongxi Li <jiongxi.li@intel.com> > Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> > --- > tools/libxc/xc_domain.c | 47 +++++++++++++++ > tools/libxc/xenctrl.h | 11 ++++ > tools/libxl/Makefile | 3 +- > tools/libxl/libxl.h | 5 ++ > tools/libxl/libxl_pqos.c | 108 +++++++++++++++++++++++++++++++++ > tools/libxl/xl.h | 3 + > tools/libxl/xl_cmdimpl.c | 146 +++++++++++++++++++++++++++++++++++++++++++++ > tools/libxl/xl_cmdtable.c | 15 +++++ > 8 files changed, 337 insertions(+), 1 deletion(-) > create mode 100644 tools/libxl/libxl_pqos.c >Would it be possible to split this patch in 3, one for libxc, one for libxl and one for xl?> diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h > index c7dceda..fdca92d 100644 > --- a/tools/libxl/libxl.h > +++ b/tools/libxl/libxl.h > @@ -285,6 +285,7 @@ > > #include <libxl_uuid.h> > #include <_libxl_list.h> > +#include <xenctrl.h> >Is this really necessary? I think it shouldn''t... <xenctrl.h> is already included in "libxl_internal.h", which you are including yourself below, so...> diff --git a/tools/libxl/libxl_pqos.c b/tools/libxl/libxl_pqos.c > new file mode 100644 > index 0000000..bf7593a > --- /dev/null > +++ b/tools/libxl/libxl_pqos.c > @@ -0,0 +1,108 @@ > +/* > + * Copyright (C) 2013 Intel Corporation > + * Author Jiongxi Li <jiongxi.li@intel.com> > + * Author Dongxiao Xu <dongxiao.xu@intel.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU Lesser General Public License as published > + * by the Free Software Foundation; version 2.1 only. with the special > + * exception on linking described in file LICENSE. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU Lesser General Public License for more details. > + */ > + > +#include "libxl_osdeps.h" /* must come before any other headers */ > +#include "libxl_internal.h"> +int libxl_pqos_attach(libxl_ctx *ctx, uint32_t domid, const char * qos_type) > +{ > + int rc; > + uint32_t flags = 0; > + > + if (!strncmp(qos_type, "cqm", 3)) > + flags |= XEN_DOMCTL_pqos_cqm; > + else { > + rc = -EINVAL; > + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[EINVAL]); >I think new code should use the LOG() / LOGE() variant of the logging macros.> + return rc; > + } >libxl functions should return libxl error codes.> + > + rc = xc_domain_pqos_attach(ctx->xch, domid, flags); > + if (rc < 0) { > + switch(errno) { > + case EINVAL: > + case ENODEV: > + case EEXIST: > + case EUSERS: > + case ESRCH: > + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[errno]); > + break; > + default: > + LIBXL__LOG(ctx, XTL_ERROR, "errno: %d", errno); > + } > + } > +Mmm... Isn''t there a better place where to do this demultiplexing and printing the correct message? Looking around, in libxl, what usually happens is printing something generic enough, together with the errno value/message (with LOGE), and then rely on lower layers to provide a more detailed explanation of what happened. This is certainly up to a maintainer to decide, but I think you at least (you''re doing this twice) should do it in a function rather than duplicating the whole switch. Regards, Dario -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Jan Beulich
2013-Dec-03 12:54 UTC
Re: [PATCH v4 1/7] x86: detect and initialize Cache QoS Monitoring feature
>>> On 03.12.13 at 12:46, Andrew Cooper <andrew.cooper3@citrix.com> wrote: > This currently won''t do what you expect, and to get regular Xen boolean > behaviour, you need tobe a little more cunning. > > Here is some completely untested code... > > static void __init parse_pqos_param(char *s) > { > char *ss; > char *val_str; > int val; > > do { > val = !!strncmp(s, "no-", 3); > if ( !val ) > s += 3; > > ss = strchr(s, '',''); > if ( ss ) > *ss = ''\0''; > > val_str = strchr(s, ''=''); > > if ( !parse_bool(s) ) > opt_pqos = 0;This won''t either - parse_bool() returns the boolean value, or negative if the input didn''t match any of the boolean tokens. Also, while I realize that you likely took this from elsewhere, I think we should stop further propagation of bad things (like allowing "pqos=no-true" or "pqos=no-cqm=on"). And using = for both the top level separator and the sub-option ones looks odd to me generally too. I''d suggest using : instead. Jan
Andrew Cooper
2013-Dec-03 13:45 UTC
Re: [PATCH v4 1/7] x86: detect and initialize Cache QoS Monitoring feature
On 03/12/13 12:54, Jan Beulich wrote:>>>> On 03.12.13 at 12:46, Andrew Cooper <andrew.cooper3@citrix.com> wrote: >> This currently won''t do what you expect, and to get regular Xen boolean >> behaviour, you need tobe a little more cunning. >> >> Here is some completely untested code... >> >> static void __init parse_pqos_param(char *s) >> { >> char *ss; >> char *val_str; >> int val; >> >> do { >> val = !!strncmp(s, "no-", 3); >> if ( !val ) >> s += 3; >> >> ss = strchr(s, '',''); >> if ( ss ) >> *ss = ''\0''; >> >> val_str = strchr(s, ''=''); >> >> if ( !parse_bool(s) ) >> opt_pqos = 0; > This won''t either - parse_bool() returns the boolean value, or > negative if the input didn''t match any of the boolean tokens. > > Also, while I realize that you likely took this from elsewhere, I > think we should stop further propagation of bad things (like > allowing "pqos=no-true" or "pqos=no-cqm=on"). > > And using = for both the top level separator and the sub-option > ones looks odd to me generally too. I''d suggest using : instead. > > Jan >Hmm yes - perhaps that would be better, and more in line with the current options such as dom0_mem So something like this? static void __init parse_pqos_param(char *s) { char *ss, *val_str; int val; do { val = !!strncmp(s, "no-", 3); if ( !val ) s += 3; ss = strchr(s, '',''); if ( ss ) *ss = ''\0''; val_str = strchr(s, '':''); if ( !parse_bool(s) ) opt_pqos = 0; else if ( !strcmp(s, "cqm") ) opt_cqm = val; else if ( val_str && !strcmp(s, "cqm_max_rmid") ) opt_cqm_max_rmid = simple_strtoul(val_str, NULL, 0); s = ss + 1; } while ( ss ); } ~Andrew
Daniel De Graaf
2013-Dec-03 13:53 UTC
Re: [PATCH v4 6/7] xsm: add platform QoS related xsm policies
On 12/03/2013 03:47 AM, Dongxiao Xu wrote:> Add xsm policies for attach/detach pqos services and get CQM info > hypercalls. > > Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> > Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> > --- > tools/flask/policy/policy/modules/xen/xen.if | 2 +- > tools/flask/policy/policy/modules/xen/xen.te | 5 ++++- > xen/xsm/flask/hooks.c | 7 +++++++ > xen/xsm/flask/policy/access_vectors | 17 ++++++++++++++--- > 4 files changed, 26 insertions(+), 5 deletions(-) >[...]> diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c > index b1e2593..6f9f355 100644 > --- a/xen/xsm/flask/hooks.c > +++ b/xen/xsm/flask/hooks.c > @@ -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,9 @@ static int flask_sysctl(int cmd) > case XEN_SYSCTL_numainfo: > return domain_has_xen(current->domain, XEN__PHYSINFO); > > + case XEN_SYSCTL_getcqminfo: > + avc_current_has_perm(SECINITSID_XEN, SECCLASS_XEN2, XEN2__PQOS_OP, NULL); > + > default: > printk("flask_sysctl: Unknown op %d\n", cmd); > return -EPERM;This needs to be "return avc_current_has_perm..." -- Daniel De Graaf National Security Agency
Jan Beulich
2013-Dec-03 14:01 UTC
Re: [PATCH v4 1/7] x86: detect and initialize Cache QoS Monitoring feature
>>> On 03.12.13 at 14:45, Andrew Cooper <andrew.cooper3@citrix.com> wrote: > On 03/12/13 12:54, Jan Beulich wrote: >> This won''t either - parse_bool() returns the boolean value, or >> negative if the input didn''t match any of the boolean tokens. >> >> Also, while I realize that you likely took this from elsewhere, I >> think we should stop further propagation of bad things (like >> allowing "pqos=no-true" or "pqos=no-cqm=on"). >> >> And using = for both the top level separator and the sub-option >> ones looks odd to me generally too. I''d suggest using : instead. > > Hmm yes - perhaps that would be better, and more in line with the > current options such as dom0_mem > > So something like this?That didn''t take into account all issues I had named. static void __init parse_pqos_param(char *s) { char *ss, *val_str; int val; do { ss = strchr(s, '',''); if ( ss ) *ss = ''\0''; val = parse_bool(s); if ( val >= 0 ) opt_pqos = val; else { val = !!strncmp(s, "no-", 3); if ( !val ) s += 3; val_str = strchr(s, '':''); if ( val_str ) *val_str++ = ''\0''; if ( !val_str && !strcmp(s, "cqm") ) opt_cqm = val; else if ( val_str && !strcmp(s, "cqm_max_rmid") ) opt_cqm_max_rmid = simple_strtoul(val_str, NULL, 0); } s = ss + 1; } while ( ss ); } Jan
Konrad Rzeszutek Wilk
2013-Dec-03 20:32 UTC
Re: [PATCH v4 1/7] x86: detect and initialize Cache QoS Monitoring feature
> @@ -0,0 +1,125 @@ > +/* > + * pqos.c: Platform QoS related service for guest. > + * > + * Copyright (c) 2013, Intel Corporation > + * Author: Jiongxi Li <jiongxi.li@intel.com> > + * Author: Dongxiao Xu <dongxiao.xu@intel.com> > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms and conditions of the GNU General Public License, > + * version 2, as published by the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * You should have received a copy of the GNU General Public License along with > + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple > + * Place - Suite 330, Boston, MA 02111-1307 USA.Linux has been removing the address since well, they ("Free Software Foundation") has actually moved to 51 Franklin St. Cheaper rent I hear. Should we start removing the addresses in the headers or just stop doing it on the new submissions?
Xu, Dongxiao
2013-Dec-04 02:44 UTC
Re: [PATCH v4 7/7] tools: enable Cache QoS Monitoring feature for libxl/libxc
> -----Original Message----- > From: Dario Faggioli [mailto:dario.faggioli@citrix.com] > Sent: Tuesday, December 03, 2013 8:17 PM > To: Xu, Dongxiao > Cc: xen-devel@lists.xen.org; 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: Re: [Xen-devel] [PATCH v4 7/7] tools: enable Cache QoS Monitoring > feature for libxl/libxc > > On mar, 2013-12-03 at 16:47 +0800, Dongxiao Xu wrote: > > 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 (domid) > > > > Signed-off-by: Jiongxi Li <jiongxi.li@intel.com> > > Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com> > > --- > > tools/libxc/xc_domain.c | 47 +++++++++++++++ > > tools/libxc/xenctrl.h | 11 ++++ > > tools/libxl/Makefile | 3 +- > > tools/libxl/libxl.h | 5 ++ > > tools/libxl/libxl_pqos.c | 108 +++++++++++++++++++++++++++++++++ > > tools/libxl/xl.h | 3 + > > tools/libxl/xl_cmdimpl.c | 146 > +++++++++++++++++++++++++++++++++++++++++++++ > > tools/libxl/xl_cmdtable.c | 15 +++++ > > 8 files changed, 337 insertions(+), 1 deletion(-) > > create mode 100644 tools/libxl/libxl_pqos.c > > > Would it be possible to split this patch in 3, one for libxc, one for > libxl and one for xl?Originally the patch is split (by functional), and later I merged them according to Andrew''s suggestion. I think merge is okay since the logic is simple and straightforward.> > > > diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h > > index c7dceda..fdca92d 100644 > > --- a/tools/libxl/libxl.h > > +++ b/tools/libxl/libxl.h > > @@ -285,6 +285,7 @@ > > > > #include <libxl_uuid.h> > > #include <_libxl_list.h> > > +#include <xenctrl.h> > > > Is this really necessary? I think it shouldn''t... <xenctrl.h> is already > included in "libxl_internal.h", which you are including yourself below, > so...libxl.h will reference "sysctl_cqminfo_t", which is defined in xenctrl.h. I didn''t see libxl_internal.h is included in libxl.h, can you help to point it out?> > > diff --git a/tools/libxl/libxl_pqos.c b/tools/libxl/libxl_pqos.c > > new file mode 100644 > > index 0000000..bf7593a > > --- /dev/null > > +++ b/tools/libxl/libxl_pqos.c > > @@ -0,0 +1,108 @@ > > +/* > > + * Copyright (C) 2013 Intel Corporation > > + * Author Jiongxi Li <jiongxi.li@intel.com> > > + * Author Dongxiao Xu <dongxiao.xu@intel.com> > > + * > > + * This program is free software; you can redistribute it and/or modify > > + * it under the terms of the GNU Lesser General Public License as published > > + * by the Free Software Foundation; version 2.1 only. with the special > > + * exception on linking described in file LICENSE. > > + * > > + * This program is distributed in the hope that it will be useful, > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > + * GNU Lesser General Public License for more details. > > + */ > > + > > +#include "libxl_osdeps.h" /* must come before any other headers */ > > +#include "libxl_internal.h" > > > +int libxl_pqos_attach(libxl_ctx *ctx, uint32_t domid, const char * qos_type) > > +{ > > + int rc; > > + uint32_t flags = 0; > > + > > + if (!strncmp(qos_type, "cqm", 3)) > > + flags |= XEN_DOMCTL_pqos_cqm; > > + else { > > + rc = -EINVAL; > > + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[EINVAL]); > > > I think new code should use the LOG() / LOGE() variant of the logging > macros.I saw a lot of existing code still uses LIBXL__LOG() function. Besides, if we use LOGE(), we need to pass another variable "gc" to the function... Is this a guideline that we will stick to LOG()/LOGE() and deprecate calling of LIBXL__LOG() in later code?> > > + return rc; > > + } > > > libxl functions should return libxl error codes.Okay.> > > + > > + rc = xc_domain_pqos_attach(ctx->xch, domid, flags); > > + if (rc < 0) { > > + switch(errno) { > > + case EINVAL: > > + case ENODEV: > > + case EEXIST: > > + case EUSERS: > > + case ESRCH: > > + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[errno]); > > + break; > > + default: > > + LIBXL__LOG(ctx, XTL_ERROR, "errno: %d", errno); > > + } > > + } > > + > Mmm... Isn''t there a better place where to do this demultiplexing and > printing the correct message? Looking around, in libxl, what usually > happens is printing something generic enough, together with the errno > value/message (with LOGE), and then rely on lower layers to provide a > more detailed explanation of what happened. > > This is certainly up to a maintainer to decide, but I think you at least > (you''re doing this twice) should do it in a function rather than > duplicating the whole switch.Will abstract the logic into an internal function. Thanks, Dongxiao> > Regards, > Dario > > -- > <<This happens because I choose it to happen!>> (Raistlin Majere) > ----------------------------------------------------------------- > Dario Faggioli, Ph.D, http://about.me/dario.faggioli > Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
Dario Faggioli
2013-Dec-04 08:14 UTC
Re: [PATCH v4 7/7] tools: enable Cache QoS Monitoring feature for libxl/libxc
On mer, 2013-12-04 at 02:44 +0000, Xu, Dongxiao wrote:> > -----Original Message----- > > From: Dario Faggioli [mailto:dario.faggioli@citrix.com]> > Would it be possible to split this patch in 3, one for libxc, one for > > libxl and one for xl? > > Originally the patch is split (by functional), and later I merged them according to Andrew''s suggestion. > I think merge is okay since the logic is simple and straightforward. >Oh, sorry for not noticing that. My personal preference is to always split, even if logic is trivial, but again, that''s just me. :-)> > > diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h > > > index c7dceda..fdca92d 100644 > > > --- a/tools/libxl/libxl.h > > > +++ b/tools/libxl/libxl.h > > > @@ -285,6 +285,7 @@ > > > > > > #include <libxl_uuid.h> > > > #include <_libxl_list.h> > > > +#include <xenctrl.h> > > > > > Is this really necessary? I think it shouldn''t... <xenctrl.h> is already > > included in "libxl_internal.h", which you are including yourself below, > > so... > > libxl.h will reference "sysctl_cqminfo_t", which is defined in xenctrl.h. > I didn''t see libxl_internal.h is included in libxl.h, can you help to point it out? >I see. No, all I said is that your new file, libxl_pqos.c, already includes xenctrl.h, and hence I was asking whether that is not enough and if not, why, and you just answered. TBH, it still looks wrong to me. It does not happen for any other similar situations and data type (or at least situations and data type that look similar enough to me). What we do there, is defining a libxl counterpart of the xc_* type, use it in the libxl interface and translate between the twos _inside_ the libxl function, which is implemented somewhere where libxl_internal.h, and then xenctrl.h, is included, and have no problem seeing the xc_* type declaration. Look, for example at libxl_get_physinfo(), xc_physinfo(), xc_physinfo_t. Or you think your case is somewhat different? If yes, how?> > > +int libxl_pqos_attach(libxl_ctx *ctx, uint32_t domid, const char * qos_type) > > > +{ > > > + int rc; > > > + uint32_t flags = 0; > > > + > > > + if (!strncmp(qos_type, "cqm", 3)) > > > + flags |= XEN_DOMCTL_pqos_cqm; > > > + else { > > > + rc = -EINVAL; > > > + LIBXL__LOG(ctx, XTL_ERROR, "%s", msg[EINVAL]); > > > > > I think new code should use the LOG() / LOGE() variant of the logging > > macros. > > I saw a lot of existing code still uses LIBXL__LOG() function. > Besides, if we use LOGE(), we need to pass another variable "gc" to the function... > Is this a guideline that we will stick to LOG()/LOGE() and deprecate calling of LIBXL__LOG() in later code? >I don''t think it''s written anywhere yet, but I''m not sure. Anyway, I''ve seen similar requests on this list (even got one! :-P) from some time now. As per the new gc parameter, that''s not true, all you need is adding a GC_INIT(ctx); call at the beginning of the function and a GC_FREE at the end. Regards, Dario -- <<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Ian Jackson
2013-Dec-04 11:37 UTC
Re: [PATCH v4 1/7] x86: detect and initialize Cache QoS Monitoring feature
Konrad Rzeszutek Wilk writes ("Re: [PATCH v4 1/7] x86: detect and initialize Cache QoS Monitoring feature"):> Linux has been removing the address since well, they ("Free Software > Foundation") has actually moved to 51 Franklin St. Cheaper rent I > hear. > > Should we start removing the addresses in the headers or just stop doing it > on the new submissions?The corresponding wording from the current GPLv3''s "How to apply these terms" section is as follows: You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. AIUI this is the wording which has been recommended by the FSF (whether for GPLv2, v2+, v3 or v3+) for some time now. I don''t think it''s necessary to fix this up everywhere but ideally new patches would have it right. Ian.