aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2016-05-19 20:09:56 -0400
committerIngo Molnar <mingo@kernel.org>2016-06-03 03:41:22 -0400
commitfc07e9f983b4b11922c22b6cccadc1f342f05a4c (patch)
treef30227eecbbc2b5c87bffc9546e55013246b5788
parent70b8301f6b8f7bc053377a9cbd0c4e42e29d9807 (diff)
perf/x86: Support sysfs files depending on SMT status
Add a way to show different sysfs events attributes depending on HyperThreading is on or off. This is difficult to determine early at boot, so we just do it dynamically when the sysfs attribute is read. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Cc: acme@kernel.org Cc: jolsa@kernel.org Link: http://lkml.kernel.org/r/1463703002-19686-3-git-send-email-andi@firstfloor.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/events/core.c23
-rw-r--r--arch/x86/events/perf_event.h10
-rw-r--r--include/linux/perf_event.h7
3 files changed, 40 insertions, 0 deletions
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 33787ee817f0..929655db5084 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1622,6 +1622,29 @@ ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, cha
1622} 1622}
1623EXPORT_SYMBOL_GPL(events_sysfs_show); 1623EXPORT_SYMBOL_GPL(events_sysfs_show);
1624 1624
1625ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,
1626 char *page)
1627{
1628 struct perf_pmu_events_ht_attr *pmu_attr =
1629 container_of(attr, struct perf_pmu_events_ht_attr, attr);
1630
1631 /*
1632 * Report conditional events depending on Hyper-Threading.
1633 *
1634 * This is overly conservative as usually the HT special
1635 * handling is not needed if the other CPU thread is idle.
1636 *
1637 * Note this does not (and cannot) handle the case when thread
1638 * siblings are invisible, for example with virtualization
1639 * if they are owned by some other guest. The user tool
1640 * has to re-read when a thread sibling gets onlined later.
1641 */
1642 return sprintf(page, "%s",
1643 topology_max_smt_threads() > 1 ?
1644 pmu_attr->event_str_ht :
1645 pmu_attr->event_str_noht);
1646}
1647
1625EVENT_ATTR(cpu-cycles, CPU_CYCLES ); 1648EVENT_ATTR(cpu-cycles, CPU_CYCLES );
1626EVENT_ATTR(instructions, INSTRUCTIONS ); 1649EVENT_ATTR(instructions, INSTRUCTIONS );
1627EVENT_ATTR(cache-references, CACHE_REFERENCES ); 1650EVENT_ATTR(cache-references, CACHE_REFERENCES );
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 8bd764df815d..e2d7285a2dac 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -668,6 +668,14 @@ static struct perf_pmu_events_attr event_attr_##v = { \
668 .event_str = str, \ 668 .event_str = str, \
669}; 669};
670 670
671#define EVENT_ATTR_STR_HT(_name, v, noht, ht) \
672static struct perf_pmu_events_ht_attr event_attr_##v = { \
673 .attr = __ATTR(_name, 0444, events_ht_sysfs_show, NULL),\
674 .id = 0, \
675 .event_str_noht = noht, \
676 .event_str_ht = ht, \
677}
678
671extern struct x86_pmu x86_pmu __read_mostly; 679extern struct x86_pmu x86_pmu __read_mostly;
672 680
673static inline bool x86_pmu_has_lbr_callstack(void) 681static inline bool x86_pmu_has_lbr_callstack(void)
@@ -803,6 +811,8 @@ struct attribute **merge_attr(struct attribute **a, struct attribute **b);
803 811
804ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, 812ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,
805 char *page); 813 char *page);
814ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,
815 char *page);
806 816
807#ifdef CONFIG_CPU_SUP_AMD 817#ifdef CONFIG_CPU_SUP_AMD
808 818
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 92e9ce737432..a7593d653b40 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1334,6 +1334,13 @@ struct perf_pmu_events_attr {
1334 const char *event_str; 1334 const char *event_str;
1335}; 1335};
1336 1336
1337struct perf_pmu_events_ht_attr {
1338 struct device_attribute attr;
1339 u64 id;
1340 const char *event_str_ht;
1341 const char *event_str_noht;
1342};
1343
1337ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr, 1344ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
1338 char *page); 1345 char *page);
1339 1346