From patchwork Thu Oct 10 11:39:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 175755 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2163038ill; Thu, 10 Oct 2019 04:41:51 -0700 (PDT) X-Received: by 2002:a19:700f:: with SMTP id h15mr3348786lfc.167.1570707624690; Thu, 10 Oct 2019 04:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707624; cv=none; d=google.com; s=arc-20160816; b=Ka8UeaMKpQiEeiDySTGY8GSmgVrrcZXBoVqJTdoVVMiIIPeSSviEoFOl6ft4ybfmL/ 1zSgJ/srGfjZtN8b+QcynRWXtyP44kQ/k//Hiky78q66C4fqQpDtv+C16UPsKUOkwOIh RZxpQuVtzeKvHA/J58XYZPEaqoScf/QnBGedkJWctVfG4XlX+Mz5/Z480TUiBGATyicR bbkdDx94E5khRj7gD5cl5gPA9Vn1pOLWAehzH70Tju3YXdxKdXTeOFEuQFLJERMPM9Xz CHqxe9XXjsc1os/5uPf0+/FjrM47G3A4YNNvRvq5Ds+PDDdTjKha9p4jxTan4Aja1EZH Q6rw== 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=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=wrAf/m9xQV7VMcisy/i232IdO9+p4WOlrmO1i/lkHwMQ6I+9LaZVJa+Mjx2pd0RXQ8 v6SwUIaHjaA1jhqtBiUOcfZjnVNjTIBdfeSBMdwOhy0j6OgPv1rXUFjEsx3eXBIlEN8E KcKsKaxBow80mrjwV+9e4ZtGcYQuCyvnnd+FQdXh3GIZOQfp1sREDW1kKpe8KPArXHHS a7/v3EnxTR49cPDaR+ME3rIC61CLvagz+mRdcBgVOAN88oM0cSmh5dUcxaft6oiZnauk 2MzQf22aS6jTet/aGbAsk10Z51p6A37+8OgUaohkIUGfCaJx7lEZG3KHsGuG3S6gQ6xR AReA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S1K49Am4; 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 v9sor3237800ljj.12.2019.10.10.04.40.24 for (Google Transport Security); Thu, 10 Oct 2019 04:40:24 -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=S1K49Am4; 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=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=S1K49Am4kSDehLMFo+y+aCn++SGdGyNEXyDKQRhsyEPFb1U+Qix4b9k4PUVRkwMwNo H1Drcbx+EDc2EDWjdPplZZWExubE/UfjqHL/TFs1EpwMdzjNtIKS46NPjhea/SBAVuq0 ayS5Uvhu+BLV2F9mmm/wYqmAwVyQLTTLhdmXercedrMYUeL842KegEAPuu1HoOsC5IYo wCEzh1VrCwNsmAM5iFSLdMYtQZX5h9kLTbBXKGX6RsmAHRa+SZp3SSXIEoYZ89kE7QUv Ygj6ExCVVuMj5lOyunwckLd0vQXnx7AbRGLkFUfRtC+bX6wI8fQg8yvPZKfW/oaWQgOe QXPQ== 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=i3G8ogm8QKvXwM8+rijht3ULF4gYpDZkzueQGi7751M=; b=agEsmcmoqXvKtnjCQmBt33A0YMlokMd9ACC/bwU11xNFtSqbsnUHyUUA+DrIdCJqrV 7RwY8sotxCtMIpLEZ5z3sfuYVY1IDMVCQOPbvXEwBHE1a5OAUfN4Thzoy0C7AO/zhODW vMOFWlChela3ThdT41E3+FRJ2lS34oxM2hW28kKkCo1jtgxE3dWZSO7ctXdroAdOYJHT j/P/LlVoPSsjxQqiQQAWtLV058ghJoTuVAkf1q+LIgT0pGnr6j6m8urAyUVlxKShzlSI ikmSOoE1qDcjrSj+t48hkEmKmoZUdkR6c6xCgOHnPE3S+T5/1PIlxD4z/NXx0BF55woZ nTlA== X-Gm-Message-State: APjAAAW7jfLTgfweU66CEMnIlcZKpyaDaADTmxg5ZxgfpN4ls11UmYf0 WP3g8+t77d1fZV+ORuu5fA17iQ98 X-Google-Smtp-Source: APXvYqwOX8ItiDZEA+kQQBb68Jv+sNmaYtISkfDtd1UlzUU+vXQj3Y0mD4hDx6nLR//tbqlRlepYnA== X-Received: by 2002:a2e:8310:: with SMTP id a16mr177041ljh.48.1570707624283; Thu, 10 Oct 2019 04:40:24 -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 p3sm1168937ljn.78.2019.10.10.04.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:23 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 12/13] cpuidle: psci: Manage runtime PM in the idle path Date: Thu, 10 Oct 2019 13:39:36 +0200 Message-Id: <20191010113937.15962-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> In case we have succeeded to attach a CPU to its PM domain, let's deploy runtime PM support for the corresponding attached device, to allow the CPU to be powered-managed accordingly. To set the triggering point for when runtime PM reference counting should be done, let's store the index of deepest idle state for the CPU in the per CPU struct. Then use this index to compare the selected idle state index when entering idle, as to understand whether runtime PM reference counting is needed or not. Note that, from the hierarchical point view, there may be good reasons to do runtime PM reference counting even on shallower idle states, but at this point this isn't supported, mainly due to limitations set by the generic PM domain. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 1510422c7a53..0919b40c1a85 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,7 @@ struct psci_cpuidle_data { u32 *psci_states; + u32 rpm_state_id; struct device *dev; }; @@ -50,14 +52,28 @@ static int psci_enter_idle_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int idx) { int ret; - u32 *states = __this_cpu_read(psci_cpuidle_data.psci_states); - u32 state = psci_get_domain_state(); + struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); + u32 *states = data->psci_states; + struct device *pd_dev = data->dev; + bool runtime_pm = (pd_dev && data->rpm_state_id == idx); + u32 state; + /* + * Do runtime PM if we are using the hierarchical CPU toplogy, but only + * when cpuidle have selected the deepest idle state for the CPU. + */ + if (runtime_pm) + pm_runtime_put_sync_suspend(pd_dev); + + state = psci_get_domain_state(); if (!state && idx) state = states[idx - 1]; ret = __psci_enter_idle_state(idx, state); + if (runtime_pm) + pm_runtime_get_sync(pd_dev); + /* Clear the domain state to start fresh when back from idle. */ psci_set_domain_state(0); return ret; @@ -142,6 +158,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, } data->dev = dev; + data->rpm_state_id = state_nodes; /* Idle states parsed correctly, store them in the per-cpu struct. */ data->psci_states = psci_states;