Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp7772pxt; Wed, 4 Aug 2021 04:42:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYUK/M+hPoMWAD/eJkBiCOL/QMuApncfoPzlea+BxkZoVaMTuO7hVTPaV/29/9RK/R55n2 X-Received: by 2002:a5d:8e11:: with SMTP id e17mr123512iod.138.1628077366056; Wed, 04 Aug 2021 04:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628077366; cv=none; d=google.com; s=arc-20160816; b=e3zfe6EvS7BooieRD6NPnCzLP70o32LSA2E8GGrr4r5LJxLiNzi/4Q2nXlgj5PeiUU IFdggEXhktUwzBaQ2dtislwOGDUfd8mtf45HfT5VVjSKSLahr9wwhO5A+b9XPXG3vtgT qG2ctMGYNtrRzadvg2euDz1CRjjDOaRj80HA6HZgZ909pmXaWmaGlzG3ArVbMmTr+cfT ZggbDD9b6Ro4FNL7TUxzT5r4+tQbQDimwg1a94vs5+3i6VoSVMKiOV5U9M7GGveuRQ6+ fahkp64jFa7nDSawXZ1HEbgZEDCxDwl+tIKnPjEYeK14pcjNedh5nNQGPNKPYQ9TUaK/ QUcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=N7aTfCxAKJ2/XU/on5/jv3kZr0ZUiaYr+3A3j6P4Pxo=; b=NbV9RaIs56fmHGmOaHLV2CcxOGuoNq6zA8+g21J8gG/fx/+eX7k6cIgP2EWDAz9v+U /mO7afGW2QFHedT1tm1O2qp0q1hyt6oh2GT2kA1ehiS1LB2wHf55HCenR+c6tknq5Jwv dSN9DBuAZBF5G9gmzUxasGRcnLWWBB9xlosgHojhi5lNtYSeROHYAuXxf37232Ub9n+Y RrKX8G4LqJaNPihKddxaAFlBgCmy5dvP1JgoRJFYZ4BZRcsxyvBv/M13u0mLWRYF3nQ6 xG6+Gw0OBpc16aG3JD8T1PB8fZVpNX4Cx+/tSjp+CAX+JLqCaZigB1sn2EWAXpaeMzvM la3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F58Cvd96; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r3si1953012jan.7.2021.08.04.04.42.32; Wed, 04 Aug 2021 04:42:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F58Cvd96; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237747AbhHDLkr (ORCPT + 99 others); Wed, 4 Aug 2021 07:40:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237456AbhHDLkr (ORCPT ); Wed, 4 Aug 2021 07:40:47 -0400 Received: from mail-vk1-xa2d.google.com (mail-vk1-xa2d.google.com [IPv6:2607:f8b0:4864:20::a2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B1D5C061799 for ; Wed, 4 Aug 2021 04:40:33 -0700 (PDT) Received: by mail-vk1-xa2d.google.com with SMTP id o2so382590vkb.4 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=lkE7hxtvV+oTJKDKTwFuX+El6DdKF/hXKRmRqh6+n8FaGd8ON14vas7VbdS6/cZKi+ KrleIlqcqT2v164ncB44x06WtC9GfodVciWevo/I8zobwGDXNJYzWVjax0SQ33oPRiDv uqHfbQZdnCpxUGSOdsyD6HVytFd6NHBxEx58o265Q4mC6AqyAJoS48QHJHkEOWCA2/sF rKu8Tm8ftEfvlISCDyN398CfPmKX/wVzyzW56Q8uE9u1NKt78oIiKktAtPPaNHxayaO9 OeiZZLTRMTNCEDch8t/kOr/joJaZEdbS/x8Y0NtaD54vmAQK+ux6udoQZ8wQW46vvRGX 5NRw== X-Gm-Message-State: AOAM532OEVC+cGbOtAt18RucZC7NX/weU8MQhpqkiJjd14Rx2G0KtC4/ Z1Ra2+Ub+dWj8GsYqhrZ9fAeQFZHCahJ7udL9O2LEA== 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-kernel@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