From patchwork Mon Dec 30 14:43:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 182624 Delivered-To: patches@linaro.org Received: by 2002:a92:815a:0:0:0:0:0 with SMTP id e87csp6422423ild; Mon, 30 Dec 2019 06:44:27 -0800 (PST) X-Received: by 2002:a2e:9942:: with SMTP id r2mr39582051ljj.182.1577717067814; Mon, 30 Dec 2019 06:44:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577717067; cv=none; d=google.com; s=arc-20160816; b=X0Aa2tSGfUuKBf3BNrbzercfwhUWIoba7L3g0Jikuzt5CcN3cp24aXqM9gZlx42vAR fDEC7mxJmXUCDUsf/eY143BrCYS9PuyCvFJ96kGwpIaeoQ7+T/BooqfDLrnrACzPd8kL dyXpiCZbUNUyi4wxssKYzUrM1a1RwyA/hZMXzgilnFbYK1gKTi7+B/efJU9SCUAGkug3 b7Ja0BgNfx68K5LqLSOmC8w4xJitmmHMy6IxYniv02zSiPYzWUt5/F6dHb6V9xfbBkMs 81D4r/H9tCaXrHLBsWJZ/U9CExXNbpBLQGhaO1hfoDwPyN+UMl4XV0TVY0MHah3RGZcO thNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iP0q67cVa7joTIBbxM/rB2PXgLYhwll7Ud0Qeuw7uE4=; b=LZH9jXN9YyzUTOuVD+M5EgQ8PvhHd8NJZUXXWtjOJwRDk23jheVPGHluqZRJD3mQlG ug1g/yyGvRyiXRiuxPlbrCv67+rs2Vp8TvrINEUmZCbxkFc3TQ+TT49+xQdT/1hVMqjW g1F9vAQ8Q/j9qCBgWvjnSt5we5vNjCtgQhfq+uZ6WZSTdOcAYLRtB5maABOCBcgZO6wA CaD3Wkv+0EDZ0l2XLgiBGOin7YTLYayRieL9i/dhBCQzVZY9qpFngCpj7AM01/TOkltF /VrrB8MUI4i9ROF7/piKxE8T0izODPp1DAEqUSpYzx4aNXOW9/caPFDHa4b3Gfb/UXNX 8xwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cZDkTeTB; 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 h18sor19591466ljj.14.2019.12.30.06.44.27 for (Google Transport Security); Mon, 30 Dec 2019 06:44:27 -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=cZDkTeTB; 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:in-reply-to:references; bh=iP0q67cVa7joTIBbxM/rB2PXgLYhwll7Ud0Qeuw7uE4=; b=cZDkTeTBaAAlRRZrP1XLtXSbuzbscAVY8zmWFyVTHUO5xJzFNqhSGbfNaVWsCH1AuX 4rT40nwkm1sYOV87tQsTVNYOpKm/XQgnTfubKy97NWJGHyYGyJ+cykHyuBuzwg1e4vI+ dP2uBSyDD85o+XaR8nCem4voDrHfRNDwol6CbGAaupD5x1CDQNr/ejTTClgbNp+xnOmR 2Bybqk0ajXhcvXbxyM51KKuqO7Pq9KUok4Z20H1s3n3ChONQsVe8t0SEdohf+xd9LlR9 TwQyqLl/Nqa3iyclS4fQCNrW5jt9RzhUB79qF7nkaemxrQzWOlFc+6vmMc74MtPky/iM eUnQ== 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=iP0q67cVa7joTIBbxM/rB2PXgLYhwll7Ud0Qeuw7uE4=; b=Lj4jKuh2/4efUAslaf8RWCUZSp1QV/2ugusRyR+EIRcxoHf+s2PXsxUl6ux1bl0oke j8pWVTfa29dCkyF4S6hQkG4/g7L9kYYSvBqxBhdSCqfpnngazWrwT9FkIORtodO8ssSC 2EEI//S8quf53E5WMB60N9FFEV6doccqdG5wX88+skDyZ+FMWh+PlnhvT6tu5/n4Stzz 4M4rE6ILfdXgafIWYEVrGpuqJzOLshB6wA5HPY4NpwQJXFtil6NTtWbumbiqY4hyQQE/ 0+v/kpySQrYuwDQ38Yg4MKFJs/HfcdRD3qXWxtn4hfriPo5HifevfhWWenVUMgcoKMks ksYg== X-Gm-Message-State: APjAAAVohnSpnhrq9qFKmskNKjgHI0fQ17vBvxLk3lNokHStfOyCezMF We16L0LANngDdbSEbrnt/0ouQ9gcw96bhA== X-Google-Smtp-Source: APXvYqzBs/tiWnncxKxVYy6elFVnD48Lxju0cyn1aR3gEPXIkZtrCY33Ut1F1NTu0L4H0jjmnQTcwg== X-Received: by 2002:a2e:8090:: with SMTP id i16mr39630757ljg.88.1577717067493; Mon, 30 Dec 2019 06:44:27 -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 a21sm18744931lfg.44.2019.12.30.06.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:26 -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 v5 12/15] cpuidle: psci: Support CPU hotplug for the hierarchical model Date: Mon, 30 Dec 2019 15:43:59 +0100 Message-Id: <20191230144402.30195-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-1-ulf.hansson@linaro.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 v5: - Make CPUHP function/variable initdata. --- 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 6e7804e697ed..9d779be27071 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 __initdata; 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 __init 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,