enable Cache Allocation Technology (CAT) for VMs
v7 cover enable Cache Allocation Technology (CAT) for VMs
Changes in v7:
Address comments from Jan/Ian, mainly:
* Introduce total_cpus to calculate nr_sockets.
* Clear the init/enable flag when a socket going offline.
* Reorder the statements in init_psr_cat.
* Copyback psr_cat_op only for XEN_SYSCTL_PSR_CAT_get_l3_info.
* Broadcast LIBXL_HAVE_SOCKET_BITMAP_ALLOC.
* Add PSR head1 level section and change CMT/CAT as its subsections for xl man page. Changes in v6:
Address comments from Andrew/Dario/Ian, mainly:
* Introduce cat_socket_init(_enable)_bitmap.
* Merge xl psr-cmt/cat-hwinfo => xl psr-hwinfo.
* Add function header to explain the 'target' parameter.
* Use bitmap instead of TARGETS_ALL.
* Document fix.
Changes in v5:
* Address comments from Andrew and Ian(Detail in patch).
* Add socket_to_cpumask.
* Add xl psr-cmt/cat-hwinfo.
* Add some libxl CMT enhancement.
Changes in v4:
* Address comments from Andrew and Ian(Detail in patch).
* Split COS/CBM management patch into 4 small patches.
* Add documentation xl-psr.markdown.
Changes in v3:
* Address comments from Jan and Ian(Detail in patch).
* Add xl sample output in cover letter.
Changes in v2:
* Address comments from Konrad and Jan(Detail in patch):
* Make all cat unrelated changes into the preparation patches.
This patch serial enables the new Cache Allocation Technology (CAT) feature found in Intel Broadwell and later server platform. In Xen's implementation, CAT is used to control cache allocation on VM basis.
Detail hardware spec can be found in section 17.15 of the Intel SDM [1]. The design for XEN can be found at [2].
patch1-2: preparation. patch3-9: real work for CAT. patch10-11: enhancement for CMT. patch12: libxl prepareation patch13: tools side work for CAT. patch14: xl document for CMT/MBM/CAT.
[1] Intel SDM (http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf)
[2] CAT design for XEN( http://lists.xen.org/archives/html/xen-devel/2014-12/msg01382.html)
Chao Peng (14):
x86: add socket_to_cpumask
x86: improve psr scheduling code
x86: detect and initialize Intel CAT feature
x86: maintain COS to CBM mapping for each socket
x86: add COS information for each domain
x86: expose CBM length and COS number information
x86: dynamically get/set CBM for a domain
x86: add scheduling support for Intel CAT
xsm: add CAT related xsm policies tools/libxl: minor name changes for CMT commands tools/libxl: add command to show PSR hardware info tools/libxl: introduce some socket helpers
tools: add tools support for Intel CAT
docs: add xl-psr.markdown
docs/man/xl.pod.1 | 76 ++++- docs/misc/xen-command-line.markdown | 15 +- docs/misc/xl-psr.markdown | 133 +++++++++ tools/flask/policy/policy/modules/xen/xen.if | 2 +- tools/flask/policy/policy/modules/xen/xen.te | 4 +- tools/libxc/include/xenctrl.h | 15 + tools/libxc/xc_psr.c | 76 +++++ tools/libxl/libxl.h | 42 +++ tools/libxl/libxl_internal.h | 2 + tools/libxl/libxl_psr.c | 143 ++++++++- tools/libxl/libxl_types.idl | 10 + tools/libxl/libxl_utils.c | 46 +++ tools/libxl/libxl_utils.h | 2 + tools/libxl/xl.h | 5 + tools/libxl/xl_cmdimpl.c | 262 ++++++++++++++++- tools/libxl/xl_cmdtable.c | 27 +- xen/arch/x86/domain.c | 13 +- xen/arch/x86/domctl.c | 20 ++ xen/arch/x86/mpparse.c | 5 + xen/arch/x86/psr.c | 422 +++++++++++++++++++++++++-- xen/arch/x86/smpboot.c | 25 +- xen/arch/x86/sysctl.c | 18 ++ xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/domain.h | 5 +- xen/include/asm-x86/msr-index.h | 1 + xen/include/asm-x86/psr.h | 13 +- xen/include/asm-x86/smp.h | 16 + xen/include/public/domctl.h | 12 + xen/include/public/sysctl.h | 16 + xen/xsm/flask/hooks.c | 6 + xen/xsm/flask/policy/access_vectors | 4 + 31 files changed, 1385 insertions(+), 52 deletions(-) create mode 100644 docs/misc/xl-psr.markdown
Signature · 1 line
1.9.1
PATCH v7 1/14 x86: add socket_to_cpumask
Maintain socket_to_cpumask which contains all the HT and core siblings in the same socket.
---
Changes in v7:
* Introduce total_cpus to calculate nr_sockets.
* Minor code sequence improvement in set_cpu_sibling_map.
* Improve comments for nr_sockets.
--- xen/arch/x86/mpparse.c | 5 +++++ xen/arch/x86/smpboot.c | 25 +++++++++++++++++++++++-- xen/include/asm-x86/smp.h | 16 ++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-)
xen/arch/x86/mpparse.c +5 -0
@@ -64,6 +64,9 @@ unsigned int __read_mostly boot_cpu_physical_apicid = BAD_APICID;static unsigned int __devinitdata num_processors;static unsigned int __initdata disabled_cpus; +/* Total detected cpus (may exceed NR_CPUS) */ +unsigned int total_cpus; +/* Bitmask of physically existing CPUs */ physid_mask_t phys_cpu_present_map;
@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct mpc_config_processor *m, {int ver, apicid, cpu =0 ; + total_cpus++; +if (!(m->mpc_cpuflag &CPU_ENABLED )) {if (!hotplug) ++disabled_cpus;
xen/arch/x86/smpboot.c +23 -2
@@ -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); +unsigned int nr_sockets__read_mostly ; +cpumask_var_t *socket_to_cpumask__read_mostly ; +struct cpuinfo_x86 cpu_data[NR_CPUS ]; u32 x86_cpu_to_apicid[NR_CPUS] __read_mostly =
@@ -239,11 +242,14 @@ static void link_thread_siblings(int cpu1, int cpu2)static void set_cpu_sibling_map (int cpu) { -int i; +int i, socket =cpu_to_socket (cpu);struct cpuinfo_x86 *c = cpu_data;cpumask_set_cpu (cpu, &cpu_sibling_setup_map); +if ( socket < nr_sockets ) +cpumask_set_cpu (cpu, socket_to_cpumask[socket]); +if ( c[cpu].x86_num_siblings >1 ) {for_each_cpu ( i, &cpu_sibling_setup_map )
@@ -301,6 +307,7 @@ static void set_cpu_sibling_map(int cpu) } } } + }void start_secondary (void *unused)
@@ -704,6 +711,8 @@ static struct notifier_block cpu_smpboot_nfb = {void __init smp_prepare_cpus (unsigned int max_cpus) { +int socket; +register_cpu_notifier (&cpu_smpboot_nfb);mtrr_aps_sync_begin ();
@@ -717,6 +726,15 @@ void __init smp_prepare_cpus(unsigned int max_cpus) stack_base[0 ] = stack_start; + nr_sockets =DIV_ROUND_UP (total_cpus, boot_cpu_data.x86_max_cores * + boot_cpu_data.x86_num_siblings); + socket_to_cpumask =xzalloc_array (cpumask_var_t, nr_sockets); +if ( !socket_to_cpumask ) +panic ("No memory for socket CPU siblings map" ); +for ( socket =0 ; socket < nr_sockets; socket++ ) +if ( !zalloc_cpumask_var (socket_to_cpumask + socket) ) +panic ("No memory for socket CPU siblings cpumask" ); +if ( !zalloc_cpumask_var (&per_cpu (cpu_sibling_mask,0 )) || !zalloc_cpumask_var (&per_cpu (cpu_core_mask,0 )) )panic ("No memory for boot CPU sibling/core maps" );
@@ -779,9 +797,12 @@ void __init smp_prepare_boot_cpu(void)static void remove_siblinginfo (int cpu) { -int sibling; +int sibling, socket =cpu_to_socket (cpu);struct cpuinfo_x86 *c = cpu_data; +if ( socket < nr_sockets ) +cpumask_clear_cpu (cpu, socket_to_cpumask[socket]); + for_each_cpu ( sibling, per_cpu(cpu_core_mask, cpu) ) {cpumask_clear_cpu (cpu,per_cpu (cpu_core_mask, sibling));
xen/include/asm-x86/smp.h +16 -0
@@ -58,6 +58,22 @@ int hard_smp_processor_id(void);void __stop_this_cpu (void ); +/* Total number of cpus in this system (may exceed NR_CPUS) */ +extern unsigned int total_cpus; + +/* +* This value is calculated by total_cpus/cpus_per_socket with the assumption +* that APIC IDs from MP table are continuous. It's possible that this value +* is less than the real socket number in the system if the APIC IDs from MP +* table are too sparse. Also the value is considered not to change from the +* initial startup. Violation of any of these assumptions may result in errors +* and requires retrofitting all the relevant places. +*/ +extern unsigned int nr_sockets; + +/* Representing HT and core siblings in each socket */ +extern cpumask_var_t *socket_to_cpumask; +#endif /* !__ASSEMBLY__ */ #endif
Signature · 1 line
1.9.1
PATCH v7 2/14 x86: improve psr scheduling code
In reply to Chao PengSwitching RMID from previous vcpu to next vcpu only needs to write MSR_IA32_PSR_ASSOC once. Write it with the value of next vcpu is enough, no need to write '0' first. Idle domain has RMID set to 0 and because MSR is already updated lazily, so just switch it as it does.
Also move the initialization of per-CPU variable which used for lazy update from context switch to CPU starting.
---
Cahnges in v6:
* blankline fix.
Changes in v5:
* use this_cpu() rather than per_cpu().
Changes in v4:
* Move psr_assoc_reg_read/psr_assoc_reg_write into psr_ctxt_switch_to.
* Use 0 instead of smp_processor_id() for boot cpu.
* add cpu parameter to psr_assoc_init.
Changes in v2:
* Move initialization for psr_assoc from context switch to CPU_STARTING.
--- xen/arch/x86/domain.c | 7 ++--- xen/arch/x86/psr.c | 71 +++++++++++++++++++++++++++++++++-------------- xen/include/asm-x86/psr.h | 2 +- 3 files changed, 53 insertions(+), 27 deletions(-)
xen/arch/x86/domain.c +2 -5
@@ -1444,8 +1444,6 @@ static void __context_switch(void) {memcpy (&p->arch.user_regs, stack_regs,CTXT_SWITCH_STACK_BYTES );vcpu_save_fpu (p); -if (psr_cmt_enabled () ) -psr_assoc_rmid (0 ); p->arch.ctxt_switch_from (p); }
@@ -1470,11 +1468,10 @@ static void __context_switch(void) }vcpu_restore_fpu_eager (n); n->arch.ctxt_switch_to (n); - -if (psr_cmt_enabled () && n->domain->arch.psr_rmid >0 ) -psr_assoc_rmid (n->domain->arch.psr_rmid); } +psr_ctxt_switch_to (n->domain); + gdt = !is_pv_32on64_vcpu (n) ?per_cpu (gdt_table, cpu) :per_cpu (compat_gdt_table, cpu);if (need_full_gdt (n) )
xen/arch/x86/psr.c +50 -21
98 lines not on this page · raw message
xen/include/asm-x86/psr.h +1 -1
@@ -46,7 +46,7 @@ static inline bool_t psr_cmt_enabled(void)int psr_alloc_rmid (struct domain *d);void psr_free_rmid (struct domain *d); -void psr_assoc_rmid (unsigned int rmid); +void psr_ctxt_switch_to (struct domain *d);#endif /* __ASM_PSR_H__ */
Signature · 1 line
1.9.1
PATCH v7 3/14 x86: detect and initialize Intel CAT feature
In reply to Chao PengDetect Intel Cache Allocation Technology(CAT) feature and store the cpuid information for later use. Currently only L3 cache allocation is supported. The L3 CAT features may vary among sockets so per-socket feature information is stored. The initialization can happen either at boot time or when CPU(s) is hot plugged after booting.
---
Changes in v7:
* Clear the init/enable flag when a socket going offline.
* Reorder the statements in init_psr_cat.
Changes in v6:
* Introduce cat_socket_init(_enable)_bitmap.
Changes in v5:
* Add cos_max boot option.
Changes in v4:
* check X86_FEATURE_CAT available before doing initialization. Changes in v3:
* Remove num_sockets boot option instead calculate it at boot time.
* Name hardcoded CAT cpuid leaf as PSR_CPUID_LEVEL_CAT.
Changes in v2:
* socket_num => num_sockets and fix several documentaion issues.
* refactor boot line parameters parsing into standlone patch.
* set opt_num_sockets = NR_CPUS when opt_num_sockets > NR_CPUS.
* replace CPU_ONLINE with CPU_STARTING and integrate that into scheduling improvement patch.
* reimplement get_max_socket() with cpu_to_socket();
* cbm is still uint64 as there is a path forward for supporting long masks.
--- docs/misc/xen-command-line.markdown | 15 ++++- xen/arch/x86/psr.c | 107 +++++++++++++++++++++++++++++++++++- xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/psr.h | 3 + 4 files changed, 122 insertions(+), 4 deletions(-)
docs/misc/xen-command-line.markdown +13 -2
@@ -1122,9 +1122,9 @@ This option can be specified more than once (up to 8 times at present). > `= <integer>` ### psr (Intel) -> `= List of ( cmt:<boolean> | rmid_max:<integer> )` +> `= List of ( cmt:<boolean> | rmid_max:<integer> | cat:<boolean> | cos_max:<integer> )` -> Default: `psr=cmt:0,rmid_max:255` +> Default: `psr=cmt:0,rmid_max:255,cat:0,cos_max:255` Platform Shared Resource(PSR) Services. Intel Haswell and later server platforms offer information about the sharing of resources.
@@ -1134,6 +1134,12 @@ Monitoring ID(RMID) is used to bind the domain to corresponding shared resource. RMID is a hardware-provided layer of abstraction between software and logical processors. +To use the PSR cache allocation service for a certain domain, a capacity +bitmasks(CBM) is used to bind the domain to corresponding shared resource. +CBM represents cache capacity and indicates the degree of overlap and isolation +between domains. In hypervisor a Class of Service(COS) ID is allocated for each +unique CBM. + The following resources are available: * Cache Monitoring Technology (Haswell and later). Information regarding the
@@ -1144,6 +1150,11 @@ The following resources are available: total/local memory bandwidth. Follow the same options with Cache Monitoring Technology. +* Cache Alllocation Technology (Broadwell and later). Information regarding + the cache allocation. + * `cat` instructs Xen to enable/disable Cache Allocation Technology. + * `cos_max` indicates the max value for COS ID. + ### reboot > `= t[riple] | k[bd] | a[cpi] | p[ci] | P[ower] | e[fi] | n[o] [, [w]arm | [c]old]`
xen/arch/x86/psr.c +105 -2
154 lines not on this page · raw message
xen/include/asm-x86/cpufeature.h +1 -0
@@ -149,6 +149,7 @@#define X86_FEATURE_CMT (7*32+12)/* Cache Monitoring Technology */ #define X86_FEATURE_NO_FPU_SEL (7*32+13)/* FPU CS/DS stored as zero */ #define X86_FEATURE_MPX (7*32+14)/* Memory Protection Extensions */ +#define X86_FEATURE_CAT (7*32+15)/* Cache Allocation Technology */ #define X86_FEATURE_RDSEED (7*32+18)/* RDSEED instruction */ #define X86_FEATURE_ADX (7*32+19)/* ADCX, ADOX instructions */ #define X86_FEATURE_SMAP (7*32+20)/* Supervisor Mode Access Prevention */
xen/include/asm-x86/psr.h +3 -0
@@ -18,6 +18,9 @@#include <xen/types.h> +/* CAT cpuid level */ +#define PSR_CPUID_LEVEL_CAT 0x10 +/* Resource Type Enumeration */ #define PSR_RESOURCE_TYPE_L3 0x2
Signature · 1 line
1.9.1
PATCH v7 4/14 x86: maintain COS to CBM mapping for each socket
In reply to Chao PengFor each socket, a COS to CBM mapping structure is maintained for each COS. The mapping is indexed by COS and the value is the corresponding CBM. Different VMs may use the same CBM, a reference count is used to indicate if the CBM is available.
---
Changes in v5:
* rename cos_cbm_map to cos_to_cbm.
--- xen/arch/x86/psr.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
xen/arch/x86/psr.c +14 -0
@@ -21,9 +21,15 @@#define PSR_CMT (1<<0)#define PSR_CAT (1<<1) +struct psr_cat_cbm { +uint64_t cbm; +unsigned int ref; +}; +struct psr_cat_socket_info {unsigned int cbm_len;unsigned int cos_max; +struct psr_cat_cbm *cos_to_cbm; };struct psr_assoc {
@@ -237,6 +243,14 @@ static void cat_cpu_init(void) info->cbm_len = (eax &0x1f ) +1 ; info->cos_max =min (opt_cos_max, edx &0xffff ); + info->cos_to_cbm = xzalloc_array(struct psr_cat_cbm, + info->cos_max +1UL ); +if ( !info->cos_to_cbm ) +return ; + +/* cos=0 is reserved as default cbm(all ones). */ + info->cos_to_cbm[0 ].cbm = (1ull << info->cbm_len) -1 ; +set_bit (socket, cat_socket_enable_bitmap);printk (XENLOG_INFO "CAT: enabled on socket %u, cos_max:%u, cbm_len:%u\n" , socket, info->cos_max, info->cbm_len);
Signature · 1 line
1.9.1
PATCH v7 5/14 x86: add COS information for each domain
In reply to Chao PengIn Xen's implementation, the CAT enforcement granularity is per domain. Due to the length of CBM and the number of COS may be socket-different, each domain has COS ID for each socket. The domain get COS=0 by default and at runtime its COS is then allocated dynamically when user specifies a CBM for the domain.
---
Changes in v6:
* Add spinlock for cos_to_cbm.
--- xen/arch/x86/domain.c | 6 +++++- xen/arch/x86/psr.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 5 ++++- xen/include/asm-x86/psr.h | 3 +++ 4 files changed, 61 insertions(+), 2 deletions(-)
xen/arch/x86/domain.c +5 -1
@@ -617,6 +617,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,/* 64-bit PV guest by default. */ d->arch.is_32bit_pv = d->arch.has_32bit_shinfo =0 ; +if ( (rc =psr_domain_init (d)) !=0 ) + goto fail; +/* initialize default tsc behavior in case tools don't */ tsc_set_info (d,TSC_MODE_DEFAULT ,0UL ,0 ,0 );spin_lock_init (&d->arch.vtsc_lock);
@@ -635,6 +638,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,free_perdomain_mappings (d);if (is_pv_domain (d) )free_xenheap_page (d->arch.pv_domain.gdt_ldt_l1tab); +psr_domain_free (d);return rc; }
@@ -658,7 +662,7 @@ void arch_domain_destroy(struct domain *d)free_xenheap_page (d->shared_info);cleanup_domain_irq_mapping (d); -psr_free_rmid (d); +psr_domain_free (d); }void arch_domain_shutdown (struct domain *d)
xen/arch/x86/psr.c +49 -0
67 lines not on this page · raw message
xen/include/asm-x86/domain.h +4 -1
@@ -333,7 +333,10 @@ struct arch_domainstruct e820entry *e820;unsigned int nr_e820; -unsigned int psr_rmid;/* RMID assigned to the domain for CMT */ +/* RMID assigned to the domain for CMT */ +unsigned int psr_rmid; +/* COS assigned to the domain for each socket */ +unsigned int *psr_cos_ids;/* Shared page for notifying that explicit PIRQ EOI is required. */ unsigned long *pirq_eoi_map;
xen/include/asm-x86/psr.h +3 -0
@@ -51,6 +51,9 @@ int psr_alloc_rmid(struct domain *d);void psr_free_rmid (struct domain *d);void psr_ctxt_switch_to (struct domain *d); +int psr_domain_init (struct domain *d); +void psr_domain_free (struct domain *d); +#endif /* __ASM_PSR_H__ */ /*
Signature · 1 line
1.9.1
PATCH v7 6/14 x86: expose CBM length and COS number information
In reply to Chao PengGeneral CAT information such as maximum COS and CBM length are exposed to user space by a SYSCTL hypercall, to help user space to construct the CBM.
---
Changes in v7:
* Copyback psr_cat_op only for XEN_SYSCTL_PSR_CAT_get_l3_info.
--- xen/arch/x86/psr.c | 31 +++++++++++++++++++++++++++++++ xen/arch/x86/sysctl.c | 18 ++++++++++++++++++ xen/include/asm-x86/psr.h | 3 +++ xen/include/public/sysctl.h | 16 ++++++++++++++++ 4 files changed, 68 insertions(+)
xen/arch/x86/psr.c +31 -0
@@ -217,6 +217,37 @@ void psr_ctxt_switch_to(struct domain *d) } } +static int get_cat_socket_info (unsigned int socket, +struct psr_cat_socket_info **info) +{ +if ( !cat_socket_info ) +return -ENODEV ; + +if ( socket >= nr_sockets ) +return -EBADSLT ; + +if ( !test_bit (socket, cat_socket_enable_bitmap) ) +return -ENOENT ; + + *info = cat_socket_info + socket; +return 0 ; +} + +int psr_get_cat_l3_info (unsigned int socket,uint32_t *cbm_len, +uint32_t *cos_max) +{ +struct psr_cat_socket_info *info; +int ret =get_cat_socket_info (socket, &info); + +if ( ret ) +return ret; + + *cbm_len = info->cbm_len; + *cos_max = info->cos_max; + +return 0 ; +} +/* Called with domain lock held, no extra lock needed for 'psr_cos_ids' */ static void psr_free_cos (struct domain *d) {
xen/arch/x86/sysctl.c +18 -0
@@ -171,6 +171,24 @@ long arch_do_sysctl(break ; +case XEN_SYSCTL_psr_cat_op: +switch ( sysctl->u.psr_cat_op.cmd ) + { +case XEN_SYSCTL_PSR_CAT_get_l3_info: + ret =psr_get_cat_l3_info (sysctl->u.psr_cat_op.target, + &sysctl->u.psr_cat_op.u.l3_info.cbm_len, + &sysctl->u.psr_cat_op.u.l3_info.cos_max); + +if ( !ret &&__copy_field_to_guest (u_sysctl, sysctl, u.psr_cat_op) ) + ret = -EFAULT ; + +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +default : ret = -ENOSYS ;break ;
xen/include/asm-x86/psr.h +3 -0
@@ -51,6 +51,9 @@ int psr_alloc_rmid(struct domain *d);void psr_free_rmid (struct domain *d);void psr_ctxt_switch_to (struct domain *d); +int psr_get_cat_l3_info (unsigned int socket,uint32_t *cbm_len, +uint32_t *cos_max); +int psr_domain_init (struct domain *d);void psr_domain_free (struct domain *d);
xen/include/public/sysctl.h +16 -0
@@ -661,6 +661,20 @@ struct xen_sysctl_psr_cmt_op {typedef struct xen_sysctl_psr_cmt_op xen_sysctl_psr_cmt_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_sysctl_psr_cmt_op_t); +#define XEN_SYSCTL_PSR_CAT_get_l3_info 0 +struct xen_sysctl_psr_cat_op { +uint32_t cmd;/* IN: XEN_SYSCTL_PSR_CAT_* */ +uint32_t target;/* IN: socket to be operated on */ +union { +struct { +uint32_t cbm_len;/* OUT: CBM length */ +uint32_t cos_max;/* OUT: Maximum COS */ + } l3_info; + } u; +}; +typedef struct xen_sysctl_psr_cat_op xen_sysctl_psr_cat_op_t ; +DEFINE_XEN_GUEST_HANDLE (xen_sysctl_psr_cat_op_t); +struct xen_sysctl {uint32_t cmd;#define XEN_SYSCTL_readconsole 1
@@ -683,6 +697,7 @@ struct xen_sysctl {#define XEN_SYSCTL_scheduler_op 19#define XEN_SYSCTL_coverage_op 20#define XEN_SYSCTL_psr_cmt_op 21 +#define XEN_SYSCTL_psr_cat_op 22uint32_t interface_version;/* XEN_SYSCTL_INTERFACE_VERSION */ union {struct xen_sysctl_readconsole readconsole;
@@ -705,6 +720,7 @@ struct xen_sysctl {struct xen_sysctl_scheduler_op scheduler_op;struct xen_sysctl_coverage_op coverage_op;struct xen_sysctl_psr_cmt_op psr_cmt_op; +struct xen_sysctl_psr_cat_op psr_cat_op;uint8_t pad[128 ]; } u; };
Signature · 1 line
1.9.1
PATCH v7 7/14 x86: dynamically get/set CBM for a domain
In reply to Chao PengFor CAT, COS is maintained in hypervisor only while CBM is exposed to user space directly to allow getting/setting domain's cache capacity. For each specified CBM, hypervisor will either use a existed COS which has the same CBM or allocate a new one if the same CBM is not found. If the allocation fails because of no enough COS available then error is returned. The getting/setting are always operated on a specified socket. For multiple sockets system, the interface may be called several times.
---
Changes in v7:
* find => found in psr_set_l3_cbm().
Changes in v6:
* Correct spin_lock scope.
Changes in v5:
* Add spin_lock to protect cbm_map.
--- xen/arch/x86/domctl.c | 20 ++++++ xen/arch/x86/psr.c | 137 ++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/msr-index.h | 1 + xen/include/asm-x86/psr.h | 2 + xen/include/public/domctl.h | 12 ++++ 5 files changed, 172 insertions(+)
xen/arch/x86/domctl.c +20 -0
@@ -1334,6 +1334,26 @@ long arch_do_domctl( }break ; +case XEN_DOMCTL_psr_cat_op: +switch ( domctl->u.psr_cat_op.cmd ) + { +case XEN_DOMCTL_PSR_CAT_OP_SET_L3_CBM : + ret =psr_set_l3_cbm (d, domctl->u.psr_cat_op.target, + domctl->u.psr_cat_op.data); +break ; + +case XEN_DOMCTL_PSR_CAT_OP_GET_L3_CBM : + ret =psr_get_l3_cbm (d, domctl->u.psr_cat_op.target, + &domctl->u.psr_cat_op.data); + copyback =1 ; +break ; + +default : + ret = -EOPNOTSUPP ; +break ; + } +break ; +default : ret =iommu_do_domctl (domctl, d, u_domctl);break ;
xen/arch/x86/psr.c +137 -0
149 lines not on this page · raw message
xen/include/asm-x86/msr-index.h +1 -0
@@ -327,6 +327,7 @@#define MSR_IA32_CMT_EVTSEL 0x00000c8d#define MSR_IA32_CMT_CTR 0x00000c8e#define MSR_IA32_PSR_ASSOC 0x00000c8f +#define MSR_IA32_PSR_L3_MASK (n) (0x00000c90 + (n))/* Intel Model 6 */ #define MSR_P6_PERFCTR (n) (0x000000c1 + (n))
xen/include/asm-x86/psr.h +2 -0
@@ -53,6 +53,8 @@ void psr_ctxt_switch_to(struct domain *d);int psr_get_cat_l3_info (unsigned int socket,uint32_t *cbm_len,uint32_t *cos_max); +int psr_get_l3_cbm (struct domain *d,unsigned int socket,uint64_t *cbm); +int psr_set_l3_cbm (struct domain *d,unsigned int socket,uint64_t cbm);int psr_domain_init (struct domain *d);void psr_domain_free (struct domain *d);
xen/include/public/domctl.h +12 -0
@@ -1001,6 +1001,16 @@ struct xen_domctl_psr_cmt_op {typedef struct xen_domctl_psr_cmt_op xen_domctl_psr_cmt_op_t ;DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cmt_op_t); +struct xen_domctl_psr_cat_op { +#define XEN_DOMCTL_PSR_CAT_OP_SET_L3_CBM 0 +#define XEN_DOMCTL_PSR_CAT_OP_GET_L3_CBM 1 +uint32_t cmd;/* IN: XEN_DOMCTL_PSR_CAT_OP_* */ +uint32_t target;/* IN: socket to be operated on */ +uint64_t data;/* IN/OUT */ +}; +typedef struct xen_domctl_psr_cat_op xen_domctl_psr_cat_op_t ; +DEFINE_XEN_GUEST_HANDLE (xen_domctl_psr_cat_op_t); +struct xen_domctl {uint32_t cmd;#define XEN_DOMCTL_createdomain 1
@@ -1075,6 +1085,7 @@ struct xen_domctl {#define XEN_DOMCTL_set_vcpu_msrs 73#define XEN_DOMCTL_setvnumainfo 74#define XEN_DOMCTL_psr_cmt_op 75 +#define XEN_DOMCTL_psr_cat_op 76#define XEN_DOMCTL_gdbsx_guestmemio 1000#define XEN_DOMCTL_gdbsx_pausevcpu 1001#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -1137,6 +1148,7 @@ struct xen_domctl {struct xen_domctl_gdbsx_domstatus gdbsx_domstatus;struct xen_domctl_vnuma vnuma;struct xen_domctl_psr_cmt_op psr_cmt_op; +struct xen_domctl_psr_cat_op psr_cat_op;uint8_t pad[128 ]; } u; };
Signature · 1 line
1.9.1
PATCH v7 8/14 x86: add scheduling support for Intel CAT
In reply to Chao PengOn context switch, write the the domain's Class of Service(COS) to MSR IA32_PQR_ASSOC, to notify hardware to use the new COS.
For performance reason, the COS mask for current cpu is also cached in the local per-CPU variable.
---
Changes in v5:
* Remove the need to cache socket.
Changes in v2:
* merge common scheduling changes into scheduling improvement patch.
* use readable expr for psra->cos_mask.
--- xen/arch/x86/psr.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
xen/arch/x86/psr.c +22 -1
@@ -35,6 +35,7 @@ struct psr_cat_socket_info {struct psr_assoc {uint64_t val; +uint64_t cos_mask; };struct psr_cmt *__read_mostly psr_cmt;
@@ -201,7 +202,16 @@ static inline void psr_assoc_init(void) {struct psr_assoc *psra = &this_cpu (psr_assoc); -if (psr_cmt_enabled () ) +if ( cat_socket_info ) + { +unsigned int socket =cpu_to_socket (smp_processor_id ()); + +if ( socket < nr_sockets &&test_bit (socket, cat_socket_enable_bitmap) ) + psra->cos_mask = ((1ull <<get_count_order ( + cat_socket_info[socket].cos_max)) -1 ) <<32 ; + } + +if (psr_cmt_enabled () || psra->cos_mask )rdmsrl (MSR_IA32_PSR_ASSOC , psra->val); }
@@ -210,6 +220,12 @@ static inline void psr_assoc_rmid(uint64_t *reg, unsigned int rmid) *reg = (*reg & ~rmid_mask) | (rmid & rmid_mask); } +static inline void psr_assoc_cos (uint64_t *reg,unsigned int cos, +uint64_t cos_mask) +{ + *reg = (*reg & ~cos_mask) | (((uint64_t )cos <<32 ) & cos_mask); +} +void psr_ctxt_switch_to (struct domain *d) {struct psr_assoc *psra = &this_cpu (psr_assoc);
@@ -218,6 +234,11 @@ void psr_ctxt_switch_to(struct domain *d)if (psr_cmt_enabled () )psr_assoc_rmid (®, d->arch.psr_rmid); +if ( psra->cos_mask ) +psr_assoc_cos (®, d->arch.psr_cos_ids ? + d->arch.psr_cos_ids[cpu_to_socket (smp_processor_id ())] : +0 , psra->cos_mask); +if ( reg != psra->val ) {wrmsrl (MSR_IA32_PSR_ASSOC , reg);
Signature · 1 line
1.9.1
PATCH v7 9/14 xsm: add CAT related xsm policies
In reply to Chao PengAdd xsm policies for Cache Allocation Technology(CAT) related hypercalls to restrict the functions visibility to control domain only.
--- tools/flask/policy/policy/modules/xen/xen.if | 2 +- tools/flask/policy/policy/modules/xen/xen.te | 4 +++- xen/xsm/flask/hooks.c | 6 ++++++ xen/xsm/flask/policy/access_vectors | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-)
tools/flask/policy/policy/modules/xen/xen.if +1 -1
@@ -51,7 +51,7 @@ define(`create_domain_common', ` getaffinity setaffinity setvcpuextstate }; allow $1 $2:domain2 { set_cpuid settsc setscheduler setclaim set_max_evtchn set_vnumainfo get_vnumainfo cacheflush - psr_cmt_op }; + psr_cmt_op psr_cat_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 updatemp };
tools/flask/policy/policy/modules/xen/xen.te +3 -1
@@ -67,6 +67,7 @@ allow dom0_t xen_t:xen { allow dom0_t xen_t:xen2 { resource_op psr_cmt_op + psr_cat_op }; allow dom0_t xen_t:mmu memorymap;
@@ -80,7 +81,8 @@ 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_vnumainfo get_vnumainfo psr_cmt_op + set_cpuid gettsc settsc setscheduler set_max_evtchn set_vnumainfo + get_vnumainfo psr_cmt_op psr_cat_op }; allow dom0_t dom0_t:resource { add remove };
xen/xsm/flask/hooks.c +6 -0
@@ -729,6 +729,9 @@ static int flask_domctl(struct domain *d, int cmd)case XEN_DOMCTL_psr_cmt_op:return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__PSR_CMT_OP ); +case XEN_DOMCTL_psr_cat_op: +return current_has_perm (d,SECCLASS_DOMAIN2 ,DOMAIN2__PSR_CAT_OP ); +default :printk ("flask_domctl: Unknown op %d\n" , cmd);return -EPERM ;
@@ -787,6 +790,9 @@ static int flask_sysctl(int cmd)case XEN_SYSCTL_psr_cmt_op:return avc_current_has_perm (SECINITSID_XEN ,SECCLASS_XEN2 ,XEN2__PSR_CMT_OP ,NULL ); +case XEN_SYSCTL_psr_cat_op: +return avc_current_has_perm (SECINITSID_XEN ,SECCLASS_XEN2 , +XEN2__PSR_CAT_OP ,NULL );default :printk ("flask_sysctl: Unknown op %d\n" , cmd);
xen/xsm/flask/policy/access_vectors +4 -0
@@ -84,6 +84,8 @@ class xen2 resource_op # XEN_SYSCTL_psr_cmt_op psr_cmt_op +# XEN_SYSCTL_psr_cat_op + psr_cat_op } # Classes domain and domain2 consist of operations that a domain performs on
@@ -219,6 +221,8 @@ class domain2 get_vnumainfo # XEN_DOMCTL_psr_cmt_op psr_cmt_op +# XEN_DOMCTL_psr_cat_op + psr_cat_op } # Similar to class domain, but primarily contains domctls related to HVM domains
Signature · 1 line
1.9.1
PATCH v7 10/14 tools/libxl: minor name changes for CMT commands
In reply to Chao PengUse "-" instead of "_" for monitor types.
--- tools/libxl/xl_cmdimpl.c | 6 +++--- tools/libxl/xl_cmdtable.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
tools/libxl/xl_cmdimpl.c +3 -3
@@ -8220,11 +8220,11 @@ int main_psr_cmt_show(int argc, char **argv)/* No options */ } -if (!strcmp (argv[optind],"cache_occupancy" )) +if (!strcmp (argv[optind],"cache-occupancy" )) type =LIBXL_PSR_CMT_TYPE_CACHE_OCCUPANCY ; -else if (!strcmp (argv[optind],"total_mem_bandwidth" )) +else if (!strcmp (argv[optind],"total-mem-bandwidth" )) type =LIBXL_PSR_CMT_TYPE_TOTAL_MEM_COUNT ; -else if (!strcmp (argv[optind],"local_mem_bandwidth" )) +else if (!strcmp (argv[optind],"local-mem-bandwidth" )) type =LIBXL_PSR_CMT_TYPE_LOCAL_MEM_COUNT ;else {help ("psr-cmt-show" );
tools/libxl/xl_cmdtable.c +3 -3
@@ -539,9 +539,9 @@ struct cmd_spec cmd_table[] = {"Show Cache Monitoring Technology information" ,"<PSR-CMT-Type> <Domain>" ,"Available monitor types:\n" -"\"cache_occupancy\": Show L3 cache occupancy(KB)\n" -"\"total_mem_bandwidth\": Show total memory bandwidth(KB/s)\n" - "\"local_mem_bandwidth\": Show local memory bandwidth(KB/s)\n", +"\"cache-occupancy\": Show L3 cache occupancy(KB)\n" +"\"total-mem-bandwidth\": Show total memory bandwidth(KB/s)\n" + "\"local-mem-bandwidth\": Show local memory bandwidth(KB/s)\n", }, #endif };
Signature · 1 line
1.9.1
PATCH v7 11/14 tools/libxl: add command to show PSR hardware info
In reply to Chao PengAdd dedicated one to show hardware information.
[root@vmm-psr]xl psr-hwinfo
Cache Monitoring Technology (CMT):
Enabled : 1
Total RMID : 63
Supported monitor types:
cache-occupancy
total-mem-bandwidth
local-mem-bandwidth
---
Changes in v6:
* Add SWITCH_FOREACH_OPT to make '-h' work.
--- docs/man/xl.pod.1 | 4 ++++ tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/libxl/xl_cmdtable.c | 5 +++++ 4 files changed, 51 insertions(+)
docs/man/xl.pod.1 +4 -0
@@ -1495,6 +1495,10 @@ for any of these monitoring types. =over 4 +=item B<psr-hwinfo> + +Show CMT hardware information. + =item B<psr-cmt-attach> [I<domain-id>] attach: Attach the platform shared resource monitoring service to a domain.
tools/libxl/xl.h +1 -0
@@ -113,6 +113,7 @@ int main_remus(int argc, char **argv);#endif int main_devd (int argc,char **argv);#ifdef LIBXL_HAVE_PSR_CMT +int main_psr_hwinfo (int argc,char **argv);int main_psr_cmt_attach (int argc,char **argv);int main_psr_cmt_detach (int argc,char **argv);int main_psr_cmt_show (int argc,char **argv);
tools/libxl/xl_cmdimpl.c +41 -0
53 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +5 -0
@@ -524,6 +524,11 @@ struct cmd_spec cmd_table[] = { "-F Run in the foreground", },#ifdef LIBXL_HAVE_PSR_CMT + {"psr-hwinfo" , + &main_psr_hwinfo,0 ,1 , +"Show hardware information for Platform Shared Resource" , +"" , + }, { "psr-cmt-attach", &main_psr_cmt_attach,0 ,1 , "Attach Cache Monitoring Technology service to a domain",
Signature · 1 line
1.9.1
PATCH v7 12/14 tools/libxl: introduce some socket helpers
In reply to Chao PengAdd libxl_socket_bitmap_alloc() to allow allocating a socket specific libxl_bitmap (as it is for cpu/node bitmap).
Internal function libxl__count_physical_sockets() is introduced together to get the socket count when the size of bitmap is not specified.
---
Changes in v7:
* Broadcast LIBXL_HAVE_SOCKET_BITMAP_ALLOC
--- tools/libxl/libxl.h | 7 +++++++ tools/libxl/libxl_internal.h | 2 ++ tools/libxl/libxl_utils.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_utils.h | 2 ++ 4 files changed, 57 insertions(+)
tools/libxl/libxl.h +7 -0
@@ -736,6 +736,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);#define LIBXL_HAVE_PSR_MBM 1#endif +/* +* LIBXL_HAVE_SOCKET_BITMAP_ALLOC +* +* If this is defined, then libxl_socket_bitmap_alloc exists. +*/ +#define LIBXL_HAVE_SOCKET_BITMAP_ALLOC 1 +typedef char **libxl_string_list ;void libxl_string_list_dispose (libxl_string_list *sl);int libxl_string_list_length (const libxl_string_list *sl);
tools/libxl/libxl_internal.h +2 -0
@@ -3684,6 +3684,8 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,*/ void libxl__bitmap_copy_best_effort (libxl__gc *gc,libxl_bitmap *dptr,const libxl_bitmap *sptr); + +int libxl__count_physical_sockets (libxl__gc *gc,int *sockets);#endif /*
tools/libxl/libxl_utils.c +46 -0
52 lines not on this page · raw message
tools/libxl/libxl_utils.h +2 -0
@@ -135,6 +135,8 @@ static inline int libxl_bitmap_equal(const libxl_bitmap *ba,int libxl_cpu_bitmap_alloc (libxl_ctx *ctx,libxl_bitmap *cpumap,int max_cpus);int libxl_node_bitmap_alloc (libxl_ctx *ctx,libxl_bitmap *nodemap,int max_nodes); +int libxl_socket_bitmap_alloc (libxl_ctx *ctx,libxl_bitmap *socketmap, +int max_sockets);/* Populate cpumap with the cpus spanned by the nodes in nodemap */ int libxl_nodemap_to_cpumap(libxl_ctx *ctx,
Signature · 1 line
1.9.1
PATCH v7 13/14 tools: add tools support for Intel CAT
In reply to Chao PengThis is the xc/xl changes to support Intel Cache Allocation Technology(CAT).
'xl psr-hwinfo' is updated to show CAT info and two new commands for CAT are introduced:
- xl psr-cat-cbm-set [-s socket] <domain> <cbm>
Set cache capacity bitmasks(CBM) for a domain.
- xl psr-cat-show <domain>
Show CAT domain information.
Examples:
[root@vmm-psr vmm]# xl psr-hwinfo --cat
Cache Allocation Technology (CAT):
Socket ID : 0
L3 Cache : 12288KB
Maximum COS : 15
CBM length : 12
Default CBM : 0xfff
[root@vmm-psr vmm]# xl psr-cat-cbm-set 0 0xff
[root@vmm-psr vmm]# xl psr-cat-show
Socket ID : 0
L3 Cache : 12288KB
Default CBM : 0xfff
ID NAME CBM
0 Domain-0 0xff
---
Changes in v7:
* Add PSR head1 level section and change CMT/CAT as its subsections for xl man page.
* Other minor document changes.
Changes in v6:
* Merge xl psr-cmt/cat-hwinfo => xl psr-hwinfo.
* Add function header to explain the 'target' parameter.
* Use bitmap instead of TARGETS_ALL.
* Remove the need to store the return value form libxc.
* Minor document/commit msg adjustment.
Changes in v5:
* Add psr-cat-hwinfo.
* Add libxl_psr_cat_info_list_free.
* malloc => libxl__malloc
* Other comments from Ian/Wei.
Changes in v4:
* Add example output in commit message.
* Make libxl__count_physical_sockets private to libxl_psr.c.
* Set errno in several error cases.
* Change libxl_psr_cat_get_l3_info to return all sockets information.
* Remove unused libxl_domain_info call.
Changes in v3:
* Add manpage.
* libxl_psr_cat_set/get_domain_data => libxl_psr_cat_set/get_cbm.
* Move libxl_count_physical_sockets into seperate patch.
* Support LIBXL_PSR_TARGET_ALL for libxl_psr_cat_set_cbm.
* Clean up the print codes.
--- docs/man/xl.pod.1 | 75 +++++++++++-- tools/libxc/include/xenctrl.h | 15 +++ tools/libxc/xc_psr.c | 76 ++++++++++++++ tools/libxl/libxl.h | 35 +++++++ tools/libxl/libxl_psr.c | 143 +++++++++++++++++++++++-- tools/libxl/libxl_types.idl | 10 ++ tools/libxl/xl.h | 4 + tools/libxl/xl_cmdimpl.c | 237 ++++++++++++++++++++++++++++++++++++++++-- tools/libxl/xl_cmdtable.c | 18 +++- 9 files changed, 584 insertions(+), 29 deletions(-)
docs/man/xl.pod.1 +65 -10
@@ -1477,28 +1477,52 @@ policy. Loading new security policy will reset runtime changes to device labels. =back -=head1 CACHE MONITORING TECHNOLOGY +=head1 PLATFORM SHARED RESOURCE MONITORING/CONTROL + +Intel Haswell and later server platforms offer shared resource monitoring +and control technologies. The availability of these technologies and the +hardware capabilities can be shown with B<psr-hwinfo>. + +=over 4 + +=item B<psr-hwinfo> [I<OPTIONS>] + +Show Platform Shared Resource (PSR) hardware information. + +B<OPTIONS> + +=over 4 + +=item B<-m>, B<--cmt> + +Show Cache Monitoring Technology (CMT) hardware information. + +=item B<-a>, B<--cat> + +Show Cache Allocation Technology (CAT) hardware information. + +=back + +=back + +=head2 CACHE MONITORING TECHNOLOGY Intel Haswell and later server platforms offer monitoring capability in each logical processor to measure specific platform shared resource metric, for -example, L3 cache occupancy. In Xen implementation, the monitoring granularity -is domain level. To monitor a specific domain, just attach the domain id with -the monitoring service. When the domain doesn't need to be monitored any more, -detach the domain id from the monitoring service. +example, L3 cache occupancy. In the Xen implementation, the monitoring +granularity is domain level. To monitor a specific domain, just attach the +domain id with the monitoring service. When the domain doesn't need to be +monitored any more, detach the domain id from the monitoring service. Intel Broadwell and later server platforms also offer total/local memory bandwidth monitoring. Xen supports per-domain monitoring for these two additional monitoring types. Both memory bandwidth monitoring and L3 cache occupancy monitoring share the same set of underlying monitoring service. Once -a domain is attached to the monitoring service, monitoring data can be showed +a domain is attached to the monitoring service, monitoring data can be shown for any of these monitoring types. =over 4 -=item B<psr-hwinfo> - -Show CMT hardware information. - =item B<psr-cmt-attach> [I<domain-id>] attach: Attach the platform shared resource monitoring service to a domain.
@@ -1517,6 +1541,37 @@ monitor types are: =back +=head2 CACHE ALLOCATION TECHNOLOGY + +Intel Broadwell and later server platforms offer capabilities to configure and +make use of the Cache Allocation Technology (CAT) mechanisms, which enable more +cache resources (i.e. L3 cache) to be made available for high priority +applications. In the Xen implementation, CAT is used to control cache allocation +on VM basis. To enforce cache on a specific domain, just set capacity bitmasks +(CBM) for the domain. + +=over 4 + +=item B<psr-cat-cbm-set> [I<OPTIONS>] I<domain-id> I<cbm> + +Set cache capacity bitmasks(CBM) for a domain. + +B<OPTIONS> + +=over 4 + +=item B<-s SOCKET>, B<--socket=SOCKET> + +Specify the socket to process, otherwise all sockets are processed. + +=back + +=item B<psr-cat-show> [I<domain-id>] + +Show CAT settings for a certain domain or all domains. + +=back + =head1 TO BE DOCUMENTED We need better documentation for:
tools/libxc/include/xenctrl.h +15 -0
@@ -2696,6 +2696,12 @@ enum xc_psr_cmt_type { XC_PSR_CMT_LOCAL_MEM_COUNT, };typedef enum xc_psr_cmt_type xc_psr_cmt_type ; + +enum xc_psr_cat_type { +XC_PSR_CAT_L3_CBM =1 , +}; +typedef enum xc_psr_cat_type xc_psr_cat_type ; +int xc_psr_cmt_attach (xc_interface *xch,uint32_t domid);int xc_psr_cmt_detach (xc_interface *xch,uint32_t domid); int xc_psr_cmt_get_domain_rmid(xc_interface *xch, uint32_t domid,
@@ -2710,6 +2716,15 @@ int xc_psr_cmt_get_data(xc_interface *xch, uint32_t rmid, uint32_t cpu, uint32_t psr_cmt_type, uint64_t *monitor_data, uint64_t *tsc);int xc_psr_cmt_enabled (xc_interface *xch); + +int xc_psr_cat_set_domain_data (xc_interface *xch,uint32_t domid, +xc_psr_cat_type type,uint32_t target, +uint64_t data); +int xc_psr_cat_get_domain_data (xc_interface *xch,uint32_t domid, +xc_psr_cat_type type,uint32_t target, +uint64_t *data); +int xc_psr_cat_get_l3_info (xc_interface *xch,uint32_t socket, +uint32_t *cos_max,uint32_t *cbm_len);#endif #endif /* XENCTRL_H */
tools/libxc/xc_psr.c +76 -0
82 lines not on this page · raw message
tools/libxl/libxl.h +35 -0
@@ -734,6 +734,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src);* If this is defined, the Memory Bandwidth Monitoring feature is supported. */ #define LIBXL_HAVE_PSR_MBM 1 + +/* +* LIBXL_HAVE_PSR_CAT +* +* If this is defined, the Cache Allocation Technology feature is supported. +*/ +#define LIBXL_HAVE_PSR_CAT 1#endif /*
@@ -1540,6 +1547,34 @@ int libxl_psr_cmt_get_sample(libxl_ctx *ctx, uint64_t *tsc_r);#endif +#ifdef LIBXL_HAVE_PSR_CAT +/* +* Function to set a domain's cbm. It operates on a single or multiple +* target(s) defined in 'target_map'. The definition of 'target_map' is +* related to 'type': +* 'L3_CBM': 'target_map' specifies all the sockets to be operated on. +*/ +int libxl_psr_cat_set_cbm (libxl_ctx *ctx,uint32_t domid, +libxl_psr_cbm_type type,libxl_bitmap *target_map, +uint64_t cbm); +/* +* Function to get a domain's cbm. It operates on a single 'target'. +* The definition of 'target' is related to 'type': +* 'L3_CBM': 'target' specifies which socket to be operated on. +*/ +int libxl_psr_cat_get_cbm (libxl_ctx *ctx,uint32_t domid, +libxl_psr_cbm_type type,uint32_t target, +uint64_t *cbm_r); + +/* +* On success, the function returns an array of elements in 'info', +* and the length in 'nr'. +*/ +int libxl_psr_cat_get_l3_info (libxl_ctx *ctx,libxl_psr_cat_info **info, +int *nr); +void libxl_psr_cat_info_list_free (libxl_psr_cat_info *list,int nr); +#endif +/* misc */ /* Each of these sets or clears the flag according to whether the
tools/libxl/libxl_psr.c +136 -7
171 lines not on this page · raw message
tools/libxl/libxl_types.idl +10 -0
@@ -709,3 +709,13 @@ libxl_psr_cmt_type = Enumeration("psr_cmt_type", [ (2, "TOTAL_MEM_COUNT"), (3, "LOCAL_MEM_COUNT"), ]) + +libxl_psr_cbm_type = Enumeration("psr_cbm_type", [ + (0, "UNKNOWN"), + (1, "L3_CBM"), + ]) + +libxl_psr_cat_info = Struct("psr_cat_info", [ + ("cos_max", uint32), + ("cbm_len", uint32), + ])
tools/libxl/xl.h +4 -0
@@ -118,6 +118,10 @@ int main_psr_cmt_attach(int argc, char **argv);int main_psr_cmt_detach (int argc,char **argv);int main_psr_cmt_show (int argc,char **argv);#endif +#ifdef LIBXL_HAVE_PSR_CAT +int main_psr_cat_cbm_set (int argc,char **argv); +int main_psr_cat_show (int argc,char **argv); +#endif void help (const char *command);
tools/libxl/xl_cmdimpl.c +226 -11
249 lines not on this page · raw message
tools/libxl/xl_cmdtable.c +17 -1
@@ -527,7 +527,9 @@ struct cmd_spec cmd_table[] = { {"psr-hwinfo" , &main_psr_hwinfo,0 ,1 ,"Show hardware information for Platform Shared Resource" , -"" , +"[options]" , +"-m, --cmt Show Cache Monitoring Technology (CMT) hardware info\n" +"-a, --cat Show Cache Allocation Technology (CAT) hardware info\n" }, { "psr-cmt-attach", &main_psr_cmt_attach, 0, 1,
@@ -549,6 +551,20 @@ struct cmd_spec cmd_table[] = { "\"local-mem-bandwidth\": Show local memory bandwidth(KB/s)\n", },#endif +#ifdef LIBXL_HAVE_PSR_CAT + { "psr-cat-cbm-set", + &main_psr_cat_cbm_set, 0, 1, + "Set cache capacity bitmasks(CBM) for a domain", + "[options] <Domain> <CBM>", + "-s <socket> Specify the socket to process, otherwise all sockets are processed\n" + }, + { "psr-cat-show", + &main_psr_cat_show, 0, 1, + "Show Cache Allocation Technology information", + "<Domain>", + }, + +#endif }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Signature · 1 line
1.9.1
PATCH v7 14/14 docs: add xl-psr.markdown
In reply to Chao PengAdd document to introduce basic concepts and terms in PSR family technologies and the xl interfaces.
---
Changes in v7:
* Correct 'xl psr-hwinfo'.
Changes in v6:
* Address comments from Ian.
Changes in v5:
* Address comments from Andrew/Ian.
--- docs/man/xl.pod.1 | 7 ++- docs/misc/xl-psr.markdown | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 docs/misc/xl-psr.markdown
docs/man/xl.pod.1 +6 -1
@@ -1483,6 +1483,9 @@ Intel Haswell and later server platforms offer shared resource monitoring and control technologies. The availability of these technologies and the hardware capabilities can be shown with B<psr-hwinfo>. +See L<http://xenbits.xen.org/docs/unstable/misc/xl-psr.html> for more +information. + =over 4 =item B<psr-hwinfo> [I<OPTIONS>]
@@ -1554,7 +1557,8 @@ on VM basis. To enforce cache on a specific domain, just set capacity bitmasks =item B<psr-cat-cbm-set> [I<OPTIONS>] I<domain-id> I<cbm> -Set cache capacity bitmasks(CBM) for a domain. +Set cache capacity bitmasks(CBM) for a domain. For how to specify I<cbm> +please refer to L<http://xenbits.xen.org/docs/unstable/misc/xl-psr.html>. B<OPTIONS>
@@ -1595,6 +1599,7 @@ And the following documents on the xen.org website: L<http://xenbits.xen.org/docs/unstable/misc/xl-network-configuration.html> L<http://xenbits.xen.org/docs/unstable/misc/xl-disk-configuration.txt> L<http://xenbits.xen.org/docs/unstable/misc/xsm-flask.txt> +L<http://xenbits.xen.org/docs/unstable/misc/xl-psr.html> For systems that don't automatically bring CPU online:
docs/misc/xl-psr.markdown new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v7 02/14] x86: improve psr scheduling code
In reply to Chao PengQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
Switching RMID from previous vcpu to next vcpu only needs to write
MSR_IA32_PSR_ASSOConce. Write it with the value of next vcpu is enough, no need to write '0' first. Idle domain has RMID set to 0 and because MSR is already updated lazily, so just switch it as it does.
Quoted 6 lines
Also move the initialization of per-CPU variable which used for lazy update from context switch to CPU starting.
Signed-off-by Chao Peng <[email protected]>Reviewed-by Andrew Cooper <[email protected]>Reviewed-by Dario Faggioli <[email protected]>
Please avoid sending again changes that got applied already.
Jan
Re: [PATCH v7 13/14] tools: add tools support for Intel CAT
In reply to Chao PengQuoted 26 lines · Chao Peng
This is the xc/xl changes to support Intel Cache Allocation Technology(CAT).
'xl psr-hwinfo' is updated to show CAT info and two new commands for CAT are introduced:
- xl psr-cat-cbm-set [-s socket] <domain> <cbm>
Set cache capacity bitmasks(CBM) for a domain.
- xl psr-cat-show <domain>
Show CAT domain information.Examples:
[root@vmm-psr vmm]# xl psr-hwinfo --cat
Cache Allocation Technology (CAT):
Socket ID : 0
L3 Cache : 12288KB
Maximum COS : 15
CBM length : 12
Default CBM :0xfff[root@vmm-psr vmm]# xl psr-cat-cbm-set 0
0xff[root@vmm-psr vmm]# xl psr-cat-show
Socket ID : 0
L3 Cache : 12288KB
Default CBM :0xfff
ID NAME CBM
Quoted 4 lines
0 Domain-0 0xffSigned-off-by Chao Peng <[email protected]>Reviewed-by Dario Faggioli <[email protected]>
Re: [PATCH v7 14/14] docs: add xl-psr.markdown
In reply to Chao PengQuoted 4 lines · Chao Peng
Add document to introduce basic concepts and terms in PSR family technologies and the xl interfaces.
Signed-off-by Chao Peng <[email protected]>
Quoted 1 line · Chao Peng
Changes in v7:
I've now acked the last of the tools stuff.
Jan, will you pick that up along with the remaining hypervisor stuff whenever it is ready please?
Chao, If there are any major changes to the tools bit please ping me since I may not be paying close attention to this thread any more.
Cheers,
Ian.
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 15:41, <[email protected]> wrote:
Quoted 1 line · Chao Peng
Changes in v7:
I've now acked the last of the tools stuff.
Jan, will you pick that up along with the remaining hypervisor stuff whenever it is ready please?
Sure, I'll try to remember.
Jan
Quoted 10 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 15:41, <[email protected]> wrote:
Quoted 1 line · Chao Peng
Changes in v7:
I've now acked the last of the tools stuff.
Jan, will you pick that up along with the remaining hypervisor stuff whenever it is ready please?
Sure, I'll try to remember.
Thanks.
I'm sure Chao will prod me if you don't ;-)
Ian.
Re: [PATCH v7 02/14] x86: improve psr scheduling code
In reply to Jan BeulichQuoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
Switching RMID from previous vcpu to next vcpu only needs to write
MSR_IA32_PSR_ASSOConce. Write it with the value of next vcpu is enough, no need to write '0' first. Idle domain has RMID set to 0 and because MSR is already updated lazily, so just switch it as it does.
Quoted 9 lines
Quoted 6 lines
Also move the initialization of per-CPU variable which used for lazy update from context switch to CPU starting.
Signed-off-by Chao Peng <[email protected]>Reviewed-by Andrew Cooper <[email protected]>Reviewed-by Dario Faggioli <[email protected]>Please avoid sending again changes that got applied already.
Just noticed it's already get merged. Sorry for the noise and thanks. Chao
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 15:41, <[email protected]> wrote:
Quoted 1 line · Chao Peng
Changes in v7:
I've now acked the last of the tools stuff.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Jan, will you pick that up along with the remaining hypervisor stuff whenever it is ready please?
Sure, I'll try to remember.
Thanks.
I'm sure Chao will prod me if you don't ;-)
I will absolutely :)
Thanks for your help made on this.
Chao
Re: [PATCH v7 07/14] x86: dynamically get/set CBM for a domain
In reply to Chao PengQuoted 10 lines · Chao Peng
For CAT, COS is maintained in hypervisor only while CBM is exposed to user space directly to allow getting/setting domain's cache capacity. For each specified CBM, hypervisor will either use a existed COS which has the same CBM or allocate a new one if the same CBM is not found. If the allocation fails because of no enough COS available then error is returned. The getting/setting are always operated on a specified socket. For multiple sockets system, the interface may be called several times.
Signed-off-by Chao Peng <[email protected]>
Just, one minor thing, only if you end up resending...
xen/arch/x86/psr.c static unsigned int opt_cos_max = 255; · line 56
Quoted 13 lines
xen/arch/x86/psr.c +5
-0@@ -49,6 +49,14 @@ static unsigned int opt_cos_max = 255;static uint64_t rmid_mask; static DEFINE_PER_CPU(struct psr_assoc, psr_assoc); +static unsigned int get_socket_cpu (unsigned int socket) +{ +if ( socket < nr_sockets ) +return cpumask_any (socket_to_cpumask[socket]); +
... What about
if ( likely(socket < nr_sockets) )
Regards,
Dario
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v7 07/14] x86: dynamically get/set CBM for a domain
Quoted 23 lines · Dario Faggioli
Quoted 10 lines · Chao Peng
For CAT, COS is maintained in hypervisor only while CBM is exposed to user space directly to allow getting/setting domain's cache capacity. For each specified CBM, hypervisor will either use a existed COS which has the same CBM or allocate a new one if the same CBM is not found. If the allocation fails because of no enough COS available then error is returned. The getting/setting are always operated on a specified socket. For multiple sockets system, the interface may be called several times.
Signed-off-by Chao Peng <[email protected]>Reviewed-by Dario Faggioli <[email protected]>Just, one minor thing, only if you end up resending...
Quoted 8 lines
xen/arch/x86/psr.c +0
-0@@ -49,6 +49,14 @@ static unsigned int opt_cos_max = 255;static uint64_t rmid_mask; static DEFINE_PER_CPU(struct psr_assoc, psr_assoc);
Quoted 8 lines
xen/arch/x86/psr.c static unsigned int opt_cos_max = 255; · line 56
Quoted 5 lines
xen/arch/x86/psr.c +5
-0+static unsigned int get_socket_cpu (unsigned int socket) +{ +if ( socket < nr_sockets ) +return cpumask_any (socket_to_cpumask[socket]); +... What about
if (
likely(socket < nr_sockets))
Agreed, it can be an optimization chance.
Let's see what others think.
Thanks for review.
Chao
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
In reply to Chao PengQuoted 14 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/mpparse.c +3
-0@@ -64,6 +64,9 @@ unsigned int __read_mostly boot_cpu_physical_apicid = BAD_APICID;static unsigned int __devinitdata num_processors;static unsigned int __initdata disabled_cpus; +/* Total detected cpus (may exceed NR_CPUS) */ +unsigned int total_cpus; +/* Bitmask of physically existing CPUs */ physid_mask_t phys_cpu_present_map;
xen/arch/x86/mpparse.c static int __devinit MP_processor_info_x(struct mpc_config_processor *m, · line 122
Quoted 8 lines
xen/arch/x86/mpparse.c +2
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct mpc_config_processor *m, {int ver, apicid, cpu =0 ; + total_cpus++; +if (!(m->mpc_cpuflag &CPU_ENABLED )) {if (!hotplug) ++disabled_cpus;
Is there a reason you can't use disabled_cpus and avoid adding yet another variable?
xen/arch/x86/smpboot.c DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask); · line 63
Quoted 8 lines
xen/arch/x86/smpboot.c +2
-0@@ -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); +unsigned int nr_sockets__read_mostly ; +cpumask_var_t *socket_to_cpumask__read_mostly ;
I'd really like to see the "to" dropped from the name. It has been confusing me not for the first time. I'd also prefer the section annotations to be at their mandated place, between type and variable name.
xen/arch/x86/smpboot.c static void link_thread_siblings(int cpu1, int cpu2) · line 245
Quoted 6 lines
xen/arch/x86/smpboot.c +1
-1@@ -239,11 +242,14 @@ static void link_thread_siblings(int cpu1, int cpu2)static void set_cpu_sibling_map (int cpu) { -int i; +int i, socket =cpu_to_socket (cpu);
unsigned int
Quoted 11 lines
xen/arch/x86/smpboot.c +3
-0struct cpuinfo_x86 *c = cpu_data;cpumask_set_cpu (cpu, &cpu_sibling_setup_map); +if ( socket < nr_sockets ) +cpumask_set_cpu (cpu, socket_to_cpumask[socket]); +if ( c[cpu].x86_num_siblings >1 ) {for_each_cpu ( i, &cpu_sibling_setup_map )
xen/arch/x86/smpboot.c static void set_cpu_sibling_map(int cpu) · line 311
Quoted 5 lines
xen/arch/x86/smpboot.c +1
-0@@ -301,6 +307,7 @@ static void set_cpu_sibling_map(int cpu) } } } + }
???
xen/arch/x86/smpboot.c static struct notifier_block cpu_smpboot_nfb = { · line 714
Quoted 5 lines
xen/arch/x86/smpboot.c +1
-0@@ -704,6 +711,8 @@ static struct notifier_block cpu_smpboot_nfb = {void __init smp_prepare_cpus (unsigned int max_cpus) { +int socket;
unsigned int
xen/arch/x86/smpboot.c void __init smp_prepare_cpus(unsigned int max_cpus) · line 736
Quoted 12 lines
xen/arch/x86/smpboot.c +8
-0@@ -717,6 +726,15 @@ void __init smp_prepare_cpus(unsigned int max_cpus) stack_base[0 ] = stack_start; + nr_sockets =DIV_ROUND_UP (total_cpus, boot_cpu_data.x86_max_cores * + boot_cpu_data.x86_num_siblings); + socket_to_cpumask =xzalloc_array (cpumask_var_t, nr_sockets); +if ( !socket_to_cpumask ) +panic ("No memory for socket CPU siblings map" ); +for ( socket =0 ; socket < nr_sockets; socket++ ) +if ( !zalloc_cpumask_var (socket_to_cpumask + socket) ) +panic ("No memory for socket CPU siblings cpumask" );
You might be allocating quite a bit too much memory now that you overestimate nr_sockets. Hence at least this second part of the change here would better be switched to an on demand allocation model.
xen/arch/x86/smpboot.c void __init smp_prepare_boot_cpu(void) · line 800
Quoted 6 lines
xen/arch/x86/smpboot.c +1
-1@@ -779,9 +797,12 @@ void __init smp_prepare_boot_cpu(void)static void remove_siblinginfo (int cpu) { -int sibling; +int sibling, socket =cpu_to_socket (cpu);
unsigned int
Quoted 7 lines
xen/include/asm-x86/smp.h +1
-0@@ -58,6 +58,22 @@ int hard_smp_processor_id(void);void __stop_this_cpu (void ); +/* Total number of cpus in this system (may exceed NR_CPUS) */
xen/include/asm-x86/smp.h int hard_smp_processor_id(void); · line 71
Quoted 10 lines
xen/include/asm-x86/smp.h +10
-0+extern unsigned int total_cpus; + +/* +* This value is calculated by total_cpus/cpus_per_socket with the assumption +* that APIC IDs from MP table are continuous. It's possible that this value +* is less than the real socket number in the system if the APIC IDs from MP +* table are too sparse. Also the value is considered not to change from the +* initial startup. Violation of any of these assumptions may result in errors +* and requires retrofitting all the relevant places. +*/
This all reads pretty frightening. How about using a better estimate of core and thread count (i.e. ones matching actually observed values instead of the nearest larger powers of two) in the nr_sockets calculation? Overestimating nr_sockets is surely better than using too small a value, as the alternative of remembering to always bounds check socket values before use (not only in your series, but also in future changes) is going to be pretty fragile.
Jan
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
In reply to Chao PengQuoted 12 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +5
-0@@ -19,14 +19,26 @@#include <asm/psr.h> #define PSR_CMT (1<<0) +#define PSR_CAT (1<<1) + +struct psr_cat_socket_info { +unsigned int cbm_len; +unsigned int cos_max;
xen/arch/x86/psr.c line 36
Quoted 10 lines
xen/arch/x86/psr.c +4
-0+};struct psr_assoc {uint64_t val; };struct psr_cmt *__read_mostly psr_cmt; + +static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;
Didn't we agree to fold these two into one? Apart from that the _bitmap name tag doesn't seem very useful...
Quoted 20 lines
xen/arch/x86/psr.c +16
-0@@ -194,16 +210,100 @@ void psr_ctxt_switch_to(struct domain *d) } } +static void cat_cpu_init (void ) +{ +unsigned int eax, ebx, ecx, edx; +struct psr_cat_socket_info *info; +unsigned int socket; +unsigned int cpu =smp_processor_id (); +const struct cpuinfo_x86 *c = cpu_data + cpu; + +if ( !cpu_has (c,X86_FEATURE_CAT ) ) +return ; + + socket =cpu_to_socket (cpu); +if ( socket >= nr_sockets ) +return ; + +/* Avoid initializing more than one times for the same socket. */
xen/arch/x86/psr.c void psr_ctxt_switch_to(struct domain *d) · line 238
Quoted 10 lines
xen/arch/x86/psr.c +10
-0+if (test_and_set_bit (socket, cat_socket_init_bitmap) ) +return ; + +cpuid_count (PSR_CPUID_LEVEL_CAT ,0 , &eax, &ebx, &ecx, &edx); +if ( ebx &PSR_RESOURCE_TYPE_L3 ) + { +cpuid_count (PSR_CPUID_LEVEL_CAT ,1 , &eax, &ebx, &ecx, &edx); + info = cat_socket_info + socket; + info->cbm_len = (eax &0x1f ) +1 ; + info->cos_max =min (opt_cos_max, edx &0xffff );
Is opt_cos_max being zero (or even one) going to result in a useful / working environment? I.e. shouldn't you rather disable CAT in that case?
xen/arch/x86/psr.c void psr_ctxt_switch_to(struct domain *d) · line 249
Quoted 4 lines
xen/arch/x86/psr.c +4
-0+static void cat_cpu_fini (void ) +{ +unsigned int cpu =smp_processor_id (); +unsigned int socket =cpu_to_socket (cpu);
This is the only use of "cpu", i.e. the variable is pretty pointless.
xen/arch/x86/psr.c void psr_ctxt_switch_to(struct domain *d) · line 306
Quoted 7 lines
xen/arch/x86/psr.c +2
-0static int cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) {if ( action ==CPU_STARTING )psr_cpu_init (); +else if ( action ==CPU_DYING ) +psr_cpu_fini ();
Are these the right notifiers for doing things involving memory allocation / freeing?
xen/arch/x86/psr.c static int __init psr_presmp_init(void) · line 325
Quoted 12 lines
xen/arch/x86/psr.c +5
-2@@ -217,9 +317,12 @@ static int __init psr_presmp_init(void)if ( (opt_psr &PSR_CMT ) && opt_rmid_max )init_psr_cmt (opt_rmid_max); +if ( opt_psr &PSR_CAT ) +init_psr_cat (); +psr_cpu_init (); -if (psr_cmt_enabled () ) -register_cpu_notifier (&cpu_nfb); +if (psr_cmt_enabled () || cat_socket_info ) +register_cpu_notifier (&cpu_nfb);
Please don't corrupt indentation here.
Jan
Re: [PATCH v7 04/14] x86: maintain COS to CBM mapping for each socket
In reply to Chao Pengxen/arch/x86/psr.c static void cat_cpu_init(void) · line 247
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +2
-0@@ -237,6 +243,14 @@ static void cat_cpu_init(void) info->cbm_len = (eax &0x1f ) +1 ; info->cos_max =min (opt_cos_max, edx &0xffff ); + info->cos_to_cbm = xzalloc_array(struct psr_cat_cbm, + info->cos_max +1UL );
How does the array dimension here match the "for each socket" in the title?
Jan
Re: [PATCH v7 07/14] x86: dynamically get/set CBM for a domain
In reply to Chao PengQuoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +3
-0+int psr_get_l3_cbm (struct domain *d,unsigned int socket,uint64_t *cbm) +{ +unsigned int cos;
xen/arch/x86/psr.c int psr_get_cat_l3_info(unsigned int socket, uint32_t *cbm_len, · line 271
Quoted 10 lines
xen/arch/x86/psr.c +10
-0+struct psr_cat_socket_info *info; +int ret =get_cat_socket_info (socket, &info); + +if ( ret ) +return ret; + + cos = d->arch.psr_cos_ids[socket]; + *cbm = info->cos_to_cbm[cos].cbm; +return 0 ; +}
Blank line before a function's final return statement please. With that and Dario's comment addressed
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
In reply to Jan BeulichQuoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/mpparse.c +3
-0@@ -64,6 +64,9 @@ unsigned int __read_mostly boot_cpu_physical_apicid = BAD_APICID;static unsigned int __devinitdata num_processors;static unsigned int __initdata disabled_cpus; +/* Total detected cpus (may exceed NR_CPUS) */ +unsigned int total_cpus; +/* Bitmask of physically existing CPUs */ physid_mask_t phys_cpu_present_map;@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct mpc_config_processor *m, {int ver, apicid, cpu =0 ;
Quoted 8 lines
xen/arch/x86/mpparse.c static int __devinit MP_processor_info_x(struct mpc_config_processor *m, · line 122
Quoted 5 lines
xen/arch/x86/mpparse.c +2
-0+ total_cpus++; +if (!(m->mpc_cpuflag &CPU_ENABLED )) {if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?
The problem is not with disabled_cpus but with num_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus = disabled_cpus + num_processors' may not be correct in some cases.
Quoted 7 lines
Quoted 7 lines
xen/arch/x86/smpboot.c +0
-0@@ -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);
Quoted 7 lines
xen/arch/x86/smpboot.c DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_mask); · line 63
Quoted 2 lines
xen/arch/x86/smpboot.c +2
-0+unsigned int nr_sockets__read_mostly ; +cpumask_var_t *socket_to_cpumask__read_mostly ;I'd really like to see the "to" dropped from the name. It has been confusing me not for the first time. I'd also prefer the section annotations to be at their mandated place, between type and variable name.
Agreed, I also disliked this name while I just copied that from node_to_cpumask.
Quoted 10 lines
xen/arch/x86/smpboot.c void __init smp_prepare_cpus(unsigned int max_cpus) · line 736
Quoted 9 lines
xen/arch/x86/smpboot.c +8
-0+ nr_sockets =DIV_ROUND_UP (total_cpus, boot_cpu_data.x86_max_cores * + boot_cpu_data.x86_num_siblings); + socket_to_cpumask =xzalloc_array (cpumask_var_t, nr_sockets); +if ( !socket_to_cpumask ) +panic ("No memory for socket CPU siblings map" ); +for ( socket =0 ; socket < nr_sockets; socket++ ) +if ( !zalloc_cpumask_var (socket_to_cpumask + socket) ) +panic ("No memory for socket CPU siblings cpumask" );
Quoted 4 lines
You might be allocating quite a bit too much memory now that you overestimate
nr_sockets. Hence at least this second part of the change here would better be switched to an on demand allocation model.
Agreed.
Quoted 9 lines
Quoted 8 lines
+/*
+ * This value is calculated by total_cpus/cpus_per_socket with the assumption
+ * that APIC IDs from MP table are continuous. It's possible that this value
+ * is less than the real socket number in the system if the APIC IDs from MP
+ * table are too sparse. Also the value is considered not to change from the
+ * initial startup. Violation of any of these assumptions may result in errors
+ * and requires retrofitting all the relevant places.
+ */
Quoted 7 lines
This all reads pretty frightening. How about using a better estimate of core and thread count (i.e. ones matching actually observed values instead of the nearest larger powers of two) in the
nr_socketscalculation? Overestimatingnr_socketsis surely better than using too small a value, as the alternative of remembering to always bounds check socket values before use (not only in your series, but also in future changes) is going to be pretty fragile.
OK I will try this.
Chao
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/mpparse.c +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct mpc_config_processor *m, {int ver, apicid, cpu =0 ;Quoted 8 lines
xen/arch/x86/mpparse.c static int __devinit MP_processor_info_x(struct mpc_config_processor *m, · line 122
Quoted 5 lines
xen/arch/x86/mpparse.c +2
-0+ total_cpus++; +if (!(m->mpc_cpuflag &CPU_ENABLED )) {if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?
Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
Jan
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
Quoted 21 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/mpparse.c +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct mpc_config_processor *m, {int ver, apicid, cpu =0 ;Quoted 8 lines
xen/arch/x86/mpparse.c static int __devinit MP_processor_info_x(struct mpc_config_processor *m, · line 122
Quoted 5 lines
xen/arch/x86/mpparse.c +2
-0+ total_cpus++; +if (!(m->mpc_cpuflag &CPU_ENABLED )) {if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.
Quoted 4 lines
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
What I really need is the original cpu count enumerated from MADT. If not introduce total_cpus then the only way getting it AFAICS is 'disabled_cpus + num_processors'.
The problem is that MP_processor_info_x() have some earlier returns before increasing num_processors. In those cases, the cpu detected will neither counted to disabled_cpus nor num_processors, which means 'disabled_cpus + num_processors' is potentially small than what I need.
Chao
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:47, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Review static int __devinit MP_processor_info_x(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct
mpc_config_processor*m,Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
xen/arch/x86/mpparse.c static int __devinit MP_processor_info_x(struct mpc_config_processor *m, · line 122
Quoted 8 lines
xen/arch/x86/mpparse.c +2
-0{int ver, apicid, cpu =0 ; + total_cpus++; +if (!(m->mpc_cpuflag &CPU_ENABLED )) {if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.Quoted 4 lines
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
Quoted 8 lines
What I really need is the original cpu count enumerated from MADT. If not introduce
total_cpusthen the only way getting it AFAICS is 'disabled_cpus+num_processors'.The problem is that
MP_processor_info_x()have some earlier returns before increasingnum_processors. In those cases, the cpu detected will neither counted todisabled_cpusnornum_processors, which means 'disabled_cpus+num_processors' is potentially small than what I need.
As said - I understand this. But you still fail to explain under what (realistic, i.e. other than someone bogusly setting NR_CPUS=1) conditions this ends up being a problem.
Jan
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:47, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Review static int __devinit MP_processor_info_x(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct
mpc_config_processor*m,Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
xen/arch/x86/mpparse.c static int __devinit MP_processor_info_x(struct mpc_config_processor *m, · line 122
Quoted 8 lines
xen/arch/x86/mpparse.c +2
-0{int ver, apicid, cpu =0 ; + total_cpus++; +if (!(m->mpc_cpuflag &CPU_ENABLED )) {if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.Quoted 4 lines
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
What I really need is the original cpu count enumerated from MADT. If not introduce
total_cpusthen the only way getting it AFAICS is 'disabled_cpus+num_processors'.
Quoted 8 lines
Quoted 4 lines
The problem is that
MP_processor_info_x()have some earlier returns before increasingnum_processors. In those cases, the cpu detected will neither counted todisabled_cpusnornum_processors, which means 'disabled_cpus+num_processors' is potentially small than what I need.As said - I understand this. But you still fail to explain under what (realistic, i.e. other than someone bogusly setting NR_CPUS=1) conditions this ends up being a problem.
As we calculate nr_sockets with:
nr_sockets = total_cpus / _cpus_per_socket__
If the calculated total_cpus is smaller than the actual cpu count on the hardware, then the nr_sockets is also potentially smaller than the actual socket count on the hardware. This is not the expectation.
Chao
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:10, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:47, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Review static int __devinit MP_processor_info_x(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct
mpc_config_processor*m,Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
Review static int __devinit MP_processor_info_x(struct · line 122
Quoted 8 lines
(quoted diff) +2
-0{ int ver, apicid, cpu = 0; + total_cpus++; + if (!(m->mpc_cpuflag & CPU_ENABLED)) { if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.Quoted 4 lines
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
What I really need is the original cpu count enumerated from MADT. If not introduce
total_cpusthen the only way getting it AFAICS is 'disabled_cpus+num_processors'.Quoted 8 lines
Quoted 4 lines
The problem is that
MP_processor_info_x()have some earlier returns before increasingnum_processors. In those cases, the cpu detected will neither counted todisabled_cpusnornum_processors, which means 'disabled_cpus+num_processors' is potentially small than what I need.As said - I understand this. But you still fail to explain under what (realistic, i.e. other than someone bogusly setting NR_CPUS=1) conditions this ends up being a problem.
Quoted 7 lines
As we calculate
nr_socketswith:
nr_sockets=total_cpus/ _cpus_per_socket__If the calculated
total_cpusis smaller than the actual cpu count on the hardware, then thenr_socketsis also potentially smaller than the actual socket count on the hardware. This is not the expectation.
Sure - but you still don't say what is going to go wrong. Remember, when I asked you to change to the total count I gave an explicit
example: Use of "nosmp" would have yielded a zero nr_sockets in the earlier code. Yet with the sum of num_processors and disabled_cpus this can't happen anymore afaict. Hence I'm looking forward to you detailing the conditions under which you would see an issue without introducing total_cpus.
Jan
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
In reply to Jan BeulichQuoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +6
-0@@ -19,14 +19,26 @@#include <asm/psr.h> #define PSR_CMT (1<<0) +#define PSR_CAT (1<<1) + +struct psr_cat_socket_info { +unsigned int cbm_len; +unsigned int cos_max; +};struct psr_assoc {uint64_t val; };
Quoted 7 lines
xen/arch/x86/psr.c line 36
Quoted 4 lines
xen/arch/x86/psr.c +3
-0struct psr_cmt *__read_mostly psr_cmt; + +static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...
Looks like this?
static unsigned long *__read_mostly cat_socket_init,
*__read_mostly cat_socket_enable;
Quoted 9 lines
xen/arch/x86/psr.c void psr_ctxt_switch_to(struct domain *d) · line 238
Quoted 7 lines
xen/arch/x86/psr.c +7
-0+cpuid_count (PSR_CPUID_LEVEL_CAT ,0 , &eax, &ebx, &ecx, &edx); +if ( ebx &PSR_RESOURCE_TYPE_L3 ) + { +cpuid_count (PSR_CPUID_LEVEL_CAT ,1 , &eax, &ebx, &ecx, &edx); + info = cat_socket_info + socket; + info->cbm_len = (eax &0x1f ) +1 ; + info->cos_max =min (opt_cos_max, edx &0xffff );
Quoted 3 lines
Is
opt_cos_maxbeing zero (or even one) going to result in a useful / working environment? I.e. shouldn't you rather disable CAT in that case?
OK, I will disable CAT in init_psr_cat() for this case.
Quoted 16 lines
xen/arch/x86/psr.c void psr_ctxt_switch_to(struct domain *d) · line 249
Quoted 5 lines
xen/arch/x86/psr.c +4
-0+static void cat_cpu_fini (void ) +{ +unsigned int cpu =smp_processor_id (); +unsigned int socket =cpu_to_socket (cpu);This is the only use of "cpu", i.e. the variable is pretty pointless.
xen/arch/x86/psr.c void psr_ctxt_switch_to(struct domain *d) · line 306
Quoted 7 lines
static int cpu_callback(
structnotifier_block*nfb, unsigned long action, void *hcpu){ if ( action == CPU_STARTING ) psr_cpu_init();xen/arch/x86/psr.c +2
-0+else if ( action ==CPU_DYING ) +psr_cpu_fini ();
Quoted 2 lines
Are these the right notifiers for doing things involving memory allocation / freeing?
psr_cpu_fini() does not really have memory allocation/freeing but psr_cpu_init() does have.
While one thing to clarify is: psr_cpu_init() will not propagate the error even when the memory allocation fails(instead it disables the CAT on the socket).
If there is still problem then perhaps I need change CPU_STARTING back to CPU_ONLINE and make on_selected_cpus() call on target cpu.
Chao
Re: [PATCH v7 04/14] x86: maintain COS to CBM mapping for each socket
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
xen/arch/x86/psr.c static void cat_cpu_init(void) · line 247
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +2
-0@@ -237,6 +243,14 @@ static void cat_cpu_init(void) info->cbm_len = (eax &0x1f ) +1 ; info->cos_max =min (opt_cos_max, edx &0xffff ); + info->cos_to_cbm = xzalloc_array(struct psr_cat_cbm, + info->cos_max +1UL );How does the array dimension here match the "for each socket" in the title?
info is already per-socket data so the dimension here is for only one socket.
Chao
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
In reply to Chao PengQuoted 28 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:40, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +6
-0@@ -19,14 +19,26 @@#include <asm/psr.h> #define PSR_CMT (1<<0) +#define PSR_CAT (1<<1) + +struct psr_cat_socket_info { +unsigned int cbm_len; +unsigned int cos_max; +};struct psr_assoc {uint64_t val; };Quoted 7 lines
xen/arch/x86/psr.c line 36
Quoted 4 lines
xen/arch/x86/psr.c +3
-0struct psr_cmt *__read_mostly psr_cmt; + +static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...
Quoted 4 lines
Looks like this?
static unsigned long
*__read_mostlycat_socket_init,*__read_mostly cat_socket_enable;
Yes, except that you will want to drop one (or make clear why you need both).
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
xen/arch/x86/psr.c +2
-0static int cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) {if ( action ==CPU_STARTING )psr_cpu_init (); +else if ( action ==CPU_DYING ) +psr_cpu_fini ();
Quoted 5 lines
Quoted 2 lines
Are these the right notifiers for doing things involving memory allocation / freeing?
psr_cpu_fini()does not really have memory allocation/freeing butpsr_cpu_init()does have.
Hmm, wait - where did I see this allocation? Looking again, I don't see it now. But if there was one, then surely it would be wrong for _fini to not free it.
Quoted 6 lines
While one thing to clarify is:
psr_cpu_init()will not propagate the error even when the memory allocation fails(instead it disables the CAT on the socket).If there is still problem then perhaps I need change
CPU_STARTINGback toCPU_ONLINEand makeon_selected_cpus()call on target cpu.
No, if there was any allocation needed, you should do the allocation in CPU_UP_PREPARE and the initialization in CPU_STARTING. But it looks like this is moot now anyway.
Jan
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
Quoted 48 lines
Quoted 29 lines
Quoted 2 lines · On 19.05.15 at 10:42, <[email protected]> wrote:
Quoted 1 line · On 19.05.15 at 09:40, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +6
-0@@ -19,14 +19,26 @@#include <asm/psr.h> #define PSR_CMT (1<<0) +#define PSR_CAT (1<<1) + +struct psr_cat_socket_info { +unsigned int cbm_len; +unsigned int cos_max; +};struct psr_assoc {uint64_t val; };Quoted 7 lines
xen/arch/x86/psr.c line 36
Quoted 4 lines
xen/arch/x86/psr.c +3
-0struct psr_cmt *__read_mostly psr_cmt; + +static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...Quoted 4 lines
Looks like this?
static unsigned long
*__read_mostlycat_socket_init,*__read_mostly cat_socket_enable;Yes, except that you will want to drop one (or make clear why you need both).
Quoted 11 lines
Quoted 10 lines
xen/arch/x86/psr.c void psr_ctxt_switch_to(struct domain *d) · line 306
Quoted 7 lines
xen/arch/x86/psr.c +2
-0static int cpu_callback (struct notifier_block *nfb,unsigned long action,void *hcpu) {if ( action ==CPU_STARTING )psr_cpu_init (); +else if ( action ==CPU_DYING ) +psr_cpu_fini ();Are these the right notifiers for doing things involving memory allocation / freeing?
Quoted 6 lines
Quoted 2 lines
psr_cpu_fini()does not really have memory allocation/freeing butpsr_cpu_init()does have.Hmm, wait - where did I see this allocation? Looking again, I don't see it now. But if there was one, then surely it would be wrong for
_finito not free it.
Ah, it's actually patch 4 where an allocation gets added. So adjustments seem to be needed there.
Jan
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:40, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/arch/x86/psr.c line 36
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +2
-0+static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...
Quoted 7 lines
Quoted 4 lines
Looks like this?
static unsigned long
*__read_mostlycat_socket_init,*__read_mostly cat_socket_enable;Yes, except that you will want to drop one (or make clear why you need both).
As said in the previous version, cat_socket_enable is the actual CAT enabled status.
And cat_socket_init is used for performance optimization purpose only. It indicate if the socket has been initialized, so that initialization happens only once for each socket, but not __cpus_in_socket__ times.
There are three possibilities:
1) Not initialized; 2) Initialized, CAT disabled; 3) Initialized, CAT enabled;
So it's not possible to use only one bit to represent three values.
Quoted 23 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
static int cpu_callback(
structnotifier_block*nfb, unsigned long action, void *hcpu){ if ( action == CPU_STARTING ) psr_cpu_init();xen/arch/x86/psr.c +2
-0+else if ( action ==CPU_DYING ) +psr_cpu_fini ();Quoted 5 lines
Quoted 2 lines
Are these the right notifiers for doing things involving memory allocation / freeing?
psr_cpu_fini()does not really have memory allocation/freeing butpsr_cpu_init()does have.Hmm, wait - where did I see this allocation? Looking again, I don't see it now. But if there was one, then surely it would be wrong for
_finito not free it.Quoted 4 lines
While one thing to clarify is:
psr_cpu_init()will not propagate the error even when the memory allocation fails(instead it disables the CAT on the socket).
Quoted 6 lines
Quoted 2 lines
If there is still problem then perhaps I need change
CPU_STARTINGback toCPU_ONLINEand makeon_selected_cpus()call on target cpu.No, if there was any allocation needed, you should do the allocation in
CPU_UP_PREPAREand the initialization inCPU_STARTING. But it looks like this is moot now anyway.
As I will add allocation in patch 4, so I will move psr_cpu_init() to CPU_UP_PREPARE(As the allocation length is based on the cpuid result, so the initialization will also be done here), but still need to move psr_cpu_fini(which will add the freeing code) to CPU_DOWN_PREPARE?
Chao
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
In reply to Jan BeulichQuoted 52 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:10, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:47, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Review static int __devinit MP_processor_info_x(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct
mpc_config_processor*m,Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
Review static int __devinit MP_processor_info_x(struct · line 122
Quoted 8 lines
(quoted diff) +2
-0{ int ver, apicid, cpu = 0; + total_cpus++; + if (!(m->mpc_cpuflag & CPU_ENABLED)) { if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.Quoted 4 lines
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
What I really need is the original cpu count enumerated from MADT. If not introduce
total_cpusthen the only way getting it AFAICS is 'disabled_cpus+num_processors'.Quoted 8 lines
Quoted 4 lines
The problem is that
MP_processor_info_x()have some earlier returns before increasingnum_processors. In those cases, the cpu detected will neither counted todisabled_cpusnornum_processors, which means 'disabled_cpus+num_processors' is potentially small than what I need.As said - I understand this. But you still fail to explain under what (realistic, i.e. other than someone bogusly setting NR_CPUS=1) conditions this ends up being a problem.
Quoted 7 lines
As we calculate
nr_socketswith:
nr_sockets=total_cpus/ _cpus_per_socket__If the calculated
total_cpusis smaller than the actual cpu count on the hardware, then thenr_socketsis also potentially smaller than the actual socket count on the hardware. This is not the expectation.
Quoted 5 lines
Sure - but you still don't say what is going to go wrong. Remember, when I asked you to change to the total count I gave an explicit
example: Use of "nosmp" would have yielded a zeronr_socketsin the earlier code. Yet with the sum ofnum_processorsanddisabled_cpusthis can't happen anymore afaict.
"nosmp" only has side effect on max_cpus and nr_cpu_ids, but they are never used at all when calculating nr_sockets. So I can't see any reason why with "num_processors + disabled_cpus" the nr_sockets would not be zero, I think this is a bug that I should fix in nosmp case.
Quoted 3 lines
Hence I'm looking
forward to you detailing the conditions under which you would see an issue without introducingtotal_cpus.
As said before, with "num_processors + disabled_cpus" I may get a smaller nr_sockets than the machine actually has. This is my exact
problem: I may miss enumerating some CAT-enabled sockets. While the assumption is that I will follow your suggestion to make nr_socket >= the socket count that the machine actually has.
Chao
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
Quoted 60 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 11:51, <[email protected]> wrote:
Quoted 52 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:10, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:47, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Review static int __devinit MP_processor_info_x(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct
mpc_config_processor*m,Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
Review static int __devinit MP_processor_info_x(struct · line 122
Quoted 8 lines
(quoted diff) +2
-0{ int ver, apicid, cpu = 0; + total_cpus++; + if (!(m->mpc_cpuflag & CPU_ENABLED)) { if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.Quoted 4 lines
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
What I really need is the original cpu count enumerated from MADT. If not introduce
total_cpusthen the only way getting it AFAICS is 'disabled_cpus+num_processors'.Quoted 8 lines
Quoted 4 lines
The problem is that
MP_processor_info_x()have some earlier returns before increasingnum_processors. In those cases, the cpu detected will neither counted todisabled_cpusnornum_processors, which means 'disabled_cpus+num_processors' is potentially small than what I need.As said - I understand this. But you still fail to explain under what (realistic, i.e. other than someone bogusly setting NR_CPUS=1) conditions this ends up being a problem.
Quoted 7 lines
As we calculate
nr_socketswith:
nr_sockets=total_cpus/ _cpus_per_socket__If the calculated
total_cpusis smaller than the actual cpu count on the hardware, then thenr_socketsis also potentially smaller than the actual socket count on the hardware. This is not the expectation.Quoted 5 lines
Sure - but you still don't say what is going to go wrong. Remember, when I asked you to change to the total count I gave an explicit
example: Use of "nosmp" would have yielded a zeronr_socketsin the earlier code. Yet with the sum ofnum_processorsanddisabled_cpusthis can't happen anymore afaict.
Quoted 4 lines
"nosmp" only has side effect on
max_cpusandnr_cpu_ids, but they are never used at all when calculatingnr_sockets. So I can't see any reason why with "num_processors+disabled_cpus" thenr_socketswould not be zero, I think this is a bug that I should fix in nosmp case.
Did you really mean to say "would _not_ be zero"? Because afaict the above resolves to "would ever be zero".
Quoted 9 lines
Quoted 3 lines
Hence I'm looking
forward to you detailing the conditions under which you would see an issue without introducingtotal_cpus.As said before, with "
num_processors+disabled_cpus" I may get a smallernr_socketsthan the machine actually has. This is my exact
problem: I may miss enumerating some CAT-enabled sockets. While the assumption is that I will follow your suggestion to makenr_socket>= the socket count that the machine actually has.
Please can you stop repeating yourself? Yes, nr_sockets can get underestimated this way, but the cases where total_cpus != num_processors + disabled_cpus are - afaict - such that this in the end does no harm. Other than the original case of nr_sockets ending up being zero when "nosmp". So to convince me of the opposite I'm afraid you won't get around constructing an explicit example where things break (and hence my earlier hint regarding NR_CPUS=1, as I wouldn't count this as a valid example).
Jan
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
In reply to Chao PengQuoted 26 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 11:33, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:40, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/arch/x86/psr.c line 36
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +2
-0+static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...Quoted 7 lines
Quoted 4 lines
Looks like this?
static unsigned long
*__read_mostlycat_socket_init,*__read_mostly cat_socket_enable;Yes, except that you will want to drop one (or make clear why you need both).
As said in the previous version,
cat_socket_enableis the actual CAT enabled status.And
cat_socket_initis used for performance optimization purpose only. It indicate if the socket has been initialized, so that initialization happens only once for each socket, but not__cpus_in_socket__times.
Quoted 6 lines
There are three possibilities:
1) Not initialized; 2) Initialized, CAT disabled; 3) Initialized, CAT enabled;So it's not possible to use only one bit to represent three values.
Why? The two bits get set together, and get cleared together. Even if they have formally different meaning, there is - afaict - no case where their values will differ (except for the brief period between setting one and then the other).
Quoted 25 lines
Quoted 25 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
static int cpu_callback(
structnotifier_block*nfb, unsigned long action, void *hcpu){ if ( action == CPU_STARTING ) psr_cpu_init();xen/arch/x86/psr.c +2
-0+else if ( action ==CPU_DYING ) +psr_cpu_fini ();Quoted 5 lines
Quoted 2 lines
Are these the right notifiers for doing things involving memory allocation / freeing?
psr_cpu_fini()does not really have memory allocation/freeing butpsr_cpu_init()does have.Hmm, wait - where did I see this allocation? Looking again, I don't see it now. But if there was one, then surely it would be wrong for
_finito not free it.Quoted 6 lines
While one thing to clarify is:
psr_cpu_init()will not propagate the error even when the memory allocation fails(instead it disables the CAT on the socket).If there is still problem then perhaps I need change
CPU_STARTINGback toCPU_ONLINEand makeon_selected_cpus()call on target cpu.
Quoted 8 lines
Quoted 3 lines
No, if there was any allocation needed, you should do the allocation in
CPU_UP_PREPAREand the initialization inCPU_STARTING. But it looks like this is moot now anyway.As I will add allocation in patch 4, so I will move
psr_cpu_init()to CPU_UP_PREPARE(As the allocation length is based on the cpuid result, so the initialization will also be done here), but still need to movepsr_cpu_fini(which will add the freeing code)toCPU_DOWN_PREPARE?
CPU_DEAD you mean.
But again - only the allocation/freeing should be done in the alternative named notifications, not the actual data setup (as that iirc needs to run on the CPU).
Jan
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
In reply to Jan BeulichQuoted 60 lines · Jan Beulich
Quoted 60 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 11:51, <[email protected]> wrote:
Quoted 57 lines · Jan Beulich
Quoted 44 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:10, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:47, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 08:12, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Review static int __devinit MP_processor_info_x(struct
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +0
-0@@ -112,6 +115,8 @@ static int __devinit MP_processor_info_x(struct
mpc_config_processor*m,Quoted 17 lines
Quoted 12 lines
Quoted 11 lines
Review static int __devinit MP_processor_info_x(struct · line 122
Quoted 8 lines
(quoted diff) +2
-0{ int ver, apicid, cpu = 0; + total_cpus++; + if (!(m->mpc_cpuflag & CPU_ENABLED)) { if (!hotplug) ++disabled_cpus;Is there a reason you can't use
disabled_cpusand avoid adding yet another variable?Quoted 4 lines
The problem is not with
disabled_cpusbut withnum_processors, which does not keep the original detected cpus in current code. Hence 'total_cpus=disabled_cpus+num_processors' may not be correct in some cases.Quoted 4 lines
Please be more specific about when this is a problem (I do note that I'm aware that the equation will not always hold, but during my inspection while reviewing your change I didn't see that this would ever become problematic).
What I really need is the original cpu count enumerated from MADT. If not introduce
total_cpusthen the only way getting it AFAICS is 'disabled_cpus+num_processors'.Quoted 8 lines
Quoted 4 lines
The problem is that
MP_processor_info_x()have some earlier returns before increasingnum_processors. In those cases, the cpu detected will neither counted todisabled_cpusnornum_processors, which means 'disabled_cpus+num_processors' is potentially small than what I need.As said - I understand this. But you still fail to explain under what (realistic, i.e. other than someone bogusly setting NR_CPUS=1) conditions this ends up being a problem.
Quoted 7 lines
As we calculate
nr_socketswith:
nr_sockets=total_cpus/ _cpus_per_socket__If the calculated
total_cpusis smaller than the actual cpu count on the hardware, then thenr_socketsis also potentially smaller than the actual socket count on the hardware. This is not the expectation.Sure - but you still don't say what is going to go wrong. Remember, when I asked you to change to the total count I gave an explicit
example: Use of "nosmp" would have yielded a zeronr_socketsin the earlier code. Yet with the sum ofnum_processorsanddisabled_cpusthis can't happen anymore afaict.
Quoted 7 lines
Quoted 4 lines
"nosmp" only has side effect on
max_cpusandnr_cpu_ids, but they are never used at all when calculatingnr_sockets. So I can't see any reason why with "num_processors+disabled_cpus" thenr_socketswould not be zero, I think this is a bug that I should fix in nosmp case.Did you really mean to say "would _not_ be zero"? Because afaict the above resolves to "would ever be zero".
Yes, I mean "would ever be zero".
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Hence I'm looking
forward to you detailing the conditions under which you would see an issue without introducingtotal_cpus.As said before, with "
num_processors+disabled_cpus" I may get a smallernr_socketsthan the machine actually has. This is my exact
problem: I may miss enumerating some CAT-enabled sockets. While the assumption is that I will follow your suggestion to makenr_socket>= the socket count that the machine actually has.
Quoted 8 lines
Please can you stop repeating yourself? Yes,
nr_socketscan get underestimated this way, but the cases wheretotal_cpus!=num_processors+disabled_cpusare - afaict - such that this in the end does no harm. Other than the original case ofnr_socketsending up being zero when "nosmp". So to convince me of the opposite I'm afraid you won't get around constructing an explicit example where things break (and hence my earlier hint regarding NR_CPUS=1, as I wouldn't count this as a valid example).
My original thought is that with newly introduced total_cpus, nr_sockets is less likely to be underestimated than with "num_processors + disabled_cpus", if not now but for the future. But perhaps I understood it incorrectly.
While this is really not a big deal for me. And "num_processors + disabled_cpus" does work for me now so I feel comfortable to use it.
I do have a problem when coming up with the final codes, there are two possible ways:
1) Make both num_processors and disabled_cpus public so that they can be used when calculating nr_sockets.
2) Add another public function set_nr_sockets in mpparse.c (just like set_nr_cpu_ids does).
Which do you prefer?
Thanks,
Chao
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
In reply to Jan BeulichQuoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 11:33, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:40, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
xen/arch/x86/psr.c line 36
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
xen/arch/x86/psr.c +2
-0+static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...Quoted 7 lines
Quoted 4 lines
Looks like this?
static unsigned long
*__read_mostlycat_socket_init,*__read_mostly cat_socket_enable;Yes, except that you will want to drop one (or make clear why you need both).
As said in the previous version,
cat_socket_enableis the actual CAT enabled status.And
cat_socket_initis used for performance optimization purpose only. It indicate if the socket has been initialized, so that initialization happens only once for each socket, but not__cpus_in_socket__times.There are three possibilities:
1) Not initialized; 2) Initialized, CAT disabled; 3) Initialized, CAT enabled;
Quoted 6 lines
Quoted 1 line
So it's not possible to use only one bit to represent three values.
Why? The two bits get set together, and get cleared together. Even if they have formally different meaning, there is - afaict - no case where their values will differ (except for the brief period between setting one and then the other).
Do you want to try the failure initialization(both because CAT is not even supported on the machine or fails to allocate cos_to_cbm) on and on?
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
static int cpu_callback(
structnotifier_block*nfb, unsigned long action, void *hcpu){ if ( action == CPU_STARTING ) psr_cpu_init();xen/arch/x86/psr.c +2
-0+else if ( action ==CPU_DYING ) +psr_cpu_fini ();Quoted 5 lines
Quoted 2 lines
Are these the right notifiers for doing things involving memory allocation / freeing?
psr_cpu_fini()does not really have memory allocation/freeing butpsr_cpu_init()does have.Hmm, wait - where did I see this allocation? Looking again, I don't see it now. But if there was one, then surely it would be wrong for
_finito not free it.Quoted 6 lines
While one thing to clarify is:
psr_cpu_init()will not propagate the error even when the memory allocation fails(instead it disables the CAT on the socket).If there is still problem then perhaps I need change
CPU_STARTINGback toCPU_ONLINEand makeon_selected_cpus()call on target cpu.No, if there was any allocation needed, you should do the allocation in
CPU_UP_PREPAREand the initialization inCPU_STARTING. But it looks like this is moot now anyway.
Quoted 6 lines
Quoted 4 lines
As I will add allocation in patch 4, so I will move
psr_cpu_init()to CPU_UP_PREPARE(As the allocation length is based on the cpuid result, so the initialization will also be done here), but still need to movepsr_cpu_fini(which will add the freeing code)toCPU_DOWN_PREPARE?
CPU_DEADyou mean.
Yes, CPU_DEAD.
Quoted 4 lines
But again - only the allocation/freeing should be done in the alternative named notifications, not the actual data setup (as that iirc needs to run on the CPU).
I know this is the general rules, but for this case, I don't think it's going to work to allocate memory in CPU_UP_PREPARE while do the initialization later(in CPU_STARTING).
As said, the allocation has dependency on the result of the initialization. E.g. before
info->cos_to_cbm = xzalloc_array(struct psr_cat_cbm,
info->cos_max + 1UL);
info->cos_max must have been known.
Chao
Re: [PATCH v7 01/14] x86: add socket_to_cpumask
In reply to Chao PengQuoted 9 lines
Quoted 1 line
Quoted 1 line · On 20.05.15 at 05:13, <[email protected]> wrote:
I do have a problem when coming up with the final codes, there are two possible ways:
1) Make bothnum_processorsanddisabled_cpuspublic so that they can be used when calculatingnr_sockets.
2) Add another public functionset_nr_socketsinmpparse.c(just likeset_nr_cpu_idsdoes).Which do you prefer?
The latter.
Jan
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
In reply to Chao PengQuoted 35 lines
Quoted 1 line
Quoted 1 line · On 20.05.15 at 05:21, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 11:33, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:40, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +2
-0+static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...Quoted 7 lines
Quoted 4 lines
Looks like this?
static unsigned long
*__read_mostlycat_socket_init,*__read_mostly cat_socket_enable;Yes, except that you will want to drop one (or make clear why you need both).
As said in the previous version,
cat_socket_enableis the actual CAT enabled status.And
cat_socket_initis used for performance optimization purpose only. It indicate if the socket has been initialized, so that initialization happens only once for each socket, but not__cpus_in_socket__times.There are three possibilities:
1) Not initialized; 2) Initialized, CAT disabled; 3) Initialized, CAT enabled;So it's not possible to use only one bit to represent three values.
Quoted 8 lines
Quoted 4 lines
Why? The two bits get set together, and get cleared together. Even if they have formally different meaning, there is - afaict - no case where their values will differ (except for the brief period between setting one and then the other).
Do you want to try the failure
initialization(both because CAT is not even supported on the machine or fails to allocate cos_to_cbm)on and on?
I don't see any harm - all you save is a cpuid_count() invocation.
Quoted 8 lines
Quoted 3 lines
But again - only the allocation/freeing should be done in the alternative named notifications, not the actual data setup (as that iirc needs to run on the CPU).
I know this is the general rules, but for this case, I don't think it's going to work to allocate memory in
CPU_UP_PREPAREwhile do the initializationlater(in CPU_STARTING).
Quoted 7 lines
As said, the allocation has dependency on the result of the initialization. E.g. before
info->cos_to_cbm= xzalloc_array(structpsr_cat_cbm,info->cos_max + 1UL);
info->cos_maxmust have been known.
Ah, yes. Otoh, considering that everywhere else we expect symmetry across CPUs, do you really think there are going to be systems with different CPUs having different cos_max values?
Jan
Re: [PATCH v7 03/14] x86: detect and initialize Intel CAT feature
Quoted 40 lines · Jan Beulich
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 20.05.15 at 05:21, <[email protected]> wrote:
Quoted 37 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 11:33, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.05.15 at 09:40, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Review
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.05.15 at 10:56, <[email protected]> wrote:
(quoted diff) +2
-0+static unsigned long *__read_mostly cat_socket_init_bitmap; +static unsigned long *__read_mostly cat_socket_enable_bitmap;Didn't we agree to fold these two into one? Apart from that the
_bitmapname tag doesn't seem very useful...Quoted 7 lines
Quoted 4 lines
Looks like this?
static unsigned long
*__read_mostlycat_socket_init,*__read_mostly cat_socket_enable;Yes, except that you will want to drop one (or make clear why you need both).
As said in the previous version,
cat_socket_enableis the actual CAT enabled status.And
cat_socket_initis used for performance optimization purpose only. It indicate if the socket has been initialized, so that initialization happens only once for each socket, but not__cpus_in_socket__times.Quoted 6 lines
There are three possibilities:
1) Not initialized; 2) Initialized, CAT disabled; 3) Initialized, CAT enabled;So it's not possible to use only one bit to represent three values.
Why? The two bits get set together, and get cleared together. Even if they have formally different meaning, there is - afaict - no case where their values will differ (except for the brief period between setting one and then the other).
Quoted 5 lines
Quoted 3 lines
Do you want to try the failure
initialization(both because CAT is not even supported on the machine or fails to allocate cos_to_cbm)on and on?I don't see any harm - all you save is a
cpuid_count()invocation.
Then I will remove cat_socket_init.
Quoted 12 lines
Quoted 12 lines
Quoted 4 lines
But again - only the allocation/freeing should be done in the alternative named notifications, not the actual data setup (as that iirc needs to run on the CPU).
I know this is the general rules, but for this case, I don't think it's going to work to allocate memory in
CPU_UP_PREPAREwhile do the initializationlater(in CPU_STARTING).As said, the allocation has dependency on the result of the initialization. E.g. before
Quoted 8 lines
Quoted 4 lines
info->cos_to_cbm= xzalloc_array(structpsr_cat_cbm,info->cos_max + 1UL);
info->cos_maxmust have been known.Ah, yes. Otoh, considering that everywhere else we expect symmetry across CPUs, do you really think there are going to be systems with different CPUs having different
cos_maxvalues?
I agree, such systems should be rare, or even doesn't exist in the real world. But as we are trying to support it, then I have to make it working.
Chao