linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Kan Liang <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: kan.liang@intel.com, linux-kernel@vger.kernel.org,
	torvalds@linux-foundation.org, peterz@infradead.org,
	hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de
Subject: [tip:perf/core] perf/x86/intel/uncore: Introduce customized event_read() for client IMC uncore
Date: Thu, 31 May 2018 05:30:03 -0700	[thread overview]
Message-ID: <tip-2da331465f44f9618abe8837d1a68405d550b66e@git.kernel.org> (raw)
In-Reply-To: <1525371913-10597-1-git-send-email-kan.liang@intel.com>

Commit-ID:  2da331465f44f9618abe8837d1a68405d550b66e
Gitweb:     https://git.kernel.org/tip/2da331465f44f9618abe8837d1a68405d550b66e
Author:     Kan Liang <kan.liang@intel.com>
AuthorDate: Thu, 3 May 2018 11:25:06 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 31 May 2018 12:36:27 +0200

perf/x86/intel/uncore: Introduce customized event_read() for client IMC uncore

There are two free-running counters for client IMC uncore. The
customized event_init() function hard codes their index to
'UNCORE_PMC_IDX_FIXED' and 'UNCORE_PMC_IDX_FIXED + 1'.
To support the index 'UNCORE_PMC_IDX_FIXED + 1', the generic
uncore_perf_event_update is obscurely hacked.
The code quality issue will bring problems when a new counter index is
introduced into the generic code, for example, a new index for
free-running counter.

Introducing a customized event_read() function for client IMC uncore.
The customized function is copied from previous generic
uncore_pmu_event_read().
The index 'UNCORE_PMC_IDX_FIXED + 1' will be isolated for client IMC
uncore only.

Signed-off-by: Kan Liang <kan.liang@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: acme@kernel.org
Cc: eranian@google.com
Link: http://lkml.kernel.org/r/1525371913-10597-1-git-send-email-kan.liang@intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/events/intel/uncore_snb.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
index aee5e8496be4..df535215d18b 100644
--- a/arch/x86/events/intel/uncore_snb.c
+++ b/arch/x86/events/intel/uncore_snb.c
@@ -450,6 +450,35 @@ static void snb_uncore_imc_event_start(struct perf_event *event, int flags)
 		uncore_pmu_start_hrtimer(box);
 }
 
+static void snb_uncore_imc_event_read(struct perf_event *event)
+{
+	struct intel_uncore_box *box = uncore_event_to_box(event);
+	u64 prev_count, new_count, delta;
+	int shift;
+
+	/*
+	 * There are two free running counters in IMC.
+	 * The index for the second one is hardcoded to
+	 * UNCORE_PMC_IDX_FIXED + 1.
+	 */
+	if (event->hw.idx >= UNCORE_PMC_IDX_FIXED)
+		shift = 64 - uncore_fixed_ctr_bits(box);
+	else
+		shift = 64 - uncore_perf_ctr_bits(box);
+
+	/* the hrtimer might modify the previous event value */
+again:
+	prev_count = local64_read(&event->hw.prev_count);
+	new_count = uncore_read_counter(box, event);
+	if (local64_xchg(&event->hw.prev_count, new_count) != prev_count)
+		goto again;
+
+	delta = (new_count << shift) - (prev_count << shift);
+	delta >>= shift;
+
+	local64_add(delta, &event->count);
+}
+
 static void snb_uncore_imc_event_stop(struct perf_event *event, int flags)
 {
 	struct intel_uncore_box *box = uncore_event_to_box(event);
@@ -472,7 +501,7 @@ static void snb_uncore_imc_event_stop(struct perf_event *event, int flags)
 		 * Drain the remaining delta count out of a event
 		 * that we are disabling:
 		 */
-		uncore_perf_event_update(box, event);
+		snb_uncore_imc_event_read(event);
 		hwc->state |= PERF_HES_UPTODATE;
 	}
 }
@@ -534,7 +563,7 @@ static struct pmu snb_uncore_imc_pmu = {
 	.del		= snb_uncore_imc_event_del,
 	.start		= snb_uncore_imc_event_start,
 	.stop		= snb_uncore_imc_event_stop,
-	.read		= uncore_pmu_event_read,
+	.read		= snb_uncore_imc_event_read,
 };
 
 static struct intel_uncore_ops snb_uncore_imc_ops = {

      parent reply	other threads:[~2018-05-31 12:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 18:25 [RESEND PATCH V7 1/8] perf/x86/intel/uncore: Customized event_read() for client IMC uncore kan.liang
2018-05-03 18:25 ` [RESEND PATCH V7 2/8] perf/x86/intel/uncore: Correct fixed counter index check for NHM kan.liang
2018-05-31 12:30   ` [tip:perf/core] " tip-bot for Kan Liang
2018-05-03 18:25 ` [RESEND PATCH V7 3/8] perf/x86/intel/uncore: Correct fixed counter index check in generic code kan.liang
2018-05-31 12:31   ` [tip:perf/core] " tip-bot for Kan Liang
2018-05-03 18:25 ` [RESEND PATCH V7 4/8] perf/x86/intel/uncore: Add new data structures for free running counters kan.liang
2018-05-31 12:31   ` [tip:perf/core] " tip-bot for Kan Liang
2018-05-03 18:25 ` [RESEND PATCH V7 5/8] perf/x86/intel/uncore: Add infrastructure for free running counter kan.liang
2018-05-31 12:32   ` [tip:perf/core] perf/x86/intel/uncore: Add infrastructure for free running counters tip-bot for Kan Liang
2018-05-03 18:25 ` [RESEND PATCH V7 6/8] perf/x86/intel/uncore: Support IIO free-running counters on SKX kan.liang
2018-05-31 12:32   ` [tip:perf/core] " tip-bot for Kan Liang
2018-05-03 18:25 ` [RESEND PATCH V7 7/8] perf/x86/intel/uncore: Expose uncore_pmu_event functions kan.liang
2018-05-31 12:33   ` [tip:perf/core] perf/x86/intel/uncore: Expose uncore_pmu_event*() functions tip-bot for Kan Liang
2018-05-03 18:25 ` [RESEND PATCH V7 8/8] perf/x86/intel/uncore: Clean up client IMC uncore kan.liang
2018-05-31 12:33   ` [tip:perf/core] " tip-bot for Kan Liang
2018-05-31 12:30 ` tip-bot for Kan Liang [this message]

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=tip-2da331465f44f9618abe8837d1a68405d550b66e@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).