Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4359753pxb; Tue, 25 Jan 2022 08:45:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8SkXpjL5Li4c32FgvEGnL2H/09QALSY5NtKLs6xGDD49QgGYWRqSkpJVe22BlC8Zs15oi X-Received: by 2002:a17:906:a04b:: with SMTP id bg11mr16566128ejb.339.1643129123133; Tue, 25 Jan 2022 08:45:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643129123; cv=none; d=google.com; s=arc-20160816; b=IiSp5lqMxhF9g8pckUPC7J3AI+4Vh9i0E2qRIQEMTvhw/WOIaFkPe27XvF/jVVHN/x uN4Q5hpV1rt4BoHQlBssEgbh+Dzf/6f5kkQo1esn1KpJ0J7S6DQsv/iXzkkGtw73hOHU gBakCPRHJbbRz53bnMInwD3BhIyR5Y9OkwZDYv5iQTOlqMdlGxljzECeGbmFamxUN/8b xEv7FAPS1e+q9sU0Bt9UpeTaYbk9JcsaX4VTUZ5EdaoYO+tEnaUW5ax4BMcMv5fS2rEp rShadql1O8o2ctA+0XYAyh2fuai4VDCkOcMsixhC0V6Zg/8rL+9wXoY7CZWj3Y2Jq22G 4PwA== 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=Wod5gWshu23pmO/7zcX1A3gygVLcoqtrX7j57tlK/80=; b=nqVAjNPejFyJeS66DzYRGH8jfJN3pXqTiXHPG4njPLlY99GbpCNh2tsWRC6Ps2jqto W0tBQ9Aviiiu8PYWMUWyFA7NokpexuUUg2kACTAQ3vdIKCbZULw4NHHwgz8ecdaPrzBc 3XbGA680EodPMoYGoc6kDS9PYVRnCIwO2ouk0jiZ3VwCC3MGSh5X4m0ZfLuIyklbO/td 0/TcONHHRaacAFkeK16uQUUcRad7D/Xi2t3BNT0BE6VCdCpQTyE6nNFXCDPp8Qxt1KPC 7KJAke82SQczIhmaGiIqDUA4tnSAnoJ1UxBmVHXr4XDpeH+zHpaV+7NEBeY2YzUGjNUK ZO9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rtB3ApHk; 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 go13si11783598ejc.823.2022.01.25.08.44.57; Tue, 25 Jan 2022 08:45:23 -0800 (PST) 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=rtB3ApHk; 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 S1386602AbiAYLzt (ORCPT + 99 others); Tue, 25 Jan 2022 06:55:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385897AbiAYLrh (ORCPT ); Tue, 25 Jan 2022 06:47:37 -0500 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93650C061749 for ; Tue, 25 Jan 2022 03:45:38 -0800 (PST) Received: by mail-lj1-x234.google.com with SMTP id c15so10608016ljf.11 for ; Tue, 25 Jan 2022 03:45:38 -0800 (PST) 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=Wod5gWshu23pmO/7zcX1A3gygVLcoqtrX7j57tlK/80=; b=rtB3ApHks/v1XsvTvyj4TgPQXU1wdN5rxb8uGTGOLMWmblyXHIM2xjP0mefAXnFyrZ YKGI3iIYLXGdib5TLqP1l9wE7VzSph5SF2lXLPFtNSdQhcPUKNrbu2SEuMzeEWI5VLUJ 6CjpMl8abJpCDCb8WRYnsBPyawPRGFV3oQABpCbF+rFmDJcMJc+IRFHipBjcNhesLsSf BwIgxkcPo0VyzDh+zIR8gvNqhYM0xguZf7hfxPLz5y9iPOLTpaBp5DKtmQt0j4vR07bS nGVYbl9sjdwopWwFdKfAFBrilMvRsP0DCgsNC0xd3T9GTIYLztb0xuWyFZsMsj+OVksg XOkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Wod5gWshu23pmO/7zcX1A3gygVLcoqtrX7j57tlK/80=; b=sp1zgffL46u6dUithoc6IXIM0jKIByhb+hBSl7//yQBUO5XL0I5LOFkR6b1QeSRw8h pB7BO/pZRR20HkhYPDiRsxQiyqCcKIjPc0wnTQGkwwDTLTUFi8rA24KEm6bYxzvH9px+ MsbMZ0U9EcKNwL9r4ArzpEyiZy1s1f8mJftW86jcPwboIK6w+g4lKOcJFN/TiNVkMOBJ DLSl0oohKNVwjcQFASfzX4Ex+ABbqSFLtoQRdZv9hvJvEHvZeCHcj3zfPw7hfaAbBjAd 5R23mFSsVonpPfbnan4bkbB2b65kiAaB5pY5E1hwwMaRJqiln1eWbR7d22BqppxsrOgp oXiQ== X-Gm-Message-State: AOAM533TCMmPRIvczxRvZl36La6VYeOcAsG9u1QaXUNmgqDUBBEbRnmJ hkJauo5h4870G2R8Yl77GwbLljAwx2cRM2h/m95O2AKmw8A= X-Received: by 2002:a2e:5356:: with SMTP id t22mr6955614ljd.300.1643111136879; Tue, 25 Jan 2022 03:45:36 -0800 (PST) MIME-Version: 1.0 References: <20220119085719.1357874-1-daniel.lezcano@linaro.org> <20220119085719.1357874-3-daniel.lezcano@linaro.org> <061cd428-c022-4058-9a11-c5dbe3cb9777@linaro.org> In-Reply-To: <061cd428-c022-4058-9a11-c5dbe3cb9777@linaro.org> From: Ulf Hansson Date: Tue, 25 Jan 2022 12:44:59 +0100 Message-ID: Subject: Re: [PATCH v6 2/5] powercap/drivers/dtpm: Add hierarchy creation To: Daniel Lezcano Cc: rjw@rjwysocki.net, robh@kernel.org, lukasz.luba@arm.com, heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Daniel Lezcano Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Jan 2022 at 11:46, Daniel Lezcano wrote: > > On 24/01/2022 21:00, Ulf Hansson wrote: > > On Wed, 19 Jan 2022 at 09:58, Daniel Lezcano wrote: > >> > >> The DTPM framework is available but without a way to configure it. > >> > >> This change provides a way to create a hierarchy of DTPM node where > >> the power consumption reflects the sum of the children's power > >> consumption. > >> > >> It is up to the platform to specify an array of dtpm nodes where each > >> element has a pointer to its parent, except the top most one. The type > >> of the node gives the indication of which initialization callback to > >> call. At this time, we can create a virtual node, where its purpose is > >> to be a parent in the hierarchy, and a DT node where the name > >> describes its path. > >> > >> In order to ensure a nice self-encapsulation, the DTPM subsys array > >> contains a couple of initialization functions, one to setup the DTPM > >> backend and one to initialize it up. With this approach, the DTPM > >> framework has a very few material to export. > >> > >> Signed-off-by: Daniel Lezcano > >> --- > >> drivers/powercap/Kconfig | 1 + > >> drivers/powercap/dtpm.c | 168 ++++++++++++++++++++++++++++++++++++++- > >> include/linux/dtpm.h | 15 ++++ > >> 3 files changed, 181 insertions(+), 3 deletions(-) > >> > >> diff --git a/drivers/powercap/Kconfig b/drivers/powercap/Kconfig > >> index 8242e8c5ed77..b1ca339957e3 100644 > >> --- a/drivers/powercap/Kconfig > >> +++ b/drivers/powercap/Kconfig > >> @@ -46,6 +46,7 @@ config IDLE_INJECT > >> > >> config DTPM > >> bool "Power capping for Dynamic Thermal Power Management (EXPERIMENTAL)" > >> + depends on OF > >> help > >> This enables support for the power capping for the dynamic > >> thermal power management userspace engine. > >> diff --git a/drivers/powercap/dtpm.c b/drivers/powercap/dtpm.c > >> index 0e5c93443c70..10032f7132c4 100644 > >> --- a/drivers/powercap/dtpm.c > >> +++ b/drivers/powercap/dtpm.c > >> @@ -23,6 +23,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> > >> #include "dtpm_subsys.h" > >> > >> @@ -463,14 +464,175 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent) > >> return 0; > >> } > >> > >> -static int __init init_dtpm(void) > >> +static struct dtpm *dtpm_setup_virtual(const struct dtpm_node *hierarchy, > >> + struct dtpm *parent) > >> { > >> + struct dtpm *dtpm; > >> + int ret; > >> + > >> + dtpm = kzalloc(sizeof(*dtpm), GFP_KERNEL); > >> + if (!dtpm) > >> + return ERR_PTR(-ENOMEM); > >> + dtpm_init(dtpm, NULL); > >> + > >> + ret = dtpm_register(hierarchy->name, dtpm, parent); > >> + if (ret) { > >> + pr_err("Failed to register dtpm node '%s': %d\n", > >> + hierarchy->name, ret); > >> + kfree(dtpm); > >> + return ERR_PTR(ret); > >> + } > >> + > >> + return dtpm; > >> +} > >> + > >> +static struct dtpm *dtpm_setup_dt(const struct dtpm_node *hierarchy, > >> + struct dtpm *parent) > >> +{ > >> + struct device_node *np; > >> + int i, ret; > >> + > >> + np = of_find_node_by_path(hierarchy->name); > >> + if (!np) { > >> + pr_err("Failed to find '%s'\n", hierarchy->name); > >> + return ERR_PTR(-ENXIO); > >> + } > >> + > >> + for (i = 0; i < ARRAY_SIZE(dtpm_subsys); i++) { > >> + > >> + if (!dtpm_subsys[i]->setup) > >> + continue; > >> + > >> + ret = dtpm_subsys[i]->setup(parent, np); > >> + if (ret) { > >> + pr_err("Failed to setup '%s': %d\n", dtpm_subsys[i]->name, ret); > >> + of_node_put(np); > >> + return ERR_PTR(ret); > >> + } > >> + } > >> + > >> + of_node_put(np); > >> + > >> + /* > >> + * By returning a NULL pointer, we let know the caller there > >> + * is no child for us as we are a leaf of the tree > >> + */ > >> + return NULL; > >> +} > >> + > >> +typedef struct dtpm * (*dtpm_node_callback_t)(const struct dtpm_node *, struct dtpm *); > >> + > >> +dtpm_node_callback_t dtpm_node_callback[] = { > >> + [DTPM_NODE_VIRTUAL] = dtpm_setup_virtual, > >> + [DTPM_NODE_DT] = dtpm_setup_dt, > >> +}; > >> + > >> +static int dtpm_for_each_child(const struct dtpm_node *hierarchy, > >> + const struct dtpm_node *it, struct dtpm *parent) > >> +{ > >> + struct dtpm *dtpm; > >> + int i, ret; > >> + > >> + for (i = 0; hierarchy[i].name; i++) { > >> + > >> + if (hierarchy[i].parent != it) > >> + continue; > >> + > >> + dtpm = dtpm_node_callback[hierarchy[i].type](&hierarchy[i], parent); > >> + if (!dtpm || IS_ERR(dtpm)) > > > > This can be tested with the "IS_ERR_OR_NULL()" macro. > > > >> + continue; > > > > We have discussed the error path previously. Just ignoring errors here > > and continuing with the initialization, isn't normally how we design > > good kernel code. > > > > However, you have also explained that the error path is special and > > somewhat non-trivial to manage in this case. I get that now and thanks > > for clarifying. > > > > Nevertheless, I think it deserves to be explained a bit with a comment > > in the code of what goes on here. Otherwise another developer that > > looks at this code in the future, may think it looks suspicious too. > > > >> + > >> + ret = dtpm_for_each_child(hierarchy, &hierarchy[i], dtpm); > >> + if (ret) > >> + return ret; > >> + } > >> + > >> + return 0; > >> +} > > > > [...] > > > > Other than the above, this looks good to me! > > With the above fixed, shall I add your reviewed-by ? Sure, that's fine! Kind regards Uffe