From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C24123B0 for ; Fri, 24 Jan 2025 10:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737715916; cv=none; b=F8IuURBwnrNSMCVWfGWe3YZhCVnJZ7XJvX2qbLyaN4IKi+nleqU5+lvXmUjjno+P5bHszTHPOs44GJBEVynDnrWXfPDUcZYiyOYPUUcNBrxncRhGzfdrZzyhxsij47gB50SrEe8uur+VisELaG/Pwy7LUn50pzPZVzSxuK+mCaA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737715916; c=relaxed/simple; bh=B/1l3tdtCZ9PRYzReDHc6UkLBAY6SnrhKfJIycn3/Gk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s6cvnBBmvJ3u3cksLdHIjyFwue69HMLTdHS6u40JNQ44L9oR+CJnffHaH4BnKkh0MWAa0GsS8qqjBfm8q5Pp0tColz8rSiuHNzFXDR0ktxVdz88DpbBv5UViVoSygQRs08xu5hWkcbbPX5/L6crc89F65a8avTW/g66xBtxCMZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=DAm09OYU; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DAm09OYU" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3862ca8e0bbso1769278f8f.0 for ; Fri, 24 Jan 2025 02:51:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737715911; x=1738320711; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=tGTlLozxCo1nf43/X/aagzssis+Atz8YpkZYRRrzAY0=; b=DAm09OYUCJHkxonVXjZalcz4Xfmevxg5Zqdd/kDgJiSewZk0pNGS1IbP8eJB6eJ4Ma O1hHqlFwuq2Qvix0WsrUozye7A66428W2sKreu9KbB1FlRbwI+2zT+vauhd/V+nzT9Un nEY+rQkcxiNL4J179N7U1U48CuPqTsQ6mAAbzNIwzldnar0zWrWt3q7wMP/AFwGERHcl p8Q3f7NjNLpwVg/ca08EAEXt98gXXWTdYssTNeP5rItQzWOtk3mC/IzO3lzhl4zGVqNg R9/S2ylg3PtjeoFNGMW929K10yFPuS7/nliMPEvQrnxyDU/7ZuhYt2Q0rF7itsMv0HiR 5LKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737715911; x=1738320711; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tGTlLozxCo1nf43/X/aagzssis+Atz8YpkZYRRrzAY0=; b=xA6KAf8aVySh440Gk5lV3IJC/Wh3HlcZ0bBZwJPfO0WVvL1nBpXACEocZWEqfovter iQTQdj0fSjb2DCPGKr15pn2LzhZi+o9nL787TgE4vwcSqhJv8D+eqRsFGPmN/cQpX84d G5QcC+2izu7KVnuYp9gxjVtqtkDjCKmHOySAIcJg5MbbNl2g1kOAqSphprP005C99Fv2 44YwYZao2XwiPpxhyKkaNRiuqPk+2p9u2VxZUsIJKXAx7CW3MdqDCiPx8YERvm+gwcBC cneENNdjiImo5XsXgVDYmcuvmtb2eIMrs6tYQkcleR6wiAgFGsflBefk4t029cB3LNYo a7Aw== X-Forwarded-Encrypted: i=1; AJvYcCXR6prnWFZrHdOm/6apTvpL92xwg/N5vsWvgpinW0AHfQE6euwrcfrhUeU0gblMErk8qcWe3p7E7oVYtBs=@vger.kernel.org X-Gm-Message-State: AOJu0Yzqm+Wi4rByvlinHqi+SjV8Gak85FcclOpL/nnH0bgEgyNY7ZxW sPzkM6mxQHN5vLAM5mBmda7eBSPcIRZQTQM/6E2tIGfRGGMPFd/P7G87JRqIuEk= X-Gm-Gg: ASbGncu92TAmWXXoAWVnMS+NPtN/J/k4gWL/XvezLgqF/YaKOTLHoL8PN+GJTBaeOvB lZpGvYMdBGFxX1CR930dn8tKv9ijZK0wPFgpBdgfCgXDbHbsRHE6LFshtBXlTcS6gM8AR2/y9sI GN5eWenoHKZbXksmSG3cZoA4Jy16X6fbVqm3tvpJC6hXMArJGYgN6hbikuW1Ly7kziuVexzBa9f ebojT8FXli76QZZ71AQMAcno4IaStlV7GIiykW7eCsJBovVFkduCO4l/zhXhrChL3jUyDc1vaIC rkBAdqcGdA== X-Google-Smtp-Source: AGHT+IFYQo9jNiHBgOR8bRaxcWjkfxh6Y7QIEImm5C6fb5pC+YqVIPsrpJEhp0PabuCFZK+cqqd41g== X-Received: by 2002:a05:6000:2a6:b0:385:eb7c:5d0f with SMTP id ffacd0b85a97d-38bf566a239mr28879962f8f.26.1737715909296; Fri, 24 Jan 2025 02:51:49 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1c418esm2332243f8f.95.2025.01.24.02.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 02:51:48 -0800 (PST) Date: Fri, 24 Jan 2025 13:51:44 +0300 From: Dan Carpenter To: zuoqian Cc: Sudeep Holla , Ionela Voinescu , "rafael@kernel.org" , "viresh.kumar@linaro.org" , "cristian.marussi@arm.com" , "arm-scmi@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-pm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] cpufreq: scpi: compare against frequency instead of rate Message-ID: References: <20250123075321.4442-1-zuoqian113@gmail.com> <8ebf8f26-c3d9-43c0-b417-ce3131a84eb4@stanley.mountain> <6793606d.050a0220.a73fe.0803@mx.google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6793606d.050a0220.a73fe.0803@mx.google.com> On Fri, Jan 24, 2025 at 09:42:01AM +0000, zuoqian wrote: > On Thu, Jan 23, 2025 at 04:04:13PM +0300, Dan Carpenter wrote: > > On Thu, Jan 23, 2025 at 12:16:50PM +0000, Sudeep Holla wrote: > > > (for some reason I don't have the original email) > > > > > > On Thu, Jan 23, 2025 at 02:12:14PM +0300, Dan Carpenter wrote: > > > > On Thu, Jan 23, 2025 at 07:53:20AM +0000, zuoqian wrote: > > > > > The CPU rate from clk_get_rate() may not be divisible by 1000 > > > > > (e.g., 133333333). But the rate calculated from frequency is always > > > > > divisible by 1000 (e.g., 133333000). > > > > > Comparing the rate causes a warning during CPU scaling: > > > > > "cpufreq: __target_index: Failed to change cpu frequency: -5". > > > > > When we choose to compare frequency here, the issue does not occur. > > > > > > > > > > Signed-off-by: zuoqian > > > > > --- > > > > > drivers/cpufreq/scpi-cpufreq.c | 5 +++-- > > > > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c > > > > > index cd89c1b9832c..3bff4bb5ab4a 100644 > > > > > --- a/drivers/cpufreq/scpi-cpufreq.c > > > > > +++ b/drivers/cpufreq/scpi-cpufreq.c > > > > > @@ -39,8 +39,9 @@ static unsigned int scpi_cpufreq_get_rate(unsigned int cpu) > > > > > static int > > > > > scpi_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index) > > > > > { > > > > > - u64 rate = policy->freq_table[index].frequency * 1000; > > > > > > > > policy->freq_table[index].frequency is a u32 so in this original > > > > calculation, even though "rate" is declared as a u64, it can't actually > > > > be more than UINT_MAX. > > > > > > > > > > Agreed and understood. > > > > > > > > + unsigned long freq = policy->freq_table[index].frequency; > > > > > struct scpi_data *priv = policy->driver_data; > > > > > + u64 rate = freq * 1000; > > > > > > > > So you've fixed this by casting policy->freq_table[index].frequency > > > > to unsigned long, which fixes the problem on 64bit systems but it still > > > > remains on 32bit systems. It would be better to declare freq as a u64. > > > > > > > > > > Just trying to understand if that matters. freq is in kHz as copied > > > from policy->freq_table[index].frequency and we compare it with > > > kHZ below as the obtained clock rate is divided by 1000. What am I > > > missing ? If it helps, it can be renamed as freq_in_khz and even keep > > > it as "unsigned int" as in struct cpufreq_frequency_table. > > > > > > > > > I misunderstood the integer overflow bug because I read too much into the > > fact that "rate" was declared as a u64. It would have been fine to > > declare it as a unsigned long. The cpufreq internals don't support > > anything more than ULONG_MAX. I have heard someone say that new systems > > are bumping up against the 4GHz limit but presumably that would only be > > high end 64bit systems, not old 32bit system. > > > > The ->freq_table[] frequency is in kHz so a u32 is fine. I guess if we > > get frequencies of a THz then we'll have to update that. But when we > > convert to Hz then we need a cast to avoid an integer overflow for systems > > which are over the 4GHz boundary. > > > > unsigned long rate = (unsigned long)khz * 1000; > > > > The second bug is that we need to compare kHz instead of Hz and that's > > straight forward. > > > > regards, > > dan carpenter > > > > Thank you for your valuable feedback.I will make the changes to the patch and > resubmit it, including renaming freq and keeping it as an "unsigned int". If you keep it as unsigned int then you will need to add a cast when you do the "* 1000" multiplication. Please make freq and rate both unsigned longs. regards, dan carpenter