From patchwork Tue Nov 3 15:06:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 320421 Delivered-To: patches@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4658174ilc; Tue, 3 Nov 2020 07:06:43 -0800 (PST) X-Received: by 2002:a2e:9b58:: with SMTP id o24mr8081999ljj.94.1604416003526; Tue, 03 Nov 2020 07:06:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604416003; cv=none; d=google.com; s=arc-20160816; b=RhMjbx4Rfwy9SzHgGNMGACc+XnwoF7GsCRAGWCaynQ/dlTk9FiXZ11hZCwi2twqyd1 OwgPdEBp25ogjkGhAKPl2jAnyM+MmPV1agvFVUqlROvoTUUcbh9o7jaEnPybvLSicDve tWDDD2mNaJzF1q0PKFEldbG41Aj1Av18nmjBiG8GIC4fcDJgLUcFln2k+eSdXTfFIXS+ BPGKcBrxi1qD04fzJAQSC7UBO4/FLkp1nJQmZ8WWJ+wYc6FNH+5poNYzKMrWWURBsvQy xqBXAGk8dHgRzutJyaunTVaGHrz2ireI+XwaY9VwXgIWNugOQV7V0VvGnyscE7936K3F 0YtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=z2aikAnlU4Rv0xJ54ndQnr8H+vElIy0SKy9Omrer1Ow=; b=ia9ISukaJKXoBbO3YFJw8EwuPao3DBPwbqmzlMXvyzpjD3tQb5Wzen/Rl3Dmg1jaVo uim/7F4yeKFBv+Z42xb9cG4uSPbrn/C44G03HOSf3zE7VnKsDdhkq8k0B5IklwFd95wG VivqCjgE4RKc4aWMT96LrRqdfjuuCcrEhdvavrf5jHbTHP0119C8ZIA5sMu3vGY9S8y4 D71vnLuf/xZJp2o3GY4wqCxpwB503offpQ+zv8IsKa5jWFKsjvujZZs2qzKi+b5CBIPY OQ98bgwNfRo+oscJwp0dt35Y5PpfvP9ZzGuwRFHnp/fR70nDonVwKS1JderIudabZLnU Rbhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ysK/IoiT"; 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 n2sor1971510lfd.24.2020.11.03.07.06.43 for (Google Transport Security); Tue, 03 Nov 2020 07:06:43 -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="ysK/IoiT"; 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 :mime-version:content-transfer-encoding; bh=z2aikAnlU4Rv0xJ54ndQnr8H+vElIy0SKy9Omrer1Ow=; b=ysK/IoiTp/UV3EPWH4UVFRHclwAjajJUvSrrM3LNcbaoGkicwm6doZuxeL3S7sfb32 DMFErTSnQPcB0MgRCAtgupil1fcRLbb/LpGIBHCMUfHOsWw9qzbQxWIGEC67sBhHFAer PDJ9z0Fcss7tqgwKKqbQgOpcdfRU+m6wbJZbaEljBcMhGeiN0O0pERIMF+E2xxDGATeT JrjkX3Cju0HiFYns0PYd1VSMF6Yu9XGNMtlesWDovCfEjuzW3UrVQ+KcbZum6o7hIvFq b27ldA7bQuHFTP0JoBqJcNNJM4rZpxEIgYrP2VCwickkqKCeq7rQvpP4TzbYkbbO2MjF aJog== 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:mime-version:content-transfer-encoding; bh=z2aikAnlU4Rv0xJ54ndQnr8H+vElIy0SKy9Omrer1Ow=; b=sdhDVaFxBQOOKYWrPKq7OcQAVBp7ciVJDZyb50JRdeLnvyl1HImBciMt9qsUFPAaO4 ADSocB4EHhy7MGZGhz/++LdlcllDOSSaz/yTUQM+npTSkmkOSABI8ClLvBZsYKDta+xy UUMMfyd7Y07+AYXt4yDNtzNpPYviN0fZCl+h+i6tQ/Yr70PSYvEfa1OI8Pbgnxg/Q/WH yKCBpVJh4TTChEaGa+yoRg3kY7ZvgZuIoFC1vg7BE97H7kLV2ecSZRwhaYYFBHHH3CIY QiDcr6CibLUntrsRBCU5QMoNQg7M7isv4yWI+LCWqSvlKjNhBwf5lvLo+VYSQLd/ANVH nPZw== X-Gm-Message-State: AOAM531VAm46pErA3v753JsZjgSy9l9+PzjlxQQmydsqqSTz7lEm3xve mAIG2rck3uChCznb0p61gjnKFxLt X-Google-Smtp-Source: ABdhPJzaNwaa4JfoulcPt1J10kPgf3A10Pfy/kvKPYlSj4ezifUxRuTpYUt3gCD3A1Gn05zKdnj4Gw== X-Received: by 2002:a19:ca4b:: with SMTP id h11mr8466061lfj.6.1604416002518; Tue, 03 Nov 2020 07:06:42 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-155-4-131-134.NA.cust.bahnhof.se. [155.4.131.134]) by smtp.gmail.com with ESMTPSA id a25sm3522169lfo.141.2020.11.03.07.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 07:06:41 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Alexandre Torgue , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 3/3] cpuidle: psci: Enable suspend-to-idle for PSCI OSI mode Date: Tue, 3 Nov 2020 16:06:27 +0100 Message-Id: <20201103150627.233438-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103150627.233438-1-ulf.hansson@linaro.org> References: <20201103150627.233438-1-ulf.hansson@linaro.org> MIME-Version: 1.0 To select domain idlestates for cpuidle-psci when OSI mode has been enabled, the PM domains via genpd are being managed through runtime PM. This works fine for the regular idlepath, but it doesn't during system wide suspend. More precisely, the domain idlestates becomes temporarily disabled, which is because the PM core disables runtime PM for devices during system wide suspend. Later in the system suspend phase, genpd intends to deal with this from its ->suspend_noirq() callback, but this doesn't work as expected for a device corresponding to a CPU, because the domain idlestates needs to be selected on a per CPU basis (the PM core doesn't invoke the callbacks like that). To address this problem, let's enable the syscore flag for the corresponding CPU device that becomes successfully attached to its PM domain (applicable only in OSI mode). This informs the PM core to skip invoke the system wide suspend/resume callbacks for the device, thus also prevents genpd from screwing up its internal state of it. Moreover, to properly select a domain idlestate for the CPUs during suspend-to-idle, let's assign a specific ->enter_s2idle() callback for the corresponding domain idlestate (applicable only in OSI mode). From that callback, let's invoke dev_pm_genpd_suspend|resume(), as this allows a domain idlestate to be selected for the current CPU by genpd. Signed-off-by: Ulf Hansson --- Changes in v2: - Rebased upon recent changes. - Updated the commit message. --- drivers/cpuidle/cpuidle-psci-domain.c | 2 ++ drivers/cpuidle/cpuidle-psci.c | 34 +++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) -- 2.25.1 diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index 4a031c62f92a..ff2c3f8e4668 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -327,6 +327,8 @@ struct device *psci_dt_attach_cpu(int cpu) if (cpu_online(cpu)) pm_runtime_get_sync(dev); + dev_pm_syscore_device(dev, true); + return dev; } diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index d928b37718bd..b51b5df08450 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -52,8 +53,9 @@ static inline int psci_enter_state(int idx, u32 state) return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); } -static int psci_enter_domain_idle_state(struct cpuidle_device *dev, - struct cpuidle_driver *drv, int idx) +static int __psci_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx, + bool s2idle) { struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); u32 *states = data->psci_states; @@ -66,7 +68,12 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return -1; /* Do runtime PM to manage a hierarchical CPU toplogy. */ - RCU_NONIDLE(pm_runtime_put_sync_suspend(pd_dev)); + rcu_irq_enter_irqson(); + if (s2idle) + dev_pm_genpd_suspend(pd_dev); + else + pm_runtime_put_sync_suspend(pd_dev); + rcu_irq_exit_irqson(); state = psci_get_domain_state(); if (!state) @@ -74,7 +81,12 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, ret = psci_cpu_suspend_enter(state) ? -1 : idx; - RCU_NONIDLE(pm_runtime_get_sync(pd_dev)); + rcu_irq_enter_irqson(); + if (s2idle) + dev_pm_genpd_resume(pd_dev); + else + pm_runtime_get_sync(pd_dev); + rcu_irq_exit_irqson(); cpu_pm_exit(); @@ -83,6 +95,19 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return ret; } +static int psci_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx) +{ + return __psci_enter_domain_idle_state(dev, drv, idx, false); +} + +static int psci_enter_s2idle_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int idx) +{ + return __psci_enter_domain_idle_state(dev, drv, idx, true); +} + static int psci_idle_cpuhp_up(unsigned int cpu) { struct device *pd_dev = __this_cpu_read(psci_cpuidle_data.dev); @@ -170,6 +195,7 @@ static int psci_dt_cpu_init_topology(struct cpuidle_driver *drv, * deeper states. */ drv->states[state_count - 1].enter = psci_enter_domain_idle_state; + drv->states[state_count - 1].enter_s2idle = psci_enter_s2idle_domain_idle_state; psci_cpuidle_use_cpuhp = true; return 0;