From nobody Thu Dec 18 20:37:01 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 809451BCA0C for ; Thu, 19 Dec 2024 20:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734639526; cv=none; b=HFAF2Krd54LcAXoeuP+Ic0gKKatVjjS5vSLaMiIlUqELTHBZ5pZ2JQR4bH/SRCKOH0fpvjhmywEJ53jf35UVxp6tpcDlZEvYH/5i8b4YKj56plGeoZAz/ZbzuCdflbD7BmBrQ7RG7NFjI9ozGgfnuQvFGobygknTJQy+Q/WR5Bo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734639526; c=relaxed/simple; bh=NMXXVilYNKTfG7XSkl0jtmfs1wL4q1PoioCycSVb15s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uxB1OuBukPM9N7B/sOxGQDXS9r8FXYrT5+akLFgrc2NJ1FIdIZHVXZjEqan7/iMnjSPt6wmDHme1xL5BIsDYjzznXM+ruZ3TNg/1bDkUVoQNRBnfQEoq/lQ6+92aI4VEKSKDqKRM0pxDVG+kq+H3q9AVOeo9SfGLYOnxhCO88dg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=XhMotE5x; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="XhMotE5x" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4363ae65100so13388785e9.0 for ; Thu, 19 Dec 2024 12:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1734639522; x=1735244322; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UNl/KDdgHfnnSxN4lrQJgad4LvdpAF5sjqJPgBUKzjY=; b=XhMotE5xcCzJvek/6oUdAIT3aVneodJSV7/8Ggxxd0evtkY/it8WE+a0xhoL6MhG+Y XUEHveiduZYUTJeyIIUeMn0IAVz95iZDxfISXX2gfqXZQnnbx6ARUFVBtWpHjRmgVvZc HFmZ4ljP6i/WC74WiTT6+wdQTZN0Ul7CEYG5r4O1OUUme/xmsE1ky1qk9D4Lo8+dgBmF 0c9gx3KctD7nvKfRL07BZ9dkW/FY6nj7/fX72xlOc4SFkcsEW5yrjLI8ehbRyGyP81Cd Qyy1MXtGvqlPu0erajExF6QaD8VKNnjONDr3d9IPf7hxMPBGrjjTWIh0fg4MZPvQ/Zud C/+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734639522; x=1735244322; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UNl/KDdgHfnnSxN4lrQJgad4LvdpAF5sjqJPgBUKzjY=; b=BU6f6ScDQ6Z1VmEj6rmzwB9MLq/pwnrgZm0kUVSrQmWFUuCocr3QZS9CkqWfAn/a8w DyWr28VioD+5nCD+Y6SUmxr8dnEmTHcqAhY4Z9GLOpW1vhZ0TroBTWR5XHx2r0qMYVW8 I2ESHh7SRw07rl3A0L6TUMYSS3VYBUJ0463xL9Kjj4ppec8Opy5hBImB6nMDGVtjIMSK Beb//YS6zFfc41Ux8UcH7mX+0IobfkyCARQ1+0UeKSN468yCwRZswzWxUVsvOIiEFOXI LaAKae3g6kDCkbAOyLbkDusi4L1eoSjeLQqQSm0sQKCfB+7h8Y3LFBvry7EZaFrhyKDy pIkA== X-Forwarded-Encrypted: i=1; AJvYcCUv2R5BncMlPhlsK4fxsgZHx1FwnUFO9MqkYgZalE6Fc6mrS+OX7zkMn8L3u9cpowmyxfRBm9k7hIfBzfw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywydo+X5jrN4cVzi+UPiaoQE/ywQNhO5G4qFM+tqwqo8jvXX1j6 Rb6+5630g5PXslfPoZKJykJ+kPJRjyW8Ar4NdZ+1Caginpo6nJTNtnVHtAOYNok= X-Gm-Gg: ASbGnctDVhevxLGMEwjqCQs63SspWMzepowO5/ncLuP5Szpwf1LHfULFBkzAz+Nm/iY 3L8321Z7QVKSBu1U2Y87DfAOMbHqIiIwITB5rYzgcfdven9rpelXnnQqZR7lyBvCtA70QSp8g4K o71kG+wcu6BzJmi60CTFpcecm9t9ho4/LwXHE6SlBjON1HYStdxkTbQkptK8CdQpknaxac+N6y9 l5MVOPaD1hYvG3OaEGIEjVKSvGcKD9lRiizwUSLkpD4eGGQvd04riat0QVmiAGrPY2rdjYXwSwr 9bw8UCzlrppA/nWMRKEiPpXiLNgq0c0ZfIWdLnxhYw82G2BkiRxM X-Google-Smtp-Source: AGHT+IGhMg/R8CEoO5icdTMg7GvMkGydpQHvuN05PPSivYFehytaR7Euq/MLib9NF/7q84XXTRRN8g== X-Received: by 2002:a05:600c:5112:b0:431:557e:b40c with SMTP id 5b1f17b1804b1-43668b5f3c2mr2052765e9.27.1734639521754; Thu, 19 Dec 2024 12:18:41 -0800 (PST) Received: from stroh80.lab.9e.network (ip-078-094-000-050.um19.pools.vodafone-ip.de. [78.94.0.50]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656b013a1sm61944385e9.11.2024.12.19.12.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 12:18:40 -0800 (PST) From: Naresh Solanki To: Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , Perry Yuan , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Naresh Solanki Subject: [PATCH v3] cpufreq/amd-pstate: Refactor max frequency calculation Date: Fri, 20 Dec 2024 01:48:32 +0530 Message-ID: <20241219201833.2750998-1-naresh.solanki@9elements.com> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The previous approach introduced roundoff errors during division when calculating the boost ratio. This, in turn, affected the maximum frequency calculation, often resulting in reporting lower frequency values. For example, on the Glinda SoC based board with the following parameters: max_perf =3D 208 nominal_perf =3D 100 nominal_freq =3D 2600 MHz The Linux kernel previously calculated the frequency as: freq =3D ((max_perf * 1024 / nominal_perf) * nominal_freq) / 1024 freq =3D 5405 MHz // Integer arithmetic. With the updated formula: freq =3D (max_perf * nominal_freq) / nominal_perf freq =3D 5408 MHz This change ensures more accurate frequency calculations by eliminating unnecessary shifts and divisions, thereby improving precision. Signed-off-by: Naresh Solanki Changes in V3: 1. Also update the same for lowest_nonlinear_freq Changes in V2: 1. Rebase on superm1.git/linux-next branch Reviewed-by: Mario Limonciello --- drivers/cpufreq/amd-pstate.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index d7b1de97727a..6f6f3220ffe4 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -908,9 +908,8 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpu= data) { int ret; u32 min_freq, max_freq; - u32 nominal_perf, nominal_freq; + u32 highest_perf, nominal_perf, nominal_freq; u32 lowest_nonlinear_perf, lowest_nonlinear_freq; - u32 boost_ratio, lowest_nonlinear_ratio; struct cppc_perf_caps cppc_perf; =20 ret =3D cppc_get_perf_caps(cpudata->cpu, &cppc_perf); @@ -927,16 +926,12 @@ static int amd_pstate_init_freq(struct amd_cpudata *c= pudata) else nominal_freq =3D cppc_perf.nominal_freq; =20 + highest_perf =3D READ_ONCE(cpudata->highest_perf); nominal_perf =3D READ_ONCE(cpudata->nominal_perf); - - boost_ratio =3D div_u64(cpudata->highest_perf << SCHED_CAPACITY_SHIFT, no= minal_perf); - max_freq =3D (nominal_freq * boost_ratio >> SCHED_CAPACITY_SHIFT); + max_freq =3D div_u64((u64)highest_perf * nominal_freq, nominal_perf); =20 lowest_nonlinear_perf =3D READ_ONCE(cpudata->lowest_nonlinear_perf); - lowest_nonlinear_ratio =3D div_u64(lowest_nonlinear_perf << SCHED_CAPACIT= Y_SHIFT, - nominal_perf); - lowest_nonlinear_freq =3D (nominal_freq * lowest_nonlinear_ratio >> SCHED= _CAPACITY_SHIFT); - + lowest_nonlinear_freq =3D div_u64((u64)nominal_freq * lowest_nonlinear_pe= rf, nominal_perf); WRITE_ONCE(cpudata->min_freq, min_freq * 1000); WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq * 1000); WRITE_ONCE(cpudata->nominal_freq, nominal_freq * 1000); --=20 2.42.0