Skip to contentSkip to conversation

x86/VPMU: implement ipc and arch filter flags

PATCH Superseded Brendan Gregg 3 participants 5 messages Dec 1, 2015 – Jan 5, 2016

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 2/2 x86/VPMU: implement ipc and arch filter flags

This introduces a way to have a restricted VPMU, by specifying one of two predefined groups of PMCs to make available. For secure environments, this allows the VPMU to be used without needing to enable all PMCs.

---
 docs/misc/xen-command-line.markdown | 15 ++++++++++-
 xen/arch/x86/cpu/vpmu.c             | 51 +++++++++++++++++++++++++++++--------
 xen/arch/x86/cpu/vpmu_intel.c       | 50 ++++++++++++++++++++++++++++++++++++
 xen/include/asm-x86/msr-index.h     |  1 +
 xen/include/public/pmu.h            | 14 ++++++++--
 5 files changed, 117 insertions(+), 14 deletions(-)
docs/misc/xen-command-line.markdown +14 -1
index 70daa84..795661e 100644
@@ -1452,7 +1452,7 @@ Use Virtual Processor ID support if available.  This prevents the need for TLB
 flushes on VM entry and exit, increasing performance.
 
 ### vpmu
-> `= ( bts )`
+> `= ( <boolean> | { bts | ipc | arch [, ...] } )`
 
 > Default: `off`
 
@@ -1468,6 +1468,19 @@ wrong behaviour (see handle\_pmc\_quirk()).
 If 'vpmu=bts' is specified the virtualisation of the Branch Trace Store (BTS)
 feature is switched on on Intel processors supporting this feature.
 
+vpmu=ipc enables performance monitoring, but restricts the counters to the
+most minimum set possible: instructions, cycles, and reference cycles. These
+can be used to calculate instructions per cycle (IPC).
+
+vpmu=arch enables performance monitoring, but restricts the counters to the
+pre-defined architectural events only. These are exposed by cpuid, and listed
+in the Pre-Defined Architectural Performance Events table from the Intel 64
+and IA-32 Architectures Software Developer's Manual, Volume 3B, System
+Programming Guide, Part 2.
+
+If a boolean is not used, combinations of flags are allowed, comma separated.
+For example, vpmu=arch,bts.
+
 Note that if **watchdog** option is also specified vpmu will be turned off.
 
 *Warning:*
xen/arch/x86/cpu/vpmu.c +40 -11

80 lines not on this page · raw message

xen/arch/x86/cpu/vpmu_intel.c +50 -0

74 lines not on this page · raw message

xen/include/asm-x86/msr-index.h +1 -0
index b8ad93c..0542064 100644
@@ -328,6 +328,7 @@
 
 /* Platform Shared Resource MSRs */
 #define MSR_IA32_CMT_EVTSEL		0x00000c8d
+#define MSR_IA32_CMT_EVTSEL_UE_MASK	0x0000ffff
 #define MSR_IA32_CMT_CTR		0x00000c8e
 #define MSR_IA32_PSR_ASSOC		0x00000c8f
 #define MSR_IA32_PSR_L3_QOS_CFG	0x00000c81
xen/include/public/pmu.h +12 -2
index 7753df0..f9ad7b4 100644
@@ -84,9 +84,19 @@ DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);
 
 /*
  * PMU features:
- * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_INTEL_BTS:  Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_IPC_ONLY:   Restrict PMC to the most minimum set possible.
+ *                              Instructions, cycles, and ref cycles. Can be
+ *                              used to calculate instructions-per-cycle (IPC)
+ *                              (ignored on AMD).
+ * - XENPMU_FEATURE_ARCH_ONLY:  Restrict PMCs to the Intel Pre-Defined
+ *                              Architecteral Performance Events exposed by
+ *                              cpuid and listed in the Intel developer's manual
+ *                              (ignored on AMD).
  */
-#define XENPMU_FEATURE_INTEL_BTS  1
+#define XENPMU_FEATURE_INTEL_BTS  (1<<0)
+#define XENPMU_FEATURE_IPC_ONLY   (1<<1)
+#define XENPMU_FEATURE_ARCH_ONLY  (1<<2)
 
 /*
  * Shared PMU data between hypervisor and PV(H) domains.
Signature · 1 line
1.9.1
#1 lore raw
Quoted 6 lines · Brendan Gregg

This introduces a way to have a restricted VPMU, by specifying one of two predefined groups of PMCs to make available. For secure environments, this allows the VPMU to be used without needing to enable all PMCs.

This needs to be reviewed also by Intel maintainers (copied). Plus x86 maintainers.

-boris

Quoted 245 lines
---
  docs/misc/xen-command-line.markdown | 15 ++++++++++-
  xen/arch/x86/cpu/vpmu.c             | 51 +++++++++++++++++++++++++++++--------
  xen/arch/x86/cpu/vpmu_intel.c       | 50 ++++++++++++++++++++++++++++++++++++
  xen/include/asm-x86/msr-index.h     |  1 +
  xen/include/public/pmu.h            | 14 ++++++++--
  5 files changed, 117 insertions(+), 14 deletions(-)
docs/misc/xen-command-line.markdown +14 -1
index 70daa84..795661e 100644
@@ -1452,7 +1452,7 @@ Use Virtual Processor ID support if available.  This prevents the need for TLB
  flushes on VM entry and exit, increasing performance.
 
  ### vpmu
-> `= ( bts )`
+> `= ( <boolean> | { bts | ipc | arch [, ...] } )`
 
  > Default: `off`
 
@@ -1468,6 +1468,19 @@ wrong behaviour (see handle\_pmc\_quirk()).
  If 'vpmu=bts' is specified the virtualisation of the Branch Trace Store (BTS)
  feature is switched on on Intel processors supporting this feature.
 
+vpmu=ipc enables performance monitoring, but restricts the counters to the
+most minimum set possible: instructions, cycles, and reference cycles. These
+can be used to calculate instructions per cycle (IPC).
+
+vpmu=arch enables performance monitoring, but restricts the counters to the
+pre-defined architectural events only. These are exposed by cpuid, and listed
+in the Pre-Defined Architectural Performance Events table from the Intel 64
+and IA-32 Architectures Software Developer's Manual, Volume 3B, System
+Programming Guide, Part 2.
+
+If a boolean is not used, combinations of flags are allowed, comma separated.
+For example, vpmu=arch,bts.
+
  Note that if **watchdog** option is also specified vpmu will be turned off.
 
  *Warning:*
xen/arch/x86/cpu/vpmu.c +40 -11
index 2f5156a..46b5324 100644
@@ -43,34 +43,59 @@ CHECK_pmu_data;
  CHECK_pmu_params;
 
  /*
- * "vpmu" :     vpmu generally enabled
- * "vpmu=off" : vpmu generally disabled
- * "vpmu=bts" : vpmu enabled and Intel BTS feature switched on.
+ * "vpmu" :     vpmu generally enabled (all counters)
+ * "vpmu=off"  : vpmu generally disabled
+ * "vpmu=bts"  : vpmu enabled and Intel BTS feature switched on.
+ * "vpmu=ipc"  : vpmu enabled for IPC counters only (most restrictive)
+ * "vpmu=arch" : vpmu enabled for predef arch counters only (restrictive)
+ * flag combinations are allowed, eg, "vpmu=ipc,bts".
   */
  static unsigned int __read_mostly opt_vpmu_enabled;
  unsigned int __read_mostly vpmu_mode = XENPMU_MODE_OFF;
  unsigned int __read_mostly vpmu_features = 0;
-static void parse_vpmu_param(char *s);
-custom_param("vpmu", parse_vpmu_param);
+static void parse_vpmu_params(char *s);
+custom_param("vpmu", parse_vpmu_params);
 
  static DEFINE_SPINLOCK(vpmu_lock);
  static unsigned vpmu_count;
 
  static DEFINE_PER_CPU(struct vcpu *, last_vcpu);
 
-static void __init parse_vpmu_param(char *s)
+static int parse_vpmu_param(char *s, int len)
  {
+    if ( ! *s || ! len )
+        return 0;
+    if ( !strncmp(s, "bts", len) )
+        vpmu_features |= XENPMU_FEATURE_INTEL_BTS;
+    else if ( !strncmp(s, "ipc", len) )
+        vpmu_features |= XENPMU_FEATURE_IPC_ONLY;
+    else if ( !strncmp(s, "arch", len) )
+        vpmu_features |= XENPMU_FEATURE_ARCH_ONLY;
+    else
+        return 1;
+    return 0;
+}
+
+static void __init parse_vpmu_params(char *s)
+{
+    char *sep, *p = s;
+
      switch ( parse_bool(s) )
      {
      case 0:
          break;
      default:
-        if ( !strcmp(s, "bts") )
-            vpmu_features |= XENPMU_FEATURE_INTEL_BTS;
-        else if ( *s )
+        while (1)
          {
-            printk("VPMU: unknown flag: %s - vpmu disabled!\n", s);
-            break;
+            sep = strchr(p, ',');
+            if ( sep == NULL )
+                sep = strchr(p, 0);
+            if ( parse_vpmu_param(p, sep - p) )
+                goto error;
+            if ( *sep == 0 )
+                /* reached end of flags */
+                break;
+            p = sep + 1;
          }
          /* fall through */
      case 1:
@@ -79,6 +104,10 @@ static void __init parse_vpmu_param(char *s)
          opt_vpmu_enabled = 1;
          break;
      }
+    return;
+
+ error:
+    printk("VPMU: unknown flags: %s - vpmu disabled!\n", s);
  }
 
  void vpmu_lvtpc_update(uint32_t val)
xen/arch/x86/cpu/vpmu_intel.c +50 -0
index 8d83a1a..a6c5545 100644
@@ -602,12 +602,19 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content,
                   "MSR_PERF_GLOBAL_STATUS(0x38E)!\n");
          return -EINVAL;
      case MSR_IA32_PEBS_ENABLE:
+        if ( vpmu_features & (XENPMU_FEATURE_IPC_ONLY |
+             XENPMU_FEATURE_ARCH_ONLY) )
+            return -EINVAL;
          if ( msr_content & 1 )
              gdprintk(XENLOG_WARNING, "Guest is trying to enable PEBS, "
                       "which is not supported.\n");
          core2_vpmu_cxt->pebs_enable = msr_content;
          return 0;
      case MSR_IA32_DS_AREA:
+        if ( (vpmu_features & (XENPMU_FEATURE_IPC_ONLY |
+             XENPMU_FEATURE_ARCH_ONLY)) &&
+             !(vpmu_features & XENPMU_FEATURE_INTEL_BTS) )
+            return -EINVAL;
          if ( vpmu_is_set(vpmu, VPMU_CPU_HAS_DS) )
          {
              if ( !is_canonical_address(msr_content) )
@@ -652,12 +659,55 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content,
          tmp = msr - MSR_P6_EVNTSEL(0);
          if ( tmp >= 0 && tmp < arch_pmc_cnt )
          {
+            bool_t blocked = 0;
+            uint64_t umaskevent;
              struct xen_pmu_cntr_pair *xen_pmu_cntr_pair =
                  vpmu_reg_pointer(core2_vpmu_cxt, arch_counters);
 
              if ( msr_content & ARCH_CTRL_MASK )
                  return -EINVAL;
 
+            /* PMC filters */
+            umaskevent = msr_content & MSR_IA32_CMT_EVTSEL_UE_MASK;
+            if ( vpmu_features & XENPMU_FEATURE_IPC_ONLY ||
+                 vpmu_features & XENPMU_FEATURE_ARCH_ONLY )
+            {
+                blocked = 1;
+                switch ( umaskevent )
+                {
+                /*
+                 * See the Pre-Defined Architectural Performance Events table
+                 * from the Intel 64 and IA-32 Architectures Software
+                 * Developer's Manual, Volume 3B, System Programming Guide,
+                 * Part 2.
+                 */
+                case 0x003c:	/* unhalted core cycles */
+                case 0x013c:	/* unhalted ref cycles */
+                case 0x00c0:	/* instruction retired */
+                    blocked = 0;
+                default:
+                    break;
+                }
+            }
+
+            if ( vpmu_features & XENPMU_FEATURE_ARCH_ONLY )
+            {
+                /* additional counters beyond IPC only; blocked already set */
+                switch ( umaskevent )
+                {
+                case 0x4f2e:	/* LLC reference */
+                case 0x412e:	/* LLC misses */
+                case 0x00c4:	/* branch instruction retired */
+                case 0x00c5:	/* branch */
+                    blocked = 0;
+                default:
+                    break;
+               }
+            }
+
+            if ( blocked )
+                return -EINVAL;
+
              if ( has_hvm_container_vcpu(v) )
                  vmx_read_guest_msr(MSR_CORE_PERF_GLOBAL_CTRL,
                                     &core2_vpmu_cxt->global_ctrl);
xen/include/asm-x86/msr-index.h +1 -0
index b8ad93c..0542064 100644
@@ -328,6 +328,7 @@
 
  /* Platform Shared Resource MSRs */
  #define MSR_IA32_CMT_EVTSEL		0x00000c8d
+#define MSR_IA32_CMT_EVTSEL_UE_MASK	0x0000ffff
  #define MSR_IA32_CMT_CTR		0x00000c8e
  #define MSR_IA32_PSR_ASSOC		0x00000c8f
  #define MSR_IA32_PSR_L3_QOS_CFG	0x00000c81
xen/include/public/pmu.h +12 -2
index 7753df0..f9ad7b4 100644
@@ -84,9 +84,19 @@ DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);
 
  /*
   * PMU features:
- * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_INTEL_BTS:  Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_IPC_ONLY:   Restrict PMC to the most minimum set possible.
+ *                              Instructions, cycles, and ref cycles. Can be
+ *                              used to calculate instructions-per-cycle (IPC)
+ *                              (ignored on AMD).
+ * - XENPMU_FEATURE_ARCH_ONLY:  Restrict PMCs to the Intel Pre-Defined
+ *                              Architecteral Performance Events exposed by
+ *                              cpuid and listed in the Intel developer's manual
+ *                              (ignored on AMD).
   */
-#define XENPMU_FEATURE_INTEL_BTS  1
+#define XENPMU_FEATURE_INTEL_BTS  (1<<0)
+#define XENPMU_FEATURE_IPC_ONLY   (1<<1)
+#define XENPMU_FEATURE_ARCH_ONLY  (1<<2)
 
  /*
   * Shared PMU data between hypervisor and PV(H) domains.
#2 lore raw
Quoted 8 lines

From: Boris Ostrovsky [mailto:[email protected]]
Sent: Tuesday, December 08, 2015 3:14 AM

Quoted 4 lines · Brendan Gregg

This introduces a way to have a restricted VPMU, by specifying one of two predefined groups of PMCs to make available. For secure environments, this allows the VPMU to be used without needing to enable all PMCs.

Quoted 8 lines
Quoted 2 lines

This needs to be reviewed also by Intel maintainers (copied). Plus x86 maintainers.

-boris

In my review queue... since it introduces new logic I'll find a better time to look at it carefully next week.

Thanks
Kevin

#3 lore raw
In reply to Boris Ostrovsky
Quoted 16 lines

From: Boris Ostrovsky [mailto:[email protected]]
Sent: Tuesday, December 08, 2015 3:14 AM

Quoted 6 lines · Brendan Gregg

This introduces a way to have a restricted VPMU, by specifying one of two predefined groups of PMCs to make available. For secure environments, this allows the VPMU to be used without needing to enable all PMCs.

This needs to be reviewed also by Intel maintainers (copied). Plus x86 maintainers.

-boris

[...]

Quoted 22 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t

Quoted 5 lines
xen/arch/x86/cpu/vpmu_intel.c +0 -0
index 8d83a1a..a6c5545 100644
@@ -602,12 +602,19 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t

msr_content,

Quoted 16 lines
xen/arch/x86/cpu/vpmu_intel.c +7 -0
                   "MSR_PERF_GLOBAL_STATUS(0x38E)!\n");
          return -EINVAL;
      case MSR_IA32_PEBS_ENABLE:
+        if ( vpmu_features & (XENPMU_FEATURE_IPC_ONLY |
+             XENPMU_FEATURE_ARCH_ONLY) )
+            return -EINVAL;
          if ( msr_content & 1 )
              gdprintk(XENLOG_WARNING, "Guest is trying to enable PEBS, "
                       "which is not supported.\n");
          core2_vpmu_cxt->pebs_enable = msr_content;
          return 0;
      case MSR_IA32_DS_AREA:
+        if ( (vpmu_features & (XENPMU_FEATURE_IPC_ONLY |
+             XENPMU_FEATURE_ARCH_ONLY)) &&
+             !(vpmu_features & XENPMU_FEATURE_INTEL_BTS) )
+            return -EINVAL;

should the check be made just based on BTS?

Quoted 31 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t

Quoted 4 lines
xen/arch/x86/cpu/vpmu_intel.c +0 -0
          if ( vpmu_is_set(vpmu, VPMU_CPU_HAS_DS) )
          {
              if ( !is_canonical_address(msr_content) )
@@ -652,12 +659,55 @@ static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t

msr_content,

Quoted 26 lines
xen/arch/x86/cpu/vpmu_intel.c +17 -0
          tmp = msr - MSR_P6_EVNTSEL(0);
          if ( tmp >= 0 && tmp < arch_pmc_cnt )
          {
+            bool_t blocked = 0;
+            uint64_t umaskevent;
              struct xen_pmu_cntr_pair *xen_pmu_cntr_pair =
                  vpmu_reg_pointer(core2_vpmu_cxt, arch_counters);
 
              if ( msr_content & ARCH_CTRL_MASK )
                  return -EINVAL;
 
+            /* PMC filters */
+            umaskevent = msr_content & MSR_IA32_CMT_EVTSEL_UE_MASK;
+            if ( vpmu_features & XENPMU_FEATURE_IPC_ONLY ||
+                 vpmu_features & XENPMU_FEATURE_ARCH_ONLY )
+            {
+                blocked = 1;
+                switch ( umaskevent )
+                {
+                /*
+                 * See the Pre-Defined Architectural Performance Events table
+                 * from the Intel 64 and IA-32 Architectures Software
+                 * Developer's Manual, Volume 3B, System Programming Guide,
+                 * Part 2.
+                 */
+                case 0x003c:	/* unhalted core cycles */

Better to copy same wording from SDM, e.g. "UnHalted Core Cycles */. same for below.

Quoted 47 lines
Quoted 47 lines
xen/arch/x86/cpu/vpmu_intel.c +26 -0
+                case 0x013c:	/* unhalted ref cycles */
+                case 0x00c0:	/* instruction retired */
+                    blocked = 0;
+                default:
+                    break;
+                }
+            }
+
+            if ( vpmu_features & XENPMU_FEATURE_ARCH_ONLY )
+            {
+                /* additional counters beyond IPC only; blocked already set */
+                switch ( umaskevent )
+                {
+                case 0x4f2e:	/* LLC reference */
+                case 0x412e:	/* LLC misses */
+                case 0x00c4:	/* branch instruction retired */
+                case 0x00c5:	/* branch */
+                    blocked = 0;
+                default:
+                    break;
+               }
+            }
+
+            if ( blocked )
+                return -EINVAL;
+
              if ( has_hvm_container_vcpu(v) )
                  vmx_read_guest_msr(MSR_CORE_PERF_GLOBAL_CTRL,
                                     &core2_vpmu_cxt->global_ctrl);
xen/include/asm-x86/msr-index.h +1 -0
index b8ad93c..0542064 100644
@@ -328,6 +328,7 @@
 
  /* Platform Shared Resource MSRs */
  #define MSR_IA32_CMT_EVTSEL		0x00000c8d
+#define MSR_IA32_CMT_EVTSEL_UE_MASK	0x0000ffff
  #define MSR_IA32_CMT_CTR		0x00000c8e
  #define MSR_IA32_PSR_ASSOC		0x00000c8f
  #define MSR_IA32_PSR_L3_QOS_CFG	0x00000c81
xen/include/public/pmu.h +0 -0
index 7753df0..f9ad7b4 100644
@@ -84,9 +84,19 @@ DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);
 
Quoted 5 lines

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); · line 88

Quoted 5 lines
xen/include/public/pmu.h +2 -1
  /*
   * PMU features:
- * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_INTEL_BTS:  Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_IPC_ONLY:   Restrict PMC to the most minimum set possible.

PMC -> PMCs

Quoted 5 lines

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); · line 93

Quoted 5 lines
xen/include/public/pmu.h +5 -0
+ *                              Instructions, cycles, and ref cycles. Can be
+ *                              used to calculate instructions-per-cycle (IPC)
+ *                              (ignored on AMD).
+ * - XENPMU_FEATURE_ARCH_ONLY:  Restrict PMCs to the Intel Pre-Defined
+ *                              Architecteral Performance Events exposed by

Architecteral -> Architectural

Quoted 10 lines
Quoted 10 lines
xen/include/public/pmu.h +5 -1
+ *                              cpuid and listed in the Intel developer's manual
+ *                              (ignored on AMD).
   */
-#define XENPMU_FEATURE_INTEL_BTS  1
+#define XENPMU_FEATURE_INTEL_BTS  (1<<0)
+#define XENPMU_FEATURE_IPC_ONLY   (1<<1)
+#define XENPMU_FEATURE_ARCH_ONLY  (1<<2)
 
  /*
   * Shared PMU data between hypervisor and PV(H) domains.
#4 lore raw

Sorry for the delay...

Quoted 47 lines · Kevin
Quoted 5 lines

From: Boris Ostrovsky [mailto:[email protected]]
Sent: Tuesday, December 08, 2015 3:14 AM

Quoted 1 line · Brendan Gregg

This introduces a way to have a restricted VPMU, by specifying one of

two

Quoted 1 line
Quoted 1 line

predefined groups of PMCs to make available. For secure environments,

this

Quoted 10 lines
Quoted 4 lines

allows the VPMU to be used without needing to enable all PMCs.

This needs to be reviewed also by Intel maintainers (copied). Plus x86 maintainers.

-boris

[...]

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/xen/arch/x86/cpu/vpmu_intel.c

Quoted 4 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr,

Quoted 4 lines

index 8d83a1a..a6c5545 100644

xen/arch/x86/cpu/vpmu_intel.c +0 -0
@@ -602,12 +602,19 @@ static int core2_vpmu_do_wrmsr(unsigned int msr,

uint64_t

Quoted 9 lines

msr_content,

Quoted 8 lines
xen/arch/x86/cpu/vpmu_intel.c +3 -0
                   "MSR_PERF_GLOBAL_STATUS(0x38E)!\n");
          return -EINVAL;
      case MSR_IA32_PEBS_ENABLE:
+        if ( vpmu_features & (XENPMU_FEATURE_IPC_ONLY |
+             XENPMU_FEATURE_ARCH_ONLY) )
+            return -EINVAL;
          if ( msr_content & 1 )
              gdprintk(XENLOG_WARNING, "Guest is trying to enable

PEBS, "

Quoted 8 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content, · line 617

Quoted 8 lines
xen/arch/x86/cpu/vpmu_intel.c +4 -0
                       "which is not supported.\n");
          core2_vpmu_cxt->pebs_enable = msr_content;
          return 0;
      case MSR_IA32_DS_AREA:
+        if ( (vpmu_features & (XENPMU_FEATURE_IPC_ONLY |
+             XENPMU_FEATURE_ARCH_ONLY)) &&
+             !(vpmu_features & XENPMU_FEATURE_INTEL_BTS) )
+            return -EINVAL;
Quoted 2 lines

should the check be made just based on BTS?

Ah, yes. The BTS check was added after the new modes, but it should be standalone. I don't think anything else uses DS_AREA other than BTS.

Quoted 30 lines
Quoted 4 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr,

Quoted 4 lines
xen/arch/x86/cpu/vpmu_intel.c +0 -0
          if ( vpmu_is_set(vpmu, VPMU_CPU_HAS_DS) )
          {
              if ( !is_canonical_address(msr_content) )
@@ -652,12 +659,55 @@ static int core2_vpmu_do_wrmsr(unsigned int msr,

uint64_t

Quoted 22 lines

msr_content,

Quoted 21 lines
xen/arch/x86/cpu/vpmu_intel.c +12 -0
          tmp = msr - MSR_P6_EVNTSEL(0);
          if ( tmp >= 0 && tmp < arch_pmc_cnt )
          {
+            bool_t blocked = 0;
+            uint64_t umaskevent;
              struct xen_pmu_cntr_pair *xen_pmu_cntr_pair =
                  vpmu_reg_pointer(core2_vpmu_cxt, arch_counters);
 
              if ( msr_content & ARCH_CTRL_MASK )
                  return -EINVAL;
 
+            /* PMC filters */
+            umaskevent = msr_content & MSR_IA32_CMT_EVTSEL_UE_MASK;
+            if ( vpmu_features & XENPMU_FEATURE_IPC_ONLY ||
+                 vpmu_features & XENPMU_FEATURE_ARCH_ONLY )
+            {
+                blocked = 1;
+                switch ( umaskevent )
+                {
+                /*
+                 * See the Pre-Defined Architectural Performance

Events table

Quoted 2 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr, · line 681

Quoted 2 lines
xen/arch/x86/cpu/vpmu_intel.c +2 -0
+                 * from the Intel 64 and IA-32 Architectures Software
+                 * Developer's Manual, Volume 3B, System Programming
Quoted 8 lines

Guide,

Quoted 3 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content, · line 684

Quoted 3 lines
xen/arch/x86/cpu/vpmu_intel.c +3 -0
+                 * Part 2.
+                 */
+                case 0x003c:       /* unhalted core cycles */

Better to copy same wording from SDM, e.g. "UnHalted Core Cycles */. same for below.

Ok, yes.

Quoted 50 lines
Quoted 12 lines

xen/arch/x86/cpu/vpmu_intel.c static int core2_vpmu_do_wrmsr(unsigned int msr, uint64_t msr_content,

Quoted 12 lines
xen/arch/x86/cpu/vpmu_intel.c +11 -0
+                case 0x013c:       /* unhalted ref cycles */
+                case 0x00c0:       /* instruction retired */
+                    blocked = 0;
+                default:
+                    break;
+                }
+            }
+
+            if ( vpmu_features & XENPMU_FEATURE_ARCH_ONLY )
+            {
+                /* additional counters beyond IPC only; blocked

already set */

Quoted 11 lines
Quoted 11 lines
xen/arch/x86/cpu/vpmu_intel.c +11 -0
+                switch ( umaskevent )
+                {
+                case 0x4f2e:       /* LLC reference */
+                case 0x412e:       /* LLC misses */
+                case 0x00c4:       /* branch instruction retired */
+                case 0x00c5:       /* branch */
+                    blocked = 0;
+                default:
+                    break;
+               }
+            }
Quoted 8 lines

Review

Quoted 8 lines
xen/arch/x86/cpu/vpmu_intel.c +4 -0
+
+            if ( blocked )
+                return -EINVAL;
+
              if ( has_hvm_container_vcpu(v) )
                  vmx_read_guest_msr(MSR_CORE_PERF_GLOBAL_CTRL,
                                     &core2_vpmu_cxt->global_ctrl);
(quoted diff) +0 -0

b/xen/include/asm-x86/msr-index.h

Quoted 17 lines
Quoted 17 lines

index b8ad93c..0542064 100644

xen/include/asm-x86/msr-index.h +1 -0
@@ -328,6 +328,7 @@
 
  /* Platform Shared Resource MSRs */
  #define MSR_IA32_CMT_EVTSEL               0x00000c8d
+#define MSR_IA32_CMT_EVTSEL_UE_MASK        0x0000ffff
  #define MSR_IA32_CMT_CTR          0x00000c8e
  #define MSR_IA32_PSR_ASSOC                0x00000c8f
  #define MSR_IA32_PSR_L3_QOS_CFG   0x00000c81
xen/include/public/pmu.h +0 -0
index 7753df0..f9ad7b4 100644
@@ -84,9 +84,19 @@ DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);
 
Quoted 9 lines
Quoted 5 lines

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);

Quoted 5 lines
xen/include/public/pmu.h +2 -1
  /*
   * PMU features:
- * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_INTEL_BTS:  Intel BTS support (ignored on AMD)
+ * - XENPMU_FEATURE_IPC_ONLY:   Restrict PMC to the most minimum set

possible.

PMC -> PMCs

Ok.

Quoted 12 lines
Quoted 2 lines

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); · line 89

Quoted 2 lines
xen/include/public/pmu.h +1 -0
+ *                              Instructions, cycles, and ref cycles.

Can be

Quoted 1 line

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); · line 90

Quoted 1 line
xen/include/public/pmu.h +1 -0
+ *                              used to calculate

instructions-per-cycle (IPC)

Quoted 3 lines

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);

Quoted 3 lines
xen/include/public/pmu.h +3 -0
+ *                              (ignored on AMD).
+ * - XENPMU_FEATURE_ARCH_ONLY:  Restrict PMCs to the Intel Pre-Defined
+ *                              Architecteral Performance Events

exposed by

Architecteral -> Architectural

Ok.

Quoted 10 lines
Quoted 2 lines

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); · line 94

Quoted 2 lines
xen/include/public/pmu.h +1 -0
+ *                              cpuid and listed in the Intel

developer's manual

Quoted 7 lines
Quoted 7 lines
xen/include/public/pmu.h +4 -1
+ *                              (ignored on AMD).
   */
-#define XENPMU_FEATURE_INTEL_BTS  1
+#define XENPMU_FEATURE_INTEL_BTS  (1<<0)
+#define XENPMU_FEATURE_IPC_ONLY   (1<<1)
+#define XENPMU_FEATURE_ARCH_ONLY  (1<<2)
 
Quoted 4 lines
Quoted 2 lines

xen/include/public/pmu.h DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t); · line 102

Quoted 2 lines
xen/include/public/pmu.h +0 -0
  /*
   * Shared PMU data between hypervisor and PV(H) domains.

Thanks for checking! New patch (v5) coming...

Brendan

Signature · 1 line
Brendan Gregg, Senior Performance Architect, Netflix

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel