From patchwork Mon May 13 19:22:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 164064 Delivered-To: patches@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1728609ili; Mon, 13 May 2019 12:23:34 -0700 (PDT) X-Received: by 2002:a19:ae14:: with SMTP id f20mr14035876lfc.49.1557775413920; Mon, 13 May 2019 12:23:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557775413; cv=none; d=google.com; s=arc-20160816; b=mmxjcr4n3Yef8R6FVCufYfOOtvSo/j2svwwPgD5KMJG23YM89dhRmQwnccvDQ+klLs soSTYbN5E1htfzIxcNVMf8BWtAUrlUyb+kYCpLcUInUheNZWWgQ+K174hGzcWtylzmiv 6X+M9s0t1sSrXadqE2HAXI25uhuC2BmuyDmkV9sHuhuzaARO5cKgyLQd6Fy4LWpqWtE+ ijL2K02GmP7ZMseil7UoLqz5W1Q2GFnyTE6hu/j6unBoZHcvQ8vcpSEqlKCRDCQmGPDO GacW8HGODWjC5A/EXrtYvePpx0DYjslQ7buj/6+xiWtd/sRYES3dGa6MfSsQppYGwYF8 B0OA== 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=WrUBlQWQzfbgrdk7klxniFTaW91XaiQj55o38mlFd9s=; b=nmbq62Xd/rY6cegKHA5btKadfxzXxOk2vuum7r60O7sTZspoyF71N/twiJQAGApynt 5Hc0gO9eUPtwJTBaBmBiHlrMQs8Bw34RyHl6f7H5/qrTLLASY5DUP90MgE3Z5QxgFpMo 1LdN/unHN2ZZHiRF3beQ25AR6mgnS7naaAbq7JSH5tAQh/1g5UtgUljWZ0AIYcTtdTqA gwMAaKgfd8lOXlW/rEUjGDGm93Mt3y4HKy+tcaon/SE0qUbAnF0OHnPPQoW0BC3tt0D3 UhQiab/OUoH/omCZccDW60Ln32oTK3FgXL0i5yZBGW3ANx9H8bMGjTq9wLVcK65LBbh6 bD+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sPy1xWva; 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 y18sor2971875lji.38.2019.05.13.12.23.33 for (Google Transport Security); Mon, 13 May 2019 12:23:33 -0700 (PDT) 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=sPy1xWva; 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=WrUBlQWQzfbgrdk7klxniFTaW91XaiQj55o38mlFd9s=; b=sPy1xWvat53hABQ29ElA2SDvZnqfRV5oZCv6u9/BoxR2ZPqFXvyAG3a5TqRkJY1a78 ViroHIx+ON0jQRU/3UrEYHgnwsRgfEfK1eI6rvzBvxBl01A+l0VD3RNQr/pCLeiGgll5 oZk8WImmrSosBLIL5WDY5HKxk6DoQYAY3hOyay9Zaekc0Qx48OBqfoEIU9LOQbcuUzO9 y21fdWLhr9sVngZjVbZUtziI2z+WwnXK05qOJ7jaN6FqE68r4gmG+pebrx9IRchSta0X VzfAclg9EtvAhwIfrDB0k8yyetyh5giqMkUfQdSjeFYl6oWMRIbrHygy50HEN/rtT2Ov JANw== 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=WrUBlQWQzfbgrdk7klxniFTaW91XaiQj55o38mlFd9s=; b=l9PZKbi/NzvmseD4HW0zLNUzMEc+ElYCJUl/x1935VXWd2K4NLUPo6Wq5+YxsVUt7p H062zEuH3v6xSQuEUnFgD/1WA3+xVNUdbOgVcjkDFr+GWcX3MV3fXLjGm6R4SrrEWb/p b0P+jo8PDcNd3F+oPPteLex/qDPoJlyOo0LrIDBFy1G7ovxmuxWRsy82zykF/peD7/1A Lvc2oiDMgQ/evq8zpLlC0E1/laVOvbm3pZFMnsc9FLkvYLLyO4QfRxu2Lfxmtsl4MXxP 4lfRiYnbn6+Fp+3Um1sdhUB+7nTgD6++32yXIiGY5as+zZIhVn8lMCVzdoRJ5tgn2YPP haaA== X-Gm-Message-State: APjAAAUR/7O2DmV0wSr9q0scdiAUwpx/TikYxJYs3Nnj/t+gfU+IXwJI 9qaKF9INW6KMS2/CbGqdXAz8B7MN X-Google-Smtp-Source: APXvYqwd8hFjFHeIWZMZf2tJMuRrNt9YuVmMQEmung/qTBri+UbFr4ziejpMmn/ZiqWmeUdPeQNSbw== X-Received: by 2002:a2e:2b58:: with SMTP id q85mr14768159lje.179.1557775413538; Mon, 13 May 2019 12:23:33 -0700 (PDT) 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 q21sm3449365lfa.84.2019.05.13.12.23.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 12:23:32 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , "Raju P . L . S . S . S . N" , Amit Kucheria , Bjorn Andersson , Stephen Boyd , Niklas Cassel , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , Souvik Chakravarty , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Ulf Hansson Subject: [PATCH 15/18] drivers: firmware: psci: Support CPU hotplug for the hierarchical model Date: Mon, 13 May 2019 21:22:57 +0200 Message-Id: <20190513192300.653-16-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513192300.653-1-ulf.hansson@linaro.org> References: <20190513192300.653-1-ulf.hansson@linaro.org> When the hierarchical CPU topology is used and when a CPU has been put offline (hotplug), that same CPU prevents its PM domain and thus also potential master PM domains, from being powered off. This is because genpd observes the CPU's attached device as being active from a runtime PM point of view. To deal with this, let's decrease the runtime PM usage count by calling pm_runtime_put_sync_suspend() of the attached struct device when putting the CPU offline. Consequentially, we must then increase the runtime PM usage count, while putting the CPU online again. Signed-off-by: Ulf Hansson --- Changes: - Use get_logical_index() to find the CPU number. - Verify that a corresponding struct device* has been attached to the PM domain before doing runtime PM refrence counting. - Clear the domain state when the CPU goes offline, to start fresh. - Move code to internal helper functions and move them inside "ifdef CONFIG_CPU_IDLE. --- drivers/firmware/psci/psci.c | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 2c4157d3a616..5ad93c3694b5 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -93,6 +94,9 @@ static u32 psci_function_id[PSCI_FN_MAX]; static u32 psci_cpu_suspend_feature; static bool psci_system_reset2_supported; +static void psci_cpuidle_cpu_off(void); +static void psci_cpuidle_cpu_on(unsigned long cpuid); + static inline bool psci_has_ext_power_state(void) { return psci_cpu_suspend_feature & @@ -188,6 +192,8 @@ static int psci_cpu_off(u32 state) int err; u32 fn; + psci_cpuidle_cpu_off(); + fn = psci_function_id[PSCI_FN_CPU_OFF]; err = invoke_psci_fn(fn, state, 0, 0); return psci_to_linux_errno(err); @@ -200,7 +206,13 @@ static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point) fn = psci_function_id[PSCI_FN_CPU_ON]; err = invoke_psci_fn(fn, cpuid, entry_point, 0); - return psci_to_linux_errno(err); + err = psci_to_linux_errno(err); + if (err) + return err; + + psci_cpuidle_cpu_on(cpuid); + + return 0; } static int psci_migrate(unsigned long cpuid) @@ -540,8 +552,41 @@ static int __init _psci_dt_topology_init(struct device_node *np) return ret; } + +static void psci_cpuidle_cpu_off(void) +{ + struct device *dev = __this_cpu_read(psci_cpuidle_data.dev); + + /* + * Drop the runtime PM usage count if the CPU has been attached to a + * CPU PM domain. This is needed to, for example, not prevent other + * master domains in the hierarchy to remain powered on. + */ + if (dev) + pm_runtime_put_sync_suspend(dev); +} + +static void psci_cpuidle_cpu_on(unsigned long cpuid) +{ + struct device *dev; + int cpu; + + if (!psci_dt_topology) + return; + + cpu = get_logical_index(cpuid); + if (cpu < 0) + return; + + dev = per_cpu(psci_cpuidle_data.dev, cpu); + if (dev) + pm_runtime_get_sync(dev); +} + #else static inline int _psci_dt_topology_init(struct device_node *np) { return 0; } +static void psci_cpuidle_cpu_off(void) {} +static void psci_cpuidle_cpu_on(unsigned long cpuid) {} #endif static int psci_system_suspend(unsigned long unused)