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 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 B8F92ECAAD5 for ; Mon, 5 Sep 2022 10:17:55 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=J3TFNDS2dx6poYr1j44FqtkGB0fS6jXeKuJQvlKks04=; b=FDRcFpM/NL+9sb lVJGQKywbnHbjROFwtp2hxewbHMr0+70bZux3nZqzwXOv3UqcwNo2eO40ghG0PQWITCOPqCmCmPil uqxAItAbBzfjX0+aZydIY9awwegTEmjjk+xa/iMpjVJ/JpSeoZw965JOaC8Wu//vKQ2pwdNOHMDJw fuOs+k99bVHhOZk/BGVnUOPGx7Znxc8qZbghBhjZ623HXSW0XjHJaBnqwbpIfxBhI8g42pEP2SiHB ZFhV04nzVlk4TXCoP2TE+wFH9r9p5dnMBpSdBJDcc+Ms14I86xsqJl8AFI6Z7sqbNYzOJYJ9oLRtF yy3JOmWFgMM1jdHmzlGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oV99U-00Hb4G-59; Mon, 05 Sep 2022 10:16:24 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oV7jk-00Eu2q-2r for linux-arm-kernel@lists.infradead.org; Mon, 05 Sep 2022 08:46:32 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0A44CED1; Mon, 5 Sep 2022 01:45:44 -0700 (PDT) Received: from [10.57.17.6] (unknown [10.57.17.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B93A73F534; Mon, 5 Sep 2022 01:45:34 -0700 (PDT) Message-ID: <31b205ad-6ce9-df41-85fc-d8fee8e26f20@arm.com> Date: Mon, 5 Sep 2022 09:45:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 1/3] powercap: arm_scmi: Add SCMI Powercap based driver Content-Language: en-US To: Cristian Marussi Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@huawei.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, daniel.lezcano@linaro.org, tarek.el-sherbiny@arm.com, adrian.slatineanu@arm.com, souvik.chakravarty@arm.com, wleavitt@marvell.com, wbartczak@marvell.com, dan.carpenter@oracle.com, "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org References: <20220817105424.3124006-1-cristian.marussi@arm.com> <20220817105424.3124006-2-cristian.marussi@arm.com> <9ee42d60-1bdd-c1e8-ec6e-38d0e1fcf4d8@arm.com> From: Lukasz Luba In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220905_014558_151715_562D58DB X-CRM114-Status: GOOD ( 41.28 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 9/4/22 16:41, Cristian Marussi wrote: > On Tue, Aug 30, 2022 at 02:16:42PM +0100, Lukasz Luba wrote: >> Hi Cristian, >> > > Hi Lukasz, > [snip] >>> +static int scmi_powercap_get_max_power_range_uw(struct powercap_zone *pz, >>> + u64 *max_power_range_uw) >>> +{ >>> + *max_power_range_uw = U32_MAX; >> >> Shouldn't be calculated based on pai info from the platform FW? >> e.g. >> *max_power_range_uw = spz->info->max_power_cap - spz->info->min_power_cap >> >> (but with uW conversion in mind if needed) >> > > I double checked this and in include/linux/powercap.h these > powercap_zone_ops are defined as: > > * @get_max_power_range_uw: Get maximum range of power counter in > * micro-watts. > * @get_power_uw: Get current power counter in micro-watts. > > so these are really data related to average power consumed, i.e. in SCMI > parlance, info counters I can retrieve for a powercapping domain with > POWERCAP_MEASUREMENTS_GET, which returns a uint32 representing the > "average power consumption of the powercapping domain in the last PAI" > > It seemed to me that this was unrelated to min/max powercap but more > something used to report actual powercap domain consumption, so I use > UINT32_MAX to represent the max range...on the other side in Linux these > powercap ops may seem more to expect to report a sort of progressive > accumulated comsuption value while I can only expose the average consumption > as calculated and reported by fw across the last PAI. (SCMI 4.10.3.10) > > Looking again at this, I'm not sure really if this is ok for the powercap > Linux framework or should I instead try to keep a running accumulated value > inside this driver (built from the values I get from > POWERCAP_MEASUREMENTS_GET) and expose that.... > > ... so thanks for pointing this out because it triggered more doubts :D > ...any hint about this welcome. I recalled this code in DTPM [1]. Although, I have checked the documentation of Powercap sysfs for this file [2]. This 'range' for power (or energy) describes the values for related: 'power_uw' or 'energy_uj'. Which means the 'power_uw' value can be actually lower that setting in 'min_power_cap' (e.g. due to lightly loaded CPU). I'm not sure for the upper bound: 'max_power_cap'. In real world we can get a power spike which is bigger than that, so probably your original U32_MAX is OK. Therefore, probably the DTPM [1] could be adjusted not your aproach. [snip] >>> + for (i = 0, spz = pr->spzones; i < pr->num_zones; i++, spz++) { >>> + /* >>> + * Powercap domains are validate by the protocol layer, i.e. >>> + * when only non-NULL domains are returned here, whose >>> + * parent_id is assured to point to another valid domain. >>> + */ >>> + spz->info = powercap_ops->info_get(ph, i); >>> + >>> + spz->dev = dev; >>> + spz->ph = ph; >>> + spz->spzones = pr->spzones; >>> + INIT_LIST_HEAD(&spz->node); >>> + INIT_LIST_HEAD(&pr->registered_zones[i]); >>> + >>> + /* >>> + * Forcibly skip powercap domains using an abstract scale. >>> + * Note that only leaves domains can be skipped, so this could >>> + * lead later to a global failure. >>> + */ >>> + if (!spz->info->powercap_scale_uw && >>> + !spz->info->powercap_scale_mw) { >>> + dev_warn(dev, >>> + "Abstract power scale not supported. Skip %s.\n", >>> + spz->info->name); >>> + spz->info = NULL; >>> + continue; >>> + } >> >> We can say that the power scale should be consistent in >> a platform. Then we can bail out when abstract scale has >> been found. This could also simplify code by a bit. >> > > I do NOT agree on this since I do NOT think from the SCMI spec we can > assume this semplification: Linux powercap has indeed this limitation on > scales BUT other non-Linux agents could indeed support abstract scales and > the SCMI server could advertise a well built hierarchy of powercap domains > including some abstract scale ones tha, if placed as leaves of the hierarchy, > could be ignored by Linux but used instead by other agents...or in the future > used by Linux too ? This diversity makes me a headache ;) I would hope the SCMI spec would restrict the span of variety. Although, I cannot find in the spec that all powercap domains must use the same power scale... It looks like, you will have to implement it this way. > > I'll double check with Archs since I had already an internal exchange on > this and seemed to me that the current approach (of only bailing out when > non-leaves abstract scale domains are found) was fine, i.e. that I could > not just assume to receive only uw/mv scale domains. > >> Can we also validate here some those lines, which are >> checked in many callback funcitons? >> > > Partially yes....see below... > >> These are the lines, which could be then removed if we bail >> out here earlier: >> if (!spz->info) >> return -ENODEV; > > I can remove this surely from everywhere since I really never register a > zone with NULL spx->info, this check all-around, my bad, is redundant. > >> if (!spz->info->powercap_pai_config) >> return -EINVAL; >> if (!spz->info->powercap_monitoring) >> return -EINVAL; >> > > Instead I cannot see why a powercap domain missing this capabilities > (PAI configuration and power consumption monitoring) should be > excluded as a whole...for this reason (if valid from the scale > perspective as said above) I currently register these powercap SCMI > zones even if lacking these supports and then return -EINVAL only for > the related Powercap unsupported callbacks...while still supporting as > an example setting min/max powercaps. It's a bit more complicated than I thought. We cannot simplify too much and make weak assumption. You're right, please keep your approach. [1] https://elixir.bootlin.com/linux/latest/source/drivers/powercap/dtpm.c#L54 [2] https://elixir.bootlin.com/linux/latest/source/Documentation/power/powercap/powercap.rst#L206 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel