From patchwork Thu Dec 5 10:33:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 180875 Delivered-To: patches@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1781549ile; Thu, 5 Dec 2019 02:33:38 -0800 (PST) X-Received: by 2002:a2e:3c1a:: with SMTP id j26mr4949395lja.79.1575542018235; Thu, 05 Dec 2019 02:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575542018; cv=none; d=google.com; s=arc-20160816; b=vkI+ruhWPmtLlftMKgnZBm/P28XU32NxJXwBA5eKwu7z/IjyG7cXc7ByRK2XY61ACn 4D4k1n7BMVGO3L6H6xC05zIiVqoDw0dnAbrxZHuw4V9Ak8/a7osB5g1UU+QsYrZPRWKS h7xgRa2DZ55Tuh+jjEM9PS9NG7PAc1URr6t3EWKw7LgPWCkZEmp/bXEERGa9TqFfBuyX jdYjW00D5F8SZu0xfe03crPFxxocZlxhzwMnyQh2aJVgh97N1pUBgLHN2tH+eWBgocGM pZx+WuuILTt9Zr3Gn+kJItP001J7qApnc/wHn7sYFcXLZvPjNrpyHzK8DdhyFGrysqJa nfBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=pG2r2/g6r/cRCtHmJlWgFPElnDAc0sUuBSOFJTt/9mM=; b=cVz1w8F90xcF7+bu/j9JTp7xBEFJVJztJyDB3fHHSL4nBcGZLDomAveNa0jspysRZj K0uyxngbIkKpRLfWD1dIaiu9XwgkK0tCBWHR1hZWtNBhLSb6f0G4ZFFJ9Kzukl7fi4r9 cBAbkt2pak/Qcjh3wGjU6pZ8tGci+2t3+nf2JAY6QNsJVWYPfvE+if0unTpnJtzlZJCG CQ17DEk57vy+mCliZIBfuBiI+cdKaoE//rTq8/k9chG08rAekthZHvhjMuS9ZCEMx5VJ AQc93vDUt7wQ1YpBRAF2lJ7QgLPDNuhzmKaIzk0z1xMQKZeWZvhh4hIvw3++p7YNKbo/ l4eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aDoxulZl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i17sor2699336lfo.72.2019.12.05.02.33.38 for (Google Transport Security); Thu, 05 Dec 2019 02:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aDoxulZl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=pG2r2/g6r/cRCtHmJlWgFPElnDAc0sUuBSOFJTt/9mM=; b=aDoxulZlbbd5bF/v/4CyK6vhcnMYCh7Inj4fn0/I97KJcUrFG4prGB7UZESZdT6Iwl 7yHiMEAXT+089BDZHMhap7VfP08w0DuVWp02Td6DHD/YJPi4sf1lrDsYgbrExDYUiyHe bOFXAG5Cp/2IkMddKesk3iktaRQ9W3ugPFcZimD0Y/dEQdMrQV4wNnFb/d6i8tdqTOw0 QsHdnXVNj46/6nMnDMfyDhz2IifArYSDS/abkMtb9vXKj0TMm4N/m0aVfJKRXdEUyzU6 Er/AUYXpEV7VFZ2mzG81IiZq92mONgdNKDK6KFYD+UBMNSSHtJl/fkto9EaDrOe04e/7 4lmQ== 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; bh=pG2r2/g6r/cRCtHmJlWgFPElnDAc0sUuBSOFJTt/9mM=; b=JG5ShbVZVDZECUJsEdBL1aUy1T5MTbFEoSXvRnIfme9Eesjh9ui1bI+/eF15TLVXUS Xr1SXYOupRDlEfgQ60BGTcLAvotuhjaQyGtvUShdiMw2i/2UCKiNzKI6EFaAMFJyZ2KL MGMixfqW8iwsDIapZdFk0e0++l/iRXznmzS67sgTc5u4U0B2ld/wxOsQQ0m0omZRZh3C 2gPD6IanZBtu5VFscEzAC5qWetOULx4amqBD2DhT/m2Kba6HR10ouuRG6ok4f5wVPWnV lKFFYIKTuovLaOD2GIJv8n72moN7dYsDzoOMYibCf97Frbjjvr8675wW34umSi7V7/Ga Jf2Q== X-Gm-Message-State: APjAAAXczn1uJS+rYq2i/u0V58Juhakq6PYWpJ3Wu3SqNq7wgsL6siJw txhtiMapafM2dHBvTKmKAdKH8KFN X-Google-Smtp-Source: APXvYqxJHIgterRi/o0jlDeDLVi9QArtZJQzyNYGI94YgKkmQimIHKm8hdCfRNfrwkyYxntcSN6ejw== X-Received: by 2002:a19:e002:: with SMTP id x2mr5043191lfg.28.1575542017782; Thu, 05 Dec 2019 02:33:37 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id w2sm4680438ljo.61.2019.12.05.02.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2019 02:33:37 -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] cpuidle: psci: Support CPU hotplug for the hierarchical model Date: Thu, 5 Dec 2019 11:33:30 +0100 Message-Id: <20191205103330.27166-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 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 --- Lorenzo, Sudeep, Rafael, Daniel, Note that, this patch is based upon a recently posted series [1] and the intent is to queue it on top. I can fold it into the series and resend it all, if that makes it easier for people. Just tell me what you prefer. Kind regards Uffe [1] https://patchwork.kernel.org/cover/11263735/ --- drivers/cpuidle/cpuidle-psci.c | 45 +++++++++++++++++++++++++++++++++- include/linux/cpuhotplug.h | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 835c7c3aa118..46b481c524cc 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; 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) { @@ -161,9 +201,11 @@ static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv, } /* Manage the deepest state via a dedicated enter-function. */ - if (dev) + if (dev) { drv->states[state_count - 1].enter = psci_enter_domain_idle_state; + psci_cpuidle_use_cpuhp = true; + } data->dev = dev; @@ -285,6 +327,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,