[PATCH] perf/x86/intel/cqm: Start MBM timers only for MBM events

From: Jiri Olsa
Date: Thu Jun 08 2017 - 10:41:58 EST


Currently start MBM timers for the first event
of any kind, though they are not needed for
occupancy event.

Adding check to ensure the MBM timers are started
only for MBM events.

Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Vikas Shivappa <vikas.shivappa@xxxxxxxxxxxxxxx>
Cc: Tony Luck <tony.luck@xxxxxxxxx>
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
arch/x86/events/intel/cqm.c | 39 +++++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/arch/x86/events/intel/cqm.c b/arch/x86/events/intel/cqm.c
index 2521f771f2f5..2f7253358c17 100644
--- a/arch/x86/events/intel/cqm.c
+++ b/arch/x86/events/intel/cqm.c
@@ -1286,6 +1286,35 @@ static int intel_cqm_event_add(struct perf_event *event, int mode)
return 0;
}

+/* Guarded with cache_mutex. */
+static int mbm_events;
+
+/*
+ * Start the mbm overflow timers when the first MBM event is created.
+ */
+static bool should_start_mbm_timers(struct perf_event *event)
+{
+ if (mbm_enabled && is_mbm_event(event->attr.config)) {
+ mbm_events++;
+ return mbm_events == 1;
+ }
+
+ return false;
+}
+
+/*
+ * Stop the mbm overflow timers when the last MBM event is destroyed.
+ */
+static bool should_stop_mbm_timers(struct perf_event *event)
+{
+ if (mbm_enabled && is_mbm_event(event->attr.config)) {
+ mbm_events--;
+ return mbm_events == 0;
+ }
+
+ return false;
+}
+
static void intel_cqm_event_destroy(struct perf_event *event)
{
struct perf_event *group_other = NULL;
@@ -1330,10 +1359,7 @@ static void intel_cqm_event_destroy(struct perf_event *event)

raw_spin_unlock_irqrestore(&cache_lock, flags);

- /*
- * Stop the mbm overflow timers when the last event is destroyed.
- */
- if (mbm_enabled && list_empty(&cache_groups))
+ if (should_stop_mbm_timers(event))
mbm_stop_timers();

mutex_unlock(&cache_mutex);
@@ -1373,10 +1399,7 @@ static int intel_cqm_event_init(struct perf_event *event)

mutex_lock(&cache_mutex);

- /*
- * Start the mbm overflow timers when the first event is created.
- */
- if (mbm_enabled && list_empty(&cache_groups))
+ if (should_start_mbm_timers(event))
mbm_start_timers();

/* Will also set rmid */
--
2.9.4