Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1048657ybi; Tue, 16 Jul 2019 08:54:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOAzbThQBM/M05V7jj1MYu1YKrXZ9T8fvnDQJlhMs2HUtZ6CN2FY/uu5PnPpxbp1GTYaYr X-Received: by 2002:a17:902:b68f:: with SMTP id c15mr37014208pls.104.1563292478663; Tue, 16 Jul 2019 08:54:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563292478; cv=none; d=google.com; s=arc-20160816; b=cMS9cox2ehmc5l6K4oifxAFda1P1wVy/x6v6r+yCWiV84m/u+1mQ0A1dcMK9lL8H0W +bYDlBfRt1CBYRgZG1rHB9uXKeSbXwUweO2C0YviT0TJ3OeuqAveMUJ9myvN3QndFVZB GnoS1aCR4h1Dv2ou1jVzHBcfWIO/2pGwLyUaEDMz9OLWYpO7y9MF4JU6dogk8+DgA6cl V33SyNy3mPiUpfKuim/BTKUKgsBKIidYjnFK9OCwqrJDllEBtfHktuyqTDwriipHu0c2 wO/RGm9z8TmspCEEDfnAzydiIHjrK31f77FEYj1i7RBcZHaoDu7OtKfCp+BvrGMs1227 NpPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=N7xfYGXOQ/Mx+kP/gcD7iazB/HzN6NBoFaz32rUKYkg=; b=fnWdiAZn3Yf4lJWkZEF1dLkMOn12E1ckRPXYZMqVhH3fwgz+qgY52/ov7bcXxvDtNI 5Tz+sR8d4oK0fcWjM8qCymgPACPZwjBQZ2ZZIngQLwRZ0WyQn+5f58EeMXR8XBUK8zqV ZKz3SAm8QXHYOBV7h2jV8CjTXDSQDHryl11c95ZtemJgdkhNQV0FtmO+Q0WexQ0ie6sc e1hytE1ohBJIwiQtYgaah2YhOK8brXeuFq4PVs2FIMfJJy0s3gd5W7DoFYGqhDTTQh4y 4jO8ztvc7oRwHPajEAlmtsRoZezhsFg4jq4YvGmu4MFIhsnjwf1wd+2QfCCG1GJAdo8Y 2cqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si19288542plq.157.2019.07.16.08.54.22; Tue, 16 Jul 2019 08:54:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388110AbfGPPxY (ORCPT + 99 others); Tue, 16 Jul 2019 11:53:24 -0400 Received: from foss.arm.com ([217.140.110.172]:37024 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728573AbfGPPxY (ORCPT ); Tue, 16 Jul 2019 11:53:24 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D041B337; Tue, 16 Jul 2019 08:53:22 -0700 (PDT) Received: from e121166-lin.cambridge.arm.com (unknown [10.1.196.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 432013F71A; Tue, 16 Jul 2019 08:53:20 -0700 (PDT) Date: Tue, 16 Jul 2019 16:53:17 +0100 From: Lorenzo Pieralisi To: Ulf Hansson Cc: Sudeep Holla , Mark Rutland , linux-arm-kernel@lists.infradead.org, "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 Subject: Re: [PATCH 14/18] drivers: firmware: psci: Manage runtime PM in the idle path for CPUs Message-ID: <20190716155317.GB32490@e121166-lin.cambridge.arm.com> References: <20190513192300.653-1-ulf.hansson@linaro.org> <20190513192300.653-15-ulf.hansson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190513192300.653-15-ulf.hansson@linaro.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 13, 2019 at 09:22:56PM +0200, Ulf Hansson wrote: > When the hierarchical CPU topology layout is used in DT, let's allow the > CPU to be power managed through its PM domain, via deploying runtime PM > support. > > To know for which idle states runtime PM reference counting is needed, > let's store the index of deepest idle state for the CPU, in a per CPU > variable. This allows psci_cpu_suspend_enter() to compare this index with > the requested idle state index and then act accordingly. I do not see why a system with two CPU CPUidle states, say CPU retention and CPU shutdown, should not be calling runtime PM on CPU retention entry. The question then is what cluster/package/system states are allowed for a given CPU idle state, to understand what idle states can be actually entered at any hierarchy level given the choice made for the CPU idle state. In the case above, a CPU entering retention state should prevent runtime PM selecting a cluster shutdown state; most likely firmware would demote the request to cluster retention but still, we should find a way to describe these dependencies. Thanks, Lorenzo > Signed-off-by: Ulf Hansson > --- > > Changes: > - Simplify the code by using the new per CPU struct, that stores the > needed struct device*. > > --- > drivers/firmware/psci/psci.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c > index 54e23d4ed0ea..2c4157d3a616 100644 > --- a/drivers/firmware/psci/psci.c > +++ b/drivers/firmware/psci/psci.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -298,6 +299,7 @@ static int __init psci_features(u32 psci_func_id) > > struct psci_cpuidle_data { > u32 *psci_states; > + u32 rpm_state_id; > struct device *dev; > }; > > @@ -385,6 +387,7 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, > goto free_mem; > > data->dev = dev; > + data->rpm_state_id = drv->state_count - 1; > } > > /* Idle states parsed correctly, store them in the per-cpu struct. */ > @@ -481,8 +484,11 @@ static int psci_suspend_finisher(unsigned long index) > int psci_cpu_suspend_enter(unsigned long index) > { > int ret; > - u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states); > - u32 composite_state = state[index - 1] | psci_get_domain_state(); > + struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); > + u32 *states = data->psci_states; > + struct device *dev = data->dev; > + bool runtime_pm = (dev && data->rpm_state_id == index); > + u32 composite_state; > > /* > * idle state index 0 corresponds to wfi, should never be called > @@ -491,11 +497,23 @@ int psci_cpu_suspend_enter(unsigned long index) > if (WARN_ON_ONCE(!index)) > return -EINVAL; > > + /* > + * 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(dev); > + > + composite_state = states[index - 1] | psci_get_domain_state(); > + > if (!psci_power_state_loses_context(composite_state)) > ret = psci_ops.cpu_suspend(composite_state, 0); > else > ret = cpu_suspend(index, psci_suspend_finisher); > > + if (runtime_pm) > + pm_runtime_get_sync(dev); > + > /* Clear the domain state to start fresh when back from idle. */ > psci_set_domain_state(0); > > -- > 2.17.1 >