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: 12750006 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68871C433F5 for ; Thu, 17 Feb 2022 12:51:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=WMYlV2M7sq2f+xMwtwab3Nwj5yK+0+UJ5sfBhXhLyuI=; b=mGvedxoY9fzWjD UQj1mrxPeKSttm95xyQtMn3Ndw3WUTy23YaCeLPXp65BBLsAmhJ+SFdxmv2VA9LGbrjBksUZfryiE ov/jgXy8yv5sOXD8jIDeI72HyXz+7ra5jN4Csr1mL9jaUceFMzXZqMUBsHqIOvuPV3fmSSQHDQIUC Quq2X+HDvJTxGcX09D2riozMXkjVU92fT7Nx9o0IxJgMVKbqB/Tbdo8B8rqqN/NAAM7WjA8OGT9y6 Xp+xlvEQdVhP5Ju3HLi43S9MKM90q03JR2uPGSbcmVFHdAlNShntbcunKodP37mhrBwVBChxUKs8A dlcnnQGoEPjQd6qmDsEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKgEX-00AUD8-TX; Thu, 17 Feb 2022 12:50:06 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKgEU-00AUCM-9y for linux-arm-kernel@lists.infradead.org; Thu, 17 Feb 2022 12:50:03 +0000 Received: by mail-lf1-x132.google.com with SMTP id e5so9726339lfr.9 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=X4Qt5rAhud2rqvc6UH6oLo9bqU9VTtGqKe684SbuP/kejRLgfz2lS2I1B1nJn9icCQ VfogrI8U4uTfa8K7LHMpj72rnzO6ws1Y1on6TVUcfX4tj3E/eZeB2PBqTn70xYss58Av cSNxUnW7lHKawtxYG3uzlEWbAlFiNBJ0DlduqzXv7mzIZqB7YOj2lffDGzmpzsKaqttk oA8DWYg4v7tx1XTozvsjXoVo1xsK7qTqPB17xOyJCIHhuAilRRe0HdU1Xz/S5ZGWtI50 iUxvcF/3OI2Mh9UUwly/rgPDVu+QfECeEh4bs/OR9xBy5wdE+oKtmLYEjiypZMLfCg5O zYMQ== X-Gm-Message-State: AOAM530L/KQQ4yaRFtZt4Y7VVR7Bo70b221DSkmKEA2dRSGWzOZ3Pxks E/O9mqnB9UfYIJYn+zN2rVNgAg== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220217_045002_438165_5752B9DF X-CRM114-Status: GOOD ( 18.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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))