public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf/x86/intel/cqm: Start MBM timers only for MBM events
@ 2017-06-08 14:41 Jiri Olsa
  0 siblings, 0 replies; only message in thread
From: Jiri Olsa @ 2017-06-08 14:41 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Peter Zijlstra, Peter Zijlstra, Vikas Shivappa, Tony Luck, lkml,
	Ingo Molnar

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@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Vikas Shivappa <vikas.shivappa@linux.intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-08 14:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-08 14:41 [PATCH] perf/x86/intel/cqm: Start MBM timers only for MBM events Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox