From patchwork Thu Apr 11 09:12:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 2427771 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id 8703E3FD40 for ; Thu, 11 Apr 2013 11:32:27 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UQFjr-0002lZ-QB; Thu, 11 Apr 2013 11:32:23 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UQDbv-0002E9-Gp; Thu, 11 Apr 2013 09:16:03 +0000 Received: from service87.mimecast.com ([91.220.42.44]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UQDbs-0002Dk-Tc for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2013 09:16:01 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 11 Apr 2013 10:15:58 +0100 Received: from e106331-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Thu, 11 Apr 2013 10:15:54 +0100 From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 07/11] arm: perf: treat PMUs as CPU affine Date: Thu, 11 Apr 2013 10:12:38 +0100 Message-Id: <1365671562-2403-8-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.8.1.1 In-Reply-To: <1365671562-2403-1-git-send-email-mark.rutland@arm.com> References: <1365671562-2403-1-git-send-email-mark.rutland@arm.com> X-OriginalArrivalTime: 11 Apr 2013 09:15:54.0524 (UTC) FILETIME=[2B5375C0:01CE3695] X-MC-Unique: 113041110155817901 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130411_051601_127731_71BE45DB X-CRM114-Status: GOOD ( 13.79 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [91.220.42.44 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Mark Rutland , Lorenzo.Pieralisi@arm.com, benh@kernel.crashing.org, devicetree-discuss@lists.ozlabs.org, will.deacon@arm.com, rob.herring@calxeda.com, grant.likely@secretlab.ca, dave.martin@arm.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In multi-cluster systems, the PMUs can be different across clusters, and so our logical PMU may not be able to schedule events on all CPUs. This patch adds a cpumask to encode which CPUs a PMU driver supports controlling events for, and limits the driver to scheduling events on those CPUs. Currently the cpumask is set to match all CPUs. Signed-off-by: Mark Rutland Reviewed-by: Will Deacon --- arch/arm/include/asm/pmu.h | 1 + arch/arm/kernel/perf_event.c | 20 ++++++++++++++++++++ arch/arm/kernel/perf_event_cpu.c | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/pmu.h b/arch/arm/include/asm/pmu.h index 56724b2..4688692 100644 --- a/arch/arm/include/asm/pmu.h +++ b/arch/arm/include/asm/pmu.h @@ -65,6 +65,7 @@ struct pmu_hw_events { 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); void (*enable)(struct perf_event *event); diff --git a/arch/arm/kernel/perf_event.c b/arch/arm/kernel/perf_event.c index 5bcd8ac..ebcd123 100644 --- a/arch/arm/kernel/perf_event.c +++ b/arch/arm/kernel/perf_event.c @@ -12,6 +12,7 @@ */ #define pr_fmt(fmt) "hw perfevents: " fmt +#include #include #include #include @@ -21,6 +22,11 @@ #include #include +static bool cpu_supported(struct arm_pmu *armpmu, int cpu) +{ + return cpumask_test_cpu(cpu, &armpmu->supported_cpus); +} + static int armpmu_map_cache_event(const unsigned (*cache_map) [PERF_COUNT_HW_CACHE_MAX] @@ -221,6 +227,10 @@ armpmu_add(struct perf_event *event, int flags) int idx; int err = 0; + /* An event following a process won't be stopped earlier */ + if (!cpu_supported(armpmu, smp_processor_id())) + return -ENOENT; + perf_pmu_disable(event->pmu); /* If we don't have a space for the counter then finish early. */ @@ -417,6 +427,16 @@ static int armpmu_event_init(struct perf_event *event) int err = 0; atomic_t *active_events = &armpmu->active_events; + /* + * Reject CPU-affine events for CPUs that are of a different class to + * that which this PMU handles. Process-following events (where + * event->cpu == -1) can be migrated between CPUs, and thus we have to + * reject them later (in armpmu_add) if they're scheduled on a + * different class of CPU. + */ + if (event->cpu != -1 && !cpu_supported(armpmu, event->cpu)) + return -ENOENT; + /* does not support taken branch sampling */ if (has_branch_stack(event)) return -EOPNOTSUPP; diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c index ae5be75..c1a9880c 100644 --- a/arch/arm/kernel/perf_event_cpu.c +++ b/arch/arm/kernel/perf_event_cpu.c @@ -168,7 +168,8 @@ static void cpu_pmu_init(struct cpu_pmu *cpu_pmu) /* Ensure the PMU has sane values out of reset. */ if (arm_pmu->reset) - on_each_cpu(arm_pmu->reset, arm_pmu, 1); + on_each_cpu_mask(&arm_pmu->supported_cpus, arm_pmu->reset, + arm_pmu, 1); } /* @@ -180,9 +181,13 @@ static void cpu_pmu_init(struct cpu_pmu *cpu_pmu) static int __cpuinit cpu_pmu_notify(struct notifier_block *b, unsigned long action, void *hcpu) { + int cpu = (long)hcpu; if ((action & ~CPU_TASKS_FROZEN) != CPU_STARTING) return NOTIFY_DONE; + if (!cpumask_test_cpu(cpu, &cpu_pmu->supported_cpus)) + return NOTIFY_DONE; + if (cpu_pmu && cpu_pmu->reset) cpu_pmu->reset(cpu_pmu); else @@ -296,6 +301,9 @@ static int cpu_pmu_device_probe(struct platform_device *pdev) goto out_pmu; } + /* Assume by default that we're on a homogeneous system */ + cpumask_setall(&pmu->armpmu.supported_cpus); + if (node && (of_id = of_match_node(cpu_pmu_of_device_ids, pdev->dev.of_node))) { init_fn = of_id->data; ret = init_fn(&pmu->armpmu);