linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Glauber <jglauber@cavium.com>
To: Will Deacon <will.deacon@arm.com>, Mark Rutland <mark.rutland@arm.com>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Jan Glauber <jglauber@cavium.com>
Subject: [PATCH v3 4/5] arm64/perf: Enable PMCR long cycle counter bit
Date: Wed,  3 Feb 2016 18:11:59 +0100	[thread overview]
Message-ID: <de7340e1843f7823384551db64b12eadde7eded7.1454516082.git.jglauber@cavium.com> (raw)
In-Reply-To: <cover.1454516082.git.jglauber@cavium.com>
In-Reply-To: <cover.1454516082.git.jglauber@cavium.com>

With the long cycle counter bit (LC) disabled the cycle counter is not
working on ThunderX SOC (ThunderX only implements Aarch64).
Also, according to documentation LC == 0 is deprecated.

To keep the code simple the patch does not introduce 64 bit wide counter
functions. Instead writing the cycle counter always sets the upper
32 bits so overflow interrupts are generated as before.

Original patch from Andrew Pinksi <Andrew.Pinksi@caviumnetworks.com>

Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
 arch/arm64/kernel/perf_event.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index c038e4e..5e4275e 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -405,6 +405,7 @@ static const struct attribute_group *armv8_pmuv3_attr_groups[] = {
 #define ARMV8_PMCR_D		(1 << 3) /* CCNT counts every 64th cpu cycle */
 #define ARMV8_PMCR_X		(1 << 4) /* Export to ETM */
 #define ARMV8_PMCR_DP		(1 << 5) /* Disable CCNT if non-invasive debug*/
+#define ARMV8_PMCR_LC		(1 << 6) /* Overflow on 64 bit cycle counter */
 #define	ARMV8_PMCR_N_SHIFT	11	 /* Number of counters supported */
 #define	ARMV8_PMCR_N_MASK	0x1f
 #define	ARMV8_PMCR_MASK		0x3f	 /* Mask for writable bits */
@@ -494,9 +495,16 @@ static inline void armv8pmu_write_counter(struct perf_event *event, u32 value)
 	if (!armv8pmu_counter_valid(cpu_pmu, idx))
 		pr_err("CPU%u writing wrong counter %d\n",
 			smp_processor_id(), idx);
-	else if (idx == ARMV8_IDX_CYCLE_COUNTER)
-		asm volatile("msr pmccntr_el0, %0" :: "r" (value));
-	else if (armv8pmu_select_counter(idx) == idx)
+	else if (idx == ARMV8_IDX_CYCLE_COUNTER) {
+		/*
+		 * Set the upper 32bits as this is a 64bit counter but we only
+		 * count using the lower 32bits and we want an interrupt when
+		 * it overflows.
+		 */
+		u64 value64 = 0xffffffff00000000ULL | value;
+
+		asm volatile("msr pmccntr_el0, %0" :: "r" (value64));
+	} else if (armv8pmu_select_counter(idx) == idx)
 		asm volatile("msr pmxevcntr_el0, %0" :: "r" (value));
 }
 
@@ -768,8 +776,11 @@ static void armv8pmu_reset(void *info)
 		armv8pmu_disable_intens(idx);
 	}
 
-	/* Initialize & Reset PMNC: C and P bits. */
-	armv8pmu_pmcr_write(ARMV8_PMCR_P | ARMV8_PMCR_C);
+	/*
+	 * Initialize & Reset PMNC. Request overflow on 64 bit but
+	 * cheat in armv8pmu_write_counter().
+	 */
+	armv8pmu_pmcr_write(ARMV8_PMCR_P | ARMV8_PMCR_C | ARMV8_PMCR_LC);
 }
 
 static int armv8_pmuv3_map_event(struct perf_event *event)
-- 
1.9.1

  parent reply	other threads:[~2016-02-03 17:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-03 17:11 [PATCH v3 0/5] Cavium ThunderX PMU support Jan Glauber
2016-02-03 17:11 ` [PATCH v3 1/5] arm64/perf: Rename Cortex A57 events Jan Glauber
2016-02-15 19:40   ` Will Deacon
2016-02-15 20:06     ` Will Deacon
2016-02-18  9:13       ` Jan Glauber
2016-02-18 11:24         ` Will Deacon
2016-02-18 13:45           ` Jan Glauber
2016-02-03 17:11 ` [PATCH v3 2/5] arm64/perf: Add Cavium ThunderX PMU support Jan Glauber
2016-02-03 17:11 ` [PATCH v3 3/5] arm64: dts: Add Cavium ThunderX specific PMU Jan Glauber
2016-02-03 17:11 ` Jan Glauber [this message]
2016-02-15 19:55   ` [PATCH v3 4/5] arm64/perf: Enable PMCR long cycle counter bit Will Deacon
2016-02-16  8:04     ` Jan Glauber
2016-02-03 17:12 ` [PATCH v3 5/5] arm64/perf: Extend event mask for ARMv8.1 Jan Glauber
2016-02-15 20:04   ` Will Deacon
2016-02-16  8:00     ` Jan Glauber
2016-02-16 15:12       ` Will Deacon
2016-02-17 10:47         ` Jan Glauber
2016-02-11 13:28 ` [PATCH v3 0/5] Cavium ThunderX PMU support Jan Glauber

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=de7340e1843f7823384551db64b12eadde7eded7.1454516082.git.jglauber@cavium.com \
    --to=jglauber@cavium.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=will.deacon@arm.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;
as well as URLs for NNTP newsgroup(s).