# Frequency scaling on AMD A10 platform



## user0 (Apr 6, 2016)

Is adding these lines to /etc/rc.conf the right method for enabling frequency scaling?


```
powerd_enable="YES"
powerd_flags="-b adaptive -a max"
```

I did so but the A10-6800K APU still runs at 4100 Mhz only.


----------



## User23 (Apr 6, 2016)

Check the freq_levels with sysctl(8). In my example the CPU has a base freq of 2000 MHz and a turbo of max 2500 MHz. The freq_level 2001/95000 indicates the use of the turbo freq.


```
sysctl -a | grep freq
...
dev.cpu.0.freq: 2001
dev.cpu.0.freq_levels: 2001/95000 2000/95000 1900/89224 1800/83561 1700/78011 1600/72573 1500/67246 1400/62042 1300/56932 1200/51931
...
```

I added

```
performance_cpu_freq="HIGH"
```
to the rc.conf 

Turbo Boost operation can be monitored in run-time via the PMC with command that prints number or really executed cycles per CPU core: `pmcstat -s unhalted-core-cycles -w 1`


----------



## user0 (Apr 6, 2016)

The command that you have added, was it to achieve turbo boost?
I am trying rather to drop the frequency when idle.
Where can I find the full list of the commands to control scaling?


----------



## User23 (Apr 6, 2016)

user0 said:


> The command that you have added, was it to achieve turbo boost?
> I am trying rather to drop the frequency when idle, where can I find the full list of the commands to control scaling?



I think the extra line in the rc.conf was needed, but I am not sure if it is (still) necessary.
According to the rc.conf()

```
performance_cpu_freq
         (str) CPU clock frequency to use while    on AC power.  The
         string    ``LOW''    indicates that cpufreq(4) should use the low-
         est frequency available while ``HIGH''    indicates that the
         highest frequency (less power savings)    should be used.
```
it looks to me more like to keeping the highest possible performance.

Read the powerd() to learn more about its scaling capabilities.
If the powerd is not running you can set the freq_level by hand using for example

```
sysctl dev.cpu.0.freq=2001
```

old but usefull links
https://wiki.freebsd.org/TuningPowerConsumption
https://forums.freebsd.org/threads/172/


----------



## user0 (Apr 6, 2016)

Great info  It did not occur to me to run man powerd 
So in my case I guess the lines should be:

```
powerd_enable="YES"
powerd_flags="-n hiadaptive -a hiadaptive -m 2000 -M 4100"
```
but I am not sure about the last one. Should it be 4100 - normal operating maximum, or 4400 - turbo maximum?

It has these boosted frequencies:

#1: 4400 MHz, 1.325V
#2: 4300 MHz, 1.25V
#3: 4200 MHz, 1.15V

and these lower-powered frequencies:

#1: 3800 MHz, 0.9V
#2: 3200 MHz, 0.675V
#3: 2600 MHz, 0.45V
#4: 2000 MHz, 0.25V

Does powerd replace BIOS when it comes to Turbo frequencies, or does it only try to use the frequencies, made available by the Turbo CPB BIOS setting? In other words, if I specified -M 4400 and Turbo CPB was turned off in the BIOS, would powerd be smart enough go up to 4100? I guess only an experiment would tell.


----------



## user0 (Apr 9, 2016)

This is truly amazing! I tried changing the option to use 4400 boost frequency

-M 4400

and when the machine rebooted, there was no more xdm. How it disappeared is a complete mystery.

Also it looks like CPU runs at 4100 only again.
Does this look like powerd is running as it should? Why is there another powerd process (1st line)?


```
[root@leo00] /etc# ps lmax|grep powerd
  0 1919  1  0  20  0  52840  6400 select  I  -  0:00.01 /usr/local/libexec/upowerd
  0 3761 3694  0  20  0  18840  2508 piperd  S+  2  0:00.00 grep powerd
  0  857  1  0  20  0  14504  1928 select  Ss  -  0:00.09 /usr/sbin/powerd -b hiadaptive -a hiadaptive -n hiadaptive -m 2000 -M 4100
```


----------



## user0 (Apr 9, 2016)

Also getting this error:


```
[root@leo00] /etc# pmcstat -s unhalted-core-cycles -w 1
pmcstat: ERROR: Initialization of the pmc(3) library failed: No such file or directory
```

Do I need to install anything to use this command?


----------



## trev (Apr 10, 2016)

Curiously, that command works on my 10.2-STABLE machine, but fails as you indicate on my newly installed 10.3-Release machine.

The solution was `kldload hwpmc` and it works as expected


----------



## user0 (Apr 10, 2016)

PCBSD 10.3 is installed on this machine and it exhibits truly bizarre behaviour.
Apparently, disappearance of xdm had nothing to do with powerd parameter change! AppCafe did that - it got stuck removing one obscure application and I did not notice that, assuming that it should have completed in less than 30 seconds, and rebooted.
After reboot the entire pcbsd-base package was missing and I had to reinstall it with 700+ components.

After reboot powerd runs, and it uses the command line from rc.conf, but there is no frequency scaling anymore.
In light of all these problems with 10.2 and 10.3 I will be downgrading to 10 or 10.1 as this kind of behaviour is so-Linux like, that it is nauseous.


----------



## user0 (Apr 11, 2016)

trev said:


> Curiously, that command works on my 10.2-STABLE machine, but fails as you indicate on my newly installed 10.3-Release machine.
> 
> The solution was `kldload hwpmc` and it works as expected


That command has done nothing for me. Still cannot get the stats, same error.


----------



## trev (Apr 12, 2016)

What does `kldstat` show?


----------



## user0 (Apr 12, 2016)

Will have to check!
Last night I became really desperate and submitted this bug report https://bugs.pcbsd.org/issues/14596
And then it occurred to me to run `powerd -v` and voila! I saw it momentarily dropping to 3800 and 2000, but only for split second and every tiny spike in CPU kicked it back up to 4100, so it practically stayed at 4100 90% of the time and I did not have a chance to notice the short-term drops in frequency using the buggy KDE System Load Viewer applet.

So I ended up replacing hiadaptive with adaptive for the time being.

When using -W 4400 and loading the CPU intensive task on all cores or only 1 core powerd still only used 4100 as max. It never boosted the frequency despite pretty good cooling. Does anybody know if powerd can support the boost frequencies on AMD APU?


----------



## user0 (Apr 13, 2016)

```
Id Refs Address  Size  Name
 1  172 0xffffffff80200000 152b000  kernel
 2  1 0xffffffff819da000 2504e  drm.ko
 3  2 0xffffffff81a00000 719ed  drm2.ko
 4  5 0xffffffff81a72000 5675  iicbus.ko
 5  3 0xffffffff81a78000 6899e  vboxdrv.ko
 6  3 0xffffffff81ae1000 324f5  crypto.ko
 7  1 0xffffffff81b14000 4f19  aesni.ko
 8  1 0xffffffff81b19000 1f928  geom_eli.ko
 9  1 0xffffffff81b39000 2e15c9  zfs.ko
10  2 0xffffffff81e1b000 53ae  opensolaris.ko
11  1 0xffffffff81e21000 10c9a  tmpfs.ko
12  1 0xffffffff81e32000 8cf20  linux.ko
13  5 0xffffffff81ebf000 adff  linux_common.ko
14  1 0xffffffff81eca000 229b1  geom_journal.ko
15  1 0xffffffff81eed000 22b1b  geom_mirror.ko
16  1 0xffffffff81f10000 63b2  ums.ko
17  1 0xffffffff82021000 9fbb  linprocfs.ko
18  2 0xffffffff8202b000 429e  libiconv.ko
19  1 0xffffffff82030000 1566  libmchain.ko
20  1 0xffffffff82032000 7da  msdosfs_iconv.ko
21  1 0xffffffff82033000 31cf7  if_bwn.ko
22  1 0xffffffff82065000 6ed0  siba_bwn.ko
23  1 0xffffffff8206c000 1faa7  if_bwi.ko
24  1 0xffffffff8208c000 273c  runfw.ko
25  1 0xffffffff8208f000 476a  cuse4bsd.ko
26  1 0xffffffff82094000 66ee  sem.ko
27  1 0xffffffff8209b000 22d9  geom_uzip.ko
28  1 0xffffffff8209e000 56f6  fdescfs.ko
29  1 0xffffffff820a4000 55ec  linsysfs.ko
30  1 0xffffffff820aa000 2e58a  iwn4965fw.ko
31  1 0xffffffff820d9000 52db3  iwn1000fw.ko
32  1 0xffffffff8212c000 53a21  iwn5000fw.ko
33  1 0xffffffff82180000 52d43  iwn5150fw.ko
34  1 0xffffffff821d3000 6f71f  iwn6000fw.ko
35  1 0xffffffff82243000 a5d05  iwn6000g2afw.ko
36  1 0xffffffff822e9000 70fc3  iwn6000g2bfw.ko
37  1 0xffffffff8235a000 73265  iwn6050fw.ko
38  1 0xffffffff823ce000 3749  acpi_video.ko
39  1 0xffffffff823d2000 ddae  fuse.ko
40  1 0xffffffff823e0000 2b5c  uhid.ko
41  1 0xffffffff823e3000 11dff  ipfw.ko
42  2 0xffffffff823f5000 2b32  vboxnetflt.ko
43  2 0xffffffff823f8000 bea1  netgraph.ko
44  1 0xffffffff82404000 41c2  ng_ether.ko
45  1 0xffffffff82409000 3fd4  vboxnetadp.ko
46  1 0xffffffff8240d000 377a9  linux64.ko
47  1 0xffffffff82445000 ca7e  iscsi.ko
48  1 0xffffffff82452000 7835  autofs.ko
49  1 0xffffffff8245a000 eb14a  radeonkms.ko
50  1 0xffffffff82546000 1c7e  iic.ko
51  1 0xffffffff82548000 1de3  iicbb.ko
52  1 0xffffffff8254a000 28ee  radeonkmsfw_PITCAIRN_pfp.ko
53  1 0xffffffff8254d000 28f3  radeonkmsfw_PITCAIRN_me.ko
54  1 0xffffffff82550000 28ec  radeonkmsfw_PITCAIRN_ce.ko
55  1 0xffffffff82553000 2776  radeonkmsfw_PITCAIRN_rlc.ko
56  1 0xffffffff82556000 80d9  radeonkmsfw_PITCAIRN_mc.ko
57  1 0xffffffff8255f000 b3df  if_lagg.ko
```


----------



## trev (Apr 13, 2016)

I don't see hwpmc.ko in your kernel module listing. 

What happens when you `kldload hwpmc` ?


----------



## user0 (Apr 13, 2016)

If I remember correctly, the command prints nothing to the output.


----------



## user0 (Apr 14, 2016)

Sorry, I misunderstood your question.

Running `kldload hwpmc` adds another line to the output of kldstat:

```
58  1 0xffffffff8256b000 1a610  hwpmc.ko
```

Then pmcstat prints an error:


```
[root@leo00] ~# pmcstat -s unhalted-core-cycles -w 1
pmcstat: ERROR: Cannot allocate system-mode pmc with specification "unhalted-core-cycles": Invalid argument
```


----------



## trev (Apr 14, 2016)

What does `pmccontrol -L` show?

An `apropos hwpmc` suggests hwpmc may not support your CPU.


----------



## user0 (Apr 14, 2016)

Does that mean no turbo frequencies supported on the modern AMD CPUs?


----------



## user0 (Apr 15, 2016)

```
[leo@leo00] ~% sudo pmccontrol -L
SOFT
  PAGE_FAULT.WRITE
  CLOCK.PROF
  LOCK.FAILED
  CLOCK.HARD
  CLOCK.STAT
  PAGE_FAULT.ALL
  PAGE_FAULT.READ
TSC
  TSC
K8
  FP_DISPATCHED_FPU_OPS
  FP_CYCLES_WITH_NO_FPU_OPS_RETIRED
  FP_DISPATCHED_FPU_FAST_FLAG_OPS
  LS_SEGMENT_REGISTER_LOAD
  LS_MICROARCHITECTURAL_RESYNC_BY_SELF_MODIFYING_CODE
  LS_MICROARCHITECTURAL_RESYNC_BY_SNOOP
  LS_BUFFER2_FULL
  LS_LOCKED_OPERATION
  LS_MICROARCHITECTURAL_LATE_CANCEL
  LS_RETIRED_CFLUSH_INSTRUCTIONS
  LS_RETIRED_CPUID_INSTRUCTIONS
  DC_ACCESS
  DC_MISS
  DC_REFILL_FROM_L2   
  DC_REFILL_FROM_SYSTEM   
  DC_COPYBACK   
  DC_L1_DTLB_MISS_AND_L2_DTLB_HIT   
  DC_L1_DTLB_MISS_AND_L2_DTLB_MISS   
  DC_MISALIGNED_DATA_REFERENCE   
  DC_MICROARCHITECTURAL_LATE_CANCEL   
  DC_MICROARCHITECTURAL_EARLY_CANCEL   
  DC_ONE_BIT_ECC_ERROR   
  DC_DISPATCHED_PREFETCH_INSTRUCTIONS   
  DC_DCACHE_ACCESSES_BY_LOCKS   
  BU_CPU_CLK_UNHALTED   
  BU_INTERNAL_L2_REQUEST   
  BU_FILL_REQUEST_L2_MISS   
  BU_FILL_INTO_L2   
  IC_FETCH
  IC_MISS
  IC_REFILL_FROM_L2
  IC_REFILL_FROM_SYSTEM
  IC_L1_ITLB_MISS_AND_L2_ITLB_HIT
  IC_L1_ITLB_MISS_AND_L2_ITLB_MISS
  IC_MICROARCHITECTURAL_RESYNC_BY_SNOOP
  IC_INSTRUCTION_FETCH_STALL
  IC_RETURN_STACK_HIT
  IC_RETURN_STACK_OVERFLOW
  FR_RETIRED_X86_INSTRUCTIONS
  FR_RETIRED_UOPS
  FR_RETIRED_BRANCHES
  FR_RETIRED_BRANCHES_MISPREDICTED
  FR_RETIRED_TAKEN_BRANCHES
  FR_RETIRED_TAKEN_BRANCHES_MISPREDICTED
  FR_RETIRED_FAR_CONTROL_TRANSFERS
  FR_RETIRED_RESYNCS
  FR_RETIRED_NEAR_RETURNS
  FR_RETIRED_NEAR_RETURNS_MISPREDICTED
  FR_RETIRED_TAKEN_BRANCHES_MISPREDICTED_BY_ADDR_MISCOMPARE
  FR_RETIRED_FPU_INSTRUCTIONS
  FR_RETIRED_FASTPATH_DOUBLE_OP_INSTRUCTIONS
  FR_INTERRUPTS_MASKED_CYCLES
  FR_INTERRUPTS_MASKED_WHILE_PENDING_CYCLES
  FR_TAKEN_HARDWARE_INTERRUPTS
  FR_DECODER_EMPTY
  FR_DISPATCH_STALLS
  FR_DISPATCH_STALL_FROM_BRANCH_ABORT_TO_RETIRE
  FR_DISPATCH_STALL_FOR_SERIALIZATION
  FR_DISPATCH_STALL_FOR_SEGMENT_LOAD
  FR_DISPATCH_STALL_WHEN_REORDER_BUFFER_IS_FULL
  FR_DISPATCH_STALL_WHEN_RESERVATION_STATIONS_ARE_FULL
  FR_DISPATCH_STALL_WHEN_FPU_IS_FULL
  FR_DISPATCH_STALL_WHEN_LS_IS_FULL
  FR_DISPATCH_STALL_WHEN_WAITING_FOR_ALL_TO_BE_QUIET
  FR_DISPATCH_STALL_WHEN_FAR_XFER_OR_RESYNC_BRANCH_PENDING
  FR_FPU_EXCEPTIONS
  FR_NUMBER_OF_BREAKPOINTS_FOR_DR0
  FR_NUMBER_OF_BREAKPOINTS_FOR_DR1
  FR_NUMBER_OF_BREAKPOINTS_FOR_DR2
  FR_NUMBER_OF_BREAKPOINTS_FOR_DR3
  NB_MEMORY_CONTROLLER_PAGE_ACCESS_EVENT
  NB_MEMORY_CONTROLLER_PAGE_TABLE_OVERFLOW
  NB_MEMORY_CONTROLLER_DRAM_COMMAND_SLOTS_MISSED
  NB_MEMORY_CONTROLLER_TURNAROUND
  NB_MEMORY_CONTROLLER_BYPASS_SATURATION
  NB_SIZED_COMMANDS
  NB_PROBE_RESULT
  NB_HT_BUS0_BANDWIDTH
  NB_HT_BUS1_BANDWIDTH
  NB_HT_BUS2_BANDWIDTH
```


----------



## trev (Apr 15, 2016)

It would seem that hwpmc only supports the K8 features of your CPU. The quest to determine unhalted-core-cycles would appear to be doomed.  It may also be that that metric of hardware performance is only available on Intel CPUs judging by pmc(3).


----------



## user0 (Apr 18, 2016)

It's Okay, as after blowing away PCBSD 10.3 and reinstalling FreeBSD 10.1 `powerd` drops the idle frequency to 750 MHz and raises active up to 4100 which is fine.


----------



## user0 (Apr 22, 2016)

Interesting enough, FreeBSD's powerd drops the frequency of AMD APU from 4100 to quiet and cool 750.
But under Windows 7 it only drops to 2000 and I have not yet found a way to drop it further. 1% min CPU power in the advanced power profile settings does not help.


----------



## User23 (Apr 26, 2016)

Below 2000MHz the CPU wont lower the voltage anymore, so below 2GHz frequencies wont save that much energy.
Maybe you can measure the difference between 2GHz and 750MHz, if you have such a device.  

http://www.cpu-world.com/CPUs/Bulldozer/AMD-A10-Series A10-6800K.html

Low power P states [1] #1: 3800 MHz, 0.9V
#2: 3200 MHz, 0.675V
#3: 2600 MHz, 0.45V
#4: 2000 MHz, 0.25V


----------



## user0 (May 26, 2016)

The numbers reported by powerd were completely bogus. I received an email from AMD support listing the P-states and the lowest is 2000 Mhz.


----------



## User23 (May 27, 2016)

Lowest p-state doesn't mean lowest freq.


----------

