Bug 6663 - P-states reports incorrect max frequency
Summary: P-states reports incorrect max frequency
Status: RESOLVED FIXED
Alias: None
Product: MinnowBoard MAX
Classification: Hardware Platforms
Component: hw-minnowmax (show other bugs)
Version: 2C A1
Hardware: MinnowBoard Max x86_64
: Medium normal
Target Milestone: A2 Release
Assignee: John 'Warthog9' Hawley
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2014-08-26 21:41 UTC by John 'Warthog9' Hawley
Modified: 2014-11-06 23:06 UTC (History)
4 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments
Fix frequency reporting for BYT (4.47 KB, patch)
2014-10-02 19:31 UTC, Dirk Brandewie
no flags Details | Diff
Mail from JOhn (37.00 KB, application/octet-stream)
2014-10-10 02:15 UTC, David_Wei
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description John 'Warthog9' Hawley 2014-08-26 21:41:55 UTC
I suspect this is a kernel bug (and will assign to Darren)

On a 3.16 kernel (yocto built) it lacks the P-State driver and cpufreq min/max reports as follows:

min: 
  # cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
  432000

max:
  # cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
  1330000

If you were to load the P-state driver on an Arch 3.16 kernel (also reported for Ubuntu) you get

min: 
  # cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
  400000

max:
  # cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
  1000000

Indicating that the p-state driver is throttling the cpu well below it's max frequency.  Is this just a miss-understanding of what p-state is doing, or an indication of something else?
Comment 1 John 'Warthog9' Hawley 2014-08-26 21:42:18 UTC
Re-assigning to dvhart
Comment 2 John 'Warthog9' Hawley 2014-09-04 23:13:28 UTC
NEEDINFO just want Darren to triage this if it's a kernel bug or a firmware bug, as it's not clear which is at fault
Comment 3 Dirk Brandewie 2014-09-29 15:10:49 UTC
If you are not using intel_pstate the system is likely using acpi_cpufreq as
the scaling driver and the values are being read for a table supplied by
the BIOS. intel_pstate enumerates the available P states by reading the MSRs
on the CPU.

You can tell what scaling driver and governor is in use with:
  grep . /sys/devices/system/cpu/cpu0/cpufreq/*

To get the values the CPU is reporting take returned values time 100Mhz
for frequency.

Min freq:
rdmsr -d -f 16:8 0x66a

Max Freq/stamped freq:
rdmsr -d -f 24:16 0x66a

Max turbo:
rdmsr -d -f 8:0 0x66c

I looks like the BIOS is reporting something different from what the CPU is.
Comment 4 Dirk Brandewie 2014-09-29 18:42:49 UTC
After a little more investigation I think the issue is with acpi_cpufreq.
acpi_cpufreq does not know anything about BYT on BYT the bottom 8 bits of
MSR_IA32_PERF_CTL are used to set the VID (voltage) This method predates
acpi_cpufreq for some reason BYT went back to having the OS set the VID.
The value passed up in the BIOS table includes the VID for the associated
frequency as a bit pattern that gets written to MSR_IA32_PERF_CTL.  When
filling in the frequency tables and reading the MSR_IA32_PERF_CTL 
acpi_cpufreq does not mask off the lower 8 bits. This is where the
strange frequency numbers are coming from.
Comment 5 John 'Warthog9' Hawley 2014-09-30 00:41:19 UTC
So my concern there is that the strange frequencies are happening with the p-state driver, not the acpi_cpufreq driver, since it's with the p-state driver that the supposed max cpu frequency is 1ghz vs. 1.33ghz
Comment 6 Dirk Brandewie 2014-09-30 15:34:06 UTC
The strange frequencies are coming from apci_cpufreq not intel_pstate.
The table entries returned by the BIOS contain the VID (voltage ID) for
the frequency in the lower 8 bits the P state/frequency are in bits 15:8.
When reporting the frequencies acpi_cpufreq blindly multiplies the value
and returns it as the frequency. Prior to BYT the lower 8 bits were always
zero.

If you use rdmsr as described below you will see what the CPU is reporting.
Comment 7 Dirk Brandewie 2014-10-02 19:31:26 UTC
Created attachment 2159 [details]
Fix frequency reporting for BYT
Comment 8 Dirk Brandewie 2014-10-02 19:35:00 UTC
I retract my previous comment on the BIOS misreporting frequency.  BYT
has a different method of mapping P state to frequency from the core 
processors. The attached patch fixes the issue on my BYT based system.
Comment 9 Darren Hart 2014-10-02 20:43:25 UTC
With the patch from Dirk applied to 3.17-rc7 with both drivers compiled in (=y):

CONFIG_X86_ACPI_CPUFREQ=y
CONFIG_X86_INTEL_PSTATE=y

$ cat /sys/devices/system/cpu/cpu0/driver/cpu0/cpufreq/scaling_driver
intel_pstate

I see the following:

$ cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
533200

$ cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
1333000

The max looks correct, but the min is different from both the originally reported values. 533MHz is the base frequency for the Graphics on this part, so it isn't surprising, but does this mean ACPI is providing the wrong data too?
Comment 10 Dirk Brandewie 2014-10-03 14:02:52 UTC
You can check my math but section 13.6.2 of the BWG says the frequency is
target ratio * bus frequency.  In this case 4 * 133.3 MHz = 533.2 MHz for min
frequency. I just reread the section and I can't find any way to come up with the
432000 number.
Comment 11 Darren Hart 2014-10-06 16:23:28 UTC
Now that we have a kernel fix working it's way upstream, thanks Dirk!, I'm kicking this back over to Tim to verify the acpi frequency tables we're passing up from firmware as the min frequency appears to be incorrect as reported from there. Tim, can you investigate why the firmware tables are reporting 400MHz instead of 533MHz?
Comment 12 He, Tim 2014-10-09 23:56:20 UTC
Darren, I got the email from John , seems that everything is working for this bug, so can we close this bug?
Comment 13 David_Wei 2014-10-10 02:15:31 UTC
Created attachment 2176 [details]
Mail from JOhn
Comment 14 David_Wei 2014-10-10 02:18:23 UTC
Hi John,
Could you help reivew it and then close it?
Comment 15 John 'Warthog9' Hawley 2014-11-06 01:47:14 UTC
As a note this bug is staying open as a tracking bug till the patch makes it into a mainline kernel
Comment 16 Dirk Brandewie 2014-11-06 14:51:01 UTC
merged commit b27580b05e6f5253228debc60b8ff4a786ff573a
Comment 17 Darren Hart 2014-11-06 23:06:28 UTC
Dirk has completed the fix, the driver is enabled in yocto builds, although it will not have the fix until the next stable update, which is a normal part of the release process. Marking as closed. Thank you Dirk!