Skip to contentSkip to conversation

x86/VPMU: implement ipc and arch filter flags

PATCH Superseded Brendan Gregg 2 participants 3 messages Jan 8, 2016

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 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.

---
Changes in v6:
* addressing review comments from Jan:
* code style changes
* updated sysfs PMU interface flag check

Changes in v5:
* addressing review comments from Kevin:
* simplified BTS DS_AREA filter
* improvements to comments, incl. matching Intel SDM descriptions

Changes in v4:
* changed table reference in comments, suggested by Dietmar

Changes in v3:
* addressing review comments from Boris:
* ensure final flag is validated
* code tidy

Changes in v2:
* feature flags can now be combined (eg, "vpmu=ipc,bts")
* addressing review comments from Boris:
* restrict DS_AREA and PEBS_ENABLE access when filters are in use
* better variable types
* include MSR_IA32_CMT_EVTSEL_UE_MASK flag

---
 docs/misc/xen-command-line.markdown | 15 +++++++++-
 xen/arch/x86/cpu/vpmu.c             | 55 +++++++++++++++++++++++++++++--------
 xen/arch/x86/cpu/vpmu_intel.c       | 44 +++++++++++++++++++++++++++++
 xen/include/asm-x86/msr-index.h     |  1 +
 xen/include/public/pmu.h            | 14 ++++++++--
 5 files changed, 114 insertions(+), 15 deletions(-)
docs/misc/xen-command-line.markdown +14 -1
index 467dc8f..5ed0730 100644
@@ -1476,7 +1476,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`
 
@@ -1492,6 +1492,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 +43 -12

90 lines not on this page · raw message

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

68 lines not on this page · raw message

xen/include/asm-x86/msr-index.h +1 -0
index 2b97861..84da631 100644
@@ -329,6 +329,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..0e1312c 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 PMCs 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
+ *                              Architectural 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 still stands with one correction below

Quoted 8 lines
xen/arch/x86/cpu/vpmu_intel.c +2 -0
@@ -656,12 +661,51 @@ 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);

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

Quoted 10 lines
xen/arch/x86/cpu/vpmu_intel.c +5 -0
 
              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 ||
+                                  XENPMU_FEATURE_ARCH_ONLY) )
+            {
 

Typo: Should be '|', not '||'.

-boris

#2 lore raw
Quoted 31 lines · Boris Ostrovsky
Quoted 7 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 still stands with one correction below

(quoted diff) +0 -0
@@ -656,12 +661,51 @@ 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;

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

Quoted 11 lines

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 */

xen/arch/x86/cpu/vpmu_intel.c +4 -0
+            umaskevent = msr_content & MSR_IA32_CMT_EVTSEL_UE_MASK;
+            if ( vpmu_features & (XENPMU_FEATURE_IPC_ONLY ||
+                                  XENPMU_FEATURE_ARCH_ONLY) )
+            {
Quoted 4 lines

Typo: Should be '|', not '||'.

Ah, well spotted, thanks Boris. Patch v7 coming...

Brendan

Quoted 2 lines

-boris

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

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