From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 7/8] arm_pmu: note IRQs and PMUs per-cpu
Date: Mon, 5 Feb 2018 16:42:01 +0000 [thread overview]
Message-ID: <20180205164202.26502-8-mark.rutland@arm.com> (raw)
In-Reply-To: <20180205164202.26502-1-mark.rutland@arm.com>
To support ACPI systems, we need to request IRQs before we know the
associated PMU, and thus we need some percpu variable that the IRQ
handler can find the PMU from.
As we're going to request IRQs without the PMU, we can't rely on the
arm_pmu::active_irqs mask, and similarly need to track requested IRQs
with a percpu variable.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
---
drivers/perf/arm_pmu.c | 76 +++++++++++++++++++++++++++++++-------------
include/linux/perf/arm_pmu.h | 1 -
2 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c
index 72118e6f9122..023a8ebdace6 100644
--- a/drivers/perf/arm_pmu.c
+++ b/drivers/perf/arm_pmu.c
@@ -25,6 +25,9 @@
#include <asm/irq_regs.h>
+static DEFINE_PER_CPU(struct arm_pmu *, cpu_armpmu);
+static DEFINE_PER_CPU(int, cpu_irq);
+
static int
armpmu_map_cache_event(const unsigned (*cache_map)
[PERF_COUNT_HW_CACHE_MAX]
@@ -325,13 +328,9 @@ static irqreturn_t armpmu_dispatch_irq(int irq, void *dev)
int ret;
u64 start_clock, finish_clock;
- /*
- * we request the IRQ with a (possibly percpu) struct arm_pmu**, but
- * the handlers expect a struct arm_pmu*. The percpu_irq framework will
- * do any necessary shifting, we just need to perform the first
- * dereference.
- */
- armpmu = *(void **)dev;
+ armpmu = this_cpu_read(cpu_armpmu);
+ if (WARN_ON_ONCE(!armpmu))
+ return IRQ_NONE;
start_clock = sched_clock();
ret = armpmu->handle_irq(irq, armpmu);
@@ -517,29 +516,47 @@ int perf_num_counters(void)
}
EXPORT_SYMBOL_GPL(perf_num_counters);
-void armpmu_free_irq(struct arm_pmu *armpmu, int cpu)
+int armpmu_count_irq_users(const int irq)
{
- struct pmu_hw_events __percpu *hw_events = armpmu->hw_events;
- int irq = per_cpu(hw_events->irq, cpu);
+ int cpu, count = 0;
+
+ for_each_possible_cpu(cpu) {
+ if (per_cpu(cpu_irq, cpu) == irq)
+ count++;
+ }
- if (!cpumask_test_and_clear_cpu(cpu, &armpmu->active_irqs))
+ return count;
+}
+
+void armpmu_free_cpu_irq(int irq, int cpu)
+{
+ if (per_cpu(cpu_irq, cpu) == 0)
+ return;
+ if (WARN_ON(irq != per_cpu(cpu_irq, cpu)))
return;
if (irq_is_percpu_devid(irq)) {
- free_percpu_irq(irq, &hw_events->percpu_pmu);
- cpumask_clear(&armpmu->active_irqs);
- return;
+ if (armpmu_count_irq_users(irq) == 1)
+ free_percpu_irq(irq, &cpu_armpmu);
+ } else {
+ free_irq(irq, NULL);
}
- free_irq(irq, per_cpu_ptr(&hw_events->percpu_pmu, cpu));
+ per_cpu(cpu_irq, cpu) = 0;
}
-int armpmu_request_irq(struct arm_pmu *armpmu, int cpu)
+void armpmu_free_irq(struct arm_pmu *armpmu, int cpu)
{
- int err = 0;
struct pmu_hw_events __percpu *hw_events = armpmu->hw_events;
- const irq_handler_t handler = armpmu_dispatch_irq;
int irq = per_cpu(hw_events->irq, cpu);
+
+ armpmu_free_cpu_irq(irq, cpu);
+}
+
+int armpmu_request_cpu_irq(int irq, int cpu)
+{
+ int err = 0;
+ const irq_handler_t handler = armpmu_dispatch_irq;
if (!irq)
return 0;
@@ -560,16 +577,16 @@ int armpmu_request_irq(struct arm_pmu *armpmu, int cpu)
irq_set_status_flags(irq, IRQ_NOAUTOEN);
err = request_irq(irq, handler, irq_flags, "arm-pmu",
- per_cpu_ptr(&hw_events->percpu_pmu, cpu));
- } else if (cpumask_empty(&armpmu->active_irqs)) {
+ NULL);
+ } else if (armpmu_count_irq_users(irq) == 0) {
err = request_percpu_irq(irq, handler, "arm-pmu",
- &hw_events->percpu_pmu);
+ cpu_armpmu);
}
if (err)
goto err_out;
- cpumask_set_cpu(cpu, &armpmu->active_irqs);
+ per_cpu(cpu_irq, cpu) = irq;
return 0;
err_out:
@@ -577,6 +594,17 @@ int armpmu_request_irq(struct arm_pmu *armpmu, int cpu)
return err;
}
+int armpmu_request_irq(struct arm_pmu *armpmu, int cpu)
+{
+ struct pmu_hw_events __percpu *hw_events = armpmu->hw_events;
+ int irq = per_cpu(hw_events->irq, cpu);
+ if (!irq)
+ return 0;
+
+
+ return armpmu_request_cpu_irq(irq, cpu);
+}
+
static int armpmu_get_cpu_irq(struct arm_pmu *pmu, int cpu)
{
struct pmu_hw_events __percpu *hw_events = pmu->hw_events;
@@ -599,6 +627,8 @@ static int arm_perf_starting_cpu(unsigned int cpu, struct hlist_node *node)
if (pmu->reset)
pmu->reset(pmu);
+ per_cpu(cpu_armpmu, cpu) = pmu;
+
irq = armpmu_get_cpu_irq(pmu, cpu);
if (irq) {
if (irq_is_percpu_devid(irq))
@@ -626,6 +656,8 @@ static int arm_perf_teardown_cpu(unsigned int cpu, struct hlist_node *node)
disable_irq(irq);
}
+ per_cpu(cpu_armpmu, cpu) = NULL;
+
return 0;
}
diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h
index 1f8bb83ef42f..feec9e7e85db 100644
--- a/include/linux/perf/arm_pmu.h
+++ b/include/linux/perf/arm_pmu.h
@@ -75,7 +75,6 @@ enum armpmu_attr_groups {
struct arm_pmu {
struct pmu pmu;
- cpumask_t active_irqs;
cpumask_t supported_cpus;
char *name;
irqreturn_t (*handle_irq)(int irq_num, void *dev);
--
2.11.0
next prev parent reply other threads:[~2018-02-05 16:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-05 16:41 [PATCHv2 0/8] arm_pmu: fix lockdep issues with ACPI systems Mark Rutland
2018-02-05 16:41 ` [PATCHv2 1/8] ARM: ux500: remove PMU IRQ bouncer Mark Rutland
2018-02-05 19:05 ` Linus Walleij
2018-02-06 11:26 ` Mark Rutland
2018-02-05 16:41 ` [PATCHv2 2/8] arm_pmu: kill arm_pmu_platdata Mark Rutland
2018-02-05 16:41 ` [PATCHv2 3/8] arm_pmu: fold platform helpers into platform code Mark Rutland
2018-02-05 16:41 ` [PATCHv2 4/8] arm_pmu: add armpmu_alloc_atomic() Mark Rutland
2018-02-05 16:41 ` [PATCHv2 5/8] arm_pmu: acpi: check for mismatched PPIs Mark Rutland
2018-02-05 16:42 ` [PATCHv2 6/8] arm_pmu: explicitly enable/disable SPIs at hotplug Mark Rutland
2018-02-26 15:16 ` Geert Uytterhoeven
2018-02-26 15:22 ` Will Deacon
2018-02-26 15:56 ` Geert Uytterhoeven
2018-02-26 16:01 ` Mark Rutland
2018-02-05 16:42 ` Mark Rutland [this message]
2018-02-05 17:07 ` [PATCHv2 7/8] arm_pmu: note IRQs and PMUs per-cpu Robin Murphy
2018-02-05 17:13 ` Mark Rutland
2018-02-14 13:11 ` Will Deacon
2018-02-14 13:24 ` Mark Rutland
2018-02-14 13:26 ` Will Deacon
2018-02-14 13:45 ` Mark Rutland
2018-02-14 18:22 ` Mark Rutland
2018-02-05 16:42 ` [PATCHv2 8/8] arm_pmu: acpi: request IRQs up-front Mark Rutland
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=20180205164202.26502-8-mark.rutland@arm.com \
--to=mark.rutland@arm.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 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).