All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/vpmu_intel: Handle SMT consistently for programmable and fixed counters
@ 2017-04-05 19:50 Mohit Gambhir
  2017-04-06  9:31 ` Jan Beulich
  2017-04-07  7:32 ` Tian, Kevin
  0 siblings, 2 replies; 3+ messages in thread
From: Mohit Gambhir @ 2017-04-05 19:50 UTC (permalink / raw)
  To: jun.nakajima, kevin.tian, boris.ostrovsky, andrew.cooper3,
	jbeulich, xen-devel
  Cc: Mohit Gambhir

The patch introduces a macro FIXED_CTR_CTRL_ANYTHREAD_MASK and uses it
to mask .Anythread bit for all counter in IA32_FIXED_CTR_CTRL MSR in all
versions of Intel Arhcitectural Performance Monitoring.  Masking .AnyThread bit
 is necesssry for two reasons:

1. We need to be consistent in the implementation. We disable .Anythread bit in
programmable counters (regardless of the version) by masking bit 21 in
IA32_PERFEVTSELx.  (See code snippet below from vpmu_intel.c)

 /* Masks used for testing whether and MSR is valid */
 #define ARCH_CTRL_MASK  (~((1ull << 32) - 1) | (1ull << 21))

But we leave it enabled in fixed function counters for version 3. Removing the
condition disables the bit in fixed function counters regardless of the version,
which is consistent with what is done for programmable counters.

2. We don't want to expose event counts from another guest (or hypervisor)
which can happen if .AnyThread bit is not masked and a VCPU is only scheduled
to run on one of the hardware threads in a hyper-threaded CPU.

Also, note that Intel SDM discourages the  use of .AnyThread bit in virtualized
 environments (per section 18.2.3.1 AnyThread Counting and Software Evolution).

Signed-off-by: Mohit Gambhir <mohit.gambhir@oracle.com>
---
 xen/arch/x86/cpu/vpmu_intel.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/cpu/vpmu_intel.c b/xen/arch/x86/cpu/vpmu_intel.c
index 0d66ecb..3f0322c 100644
--- a/xen/arch/x86/cpu/vpmu_intel.c
+++ b/xen/arch/x86/cpu/vpmu_intel.c
@@ -73,6 +73,7 @@ static bool_t __read_mostly full_width_write;
  */
 #define FIXED_CTR_CTRL_BITS 4
 #define FIXED_CTR_CTRL_MASK ((1 << FIXED_CTR_CTRL_BITS) - 1)
+#define FIXED_CTR_CTRL_ANYTHREAD_MASK 0x4
 
 #define ARCH_CNTR_ENABLED   (1ULL << 22)
 
@@ -946,6 +947,7 @@ int __init core2_vpmu_init(void)
 {
     u64 caps;
     unsigned int version = 0;
+    unsigned int i;
 
     if ( current_cpu_data.cpuid_level >= 0xa )
         version = MASK_EXTR(cpuid_eax(0xa), PMU_VERSION_MASK);
@@ -979,8 +981,11 @@ int __init core2_vpmu_init(void)
     full_width_write = (caps >> 13) & 1;
 
     fixed_ctrl_mask = ~((1ull << (fixed_pmc_cnt * FIXED_CTR_CTRL_BITS)) - 1);
-    if ( version == 2 )
-        fixed_ctrl_mask |= 0x444;
+    /* mask .AnyThread bits for all fixed counters */
+    for( i = 0; i < fixed_pmc_cnt; i++ )
+       fixed_ctrl_mask |=
+           (FIXED_CTR_CTRL_ANYTHREAD_MASK << (FIXED_CTR_CTRL_BITS * i));
+
     fixed_counters_mask = ~((1ull << core2_get_bitwidth_fix_count()) - 1);
     global_ctrl_mask = ~((((1ULL << fixed_pmc_cnt) - 1) << 32) |
                          ((1ULL << arch_pmc_cnt) - 1));
-- 
2.9.3


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86/vpmu_intel: Handle SMT consistently for programmable and fixed counters
  2017-04-05 19:50 [PATCH v2] x86/vpmu_intel: Handle SMT consistently for programmable and fixed counters Mohit Gambhir
@ 2017-04-06  9:31 ` Jan Beulich
  2017-04-07  7:32 ` Tian, Kevin
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2017-04-06  9:31 UTC (permalink / raw)
  To: Mohit Gambhir
  Cc: andrew.cooper3, kevin.tian, boris.ostrovsky, jun.nakajima, xen-devel

>>> On 05.04.17 at 21:50, <mohit.gambhir@oracle.com> wrote:
> The patch introduces a macro FIXED_CTR_CTRL_ANYTHREAD_MASK and uses it
> to mask .Anythread bit for all counter in IA32_FIXED_CTR_CTRL MSR in all
> versions of Intel Arhcitectural Performance Monitoring.  Masking .AnyThread bit
>  is necesssry for two reasons:
> 
> 1. We need to be consistent in the implementation. We disable .Anythread bit in
> programmable counters (regardless of the version) by masking bit 21 in
> IA32_PERFEVTSELx.  (See code snippet below from vpmu_intel.c)
> 
>  /* Masks used for testing whether and MSR is valid */
>  #define ARCH_CTRL_MASK  (~((1ull << 32) - 1) | (1ull << 21))
> 
> But we leave it enabled in fixed function counters for version 3. Removing the
> condition disables the bit in fixed function counters regardless of the version,
> which is consistent with what is done for programmable counters.
> 
> 2. We don't want to expose event counts from another guest (or hypervisor)
> which can happen if .AnyThread bit is not masked and a VCPU is only scheduled
> to run on one of the hardware threads in a hyper-threaded CPU.
> 
> Also, note that Intel SDM discourages the  use of .AnyThread bit in virtualized
>  environments (per section 18.2.3.1 AnyThread Counting and Software 
> Evolution).
> 
> Signed-off-by: Mohit Gambhir <mohit.gambhir@oracle.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>

Thanks for the much better description.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] x86/vpmu_intel: Handle SMT consistently for programmable and fixed counters
  2017-04-05 19:50 [PATCH v2] x86/vpmu_intel: Handle SMT consistently for programmable and fixed counters Mohit Gambhir
  2017-04-06  9:31 ` Jan Beulich
@ 2017-04-07  7:32 ` Tian, Kevin
  1 sibling, 0 replies; 3+ messages in thread
From: Tian, Kevin @ 2017-04-07  7:32 UTC (permalink / raw)
  To: Mohit Gambhir, Nakajima, Jun, boris.ostrovsky, andrew.cooper3,
	jbeulich, xen-devel

> From: Mohit Gambhir [mailto:mohit.gambhir@oracle.com]
> Sent: Thursday, April 6, 2017 3:50 AM
> 
> The patch introduces a macro FIXED_CTR_CTRL_ANYTHREAD_MASK and uses
> it
> to mask .Anythread bit for all counter in IA32_FIXED_CTR_CTRL MSR in all
> versions of Intel Arhcitectural Performance Monitoring.  Masking .AnyThread
> bit
>  is necesssry for two reasons:
> 
> 1. We need to be consistent in the implementation. We disable .Anythread
> bit in
> programmable counters (regardless of the version) by masking bit 21 in
> IA32_PERFEVTSELx.  (See code snippet below from vpmu_intel.c)
> 
>  /* Masks used for testing whether and MSR is valid */
>  #define ARCH_CTRL_MASK  (~((1ull << 32) - 1) | (1ull << 21))
> 
> But we leave it enabled in fixed function counters for version 3. Removing
> the
> condition disables the bit in fixed function counters regardless of the version,
> which is consistent with what is done for programmable counters.
> 
> 2. We don't want to expose event counts from another guest (or hypervisor)
> which can happen if .AnyThread bit is not masked and a VCPU is only
> scheduled
> to run on one of the hardware threads in a hyper-threaded CPU.
> 
> Also, note that Intel SDM discourages the  use of .AnyThread bit in virtualized
>  environments (per section 18.2.3.1 AnyThread Counting and Software
> Evolution).
> 
> Signed-off-by: Mohit Gambhir <mohit.gambhir@oracle.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-07  7:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-05 19:50 [PATCH v2] x86/vpmu_intel: Handle SMT consistently for programmable and fixed counters Mohit Gambhir
2017-04-06  9:31 ` Jan Beulich
2017-04-07  7:32 ` Tian, Kevin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.