From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 8834C224880 for ; Thu, 19 Dec 2024 09:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734600078; cv=none; b=Zir70FxCItbxZ6NjLEOJNy9jPHgTh5WX5zf+YdFIgJL9dceMOhT0YYcxYsw4gCjxPZe7vXZ5xslD1jGf39UIb4d/aiNDCvTOn+X5SWlmss5n6Q9OgwJNmn4WK+qwixYcg9+xZVh0MTKcJaVCSJSHsUflTuf/2rwtjYg7Ng27ky8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734600078; c=relaxed/simple; bh=PeK3Erz2u2VNsT1KrhNrC1lKahHsiRjttm3DwxNi8zs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=VTE30zIP4U1rRca82+Ht8YJJHmAkjUPUpwTAVkNpxByWOp87kK7riWuuPsohuujIsuPQVyPbjuL1OTLBA2hYS8cT4fkkUEWSRhxA3z3GCI/CBJmJtrC7SSgWYf5k504qqH20q2SzADRVCQowhUXvvvmBxOPQq1Ek3R/jevFNnVQ= 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=KRWQ9pp4; arc=none smtp.client-ip=209.85.215.182 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="KRWQ9pp4" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-8019f048bc7so333028a12.1 for ; Thu, 19 Dec 2024 01:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1734600076; x=1735204876; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IsPONPE+X13c/VfEPHRay9Cqx4TtGB/TUoXn2SEqYbM=; b=KRWQ9pp42Ydag88tGXFxx1RPniK1agie7UmLq1ZOIv+o/19do7oztDc+sJMrv0vr7w mhqihoLSRvCYAC8A4HrSH14Pit4Vl4qk3cm3f0EJDWqWvyuo3LuAAsFeHscNSGkXS5UM 2GrwzU+Y/M9gSLExnLnp0TstWhRwFVKH3XccoA8s6bxiwhJF9tAV99kSOq8mW5fIYPGZ OWTab+Vr7Q58X0mpTB+QH8N4+aY9OENYS8sI+u89yWX2Q991dU9Rj3DYKe+TRP6ThNBf xEGTh82vB+fdIWtpP/Rb4q4wzAOlIg38ADXVteZLLidRpxz69ADOsoFwuV2+lCBcWGK3 OkCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734600076; x=1735204876; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IsPONPE+X13c/VfEPHRay9Cqx4TtGB/TUoXn2SEqYbM=; b=mtF2ekPs5RW53F8N3+4aUYuhlvmdzBLSQNOWfksbttR6Kn8TceOoNW/oFWdiZ3vxve ib9yYvpQa9OF3ylgxItPuf80DAYLLycwZ38D/ukMjougOhr92V63RiQUqll/entMK18w dIWiz0cISLadQTqFHJst8D8tQEQNmMCkiMKDFHbayWvEoWJrOZlcn//lfj41dHukrGM3 tw30rVrhVMrloOzmGoGzGRG9IH0S9arWMFnnZWuF83YZ5KSoXR2UQkIM5qolpCNX5q2P 3vAwslc8pzVScgsWoCAECFAYeqFLHSZNujtY1atIL+bDBmo9sp4n+m/uLqcN0GcDFozF 4cLw== X-Forwarded-Encrypted: i=1; AJvYcCXDuYLiPhC97o4TK+A4uI976BuP81odF7bdaor+GBQCvwJYOMvD/d2gyErnywkJF/xa0xb1A47wzejLtOg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+CdwNeYVxhuq+UZM91hUYBKHii43H2OQLD0djDCe2asnsY/LR kjitTpZGPoTgAlwzIjiDofV5A6hoFNjvBi4zaDSwXm6wiO5mHKw2LLIZb5VEu0Ap5s8S6SI1o9u RFxQAbxZAlKFATuAzoF5kB9vyrsn7yDMDle9EJA== X-Gm-Gg: ASbGncs9iUy4hh21UHkLqs//vmyCtcp9UVOfZv+y6WN1Cs1cOaqAnGwDd4wNkyKRgFM tC6uHEV8AD8Po0DgPnp2ww4c/1A/bniCX6nSRf/o= X-Google-Smtp-Source: AGHT+IFfmk0LhhhUZWa9TPRyEGMYUEe+2S62e6wTE3V3wNGeIrZpxGsKZ1tmE70rz4nx4PGB3GM3SYo491wHRhNMfNc= X-Received: by 2002:a17:90b:2804:b0:2ee:f80c:6884 with SMTP id 98e67ed59e1d1-2f443d6e77amr3809323a91.33.1734600075862; Thu, 19 Dec 2024 01:21:15 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20241218190030.1228868-1-naresh.solanki@9elements.com> In-Reply-To: From: Naresh Solanki Date: Thu, 19 Dec 2024 14:51:05 +0530 Message-ID: Subject: Re: [PATCH] cpufreq/amd-pstate: Refactor max frequency calculation To: Mario Limonciello Cc: Huang Rui , "Gautham R. Shenoy" , Perry Yuan , "Rafael J. Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Hi , On Thu, 19 Dec 2024 at 00:50, Mario Limonciello wrote: > > On 12/18/2024 13:00, Naresh Solanki wrote: > > Refactor to calculate max-freq more accurately. > > Can you add some more detail about what you're finding? > What was it before, what is it now, why is it more accurate? Sure. The previous approach had some roundoff error due to division compute when calculating boost ratio. Which intern affected max-freq calculation resulting in reporting lower value In my Glinda SoC board, See below calculations with below values: max_perf = 208 nominal_perf = 100 normal_freq = 2600 How linux kernel calculates: freq = ( (max_perf * 1024 / nominal_perf) * normal_freq) / 1024 freq = 5405 // Integer arithmatic. With the changes freq = (max_perf * normal_freq) / nominal_perf freq = 5408 > > > > > Signed-off-by: Naresh Solanki > > --- > > drivers/cpufreq/amd-pstate.c | 5 ++--- > > 1 file changed, 2 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > > index d7630bab2516..78a2cbd14952 100644 > > --- a/drivers/cpufreq/amd-pstate.c > > +++ b/drivers/cpufreq/amd-pstate.c > > @@ -892,7 +892,7 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata) > > u64 numerator; > > u32 nominal_perf, nominal_freq; > > u32 lowest_nonlinear_perf, lowest_nonlinear_freq; > > - u32 boost_ratio, lowest_nonlinear_ratio; > > + u32 lowest_nonlinear_ratio; > > struct cppc_perf_caps cppc_perf; > > > > ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); > > @@ -914,8 +914,7 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata) > > ret = amd_get_boost_ratio_numerator(cpudata->cpu, &numerator); > > if (ret) > > return ret; > > - boost_ratio = div_u64(numerator << SCHED_CAPACITY_SHIFT, nominal_perf); > > - max_freq = (nominal_freq * boost_ratio >> SCHED_CAPACITY_SHIFT) * 1000; > > + max_freq = div_u64(numerator * nominal_freq * 1000, nominal_perf); > > This doesn't apply currently, because of some changes in the > superm1.git/linux-next branch; specifically: > > https://git.kernel.org/superm1/c/68cb0e77b6439 > > I haven't sent this out to linux-pm yet so it could be in linux-next, > but will be doing that soon. So can you please rebase on that branch if > this change still makes sense? Sure. Will do Regards, Naresh Solanki > > > > > lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); > > lowest_nonlinear_ratio = div_u64(lowest_nonlinear_perf << SCHED_CAPACITY_SHIFT, >