From patchwork Tue Mar 10 17:31:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 5979801 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7C515BF440 for ; Tue, 10 Mar 2015 17:31:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A76DA20251 for ; Tue, 10 Mar 2015 17:31:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC4712021F for ; Tue, 10 Mar 2015 17:31:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753642AbbCJRbZ (ORCPT ); Tue, 10 Mar 2015 13:31:25 -0400 Received: from foss.arm.com ([217.140.101.70]:43632 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751620AbbCJRbZ (ORCPT ); Tue, 10 Mar 2015 13:31:25 -0400 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 4EA5C29; Tue, 10 Mar 2015 10:31:42 -0700 (PDT) Received: from red-moon.cambridge.arm.com (red-moon.cambridge.arm.com [10.1.203.137]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 201CE3F7E6; Tue, 10 Mar 2015 10:31:23 -0700 (PDT) From: Lorenzo Pieralisi To: linux-arm-kernel@lists.infradead.org Cc: linux-pm@vger.kernel.org, Lorenzo Pieralisi , Will Deacon , Mark Rutland Subject: [RFC PATCH 1/2] arm64: kernel: perf: add cpu hotplug notifier Date: Tue, 10 Mar 2015 17:31:21 +0000 Message-Id: <1426008682-5680-1-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 2.2.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a CPU is taken offline, its PMU registers content is lost and needs to be reset on power up, since for most of the PMU registers content is UNKNOWN upon CPU reset. This patch implements a cpu hotplug notifier and hooks the reset call in the respective notifier callback function. Cc: Will Deacon Cc: Mark Rutland Signed-off-by: Lorenzo Pieralisi --- arch/arm64/kernel/perf_event.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 25a5308..83f21d8 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -21,6 +21,7 @@ #define pr_fmt(fmt) "hw perfevents: " fmt #include +#include #include #include #include @@ -1315,6 +1316,30 @@ static struct pmu_hw_events *armpmu_get_cpu_events(void) return this_cpu_ptr(&cpu_hw_events); } +/* + * PMU hardware loses all context when a CPU goes offline. + * When a CPU is hotplugged back in, since some hardware registers are + * UNKNOWN at reset, the PMU must be explicitly reset to avoid reading + * junk values out of them. + */ +static int cpu_pmu_notifier(struct notifier_block *b, unsigned long action, + void *hcpu) +{ + if ((action & ~CPU_TASKS_FROZEN) != CPU_STARTING) + return NOTIFY_DONE; + + if (cpu_pmu->reset) + cpu_pmu->reset(NULL); + else + return NOTIFY_DONE; + + return NOTIFY_OK; +} + +static struct notifier_block cpu_pmu_notifier_block = { + .notifier_call = cpu_pmu_notifier, +}; + static void __init cpu_pmu_init(struct arm_pmu *armpmu) { int cpu; @@ -1325,6 +1350,8 @@ static void __init cpu_pmu_init(struct arm_pmu *armpmu) raw_spin_lock_init(&events->pmu_lock); } armpmu->get_hw_events = armpmu_get_cpu_events; + + register_cpu_notifier(&cpu_pmu_notifier_block); } static int __init init_hw_perf_events(void)