From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52621C4338F for ; Wed, 4 Aug 2021 11:40:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E8AA60EE7 for ; Wed, 4 Aug 2021 11:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237592AbhHDLkq (ORCPT ); Wed, 4 Aug 2021 07:40:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237456AbhHDLkq (ORCPT ); Wed, 4 Aug 2021 07:40:46 -0400 Received: from mail-vk1-xa2e.google.com (mail-vk1-xa2e.google.com [IPv6:2607:f8b0:4864:20::a2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9168DC06179A for ; Wed, 4 Aug 2021 04:40:33 -0700 (PDT) Received: by mail-vk1-xa2e.google.com with SMTP id j14so374724vkd.11 for ; Wed, 04 Aug 2021 04:40:33 -0700 (PDT) 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=N7aTfCxAKJ2/XU/on5/jv3kZr0ZUiaYr+3A3j6P4Pxo=; b=F58Cvd96+VeMEyWQZWIhBEZM7Vhgt/eKNvvl5M3d6yxCe4oWUtOM5+UiJ5F/4wyubz HAbgd+EExQL8lCLg0LqPWO/RE19sOT2PtiKwzNHgp2Ag5H0YXnZbS47iQz8/ARPveUf2 L1begTuBFdnQ9JaDlkFITHE1gi3CKxf8d20ob4G6hMnHLiyXzyvTGzpS13LQRZZx7bz1 XgWA86Skwuh43dTiStAjaTUC+M7VH+w6k2IlKdAGkdwL/20XNaADZ391zeWPbvBJ40pR 8dXOIu7xU889d8ai1rVE45XAPWJfjrhb2LgXCo+BsvhnxHh1F2HKZntXuY/AsHoJ77fV s71Q== 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=N7aTfCxAKJ2/XU/on5/jv3kZr0ZUiaYr+3A3j6P4Pxo=; b=FrfupWPWj1SRstNDRKA6M9D4FRqS5iVFdE63+l0ky/kBvbyiuV1CT7POjzpa5k/BhA kYQMwxTcOg81huE9qEKBcWDMcStOEuSqXZLldrBeNntT5d5b8lbgTPaf5ANTpbf54jQ5 OCh/t+tVJ8jTO28OHmxzuQsSXuR2xsTWBCiKLgqTVF9bPLBvbPTmVqSUCgeksA0dbsur 0p7DxU9zxZgtcs49FGsiMkKWD+zkif2DMEeimO+1IHsjHiEU3nYDwmrpqCY/turRWTTS jsZUtGEhg69meG3FZRx2D3D/lI2kSioXrjkuhvXPjW0/od+1yWw2STFXT9ADEOWPStX0 V5QA== X-Gm-Message-State: AOAM530zm++WbJ/yiuA9fzZSsE6DgcpkZH/mSNNN7ci0WO1pST1EqUUr yIQ8Ycv/e2+DRGMTslvcGxKiNzNGU4QersSJ/HgZSw== X-Google-Smtp-Source: ABdhPJwd7X+yAh+jm61MAYmQnQU0NWt09TvXYK9U3lvNwCskd5VyvewblGteqgYoLsoVAlGrwuIhaqntzGyE3/mMCsk= X-Received: by 2002:a1f:cf47:: with SMTP id f68mr16089473vkg.7.1628077232121; Wed, 04 Aug 2021 04:40:32 -0700 (PDT) MIME-Version: 1.0 References: <1626764876-10229-1-git-send-email-rnayak@codeaurora.org> <1626764876-10229-2-git-send-email-rnayak@codeaurora.org> <35950d34-5cab-1b09-9864-49217a83f68d@codeaurora.org> <6fe7d326-1822-5a49-cca7-df9a2739dca8@codeaurora.org> In-Reply-To: <6fe7d326-1822-5a49-cca7-df9a2739dca8@codeaurora.org> From: Ulf Hansson Date: Wed, 4 Aug 2021 13:39:55 +0200 Message-ID: Subject: Re: [PATCH v5 1/2] PM / Domains: Add support for 'required-opps' to set default perf state To: Rajendra Nayak , Viresh Kumar Cc: Bjorn Andersson , Linux PM , DTML , Linux Kernel Mailing List , linux-arm-msm , Stephen Boyd , Roja Rani Yarubandi , Stephan Gerhold Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On Wed, 4 Aug 2021 at 13:08, Rajendra Nayak wrote: > > > On 8/3/2021 10:08 AM, Rajendra Nayak wrote: > > > > On 8/2/2021 6:29 PM, Ulf Hansson wrote: > >> On Tue, 20 Jul 2021 at 09:12, Rajendra Nayak wrote: > >>> > >>> Some devices within power domains with performance states do not > >>> support DVFS, but still need to vote on a default/static state > >>> while they are active. They can express this using the 'required-opps' > >>> property in device tree, which points to the phandle of the OPP > >>> supported by the corresponding power-domains. > >>> > >>> Add support to parse this information from DT and then set the > >>> specified performance state during attach and drop it on detach. > >>> runtime suspend/resume callbacks already have logic to drop/set > >>> the vote as needed and should take care of dropping the default > >>> perf state vote on runtime suspend and restore it back on runtime > >>> resume. > >>> > >>> Signed-off-by: Rajendra Nayak > >>> --- > >>> drivers/base/power/domain.c | 28 +++++++++++++++++++++++++--- > >>> include/linux/pm_domain.h | 1 + > >>> 2 files changed, 26 insertions(+), 3 deletions(-) > >>> > >>> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > >>> index a934c67..f454031 100644 > >>> --- a/drivers/base/power/domain.c > >>> +++ b/drivers/base/power/domain.c > >>> @@ -2598,6 +2598,12 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off) > >>> > >>> dev_dbg(dev, "removing from PM domain %s\n", pd->name); > >>> > >>> + /* Drop the default performance state */ > >>> + if (dev_gpd_data(dev)->default_pstate) { > >>> + dev_pm_genpd_set_performance_state(dev, 0); > >>> + dev_gpd_data(dev)->default_pstate = 0; > >>> + } > >>> + > >>> for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) { > >>> ret = genpd_remove_device(pd, dev); > >>> if (ret != -EAGAIN) > >>> @@ -2635,9 +2641,10 @@ static void genpd_dev_pm_sync(struct device *dev) > >>> static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev, > >>> unsigned int index, bool power_on) > >>> { > >>> + struct device_node *np; > >>> struct of_phandle_args pd_args; > >>> struct generic_pm_domain *pd; > >>> - int ret; > >>> + int ret, pstate; > >>> > >>> ret = of_parse_phandle_with_args(dev->of_node, "power-domains", > >>> "#power-domain-cells", index, &pd_args); > >>> @@ -2675,10 +2682,25 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev, > >>> genpd_unlock(pd); > >>> } > >>> > >>> - if (ret) > >>> + if (ret) { > >>> genpd_remove_device(pd, dev); > >>> + return -EPROBE_DEFER; > >>> + } > >>> + > >>> + /* Set the default performance state */ > >>> + np = base_dev->of_node; > >> > >> Please use dev->of_node instead (it is set to the same of_node as > >> base_dev by the callers of __genpd_dev_pm_attach) as it's more > >> consistent with existing code. > >> > >>> + if (of_parse_phandle(np, "required-opps", index)) { > >>> + pstate = of_get_required_opp_performance_state(np, index); > >>> + if (pstate < 0) { > >>> + ret = pstate; > >>> + dev_err(dev, "failed to set required performance state for power-domain %s: %d\n", > >>> + pd->name, ret); > >>> + } > >>> + dev_pm_genpd_set_performance_state(dev, pstate); > >>> + dev_gpd_data(dev)->default_pstate = pstate; > >> > >> This doesn't look entirely correct to me. If we fail to translate a > >> required opp to a performance state, we shouldn't try to set it. > > > > yeah, that does not seem right at all :( > > > >> Perhaps it's also easier to call > >> of_get_required_opp_performance_state() unconditionally of whether a > >> "required-opps" specifier exists. If it fails with the translation, > >> then we just skip setting a default state and continue with returning > >> 1. > >> > >> Would that work? > > Looks like calling of_get_required_opp_performance_state() unconditionally > makes it spit out a pr_err() in case the node is missing "required-opps" property, > so I posted a v6 [1] with the check in place and adding the missing else > condition. I see. Viresh, would it make sense to remove that print? I mean, the required-opps property could be considered as optional and it seems a bit silly that a pre-parsing of the property is needed to figure that out. > > [1] https://lore.kernel.org/patchwork/project/lkml/list/?series=510727 Kind regards Uffe