Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5144060imu; Wed, 19 Dec 2018 06:23:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/XNepedtIZ32ZI0j0xpWS5AUagFNqBQ6rVpcvwM7uwgRqu2Ad1j0B8TOqSV292P4Uth7e+k X-Received: by 2002:a17:902:9b93:: with SMTP id y19mr20704564plp.336.1545229402226; Wed, 19 Dec 2018 06:23:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545229402; cv=none; d=google.com; s=arc-20160816; b=eoFCZ/WgLp+Ge9aXknYryySrSld64BdScQUPIPvedGEgupBHRK4ZA6NeEdhSJZgNZE kjR3lvjnp1omXNAzfJfTmDK1O0J7w2dFKv+lyNsj6WMhA9E+G8jTm3+sp/QVWZ3LQ9l5 /EAk2tZrZ6zmQFAAHNmCiwCiLx6dy5IExmUUzIU1fh7e1JlhYNRBaNyNEir52Ty/cbh0 na1+nk1UJ3u8tE/wPt2sImqm2Q6PmgZDR49k0d/lspyOygpl13gjMiaDjvHcSqAnJobG fCjil8bxyOrzWwORQBYDUZvHa/Ou12H6br0HK2gRtns9PkBHl/paKVUvUvb7IYCvOh2r FIgw== 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=Yr73mHttrrjHNJBH/fu9m4EDdxsXbDuRrq5ixZbPFfc=; b=t7r1GYVOFaL8WDXRce8YD+oG5mmXqNckO0Q+X6Q+3TzaicPR/vM0Hn+b92ZHm+dmx6 3Jf8aZI32D0LfR6ox83tA0eaIDS5I96++NUqgMl8zpNLl2oq7dXln16zm/nFG0H51dJA WOCbhM41u65ebURrcWgNGk70RZrpyUUBigoqatnKDvfqny3XcYJGPAIgE2yrbz7oy905 TJCnzVMuaA6ZmVXP26VIQRKUFkMidMDNNFhEEaAMZ1tUbnBet1ORR9FXyGhGlW6VyosW nVT0HWe/JFo6cnLV+4z4k3enWStc0H6oa3ZB8G2c2FTVFD6NNFp1gakOjbAO0Z8ok07k jm9A== 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 d69si16459121pga.184.2018.12.19.06.23.06; Wed, 19 Dec 2018 06:23:22 -0800 (PST) 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 S1729227AbeLSLRx (ORCPT + 99 others); Wed, 19 Dec 2018 06:17:53 -0500 Received: from foss.arm.com ([217.140.101.70]:33126 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727155AbeLSLRx (ORCPT ); Wed, 19 Dec 2018 06:17:53 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9D5F8EBD; Wed, 19 Dec 2018 03:17:52 -0800 (PST) Received: from e107981-ln.cambridge.arm.com (e107981-ln.cambridge.arm.com [10.1.197.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CAC293F5C0; Wed, 19 Dec 2018 03:17:49 -0800 (PST) Date: Wed, 19 Dec 2018 11:17:44 +0000 From: Lorenzo Pieralisi To: Ulf Hansson Cc: "Rafael J . Wysocki" , Sudeep Holla , Mark Rutland , Daniel Lezcano , linux-pm@vger.kernel.org, "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 24/27] drivers: firmware: psci: Support CPU hotplug for the hierarchical model Message-ID: <20181219111744.GA23393@e107981-ln.cambridge.arm.com> References: <20181129174700.16585-1-ulf.hansson@linaro.org> <20181129174700.16585-25-ulf.hansson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181129174700.16585-25-ulf.hansson@linaro.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 29, 2018 at 06:46:57PM +0100, Ulf Hansson wrote: > 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 struct device to remain 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 CPU's struct device when putting it > offline. Consequentially, we must then increase the runtime PM usage for > the CPU, while putting it online again. > > Signed-off-by: Ulf Hansson > --- > > Changes in v10: > - Make it work when the hierarchical CPU topology is used, which may be > used both for OSI and PC mode. > - Rework the code to prevent "BUG: sleeping function called from > invalid context". > --- > drivers/firmware/psci/psci.c | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c > index b03bccce0a5d..f62c4963eb62 100644 > --- a/drivers/firmware/psci/psci.c > +++ b/drivers/firmware/psci/psci.c > @@ -15,6 +15,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -199,9 +200,20 @@ static int psci_cpu_suspend(u32 state, unsigned long entry_point) > > static int psci_cpu_off(u32 state) > { > + struct device *dev; > int err; > u32 fn; > > + /* > + * When the hierarchical CPU topology is used, decrease the runtime PM > + * usage count for the current CPU, as to allow other parts in the > + * topology to enter low power states. > + */ > + if (psci_dt_topology) { > + dev = get_cpu_device(smp_processor_id()); > + pm_runtime_put_sync_suspend(dev); > + } > + > fn = psci_function_id[PSCI_FN_CPU_OFF]; > err = invoke_psci_fn(fn, state, 0, 0); > return psci_to_linux_errno(err); > @@ -209,6 +221,7 @@ static int psci_cpu_off(u32 state) > > static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point) > { > + struct device *dev; > int err; > u32 fn; > > @@ -216,6 +229,13 @@ static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point) > err = invoke_psci_fn(fn, cpuid, entry_point, 0); > /* Clear the domain state to start fresh. */ > psci_set_domain_state(0); > + > + /* Increase runtime PM usage count if the hierarchical CPU toplogy. */ > + if (!err && psci_dt_topology) { > + dev = get_cpu_device(cpuid); I do not like adding this code in the cpu_{on/off} method themselves, I will have a look at the patchset as whole to see how we can restructure it. More to the point, using cpuid as a logical cpu id is wrong, it is a physical id that you should convert to a logical id through get_logical_index(). Lorenzo > + pm_runtime_get_sync(dev); > + } > + > return psci_to_linux_errno(err); > } > > -- > 2.17.1 >