All of lore.kernel.org
 help / color / mirror / Atom feed
From: mfuzzey@parkeon.com (Martin Fuzzey)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] ARM: perf: Set suniden bit.
Date: Tue, 29 Jul 2014 14:32:59 +0200	[thread overview]
Message-ID: <20140729123259.13347.33212.stgit@localhost> (raw)
In-Reply-To: <20140729123256.13347.79778.stgit@localhost>

Counters other than the CPU cycle counter only work if the security module
SUNIDEN bit is set.

Without this:
# perf stat -e cycles,instructions sleep 1

 Performance counter stats for 'sleep 1':

          14606094 cycles                    #    0.000 GHz
                 0 instructions              #    0.00  insns per cycle

Some platforms (eg i.MX53) may also need additional platform specific setup.

Signed-off-by: Martin Fuzzey <mfuzzey@parkeon.com>
---
 arch/arm/include/asm/pmu.h      |    7 +++++++
 arch/arm/kernel/perf_event_v7.c |   23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/arch/arm/include/asm/pmu.h b/arch/arm/include/asm/pmu.h
index ae1919b..0bd181f 100644
--- a/arch/arm/include/asm/pmu.h
+++ b/arch/arm/include/asm/pmu.h
@@ -60,6 +60,13 @@ struct pmu_hw_events {
 	 * read/modify/write sequences.
 	 */
 	raw_spinlock_t		pmu_lock;
+
+	/*
+	 * Bits indicating any CPU or platform specific activations that have
+	 * been done so we can undo them when stopping
+	 */
+	unsigned int		activated_flags;
+	#define ARM_PMU_ACTIVATED_SECURE_DEBUG	(1 << 0)
 };
 
 struct arm_pmu {
diff --git a/arch/arm/kernel/perf_event_v7.c b/arch/arm/kernel/perf_event_v7.c
index 1d37568..91a41bd 100644
--- a/arch/arm/kernel/perf_event_v7.c
+++ b/arch/arm/kernel/perf_event_v7.c
@@ -1377,12 +1377,26 @@ static irqreturn_t armv7pmu_handle_irq(int irq_num, void *dev)
 	return IRQ_HANDLED;
 }
 
+#define SDER_SUNIDEN (1 << 1)
+
 static void armv7pmu_start(struct arm_pmu *cpu_pmu)
 {
 	unsigned long flags;
 	struct pmu_hw_events *events = cpu_pmu->get_hw_events();
+	u32 sder;
 
 	raw_spin_lock_irqsave(&events->pmu_lock, flags);
+
+	/* Counters other than cycle counter require SUNIDEN bit set */
+	asm volatile("mrc p15, 0, %0, c1, c1, 1" : "=r" (sder));
+	if (sder & SDER_SUNIDEN) {
+		events->activated_flags &= ~ARM_PMU_ACTIVATED_SECURE_DEBUG;
+	} else {
+		sder |= SDER_SUNIDEN;
+		asm volatile("mcr p15, 0, %0, c1, c1, 1" : : "r" (sder));
+		events->activated_flags |= ARM_PMU_ACTIVATED_SECURE_DEBUG;
+	}
+
 	/* Enable all counters */
 	armv7_pmnc_write(armv7_pmnc_read() | ARMV7_PMNC_E);
 	raw_spin_unlock_irqrestore(&events->pmu_lock, flags);
@@ -1392,8 +1406,17 @@ static void armv7pmu_stop(struct arm_pmu *cpu_pmu)
 {
 	unsigned long flags;
 	struct pmu_hw_events *events = cpu_pmu->get_hw_events();
+	u32 sder;
 
 	raw_spin_lock_irqsave(&events->pmu_lock, flags);
+
+	if (events->activated_flags & ARM_PMU_ACTIVATED_SECURE_DEBUG) {
+		asm volatile("mrc p15, 0, %0, c1, c1, 1" : "=r" (sder));
+		sder &= ~SDER_SUNIDEN;
+		asm volatile("mcr p15, 0, %0, c1, c1, 1" : : "r" (sder));
+		events->activated_flags &= ~ARM_PMU_ACTIVATED_SECURE_DEBUG;
+	}
+
 	/* Disable all counters */
 	armv7_pmnc_write(armv7_pmnc_read() & ~ARMV7_PMNC_E);
 	raw_spin_unlock_irqrestore(&events->pmu_lock, flags);

  reply	other threads:[~2014-07-29 12:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-29 12:32 [PATCH 0/4] ARM: perf: Support i.MX53 Martin Fuzzey
2014-07-29 12:32 ` Martin Fuzzey [this message]
2014-07-29 12:33 ` [PATCH 2/4] ARM: perf: Add platform specific start/stop callbacks Martin Fuzzey
2014-07-29 12:33 ` [PATCH 3/4] ARM: i.MX53: Add Soc specific PMU setup Martin Fuzzey
2014-07-29 12:33 ` [PATCH 4/4] ARM: dts: i.MX53: Add PMU DT entry Martin Fuzzey
2014-07-29 12:52 ` [PATCH 0/4] ARM: perf: Support i.MX53 Will Deacon
2014-07-29 16:40   ` Martin Fuzzey
2014-07-30 10:46     ` Will Deacon

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=20140729123259.13347.33212.stgit@localhost \
    --to=mfuzzey@parkeon.com \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.