Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp278847rdb; Thu, 30 Nov 2023 04:50:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IE28wSB+NFvSXOxgmbtjJP7OJYbACHotYKDU0YkoYBf1cIajoSlYm2pcbD2jLNcknUipXGe X-Received: by 2002:a05:6808:13c2:b0:3ab:8431:8037 with SMTP id d2-20020a05680813c200b003ab84318037mr30441295oiw.32.1701348613745; Thu, 30 Nov 2023 04:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701348613; cv=none; d=google.com; s=arc-20160816; b=oW+X+LPVODkJruRneJzRSzrctulY8gbeITfa1SbWa3+zu4xIpTNM3s+O7lwtG+R7QX M/W3Y7siG18hJDPD4WB8zE1ZmtwSiZvH9f0cAWHVzJPrIdEtp+lphI967lSBdUIfpGWy a8TEgGMd/zluB2OrZLB3KaHf8+HutmWLKgrkZsSTXxubu6KThx02MyGdhIIYaa+rrPzX e3tYTgNNtQKVPt0uv/6FQBAe6kxzsmILvsjqZKj87rtal5lj5sOmESq4UUA9pN4Hw6a1 Sv3Y7rSTXVTYP6zNyZeoJnV3xG4OL+uo7Msb83fB1SFWAVRqlwd2/v/Rs8UQiE/NsP+5 HVXw== 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=Cn1g8rjmhMe/z787oZpiHxGqiV3zvyH7q4Os6K0v3Cw=; fh=eklqjAdhlKrrw5/bFT/WuYGvpfp2EHXDxAHVuR+/XKk=; b=WKS1oDpWQvtZ6e67Su14d8IpTrFzovK+ExgY/zN4a7ro+aSxCF9ydKRY0SRE0Z2W0d 0CDQdfR8ldQXXUZ/mUVkQjfdboagEf4/a6OtOI3sHLfTaJ0Er922ZdS/9rU69BvDfkyr 7H/32lUFVd+oxaMPpgxjy13SHDkoacb9TXymw5Am+fwWaueBhGOhh5FkCHrqiLth3SPm fbCeNpxYT6uuz4sRw3wD2Il9Tv4DlVQM+HutDj6J6//3YXElmyICnbs5zgjrVeoegan7 qGHSAeB+b/cy390VkUe6K+bZ9jEJKNV8J5lujStPmSFvq4ojgPFK3twGTBn3MPDGr9b0 YMFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s19-20020a056a0008d300b006cc096fa2d6si1218033pfu.70.2023.11.30.04.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 04:50:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 05238802EED8; Thu, 30 Nov 2023 04:49:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345402AbjK3Mtm (ORCPT + 99 others); Thu, 30 Nov 2023 07:49:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232054AbjK3Mtk (ORCPT ); Thu, 30 Nov 2023 07:49:40 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1127410C2; Thu, 30 Nov 2023 04:49:47 -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 621951042; Thu, 30 Nov 2023 04:50:33 -0800 (PST) Received: from pluto (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 023373F5A1; Thu, 30 Nov 2023 04:49:44 -0800 (PST) Date: Thu, 30 Nov 2023 12:49:42 +0000 From: Cristian Marussi To: Sudeep Holla Cc: Sibi Sankar , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, quic_mdtipton@quicinc.com, linux-arm-kernel@lists.infradead.org, quic_asartor@quicinc.com, quic_lingutla@quicinc.com 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: 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 04:49:58 -0800 (PST) On Thu, Nov 30, 2023 at 12:05:06PM +0000, Sudeep Holla wrote: > 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 ? > Hi the cleanup seems nice in general to compact the mult_factor multipliers in one place, and regarding addressing the problem of truncation without the need of the explicit casting, should not be enough to change to additionally also change mult_factor to be an u64 ? Not tested so I could miss something... Thanks, Cristian > 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; >