From patchwork Sat Mar 7 00:54:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 5958251 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2BAA79F380 for ; Sat, 7 Mar 2015 01:02:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23C0120392 for ; Sat, 7 Mar 2015 01:02:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22EA620390 for ; Sat, 7 Mar 2015 01:02:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YU355-0004DG-Hv; Sat, 07 Mar 2015 00:59:03 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YU324-00034j-8e for linux-arm-kernel@lists.infradead.org; Sat, 07 Mar 2015 00:55:57 +0000 Received: by padet14 with SMTP id et14so31745852pad.11 for ; Fri, 06 Mar 2015 16:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pmqRW7v8Lyn6qCKafSXew+rlEzKJFQ8JZsmR1uOljGA=; b=oVfIFhGhJmPWupaW73lfXWmwcrFdlWJfebQTdF/pLDcSqfl9OXHb+CYLnMHz7WF5bu puWR2n06Fd2d/IMP1d6RhiKs7qQwiuv+zthxZaHPxomDhtWsL2Z/BfJhgvEgU9umehVf s0306AxiB3uWavRazYZpn2JB9xliFnHFCLRbcXZdAaTDnqyTvvTuqrM5IzdeG2noZ6zc mjEreWAl3esm+G5WwPQJO76AA7YQjD38Bj9qwAuzFSrENzq0AWIVB/shlQSziFyP8YBm +afEFu00IWp2HcfIEvT8SWJQjbboWoAR1lQKQCgDCecIQwd/d0UPrsjC9XJbT+0Wnz4w +dfA== X-Received: by 10.70.96.204 with SMTP id du12mr21330394pdb.151.1425689734943; Fri, 06 Mar 2015 16:55:34 -0800 (PST) Received: from fainelli-desktop.broadcom.com (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPSA id kd9sm10732871pab.0.2015.03.06.16.55.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 16:55:34 -0800 (PST) From: Florian Fainelli To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/5] ARM: B15: Add CPU hotplug awareness Date: Fri, 6 Mar 2015 16:54:52 -0800 Message-Id: <1425689693-31034-5-git-send-email-f.fainelli@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1425689693-31034-1-git-send-email-f.fainelli@gmail.com> References: <1425689693-31034-1-git-send-email-f.fainelli@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150306_165556_422327_92F8A860 X-CRM114-Status: GOOD ( 20.37 ) X-Spam-Score: -0.8 (/) Cc: mark.rutland@arm.com, Florian Fainelli , linux@arm.linux.org.uk, rngun@broadcom.com, arnd@arndb.de, nico@linaro.org, cernekee@gmail.com, will.deacon@arm.com, Alamy Liu , bcm-kernel-feedback-list@broadcom.com, gregory.0xf0@gmail.com, olof@lixom.net, computersforpeace@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 The Broadcom Brahma-B15 readahead cache needs to be disabled, respectively re-enable during a CPU hotplug. In case we were not to do, CPU hotplug would occasionally fail with random crashes when a given CPU exits the coherency domain while the RAC is still enabled, as it would get stale data from the RAC. In order to avoid adding any specific B15 readahead-cache awareness to arch/arm/mach-bcm/hotplug-brcmstb.c we use a CPU notifier which allows us to catch CPU hotplug events and disable/flush enable the RAC accordingly. Signed-off-by: Alamy Liu Signed-off-by: Florian Fainelli --- arch/arm/mm/cache-b15-rac.c | 100 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/arch/arm/mm/cache-b15-rac.c b/arch/arm/mm/cache-b15-rac.c index 1c5bca6e906b..73d29741f096 100644 --- a/arch/arm/mm/cache-b15-rac.c +++ b/arch/arm/mm/cache-b15-rac.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include @@ -44,6 +46,7 @@ extern void v7_flush_icache_all(void); static void __iomem *b15_rac_base; static DEFINE_SPINLOCK(rac_lock); +static u32 rac_config0_reg; /* Initialization flag to avoid checking for b15_rac_base, and to prevent * multi-platform kernels from crashing here as well. @@ -142,6 +145,94 @@ static void b15_rac_enable(void) __b15_rac_enable(enable); } +#ifdef CONFIG_HOTPLUG_CPU +static void b15_rac_hotplug_start(void) +{ + /* Indicate that we are starting a hotplug procedure */ + clear_bit(RAC_ENABLED, &b15_rac_flags); + + /* Disable the readahead cache and save its value to a global */ + rac_config0_reg = b15_rac_disable_and_flush(); +} + +static void b15_rac_hotplug_end(void) +{ + /* And enable it */ + __b15_rac_enable(rac_config0_reg); + set_bit(RAC_ENABLED, &b15_rac_flags); +} + +/* The CPU hotplug case is the most interesting one, we basically need to make + * sure that the RAC is disabled for the entire system prior to having a CPU + * die, in particular prior to this dying CPU having exited the coherency + * domain. + * + * Once this CPU is marked dead, we can safely re-enable the RAC for the + * remaining CPUs in the system which are still online. + * + * Offlining a CPU is the problematic case, onlining a CPU is not much of an + * issue since the CPU and its cache-level hierarchy will start filling with + * the RAC disabled, so L1 and L2 only. + * + * In this function, we should NOT have to verify any unsafe setting/condition + * b15_rac_base: + * + * It is protected by the RAC_ENABLED flag which is cleared by default, and + * being cleared when initial procedure is done. b15_rac_base had been set at + * that time. + * + * RAC_ENABLED: + * There is a small timing windows, in b15_rac_init(), between + * register_cpu_notifier(&b15_rac_cpu_nb); + * ... + * set RAC_ENABLED + * However, there is no hotplug activity based on the Linux booting procedure. + * + * Regarding the notification actions, we will receive CPU_DOWN_PREPARE, + * CPU_DOWN_FAILED, CPU_DYING, CPU_DEAD, and CPU_POST_DEAD notification (see + * _cpu_down() for detail). + * + * Since we have to disable RAC for all cores, we keep RAC on as long as as + * possible (disable it as late as possible) to gain the cache benefit. + * + * Thus, CPU_DYING/CPU_DEAD pair are chosen. + * + * We are choosing not do disable the RAC on a per-CPU basis, here, if we did + * we would want to consider disabling it as early as possible to benefit the + * other active CPUs. + */ +static int b15_rac_cpu_notify(struct notifier_block *self, + unsigned long action, void *hcpu) +{ + action &= ~CPU_TASKS_FROZEN; + + if (action != CPU_DYING && action != CPU_DOWN_FAILED && + action != CPU_DEAD) + return NOTIFY_OK; + + spin_lock(&rac_lock); + switch (action) { + /* called on the dying CPU, exactly what we want */ + case CPU_DYING: + b15_rac_hotplug_start(); + break; + + /* called on a non-dying CPU, what we want too */ + case CPU_DOWN_FAILED: + case CPU_DEAD: + b15_rac_hotplug_end(); + break; + } + spin_unlock(&rac_lock); + + return NOTIFY_OK; +} + +static struct notifier_block b15_rac_cpu_nb = { + .notifier_call = b15_rac_cpu_notify, +}; +#endif /* CONFIG_HOTPLUG_CPU */ + static int __init b15_rac_init(void) { struct device_node *dn; @@ -161,6 +252,15 @@ static int __init b15_rac_init(void) goto out; } +#ifdef CONFIG_HOTPLUG_CPU + ret = register_cpu_notifier(&b15_rac_cpu_nb); + if (ret) { + pr_err("failed to register notifier block\n"); + iounmap(b15_rac_base); + goto out; + } +#endif + spin_lock(&rac_lock); reg = __raw_readl(b15_rac_base + RAC_CONFIG0_REG); for_each_possible_cpu(cpu)