Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5045277imu; Wed, 19 Dec 2018 04:49:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/VYuIbyh3M81wQBAS/4/KrHRv5AFTNubmf9f/q1FAzwWPDA9ToiEPILlunx3hh6haRIODA+ X-Received: by 2002:a62:4b4d:: with SMTP id y74mr20178117pfa.186.1545223769173; Wed, 19 Dec 2018 04:49:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545223769; cv=none; d=google.com; s=arc-20160816; b=H2OEiKRqygNriSUHQsIvynPB45OnfSEh38fGLMY8O4cddaEROGkJgzV3l3G0s9XOxS OwKKB3klxJqlm951EZZNTjqgpvFGZ1ir7ttUYyMteujMuBAO6vU7M78V/SVaJmjvR6wv liimndFO7yvjqKbucT3RWUVRMks3LoDH/WC3ZO1SCGm2pvOf8ur6vapMDKOxQmHJmnqQ IeeJgoU/UE7aesy+YcqL5/uxCrKERYb375LBoy394JN8u5rGm8MUJknr3hR55jTp7Za5 73BCwngcic714/uR4FT0h2z4jqmB8pOa9BFT2JYPdVxUg09yZOKXzwYK3h9DFd64ZPSy cHwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=I7SDTVKItAO5FJGbZNOH6yIuLijvFxA7I0ahvnghE+w=; b=joHS21Vr+Hbkexr7n/2poju97XUF1dyuVFdvath7a3SVN1KtRnfM/r61yD4E8wFONo 9z6YQ8RAbI4K3OvZvPnGQs82jb5qPcIGOOYeA/6TcxQOfeoPGEp0oRf0U1SxUkZuDPA8 3zEJruKLS/OBmU5+ZN75W3qnINmYCxBYW8tRw4eATnmqG8olplpWV1IRZq8MP85dEG/K MtOHMd/4m9My2/n2PyX4aPwmSDuALgWOWSCqkC5DtSdyZnZaZfG/WW+ak6KW9aDpB6nx s08gtcRIbkl3/MCniOOHoTlyjV/D9nxqj/UBOJbFMpGGwUxmN24C/oknpGxGxxVTTU4u GWFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JecUyX7C; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a193si17529781pfa.214.2018.12.19.04.49.12; Wed, 19 Dec 2018 04:49:29 -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; dkim=pass header.i=@linaro.org header.s=google header.b=JecUyX7C; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729395AbeLSLsa (ORCPT + 99 others); Wed, 19 Dec 2018 06:48:30 -0500 Received: from mail-ua1-f66.google.com ([209.85.222.66]:44610 "EHLO mail-ua1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728789AbeLSLsa (ORCPT ); Wed, 19 Dec 2018 06:48:30 -0500 Received: by mail-ua1-f66.google.com with SMTP id d19so6851823uaq.11 for ; Wed, 19 Dec 2018 03:48:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=I7SDTVKItAO5FJGbZNOH6yIuLijvFxA7I0ahvnghE+w=; b=JecUyX7C/oU0T3HlZiJMGON9FAvg1DhrdnqecXiFE09+x0yoErjRuuuL76SzecvR62 TbptUyzzvMB42kDRGWOukzihmEwxSWddkYWT5F6c3wANC1rYiYcXJVVZd2cxQppYXFS6 9TGCu0nkGqdGw4X6A928dE/1zsG6vr3On3K8U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=I7SDTVKItAO5FJGbZNOH6yIuLijvFxA7I0ahvnghE+w=; b=cgAFbGsnWIgwSeOMX7/7nvTHauYHLzX5WrLOYdJk4ws3penUwgtdsA91NcuwZQ647Y qD8ibtSWhc5VJ4ceWGQHOBvx646tlP7ueOzpJ2GIRM25D3pRNmpiULzb2aJ7uWdiBPuC lcwbG1qtuYcyXxb9daLEK4ML3P4iunuajDViYKWe3F+2lIVIRg4NhRdqV1EAgrzaRqar cQWFTQQRTtLhR1BsZv6pC/R6PPhalhvWxQV1DW1JDFTZDmF8E031lkh0BRvrBbb/wgvk ye8GiGAtmHoSeywj8Q4oRAy8BxsSJB5cyzMbhBYy331KhieBTfYdLkH5vUbMOb1opSak 1uYA== X-Gm-Message-State: AA+aEWZoiCB2LmxpLIW7YkgsnGsVL00Gzsq+kq8IrAcdlj242J1lVerc 2JSiP5rnaKEOU9ksUG3JtKq2D+xbpN8C6BmEdSUk5g== X-Received: by 2002:ab0:2b0b:: with SMTP id e11mr3362455uar.77.1545220108824; Wed, 19 Dec 2018 03:48:28 -0800 (PST) MIME-Version: 1.0 References: <20181129174700.16585-1-ulf.hansson@linaro.org> <20181129174700.16585-25-ulf.hansson@linaro.org> <20181219111744.GA23393@e107981-ln.cambridge.arm.com> In-Reply-To: <20181219111744.GA23393@e107981-ln.cambridge.arm.com> From: Ulf Hansson Date: Wed, 19 Dec 2018 12:47:53 +0100 Message-ID: Subject: Re: [PATCH v10 24/27] drivers: firmware: psci: Support CPU hotplug for the hierarchical model To: Lorenzo Pieralisi Cc: "Rafael J . Wysocki" , Sudeep Holla , Mark Rutland , Daniel Lezcano , Linux PM , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , Linux ARM , linux-arm-msm , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 19 Dec 2018 at 12:17, Lorenzo Pieralisi wrote: > > 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. Any suggestions are welcome, of course. This was the best and most simple option I could come up with. Another option, could be to simply to remove the runtime PM deployment from psci_cpu_off|on() altogether and just live with that limitation for now. That works for me as well. > > 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(). Oh, didn't know that, thanks for pointing that out! > > Lorenzo > > > + pm_runtime_get_sync(dev); > > + } > > + > > return psci_to_linux_errno(err); > > } > > > > -- > > 2.17.1 > > Kind regards Uffe