From patchwork Mon Jun 12 15:55:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 9781881 X-Patchwork-Delegate: rjw@sisk.pl 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 BF7BA60352 for ; Mon, 12 Jun 2017 15:58:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2F9128547 for ; Mon, 12 Jun 2017 15:58:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7EA52861A; Mon, 12 Jun 2017 15:58:02 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3982B2854A for ; Mon, 12 Jun 2017 15:58:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753665AbdFLP5S (ORCPT ); Mon, 12 Jun 2017 11:57:18 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:33332 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752927AbdFLP5Q (ORCPT ); Mon, 12 Jun 2017 11:57:16 -0400 Received: by mail-wr0-f180.google.com with SMTP id v104so100953143wrb.0 for ; Mon, 12 Jun 2017 08:57:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BoaKjWcNrqu3XmTN2AVNCsL46SKPiITwLjAw3HkdOYs=; b=QiYjc1Yn8buy4C7G/aG6Zd+vk3Y06Y8e4NIvBxCR/3Z5LnS2TrusSBf3lIygZR7dfR 8upLn22MX1s6XQaHx7IT00z/444m6MxTjRggbKMK+1BwdJDCWdxahoUhE0StneH3qbOH hHtkXPty84+4ZWzk8lesDWJ+m3jIq8avMdOoY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BoaKjWcNrqu3XmTN2AVNCsL46SKPiITwLjAw3HkdOYs=; b=ikWMJC6Mp7KnEthln2YfoYqfMVgQQK+CWOqbMP0PsIjafhfJtAe9F7+5OLNGa0DgJ5 /IH89fmO5pFqr9jvSIRy6GugoBWhpS4MEqk8tflfwZzB/Ley0nTtLLT8WDYoEDjN6mf3 xO5hcqh+ZINestUX6T17nhFiadGK3Bm8gn8ffqsd2Aufd3b35Ayd/Kbp9bUFrl3/6SMV t8RfUtaG4dHcFMzMcL6u2BB8X3VE2rmUKCw4ps0Wtf6rkVA0l6VSl8e6Igg64bDIa3D3 Nhy81hHRv1gP0XlR8wK39frdhTyHXG8JuK3mepd4Fs3jfyx7Ar88oL8wLuefKF9GesDr XT7w== X-Gm-Message-State: AODbwcBq29p+XoyCimQc9B1Rg9274E78AuiT6ZLQnmVSeHUJe2FtWBdO w1GiKTgB9DjSlbH6 X-Received: by 10.28.52.139 with SMTP id b133mr8515564wma.119.1497283033971; Mon, 12 Jun 2017 08:57:13 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:879a:6cd0:289a:9b8c:a41f:e1d5]) by smtp.gmail.com with ESMTPSA id q77sm153978wmb.4.2017.06.12.08.57.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Jun 2017 08:57:13 -0700 (PDT) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: linux-pm@vger.kernel.org, Sudeep Holla , Lorenzo Pieralisi , Leo Yan , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/2] ARM: cpuidle: Support asymmetric idle definition Date: Mon, 12 Jun 2017 17:55:10 +0200 Message-Id: <1497282910-19085-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497282910-19085-1-git-send-email-daniel.lezcano@linaro.org> References: <20170612155441.GE2261@mai> <1497282910-19085-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some hardware have clusters with different idle states. The current code does not support this and fails as it expects all the idle states to be identical. Because of this, the Mediatek mtk8173 had to create the same idle state for a big.Little system and now the Hisilicon 960 is facing the same situation. Solve this by simply assuming the multiple driver will be needed for all the platforms using the ARM generic cpuidle driver which makes sense because of the different topologies we can support with a single kernel for ARM32 or ARM64. Every CPU has its own driver, so every single CPU can specify in the DT the idle states. This simple approach allows to support the future dynamIQ system, current SMP and HMP. Tested on: - 96boards: Hikey 620 - 96boards: Hikey 960 - 96boards: dragonboard410c - Mediatek 8173 Cc: Sudeep Holla Cc: Lorenzo Pieralisi Tested-by: Leo Yan Signed-off-by: Daniel Lezcano Acked-by: Sudeep Holla --- drivers/cpuidle/Kconfig.arm | 1 + drivers/cpuidle/cpuidle-arm.c | 62 ++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm index 21340e0..f521448 100644 --- a/drivers/cpuidle/Kconfig.arm +++ b/drivers/cpuidle/Kconfig.arm @@ -4,6 +4,7 @@ config ARM_CPUIDLE bool "Generic ARM/ARM64 CPU idle Driver" select DT_IDLE_STATES + select CPU_IDLE_MULTIPLE_DRIVERS help Select this to enable generic cpuidle driver for ARM. It provides a generic idle driver whose idle states are configured diff --git a/drivers/cpuidle/cpuidle-arm.c b/drivers/cpuidle/cpuidle-arm.c index f440d38..7080c38 100644 --- a/drivers/cpuidle/cpuidle-arm.c +++ b/drivers/cpuidle/cpuidle-arm.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -44,7 +45,7 @@ static int arm_enter_idle_state(struct cpuidle_device *dev, return CPU_PM_CPU_IDLE_ENTER(arm_cpuidle_suspend, idx); } -static struct cpuidle_driver arm_idle_driver = { +static struct cpuidle_driver arm_idle_driver __initdata = { .name = "arm_idle", .owner = THIS_MODULE, /* @@ -80,30 +81,42 @@ static const struct of_device_id arm_idle_state_match[] __initconst = { static int __init arm_idle_init(void) { int cpu, ret; - struct cpuidle_driver *drv = &arm_idle_driver; + struct cpuidle_driver *drv; struct cpuidle_device *dev; - /* - * Initialize idle states data, starting at index 1. - * This driver is DT only, if no DT idle states are detected (ret == 0) - * let the driver initialization fail accordingly since there is no - * reason to initialize the idle driver if only wfi is supported. - */ - ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); - if (ret <= 0) - return ret ? : -ENODEV; - - ret = cpuidle_register_driver(drv); - if (ret) { - pr_err("Failed to register cpuidle driver\n"); - return ret; - } - - /* - * Call arch CPU operations in order to initialize - * idle states suspend back-end specific data - */ for_each_possible_cpu(cpu) { + + drv = kmemdup(&arm_idle_driver, sizeof(*drv), GFP_KERNEL); + if (!drv) { + ret = -ENOMEM; + goto out_fail; + } + + drv->cpumask = (struct cpumask *)cpumask_of(cpu); + + /* + * Initialize idle states data, starting at index 1. This + * driver is DT only, if no DT idle states are detected (ret + * == 0) let the driver initialization fail accordingly since + * there is no reason to initialize the idle driver if only + * wfi is supported. + */ + ret = dt_init_idle_driver(drv, arm_idle_state_match, 1); + if (ret <= 0) { + ret = ret ? : -ENODEV; + goto out_fail; + } + + ret = cpuidle_register_driver(drv); + if (ret) { + pr_err("Failed to register cpuidle driver\n"); + goto out_fail; + } + + /* + * Call arch CPU operations in order to initialize + * idle states suspend back-end specific data + */ ret = arm_cpuidle_init(cpu); /* @@ -141,10 +154,11 @@ static int __init arm_idle_init(void) dev = per_cpu(cpuidle_devices, cpu); cpuidle_unregister_device(dev); kfree(dev); + drv = cpuidle_get_driver(); + cpuidle_unregister_driver(drv); + kfree(drv); } - cpuidle_unregister_driver(drv); - return ret; } device_initcall(arm_idle_init);