linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
To: Doug Smythies <dsmythies@telus.net>
Cc: "'Rafael J. Wysocki'" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org,
	'Kristen Carlson Accardi' <kristen@linux.intel.com>,
	'Viresh Kumar' <viresh.kumar@linaro.org>,
	linux-pm@vger.kernel.org
Subject: Re: [PATCH] cpufreq, Fix overflow in busy_scaled due to long delay
Date: Thu, 11 Jun 2015 10:58:13 -0400	[thread overview]
Message-ID: <5579A205.3090101@redhat.com> (raw)
In-Reply-To: <000301d0a456$09333d00$1b99b700$@net>



On 06/11/2015 10:51 AM, Doug Smythies wrote:
> 
> On 2015.06.10 16:46 Rafael J. Wysocki wrote:
>> On Wednesday, June 10, 2015 09:18:45 AM Prarit Bhargava wrote:
>>> I looked into switching to div64_s64() instead of the 32-bit version in
>>> div_fp(), however, this would result in sample_ratio and core_busy returning
>>> 0 which is something we don't want.
> 
> ???
> Due to a great many overflow related issues, div_fp() was changed to div64_s64()
> a long time ago.

/me scratches head ... Perhaps I was looking at the wrong tree (RHEL vs
linux.git) but I'll go back & double check.

P.

> 
> I have not found the actual commit to reference, but it was about a year ago.
> And the math in general was all changed to 64 bit, over a few commits.
> 
>>
>> P.
>>
>> ---8<---
>>
>> The kernel may delay interrupts for a long time which can result in timers
>> being delayed.  If this occurs the intel_pstate driver will crash with
>> a divide by zero error:
> 
> More recent versions will not crash.
> Long timer delays are extremely common, and this is a fundamental flaw
> in the duration method. Patch sets have been submitting dealing with this,
> and other, issues.
> 
>>>
>>> which results in the time between samples = last_sample_time - sample.time
>>> = 4063149215234118 - 4063132438017305 = 16777216813 which is 16.777 seconds.
> 
> I have never seen anything over 4 seconds before, and I study this stuff
> (with respect to the intel_pstate driver operation) a lot. Due to help
> from others, I have data from a variety of processors.
> 4 seconds not unusual, even under load.
> 
>>>
>>> The duration between reads of the APERF and MPERF registers overflowed a s32
>>> sized integer in intel_pstate_get_scaled_busy()'s call to div_fp().  The result
>>> is that int_tofp(duration_us) == 0, and the kernel attempts to divide by 0.
>>>
>>> While the kernel shouldn't be delaying for a long time, it can and does
>>> happen, and the intel_pstate driver should not panic in this situation.  This
>>> patch checks for an overflow and ignores the current calculation cycle by
>>> returning -EINVAL.  Since intel_pstate_sample() has been called, subsequent
>>> timer function calls will then again pick up the correct calculations and the
>>> system will continue functioning properly.
> 
> That would run the risk that the correct calculation would never be done.
> It is fairly easy (I do it all the time) to create a scenario where
> there is high load on a CPU, but also a very very high duration value,
> for each and every duration. (and O.K., in that scenario the calculation is always
> wrong anyhow, due to the long duration check engaging.)
> 
> 

  reply	other threads:[~2015-06-11 14:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 13:18 [PATCH] cpufreq, Fix overflow in busy_scaled due to long delay Prarit Bhargava
2015-06-10 23:45 ` Rafael J. Wysocki
2015-06-11 14:51   ` Doug Smythies
2015-06-11 14:58     ` Prarit Bhargava [this message]
2015-06-11 15:00     ` Prarit Bhargava
2015-06-11 16:17       ` Doug Smythies
2015-06-11 16:59         ` Prarit Bhargava

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=5579A205.3090101@redhat.com \
    --to=prarit@redhat.com \
    --cc=dsmythies@telus.net \
    --cc=kristen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=viresh.kumar@linaro.org \
    /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).