public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Peter Zijlstra <peterz@infradead.org>,
	Vikas Shivappa <vikas.shivappa@linux.intel.com>,
	Tony Luck <tony.luck@intel.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>
Subject: [PATCH] perf/x86/intel/cqm: Start MBM timers only for MBM events
Date: Thu,  8 Jun 2017 16:41:44 +0200	[thread overview]
Message-ID: <20170608144144.19253-1-jolsa@kernel.org> (raw)

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

                 reply	other threads:[~2017-06-08 14:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170608144144.19253-1-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vikas.shivappa@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox