Skip to contentSkip to conversation

perf/x86: add sysfs entry to freeze counter on SMI

PATCH Superseded [email protected] 2 participants 2 messages May 12, 2017

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 perf/x86: add sysfs entry to freeze counter on SMI

From: Kan Liang <[email protected]>

Currently, the SMIs are visible to all performance counters. Because many users want to measure everything including SMIs. But in some cases, the SMI cycles should not be count. For example, to calculate the cost of SMI itself. So a knob is needed.

When setting FREEZE_WHILE_SMM bit in IA32_DEBUGCTL, all performance counters will be effected. There is no way to do per-counter freeze on SMI. So it should not use the per-event interface (e.g. ioctl or event attribute) to set FREEZE_WHILE_SMM bit.

Adds sysfs entry /sys/device/cpu/freeze_on_smi to set FREEZE_WHILE_SMM bit in IA32_DEBUGCTL. When set, freezes perfmon and trace messages while in SMM.
Value has to be 0 or 1. It will be applied to all processors. Also serialize the entire setting so we don't get multiple concurrent threads trying to update to different values.

---

why do we need an open coded version of __flip_bit() instead of reusing that?
- msr_set_bit/msr_clear_bit is enough for our requirement. There is no extra work needed.
__flip_bit is static inline. It cannot be used directly. If we expose it, there will be two sets of interfaces to flip MSR bit. I think it's too much.

Changes since V5:
- Don't force unsigned long to bool. That will be a problem on LE machines.

Changes since V4:
- drop msr_flip_bit function
- Use on_each_cpu() which already include all the needed protection
- Some small changes according to the comments

 arch/x86/events/core.c           | 10 +++++++
 arch/x86/events/intel/core.c     | 63 ++++++++++++++++++++++++++++++++++++++++
 arch/x86/events/perf_event.h     |  3 ++
 arch/x86/include/asm/msr-index.h |  2 ++
 4 files changed, 78 insertions(+)
arch/x86/events/core.c +10 -0
index 2aa1ad1..c6ef896 100644
@@ -1750,6 +1750,8 @@ ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event)
 	return ret;
 }
 
+static struct attribute_group x86_pmu_attr_group;
+
 static int __init init_hw_perf_events(void)
 {
 	struct x86_pmu_quirk *quirk;
@@ -1813,6 +1815,14 @@ static int __init init_hw_perf_events(void)
 			x86_pmu_events_group.attrs = tmp;
 	}
 
+	if (x86_pmu.attrs) {
+		struct attribute **tmp;
+
+		tmp = merge_attr(x86_pmu_attr_group.attrs, x86_pmu.attrs);
+		if (!WARN_ON(!tmp))
+			x86_pmu_attr_group.attrs = tmp;
+	}
+
 	pr_info("... version:                %d\n",     x86_pmu.version);
 	pr_info("... bit width:              %d\n",     x86_pmu.cntval_bits);
 	pr_info("... generic registers:      %d\n",     x86_pmu.num_counters);
arch/x86/events/intel/core.c +63 -0

87 lines not on this page · raw message

arch/x86/events/perf_event.h +3 -0
index bcbb1d2..110cb9b0 100644
@@ -561,6 +561,9 @@ struct x86_pmu {
 	ssize_t		(*events_sysfs_show)(char *page, u64 config);
 	struct attribute **cpu_events;
 
+	unsigned long	attr_freeze_on_smi;
+	struct attribute **attrs;
+
 	/*
 	 * CPU Hotplug hooks
 	 */
arch/x86/include/asm/msr-index.h +2 -0
index d8b5f8a..0572f91 100644
@@ -134,6 +134,8 @@
 #define DEBUGCTLMSR_BTS_OFF_OS		(1UL <<  9)
 #define DEBUGCTLMSR_BTS_OFF_USR		(1UL << 10)
 #define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI	(1UL << 11)
+#define DEBUGCTLMSR_FREEZE_IN_SMM_BIT	14
+#define DEBUGCTLMSR_FREEZE_IN_SMM	(1UL << DEBUGCTLMSR_FREEZE_IN_SMM_BIT)
 
 #define MSR_PEBS_FRONTEND		0x000003f7
 
Signature · 1 line
2.7.4
#1 lore raw
url: https://github.com/0day-ci/linux/commits/kan-liang-intel-com/perf-x86-add-sysfs-entry-to-freeze-counter-on-SMI/20170512-223452 config: i386-tinyconfig (attached as .config) compiler: gcc-6…

Hi Kan,

[auto build test WARNING on tip/x86/core]
[also build test WARNING on v4.11 next-20170512]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/kan-liang-intel-com/perf-x86-add-sysfs-entry-to-freeze-counter-on-SMI/20170512-223452
config: i386-tinyconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All warnings (new ones prefixed by >>):

arch/x86/events/intel/core.c: In function 'freeze_on_smi_show':

>> arch/x86/events/intel/core.c:3581:24: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long unsigned int' [-Wformat=]
     return sprintf(buf, "%d\n", x86_pmu.attr_freeze_on_smi);
                           ^

vim +3581 arch/x86/events/intel/core.c

3565 EVENT_PTR(mem_ld_hsw),
3566 EVENT_PTR(mem_st_hsw),
3567 EVENT_PTR(td_slots_issued),
3568 EVENT_PTR(td_slots_retired),
3569 EVENT_PTR(td_fetch_bubbles),
3570 EVENT_PTR(td_total_slots),
3571 EVENT_PTR(td_total_slots_scale),
3572 EVENT_PTR(td_recovery_bubbles),
3573 EVENT_PTR(td_recovery_bubbles_scale),
3574 NULL
3575 };
3576
3577 static ssize_t freeze_on_smi_show(struct device *cdev,
3578 struct device_attribute *attr,
3579 char *buf)
3580 {

> 3581		return sprintf(buf, "%d\n", x86_pmu.attr_freeze_on_smi);

3582 }
3583
3584 static DEFINE_MUTEX(freeze_on_smi_mutex);
3585
3586 static ssize_t freeze_on_smi_store(struct device *cdev,
3587 struct device_attribute *attr,
3588 const char *buf, size_t count)
3589 {

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation