From patchwork Thu Nov 29 17:46:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 152447 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2672643ljp; Thu, 29 Nov 2018 09:47:49 -0800 (PST) X-Received: by 2002:a19:cd50:: with SMTP id d77mr1610444lfg.125.1543513669367; Thu, 29 Nov 2018 09:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543513669; cv=none; d=google.com; s=arc-20160816; b=wDNvWhJ23gyK2YOC3xVq8GACZtW91MDrxqyDjalKxOKQZmyAIhqcqacaFBteHAnlgf Rueq9BbLs5gry6Nz86dSgCegZfetapCJRwNxhWCXaxYlTV3xS06e37K08qGCSeMvrnYj 63/bzI0GD1rUGDLtE2fIA9d4deqzoUC4ILleaf8oNc93fWVbycX2eNkJs3JXTrYAA0fN 9Qw+IaAz4DdusaElVHHhmgXFIXklHeWe/I1ZR5hz2Ofau2hxQcLSYFIRlXRf/Gb260L7 TNWS3dLm3atzHPI2OWvutxmPLElFFivhOsc45NzeDyDTHUQ+Sn97x0bBrpPdD6nb1mFS MkgA== 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=00sBAXywF3WZULK8cp3GDi0TaSy7ngQJNGllHojB6lk=; b=TiNTIOe/3SgKq8pK1MWd02s02zpyaDQrYrLLMiHtDmvxdxv1nSHvHkfZb9sGziqkCC /WVPgKKDltytv9TQyqj6Oh3hIEogFkf2veHO54m3f0DngxtKJ3TcW9AMxfmglaA+ukbL FLjb+wH7SUObHNrj0yzEDOtoxZc2GxZyJ7d3JbG0dZBet+pR4nx9Botn0IpNCEUBsmlR QiGF3ilyoCg+UZiUy5FJhBdifZUNmNlOslU5Vl+UmG5nMpfXAqqtqi8+1nx221wTxdxe xbMkp9KpVVPTMo8/glNDeYoRLy2CBukaV7e21o1peGYAQH8Hxbc7mec2n4npt5qq3CS8 PPQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dKE3qxiT; 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 k4-v6sor1823011ljc.11.2018.11.29.09.47.49 for (Google Transport Security); Thu, 29 Nov 2018 09:47:49 -0800 (PST) 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=dKE3qxiT; 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=00sBAXywF3WZULK8cp3GDi0TaSy7ngQJNGllHojB6lk=; b=dKE3qxiTNFTTGb5T+hiqrOqJFim4aiRChTUuNwS2xw3/dZuh9DAHSNXaDLW74AS3pg lqi8hr2A4WN5tItntkMx4nEIWt69NUtA+5ATJ2GbhiBDjsUni1YWaOPqKXDu+4lgVcZ6 8HF0CsduMwAzz1Xj7pFRsv+e/Vp0FqO7xL5UI= 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=00sBAXywF3WZULK8cp3GDi0TaSy7ngQJNGllHojB6lk=; b=dLG+57LzOhmgDg4RjA2MWdlYh2HB3/VIpS2zBfOx0KjuRH/Qw8n9O1QGe2vsyYSLKh Ll9jz0bnSHo/1vywbZ1AYSjAD2iJIG1Y5VXNRTArL78nDD/i58HF9bUF65u+taNvjp0+ 9LYq7tGTaNYZbw1hOds85Nsyp3g1o0MHpLwx7/u1wUky+CEN9Z+NLQfRwHqeQJrwJwit MOA8CG/Bcgcc7+Wfzbr2uhIN6kvAAcJUw3sCrKI3d5I3e3GPE5WSrKQ2yJNsxVppMTle qJVuYfgvUz3TSdG2f0JiQOaSXqgTvEG7DbMI0X8c3sXfIfrhAXCA7BBSHDwztTflyRem C6jg== X-Gm-Message-State: AA+aEWbiGNGKgoGfMvq9luTaL8xY2LJv7DifA5SFLhYOO5e6bdil5PzJ Ghgef+JbWW3FtyCivMEWqBICCpco X-Google-Smtp-Source: AFSGD/XFzpmZt9P+s57VsvnAF06eON+JaheyOilxYXLdRGfV6H6Nt3KWs6+j8OeMMOH0S0u5nu6hVw== X-Received: by 2002:a2e:3509:: with SMTP id z9-v6mr1668038ljz.54.1543513669095; Thu, 29 Nov 2018 09:47:49 -0800 (PST) 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 j76-v6sm393983ljb.12.2018.11.29.09.47.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 09:47:48 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , linux-pm@vger.kernel.org Cc: "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v10 23/27] drivers: firmware: psci: Manage runtime PM in the idle path for CPUs Date: Thu, 29 Nov 2018 18:46:56 +0100 Message-Id: <20181129174700.16585-24-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181129174700.16585-1-ulf.hansson@linaro.org> References: <20181129174700.16585-1-ulf.hansson@linaro.org> When the hierarchical CPU topology layout is used in DT, let's allow the CPU to be power managed through its PM domain and via runtime PM. In other words, let's deploy runtime PM support to the PSCI driver during idle management of the CPU. Signed-off-by: Ulf Hansson --- Changes in v10: - New patch: Replaces the earlier patch "kernel/cpu_pm: Manage runtime PM in the idle path for CPUs". In the end it seemed like a better idea to start with something specific to PSCI, rather than (ab?)using the generic functions cpu_pm_enter|exit(). - Do runtime PM get/put for the deepest idle state for the CPU. --- drivers/firmware/psci/psci.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 94cd0431b004..b03bccce0a5d 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -319,6 +320,7 @@ int psci_dt_parse_state_node(struct device_node *np, u32 *state) #ifdef CONFIG_CPU_IDLE static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); +static DEFINE_PER_CPU_READ_MOSTLY(u32, psci_rpm_state_id); static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, struct device_node *cpu_node, int cpu) @@ -369,6 +371,9 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, ret = psci_dt_attach_cpu(cpu); if (ret) goto free_mem; + + /* Store index of deepest state to later for runtime PM. */ + per_cpu(psci_rpm_state_id, cpu) = drv->state_count - 1; } /* Idle states parsed correctly, initialize per-cpu pointer */ @@ -466,7 +471,9 @@ int psci_cpu_suspend_enter(unsigned long index) { int ret; u32 *state = __this_cpu_read(psci_power_state); - u32 composite_state = state[index - 1] | psci_get_domain_state(); + u32 composite_state, rpm_state_id; + bool runtime_pm = false; + struct device *dev = NULL; /* * idle state index 0 corresponds to wfi, should never be called @@ -475,11 +482,29 @@ 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 (psci_dt_topology) { + rpm_state_id = __this_cpu_read(psci_rpm_state_id); + runtime_pm = rpm_state_id == index; + if (runtime_pm) { + dev = get_cpu_device(smp_processor_id()); + pm_runtime_put_sync_suspend(dev); + } + } + + composite_state = state[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);