From patchwork Tue Sep 1 08:27:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11747625 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E460138A for ; Tue, 1 Sep 2020 08:27:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 671902071B for ; Tue, 1 Sep 2020 08:27:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="yxjSKuPU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725848AbgIAI1V (ORCPT ); Tue, 1 Sep 2020 04:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbgIAI1T (ORCPT ); Tue, 1 Sep 2020 04:27:19 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C696FC061245 for ; Tue, 1 Sep 2020 01:27:18 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id v23so492473ljd.1 for ; Tue, 01 Sep 2020 01:27:18 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=+5tYnQUX16Q+heMCNRPh41Y4CeDI+HHRPCn/NIvgA2k=; b=yxjSKuPUj5jB/wd3E8BkAdEXpcwx+QYNlsPC+DlHOjFfNJIeYoAl+TOYLt71CG5nws 4wfPK6ihZGANEYge9CnzaRZHhIfU85mFZAjm5NIeQHIeTcT8xhHssr37u5c82vV3Xg6e xkaIuaf0XNj5qVPUGpCAxh1r2VKsdBceZ1rao2PrnuhOMMKML5sA/N/PePhhSTZeZpiC DvQ9ojYsgfYnm3yMYakbKCVddVBeIPTRRwTGlN6Oh7ThjJdgVYpmaZi1RKDRomNJUHSf cTUn/ZKpPJV1SIQhRuxZSJkuVw2eNdB3EoSbTyhnzkNnWaC1aYkicnw01akLplRv1s5o 85RQ== 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:mime-version:content-transfer-encoding; bh=+5tYnQUX16Q+heMCNRPh41Y4CeDI+HHRPCn/NIvgA2k=; b=LA4VLPMwOHZqxsemmzsj3uF5LyaqeXO6SU8NqB8OUnvWpksC6jDU+ZQOR2Kxfavhfp PWSfXVBbpvW32obDBCaDwc6AW/gaeUqP9Nz1PtX2kTqXN+LWa60ZNmRFMpPz1N6Xj4Ah yC/rZhR2/Jj1jdLcM0Rxavy46WzWPvQP35ZlwWNqS4a8BHrO3FnScyuSGT+/jmR18WHl QMIPQfe3LcNzF/krRfgu8AKOxuHbZMq8jbrypm6LC/ZHJRrHTbbddIFYsEvL+2Mrlkpr LGnt3xstPKhIDjOCX4hbu5r2HUFBy+A6Tb16ji2bXhQqlDnncH7L5a43X/eVB8G3g2K4 B3FA== X-Gm-Message-State: AOAM532G71PhHsM8N8K+OjFJgrQX/3lDsLoUY+El0ABVqM+v80El4ybG F/VzWU8n93BshK/7VNQQGSQt2g== X-Google-Smtp-Source: ABdhPJzBA4RJyll+BAH3x5aIMti9jSrmCxrccc4R3hcNImFw9LL9oQ7gvcPr4tUtek3iqAyzWjLKIw== X-Received: by 2002:a2e:900e:: with SMTP id h14mr438675ljg.103.1598948837167; Tue, 01 Sep 2020 01:27:17 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-79.NA.cust.bahnhof.se. [98.128.180.79]) by smtp.gmail.com with ESMTPSA id c5sm111252lfb.24.2020.09.01.01.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 01:27:16 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] PM / Domains: Enable locking for syscore devices for IRQ safe genpds Date: Tue, 1 Sep 2020 10:27:06 +0200 Message-Id: <20200901082707.106860-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200901082707.106860-1-ulf.hansson@linaro.org> References: <20200901082707.106860-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The genpd lock is currently not being used, while suspending/resuming syscore devices through genpd. This because we need to avoid using a mutex when running in the syscore phase. However, the locking can be useful under special circumstances (as shown in subsequent changes) and for a genpd having the flag GENPD_FLAG_IRQ_SAFE set. Therefore, let's make use of the lock when it's possible. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 2cb5e04cf86c..55d99a36bf6b 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1342,18 +1342,27 @@ static void genpd_complete(struct device *dev) static void genpd_syscore_switch(struct device *dev, bool suspend) { struct generic_pm_domain *genpd; + bool use_lock; genpd = dev_to_genpd_safe(dev); if (!genpd) return; + use_lock = genpd_is_irq_safe(genpd); + + if (use_lock) + genpd_lock(genpd); + if (suspend) { genpd->suspended_count++; - genpd_sync_power_off(genpd, false, 0); + genpd_sync_power_off(genpd, use_lock, 0); } else { - genpd_sync_power_on(genpd, false, 0); + genpd_sync_power_on(genpd, use_lock, 0); genpd->suspended_count--; } + + if (use_lock) + genpd_unlock(genpd); } void pm_genpd_syscore_poweroff(struct device *dev) From patchwork Tue Sep 1 08:27:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11747627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8549B14E5 for ; Tue, 1 Sep 2020 08:27:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D2E9206A5 for ; Tue, 1 Sep 2020 08:27:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zfzrThjF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725989AbgIAI1Z (ORCPT ); Tue, 1 Sep 2020 04:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbgIAI1X (ORCPT ); Tue, 1 Sep 2020 04:27:23 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC528C061244 for ; Tue, 1 Sep 2020 01:27:21 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id y4so460875ljk.8 for ; Tue, 01 Sep 2020 01:27:21 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=lXhXw6gw2mHmJ9Say6lfS63FssmiQ2xQJb+o3xFUf34=; b=zfzrThjFMwF1c1XHJi778ZPH/w59mrO8rbDIg8IHZiiE0F8rQSGJCpKFoeWGheWK96 Idd0WZeKs/qriujA6iGr594rONIcY2Pe1Y1GVVQsO4lgvEGU9+96HJPQvxRP13iXjLUj Cz0eNJgi9pyOL2kxRsm79ad9LWMkDThPn4Mcgpbd9Doky3fX2IubA6wmvKv4XemYHSLt 8FabgI94lsEGxTNuzvzvg2tuD5eGP/jQX+/pWz19CWEXnwuwMGAInYbNigJBwfNqAXkQ Y9trrilA+YtBMww71ASpqRvRfImGrLaEL+yZObCcq/97LXeMmI3a6o0LdkJx2aY4/GhX IOCw== 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:mime-version:content-transfer-encoding; bh=lXhXw6gw2mHmJ9Say6lfS63FssmiQ2xQJb+o3xFUf34=; b=UFEwsSk2Lw/YWJnuLecWYxfpE2LGmFLuPWBtcD3nk+pFYOMtHgSjVZ3Icv6uE0YVQY LcoeI0OY7E3mHlkhX13/BjVTyUXWBj8tgrsu0dyKOODvL0gGFe1kEg2dOXDA3pD6WvW3 3CPYrpQaDAbgIOye5CpbjkP2fceRiUEjk3qJufoBA2MngI9euo2ShY+SBp8DU3lzNpOW 6MGHnSxlK+P5cqPAu9NoPCNsccnE24vcDyRd/oTeKYLeT5QfhuEBcr4vuDfACpGkKw86 Q+L/yKwZOcyKks4RFGE8/65LaTvHLZ6ND+CEBJyfQoGGWVTsQvto0B8hVoxzMKkERUie Us0w== X-Gm-Message-State: AOAM533wolIyh57Pbync3oR8iHSQsWE2GfL8N/yK1EeDpx3rXpjNnRuh T1Sqx4L9f8uZ7LnZEeRAiyAjTw== X-Google-Smtp-Source: ABdhPJzVe2jkEa7XevmysGxEov7CVQX9Xjx6o7FSE+FdPUQgf+fKxVXEDSf0N3C1OuCCKppIMFQdzw== X-Received: by 2002:a05:651c:110:: with SMTP id a16mr12283ljb.152.1598948839148; Tue, 01 Sep 2020 01:27:19 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-79.NA.cust.bahnhof.se. [98.128.180.79]) by smtp.gmail.com with ESMTPSA id c5sm111252lfb.24.2020.09.01.01.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 01:27:18 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] cpuidle: psci: Enable s2idle when using OSI with the PM domain topology Date: Tue, 1 Sep 2020 10:27:07 +0200 Message-Id: <20200901082707.106860-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200901082707.106860-1-ulf.hansson@linaro.org> References: <20200901082707.106860-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org To select domain idle states for cpuidle-psci, the PM domains via genpd are being managed by using runtime PM. This works fine for the regular idle path, but it doesn't when doing s2idle. More precisely, the domain idle states becomes temporarily disabled, which is because the PM core disables runtime PM for devices during system suspend. Even if genpd tries to power off the PM domain in the suspend_noirq phase, that doesn't help to properly select a domain idle state, as this needs to be done on per CPU basis. Let's address the issue by enabling the syscore flag for the attached CPU devices. This prevents genpd from trying to power off the corresponding PM domains in the suspend_noirq phase. Moreover, let's assign a specific ->enter_s2idle() callback for the corresponding domain idle state and let it invoke pm_genpd_syscore_poweroff|poweron(), rather than using runtime PM. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 2 ++ drivers/cpuidle/cpuidle-psci.c | 30 +++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index b6e9649ab0da..65437ba5fa78 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -324,6 +324,8 @@ struct device *psci_dt_attach_cpu(int cpu) if (cpu_online(cpu)) pm_runtime_get_sync(dev); + dev_pm_syscore_device(dev, true); + return dev; } diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 74463841805f..6322d55a0a7d 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -52,8 +53,9 @@ static inline int psci_enter_state(int idx, u32 state) return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, idx, state); } -static int psci_enter_domain_idle_state(struct cpuidle_device *dev, - struct cpuidle_driver *drv, int idx) +static int __psci_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx, + bool s2idle) { struct psci_cpuidle_data *data = this_cpu_ptr(&psci_cpuidle_data); u32 *states = data->psci_states; @@ -66,7 +68,10 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return -1; /* Do runtime PM to manage a hierarchical CPU toplogy. */ - pm_runtime_put_sync_suspend(pd_dev); + if (s2idle) + pm_genpd_syscore_poweroff(pd_dev); + else + pm_runtime_put_sync_suspend(pd_dev); state = psci_get_domain_state(); if (!state) @@ -74,7 +79,10 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, ret = psci_cpu_suspend_enter(state) ? -1 : idx; - pm_runtime_get_sync(pd_dev); + if (s2idle) + pm_genpd_syscore_poweron(pd_dev); + else + pm_runtime_get_sync(pd_dev); cpu_pm_exit(); @@ -83,6 +91,19 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev, return ret; } +static int psci_enter_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int idx) +{ + return __psci_enter_domain_idle_state(dev, drv, idx, false); +} + +static int psci_enter_s2idle_domain_idle_state(struct cpuidle_device *dev, + struct cpuidle_driver *drv, + int idx) +{ + return __psci_enter_domain_idle_state(dev, drv, idx, true); +} + static int psci_idle_cpuhp_up(unsigned int cpu) { struct device *pd_dev = __this_cpu_read(psci_cpuidle_data.dev); @@ -170,6 +191,7 @@ static int psci_dt_cpu_init_topology(struct cpuidle_driver *drv, * deeper states. */ drv->states[state_count - 1].enter = psci_enter_domain_idle_state; + drv->states[state_count - 1].enter_s2idle = psci_enter_s2idle_domain_idle_state; psci_cpuidle_use_cpuhp = true; return 0;