Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp251533rdb; Thu, 30 Nov 2023 04:05:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHn2bVmlZ//ykZy5Uyr4SQVjepq2ykYeEQ/1CTrbxfHOjT0nRS382TwOc3kjq6TY2yaGDc X-Received: by 2002:a05:6a21:78a3:b0:18c:3ea9:b85d with SMTP id bf35-20020a056a2178a300b0018c3ea9b85dmr24516083pzc.11.1701345956365; Thu, 30 Nov 2023 04:05:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701345956; cv=none; d=google.com; s=arc-20160816; b=aznL4lfKZejtlJ9M/NJ7n9xxTDayr6NgypV/N584Plf+o7K+5RA8rVetuPP/h3Um0s 1radZvjQH1xK4tbXJKewQjsm71OBoC4t9ySxhd/jtKW2TxPcknO1qkobAmwUxkFpLSH1 2wR6zVTnD1L/ctR/rXzLv+4mtwKvOOLmPYrgEpxgF5xOBeH5egU/+583KfiLS934QR9c tHA6AM+LHfLQWHtBQe/Tt70JS05myOen5zrbVGPCGZ3WNbzaJ40MrR/+a42uPKsTsZtd FgZpF/y2VwnDm8sWX/NX6Kh71rvkGJjma3Gv99r42E+aMHMwuhzzvNl7wlKgqYsh5SPN MiBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=0JkNOHX7hscio9ZRHw/aSxYCq6Jivt23+Gqfn0QVubk=; fh=Z3wPM/YFZ7n0vdKT7/Mj+Z3EeKyrG6pMYmgFJqkD3lc=; b=ONBjnUaQWha/GetGPYxHBjkin3145tVUVjhGwhDLVBMH01vwYf0I5geX/XhZcQe8ld h+uVQmNauUPQ2I1W1vzrWVHQxBYEJq8Eyr4i5GlBkTh4yN+HXlisJRaQj3UMqSixeky2 JMr5rUs44G2T4EUblrjj9N20tVRfZOp5kozHgp71NMAmc3otyTMpxWJRecd2LBVFv8bY bEpi+/YoIRcIZJni3r7IpoqXt+8D2c+rkB3ou8g3a3A9yWsvWtaoaZm4h8ZBKBA2Vnz3 MQgIdwuZuFfY0gzi0vzRdjPlAZR8IIZFm7zL0akffMEb5TR+aEzxmjaYKZgWC5oSbv1S MrpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id z13-20020a6552cd000000b005aaab9e7bcfsi1215468pgp.388.2023.11.30.04.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 04:05:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D602280740E4; Thu, 30 Nov 2023 04:05:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345260AbjK3MFF (ORCPT + 99 others); Thu, 30 Nov 2023 07:05:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345206AbjK3MFD (ORCPT ); Thu, 30 Nov 2023 07:05:03 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EDBC9D46; Thu, 30 Nov 2023 04:05:09 -0800 (PST) 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 526E11042; Thu, 30 Nov 2023 04:05:56 -0800 (PST) Received: from bogus (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 791C53F5A1; Thu, 30 Nov 2023 04:05:08 -0800 (PST) Date: Thu, 30 Nov 2023 12:05:06 +0000 From: Sudeep Holla To: Sibi Sankar Cc: , , Sudeep Holla , , , , , Subject: Re: [PATCH 2/3] firmware: arm_scmi: Fix freq/power truncation in the perf protocol Message-ID: References: <20231129065748.19871-1-quic_sibis@quicinc.com> <20231129065748.19871-3-quic_sibis@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231129065748.19871-3-quic_sibis@quicinc.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 30 Nov 2023 04:05:33 -0800 (PST) On Wed, Nov 29, 2023 at 12:27:47PM +0530, Sibi Sankar wrote: > Fix frequency and power truncation seen in the performance protocol by > casting it with the correct type. > While I always remembered to handle this when reviewing the spec, seem to have forgotten when it came to handling in the implementation :(. Thanks for spotting this. However I don't like the ugly type casting. I think we can do better. Also looking at the code around the recently added level index mode, I think we can simplify things like below patch. Cristian, What do you think ? Regards, Sudeep -->8 drivers/firmware/arm_scmi/perf.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c index a648521e04a3..2e828b29efab 100644 --- a/drivers/firmware/arm_scmi/perf.c +++ b/drivers/firmware/arm_scmi/perf.c @@ -268,13 +268,14 @@ scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph, dom_info->sustained_perf_level = le32_to_cpu(attr->sustained_perf_level); if (!dom_info->sustained_freq_khz || - !dom_info->sustained_perf_level) + !dom_info->sustained_perf_level || + dom_info->level_indexing_mode) /* CPUFreq converts to kHz, hence default 1000 */ dom_info->mult_factor = 1000; else dom_info->mult_factor = - (dom_info->sustained_freq_khz * 1000) / - dom_info->sustained_perf_level; + (dom_info->sustained_freq_khz * 1000UL) + / dom_info->sustained_perf_level; strscpy(dom_info->info.name, attr->name, SCMI_SHORT_NAME_MAX_SIZE); } @@ -804,9 +805,10 @@ static int scmi_dvfs_device_opps_add(const struct scmi_protocol_handle *ph, for (idx = 0; idx < dom->opp_count; idx++) { if (!dom->level_indexing_mode) - freq = dom->opp[idx].perf * dom->mult_factor; + freq = dom->opp[idx].perf; else - freq = dom->opp[idx].indicative_freq * 1000; + freq = dom->opp[idx].indicative_freq; + freq *= dom->mult_factor; data.level = dom->opp[idx].perf; data.freq = freq; @@ -879,7 +881,7 @@ static int scmi_dvfs_freq_get(const struct scmi_protocol_handle *ph, u32 domain, return ret; if (!dom->level_indexing_mode) { - *freq = level * dom->mult_factor; + *freq = level; } else { struct scmi_opp *opp; @@ -887,8 +889,9 @@ static int scmi_dvfs_freq_get(const struct scmi_protocol_handle *ph, u32 domain, if (!opp) return -EIO; - *freq = opp->indicative_freq * 1000; + *freq = opp->indicative_freq; } + freq *= dom->mult_factor; return ret; } @@ -908,9 +911,10 @@ static int scmi_dvfs_est_power_get(const struct scmi_protocol_handle *ph, for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) { if (!dom->level_indexing_mode) - opp_freq = opp->perf * dom->mult_factor; + opp_freq = opp->perf; else - opp_freq = opp->indicative_freq * 1000; + opp_freq = opp->indicative_freq; + opp_freq *= dom->mult_factor; if (opp_freq < *freq) continue;