From patchwork Thu Feb 17 12:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 543590 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0642AC433EF for ; Thu, 17 Feb 2022 12:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240549AbiBQMuY (ORCPT ); Thu, 17 Feb 2022 07:50:24 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:55588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240545AbiBQMuP (ORCPT ); Thu, 17 Feb 2022 07:50:15 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E275B2A8D38 for ; Thu, 17 Feb 2022 04:50:00 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id b11so9718766lfb.12 for ; Thu, 17 Feb 2022 04:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KlbNkhTQ+JSJKTYaDJQdA6zDHlk4vRYEdRPsoVx8JIQ=; b=RJRTgcanFd+eYKC4PMy5E0XR6182Cq2/81omogO1Ye2RHCRnwZhXxRU7nmB+QcQ7Yo KfDKHK0lAjHiQycNkeabsFl/Twov5I/ktbWPBDANLnS2zOStQaOpEbd1O1TU9COmbXP1 GreyjpJc0J56h41Ykhk0K17BOXfRUAFQT2eAA5KdBUfs05QT1B2HQ1ygKyVbJ9/9y/U7 cxl/5tVYCIv6XV3jAPHJAU/EW5dnON50ZLMM1c4uNehw71p7GbRh3jI1rEUUDoAYiH8Y LXnMC9YzHrHSaC7la+CqDN020i78xjUsHBndmk9xfiU2TxHglUOliqwSoJsRlvD2gZF2 6ftw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KlbNkhTQ+JSJKTYaDJQdA6zDHlk4vRYEdRPsoVx8JIQ=; b=3o+9zy9weisCvkl4AX0sxWWnV5zhMCaBiUDwGSxk6I8WBvPMR0j0pKdg6U+hln57Vo H1rkyU3cTWcVr7yjvEf2FKcdoFadvN+Waa15LSV+fdpHjHNFVs03f6duMRPKJdu8VAtm Gc7FeDHa6LAEbLodYt3s5UoQjRZwq3cCC1SKZTAqmRoz/cwWLSZDaNAMZxc5bOjFmvzQ v+jpg3bJuthRKQHQKHp7um1Gt8uxwUxLTm2+Fsr+ZBqaTc7cnLWu8ztN9M+2x6mXWIal 0+IChFp/3ia+oFh4yIRK4nrtpm4pIQiLALBsL1N5OtD+ztx5zse6oLIuyDeJjY4XT0NZ hpIQ== X-Gm-Message-State: AOAM5315nmFtsas99DV77PLDp2otmGrEASMBY8SMi1DCx0yaIAKaVnuU qKH1bEN8aLvXRDpgpqmTeSRL/A== X-Google-Smtp-Source: ABdhPJzcmJ+l4mFBjZY1/rS9B+sgadxfC1rTyFWFVI0vf+IQ2g6MOXACNGdIQZNWEOgWTuA9h0OMPQ== X-Received: by 2002:a05:6512:400c:b0:442:c12d:7755 with SMTP id br12-20020a056512400c00b00442c12d7755mr1875995lfb.403.1645102199245; Thu, 17 Feb 2022 04:49:59 -0800 (PST) Received: from localhost.localdomain (h-155-4-129-21.NA.cust.bahnhof.se. [155.4.129.21]) by smtp.gmail.com with ESMTPSA id p21sm5167094lja.32.2022.02.17.04.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 04:49:58 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Kevin Hilman , Alexandre Torgue , Geert Uytterhoeven , Dmitry Osipenko , Rajendra Nayak , Dong Aisheng , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] PM: domains: Prevent power off for parent unless child is in deepest state Date: Thu, 17 Feb 2022 13:49:50 +0100 Message-Id: <20220217124950.211354-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org A PM domain managed by genpd may support multiple idlestates (power-off states). During genpd_power_off() a genpd governor may be asked to select one of the idlestates based upon the dev PM QoS constraints, for example. However, there is a problem with the behaviour around this in genpd. More precisely, a parent-domain is allowed to be powered off, no matter of what idlestate that has been selected for the child-domain. For the stm32mp1 platform from STMicro, this behaviour doesn't play well. Instead, the parent-domain must not be powered off, unless the deepest idlestate has been selected for the child-domain. As the current behaviour in genpd is quite questionable anyway, let's simply change it into what is needed by the stm32mp1 platform. If it surprisingly turns out that other platforms may need a different behaviour from genpd, then we will have to revisit this to find a way to make it configurable. Signed-off-by: Ulf Hansson Reviewed-by: Dmitry Osipenko --- Changes in v2: - Clarified commit message - based upon discussions with Dmitry. - Updated a comment in the code, suggested by Dmitry. --- drivers/base/power/domain.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5db704f02e71..c87588c21700 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -636,6 +636,18 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, atomic_read(&genpd->sd_count) > 0) return -EBUSY; + /* + * The children must be in their deepest (powered-off) states to allow + * the parent to be powered off. Note that, there's no need for + * additional locking, as powering on a child, requires the parent's + * lock to be acquired first. + */ + list_for_each_entry(link, &genpd->parent_links, parent_node) { + struct generic_pm_domain *child = link->child; + if (child->state_idx < child->state_count - 1) + return -EBUSY; + } + list_for_each_entry(pdd, &genpd->dev_list, list_node) { enum pm_qos_flags_status stat; @@ -1073,6 +1085,13 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, || atomic_read(&genpd->sd_count) > 0) return; + /* Check that the children are in their deepest (powered-off) state. */ + list_for_each_entry(link, &genpd->parent_links, parent_node) { + struct generic_pm_domain *child = link->child; + if (child->state_idx < child->state_count - 1) + return; + } + /* Choose the deepest state when suspending */ genpd->state_idx = genpd->state_count - 1; if (_genpd_power_off(genpd, false))