From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754902AbbFKOvJ (ORCPT ); Thu, 11 Jun 2015 10:51:09 -0400 Received: from cmta3.telus.net ([209.171.16.76]:45250 "EHLO cmta3.telus.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751850AbbFKOvG (ORCPT ); Thu, 11 Jun 2015 10:51:06 -0400 X-Authority-Analysis: v=2.0 cv=IIfc/HTG c=1 sm=2 a=zJWegnE7BH9C0Gl4FFgQyA==:17 a=IkcTkHD0fZMA:10 a=aatUQebYAAAA:8 a=Pyq9K9CWowscuQLKlpiwfMBGOR0=:19 a=_0uP7fiA9cPQeYXM49MA:9 a=QEXdDO2ut3YA:10 a=zJWegnE7BH9C0Gl4FFgQyA==:117 X-Telus-Outbound-IP: 173.180.45.4 From: "Doug Smythies" To: "'Rafael J. Wysocki'" , "'Prarit Bhargava'" Cc: , "'Kristen Carlson Accardi'" , "'Viresh Kumar'" , , "Doug Smythies" References: <1433942325-6610-1-git-send-email-prarit@redhat.com> <2049134.oxrPdGJl10@vostro.rjw.lan> In-Reply-To: <2049134.oxrPdGJl10@vostro.rjw.lan> Subject: RE: [PATCH] cpufreq, Fix overflow in busy_scaled due to long delay Date: Thu, 11 Jun 2015 07:51:00 -0700 Message-ID: <000301d0a456$09333d00$1b99b700$@net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AdCj0/BgAXskObbcRNSqLpbmPuVkRwAfMBcQ Content-Language: en-ca Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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.)