From patchwork Wed Dec 11 15:43:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11285465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F6D915AB for ; Wed, 11 Dec 2019 15:44:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F286C21556 for ; Wed, 11 Dec 2019 15:44:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MnnWQmWE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732185AbfLKPoO (ORCPT ); Wed, 11 Dec 2019 10:44:14 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:39996 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387457AbfLKPoN (ORCPT ); Wed, 11 Dec 2019 10:44:13 -0500 Received: by mail-lj1-f195.google.com with SMTP id s22so24591466ljs.7 for ; Wed, 11 Dec 2019 07:44:12 -0800 (PST) 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=C9yDPOd0OTPQBhTZJI/d5IX3T66EXAgmCmdgu1ZiaJ4=; b=MnnWQmWEeBtnTrCwz+if5edRXhdr8n1z8NyRUUN+vY5sIwfgvW8I9kvOpkWFAei451 nND8kLG3NcWd6u+J5e37NWK4CNjCGeVhqZNkwNXqP7d5jxtP9D64PYQMpqhlHHK+doCH bdaqR8Go/MWDUGCDh60YKNTwkVFA0ZfEt9yrLkKhA/KA97D6/r1LjUahAH+VIeIqOPXQ 1ODrXRWkTCHuV154SJI8hmmNc6d7Z5sxTc/R6CQIy3F/BU9Xpq6pO/13gBpG7/G0J8Ch HvkwMA0i/FWcmSKmxXPJlpjTTS64BXL55MlhDk8DojW1fkrhMA4hOmvftk5HDjV9JtP9 9rug== 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=C9yDPOd0OTPQBhTZJI/d5IX3T66EXAgmCmdgu1ZiaJ4=; b=kgF3UonSIRADVIGbTd17XyHkSUjtb7Q6JmV3Gm4tkA/gAlIYRSbJWhqQQ15bun+6jr sS/KYhxaHD6b8XGudy5+dme5mdWf2UF7U4sO7QrGRNa3eOa/iOT3QgDX+Zuutom5epLl 9cZoRKjdmSJJZUns5SbQIliVtsnEIdoc8+ELP7NvunrCE85FnGIflXEP+HBtawGQPhXT FKnlmZ6m5aJ+BeLMbQluxpYnce9B/c84J9rqIe7E60iNMclg0OmN8/BzrxgkRj0KReob xd2HO1gx7vcQWB+cUPh0JAO37/UF2DXjlrWeR1X9d6t6MdgYiLl/a3rQ2KwoA2wfURol 0WQA== X-Gm-Message-State: APjAAAVKsBeBn2hRpZ+pTTL8cjZ+4ltU7/p2Lj3d1iYW+j1CF40FWcVD yJpBsXUI7+XnKa7C5Zy4rb8XaQ== X-Google-Smtp-Source: APXvYqzDtybEqOEpWbUBHh5vtyfTA9qvNWwzUAhOzqDHGkA5ldRK0aDwlSTGQ73RmyeYlolJmJRFnw== X-Received: by 2002:a2e:5751:: with SMTP id r17mr2591479ljd.254.1576079051400; Wed, 11 Dec 2019 07:44:11 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id b14sm1389608lff.68.2019.12.11.07.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 07:44:10 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v4 12/14] cpuidle: psci: Support CPU hotplug for the hierarchical model Date: Wed, 11 Dec 2019 16:43:41 +0100 Message-Id: <20191211154343.29765-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191211154343.29765-1-ulf.hansson@linaro.org> References: <20191211154343.29765-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org When the hierarchical CPU topology is used and when a CPU is put offline, that CPU prevents its PM domain from being powered off, which is because genpd observes the corresponding attached device as being active from a runtime PM point of view. Furthermore, any potential master PM domains are also prevented from being powered off. To address this limitation, let's add add a new CPU hotplug state (CPUHP_AP_CPU_PM_STARTING) and register up/down callbacks for it, which allows us to deal with runtime PM accordingly. Signed-off-by: Ulf Hansson Reviewed-by: Sudeep Holla --- Changes in v4: - Folded in the patch to be part of the series. - Rebased on top of earlier changes. --- drivers/cpuidle/cpuidle-psci.c | 45 +++++++++++++++++++++++++++++++++- include/linux/cpuhotplug.h | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 6e7804e697ed..34a89d99bb0f 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "CPUidle PSCI: " fmt +#include #include #include #include @@ -31,6 +32,7 @@ struct psci_cpuidle_data { static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); static DEFINE_PER_CPU(u32, domain_state); +static bool psci_cpuidle_use_cpuhp; static inline void psci_set_domain_state(u32 state) { @@ -72,6 +74,44 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return ret; } +static int psci_idle_cpuhp_up(unsigned int cpu) +{ + struct device *pd_dev = __this_cpu_read(psci_cpuidle_data.dev); + + if (pd_dev) + pm_runtime_get_sync(pd_dev); + + return 0; +} + +static int psci_idle_cpuhp_down(unsigned int cpu) +{ + struct device *pd_dev = __this_cpu_read(psci_cpuidle_data.dev); + + if (pd_dev) { + pm_runtime_put_sync(pd_dev); + /* Clear domain state to start fresh at next online. */ + psci_set_domain_state(0); + } + + return 0; +} + +static void psci_idle_init_cpuhp(void) +{ + int err; + + if (!psci_cpuidle_use_cpuhp) + return; + + err = cpuhp_setup_state_nocalls(CPUHP_AP_CPU_PM_STARTING, + "cpuidle/psci:online", + psci_idle_cpuhp_up, + psci_idle_cpuhp_down); + if (err) + pr_warn("Failed %d while setup cpuhp state\n", err); +} + static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { @@ -166,9 +206,11 @@ static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv, * selection of a shared state for the domain, assumes the * domain states are all deeper states. */ - if (data->dev) + if (data->dev) { drv->states[state_count - 1].enter = psci_enter_domain_idle_state; + psci_cpuidle_use_cpuhp = true; + } } /* Idle states parsed correctly, store them in the per-cpu struct. */ @@ -289,6 +331,7 @@ static int __init psci_idle_init(void) goto out_fail; } + psci_idle_init_cpuhp(); return 0; out_fail: diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index e51ee772b9f5..01f04ed6ad92 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -95,6 +95,7 @@ enum cpuhp_state { CPUHP_AP_OFFLINE, CPUHP_AP_SCHED_STARTING, CPUHP_AP_RCUTREE_DYING, + CPUHP_AP_CPU_PM_STARTING, CPUHP_AP_IRQ_GIC_STARTING, CPUHP_AP_IRQ_HIP04_STARTING, CPUHP_AP_IRQ_ARMADA_XP_STARTING,