From patchwork Wed Sep 14 22:32:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 9332627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B4D996077F for ; Wed, 14 Sep 2016 22:38:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC7D127F9C for ; Wed, 14 Sep 2016 22:38:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A10D12842E; Wed, 14 Sep 2016 22:38:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 372D02841D for ; Wed, 14 Sep 2016 22:38:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bkIne-0005yX-Cn; Wed, 14 Sep 2016 22:37:02 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bkIk7-000215-42 for linux-arm-kernel@lists.infradead.org; Wed, 14 Sep 2016 22:33:31 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C0CF17FC; Wed, 14 Sep 2016 15:32:43 -0700 (PDT) Received: from beelzebub.ast.arm.com (unknown [10.118.96.220]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 659A43F21A; Wed, 14 Sep 2016 15:32:43 -0700 (PDT) From: Jeremy Linton To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v9 09/10] arm: pmu: Add PMU definitions for hot-plugged CPUs Date: Wed, 14 Sep 2016 17:32:37 -0500 Message-Id: <1473892358-22574-10-git-send-email-jeremy.linton@arm.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1473892358-22574-1-git-send-email-jeremy.linton@arm.com> References: <1473892358-22574-1-git-send-email-jeremy.linton@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160914_153323_559093_B1A957AB X-CRM114-Status: GOOD ( 12.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, steve.capper@arm.com, mlangsdorf@redhat.com, punit.agrawal@arm.com, will.deacon@arm.com, linux-acpi@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP ACPI CPUs aren't associated with a PMU until they have been put online. This means that we potentially have to update a PMU definition the first time a CPU is hot added to the machine. Signed-off-by: Jeremy Linton --- drivers/perf/arm_pmu.c | 39 ++++++++++++++++++++++++++++++++++++++- include/linux/perf/arm_pmu.h | 4 ++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 47ab4e9..7835602 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -693,6 +693,34 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler) static DEFINE_SPINLOCK(arm_pmu_lock); static LIST_HEAD(arm_pmu_list); +static void arm_perf_associate_new_cpu(struct arm_pmu *lpmu, unsigned int cpu) +{ + if (lpmu) { + struct platform_device *pdev = lpmu->plat_device; + struct resource *res; + struct pmu_hw_events *events; + int num_res; + + for (num_res = 0; num_res < pdev->num_resources; num_res++) { + if (!pdev->resource[num_res].flags) + break; + } + res = &pdev->resource[num_res]; + + arm_pmu_acpi_retrieve_irq(res, cpu); + events = per_cpu_ptr(lpmu->hw_events, cpu); + cpumask_set_cpu(cpu, &lpmu->supported_cpus); + if (lpmu->irq_affinity) + lpmu->irq_affinity[num_res] = cpu; + pdev->num_resources++; + events->percpu_pmu = lpmu; + if (lpmu->reset) + lpmu->reset(lpmu); + } else { + pr_err("ACPI: unknown PMU type, unable to enable\n"); + } +} + /* * PMU hardware loses all context when a CPU goes offline. * When a CPU is hotplugged back in, since some hardware registers are @@ -702,15 +730,22 @@ static LIST_HEAD(arm_pmu_list); static int arm_perf_starting_cpu(unsigned int cpu) { struct arm_pmu *pmu; + struct arm_pmu *lpmu = NULL; + bool found = false; + unsigned int cpuid = read_specific_cpuid(cpu); spin_lock(&arm_pmu_lock); list_for_each_entry(pmu, &arm_pmu_list, entry) { - + if (cpuid == pmu->id) + lpmu = pmu; if (!cpumask_test_cpu(cpu, &pmu->supported_cpus)) continue; + found = true; if (pmu->reset) pmu->reset(pmu); } + if (!(found || acpi_disabled)) + arm_perf_associate_new_cpu(lpmu, cpu); spin_unlock(&arm_pmu_lock); return 0; } @@ -893,6 +928,8 @@ static int probe_plat_pmu(struct arm_pmu *pmu, struct platform_device *pdev = pmu->plat_device; int irq = platform_get_irq(pdev, 0); + pmu->id = pmuid; + if (irq >= 0 && !irq_is_percpu(irq)) { pmu->irq_affinity = kcalloc(pdev->num_resources, sizeof(int), GFP_KERNEL); diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 535c9e2..651b7a5 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -105,6 +105,7 @@ struct arm_pmu { struct mutex reserve_mutex; u64 max_period; bool secure_access; /* 32-bit ARM only */ + unsigned int id; #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40 DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); struct platform_device *plat_device; @@ -158,8 +159,11 @@ int arm_pmu_device_probe(struct platform_device *pdev, #ifdef CONFIG_ARM_PMU_ACPI struct acpi_madt_generic_interrupt; void arm_pmu_parse_acpi(int cpu, struct acpi_madt_generic_interrupt *gic); +int arm_pmu_acpi_retrieve_irq(struct resource *pdev, int cpu); #else #define arm_pmu_parse_acpi(a, b) do { } while (0) +#define arm_pmu_acpi_retrieve_irq(pdev, cpu) \ + do { } while (0) #endif /* CONFIG_ARM_PMU_ACPI */ #endif /* __ARM_PMU_H__ */