linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Sumit Gupta <sumitg@nvidia.com>
To: Beata Michalska <beata.michalska@arm.com>,
	<linux-kernel@vger.kernel.org>, <linux-pm@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>
Cc: <catalin.marinas@arm.com>, <mark.rutland@arm.com>,
	<will@kernel.org>, <rafael@kernel.org>, <viresh.kumar@linaro.org>,
	<sudeep.holla@arm.com>, <ionela.voinescu@arm.com>,
	<yang@os.amperecomputing.com>, <linux-tegra@vger.kernel.org>,
	Sumit Gupta <sumitg@nvidia.com>,
	"Sanjay Chandrashekara" <sanjayc@nvidia.com>
Subject: Re: [PATCH] arm64: Provide an AMU-based version of arch_freq_get_on_cpu
Date: Wed, 18 Oct 2023 18:35:47 +0530	[thread overview]
Message-ID: <6a5710f6-bfbb-5dfd-11cd-0cd02220cee7@nvidia.com> (raw)
In-Reply-To: <8e755438-4b1f-b3d6-b2b8-a5efcca813bc@nvidia.com>



On 15/06/23 00:29, Sumit Gupta wrote:
> 
> 
> On 06/06/23 21:27, Beata Michalska wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> With the Frequency Invariance Engine (FIE) being already wired up with
>> sched tick and making use of relevant (core counter and constant
>> counter) AMU counters, getting the current frequency for a given CPU
>> on supported platforms, can be achieved by utilizing the frequency scale
>> factor which reflects an average CPU frequency for the last tick period
>> length.
>>
>> With that at hand, arch_freq_get_on_cpu dedicated implementation
>> gets enrolled into cpuinfo_cur_freq policy sysfs attribute handler,
>> which is expected to represent the current frequency of a given CPU,
>> as obtained by the hardware. This is exactly the type of feedback that
>> cycle counters provide.
>>
>> In order to avoid calling arch_freq_get_on_cpu from the scaling_cur_freq
>> attribute handler for platforms that do provide cpuinfo_cur_freq, and
>> yet keeping things intact for those platform that do not, its use gets
>> conditioned on the presence of cpufreq_driver (*get) callback (which also
>> seems to be the case for creating cpuinfo_cur_freq attribute).
>>
> 
> Tested the change with frequency switch stress test but was getting big 
> delta between set and get freq.
> After passing "nohz=off" and commenting "wfi" in "cpu_do_idle()", the
> delta is less. This confirms that more delta is due to AMU counters
> stopping at "WFI".
> 
>    +++ b/arch/arm64/kernel/idle.c
>    @@ -27,7 +27,7 @@ void noinstr cpu_do_idle(void)
>            arm_cpuidle_save_irq_context(&context);
> 
>            dsb(sy);
>    -       wfi();
>    +//     wfi();
> 
> I am not sure if the expected behavior here is right.
> In our tests, we compare the last set frequency against the re-generated
> value from counters to confirm that the CPU is actually running at the
> requested frequency and the counters are working correct. But that won't
> happen with this change.
> 
> In [1] and later in the updated patch within [2], we are busy looping
> on the target CPU and avoid WFI to get the actual frequency.
> 
> Please share what you think is the right expected behavior.
> 
> [1] https://lore.kernel.org/lkml/20230418113459.12860-7-sumitg@nvidia.com/
> [2] 
> https://lore.kernel.org/lkml/cde1d8a9-3a21-e82b-7895-40603a14d898@nvidia.com/T/#mb898a75fd0c72d166b26b04da3ad162afe068a82

Observed another issue where CPUFREQ is coming too high when the
performance governor is set as default.

Below change solves that by using the new API arch_freq_get_on_cpu()
if present over the existing one, while verifying the currently set 
frequency.

  diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
  index 62face349fd2..2c74e70f701e 100644
  --- a/drivers/cpufreq/cpufreq.c
  +++ b/drivers/cpufreq/cpufreq.c
  @@ -1761,9 +1761,12 @@ static unsigned int 
cpufreq_verify_current_freq(struct cpufreq_policy *policy, b
   {
  		unsigned int new_freq;

  -       new_freq = cpufreq_driver->get(policy->cpu);
  -       if (!new_freq)
  -               return 0;
  +       new_freq = arch_freq_get_on_cpu(policy->cpu);
  +       if (!new_freq) {
  +               new_freq = cpufreq_driver->get(policy->cpu);
  +               if (!new_freq)
  +                       return 0;
  +       }


Best Regards,
Sumit Gupta

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

      parent reply	other threads:[~2023-10-18 13:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06 15:57 [PATCH] arm64: Provide an AMU-based version of arch_freq_get_on_cpu Beata Michalska
2023-06-07  9:58 ` Sudeep Holla
2023-06-07 14:00   ` Beata Michalska
2023-07-27  9:56     ` Will Deacon
2023-08-14  7:27       ` Beata Michalska
2023-06-08  5:15 ` Viresh Kumar
2023-06-08  5:18   ` Viresh Kumar
2023-06-08 14:45     ` Beata Michalska
2023-06-09  4:39       ` Viresh Kumar
2023-06-16  9:57         ` Beata Michalska
2023-06-14 18:59 ` Sumit Gupta
2023-06-16  9:53   ` Beata Michalska
2023-06-23 14:33     ` Sumit Gupta
2023-10-18 13:05   ` Sumit Gupta [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a5710f6-bfbb-5dfd-11cd-0cd02220cee7@nvidia.com \
    --to=sumitg@nvidia.com \
    --cc=beata.michalska@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=ionela.voinescu@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rafael@kernel.org \
    --cc=sanjayc@nvidia.com \
    --cc=sudeep.holla@arm.com \
    --cc=viresh.kumar@linaro.org \
    --cc=will@kernel.org \
    --cc=yang@os.amperecomputing.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).