Jump to content
XPEnology Community

CPU Frequency scaling for DS918+


Trauma

Recommended Posts

Hi,

 

Since I was not yet able to build a working cpufreq_ondemand.ko to allow automatic frequency scaling for JUN's loader 1.04b (DSM 6.2.2-24922 Update 2), i've written this script to allow dynamic CPU frequency scaling.

 

It's hosted here https://github.com/Trauma/cpufreq-userspace-scaler

 

# cpufreq-userspace-scaler
##### Cpu frequency scaling script for cpufreq userspace governor

## If you're missing ondemand or conservative governors, this script is for you.

This script is scaling cpu frequency according to current average load.
You can set 3 frequency steps : low, mid, high. This 3 thresholds will 
automatically set cpu frequency accordingly :
  - the `lowload` threshold will set the cpu to his minimal frequency, unless you force it to `scalingminfreq`
  - the `midload` threshold will set the cpu to approximate mid range cpu frequency
  - the `highload` threshold will set the cpu to his maximal frequency, unless you force it to `scalingmaxfreq`

If you set `scalingmaxfreq` and/or `scalingminfreq` the cpu will never override those values.

### Usage :
### Parameters :
Variable name   | Default | Type                        | Comments
----------------|---------|-----------------------------|-----------
lowload         | 050     | integer between 000 and 999 | 050 = load average : 0.50
midload         | 065     | integer between 000 and 999 | 065 = load average : 0.65
highload        | 085     | integer between 000 and 999 | 085 = load average : 0.85
scalingminfreq  | auto    | integer in hertz            | 800000 = 800 Mhz
scalingmaxfreq  | auto    | integer in hertz            | 2500000 = 2,5 Ghz

### Default commande line :
`./scaling.sh &`

### Custom command line example :
`lowload=100 highload=200 scalingmaxfreq=2000000 scalingminfreq=1500000 ./scaling.sh &`

Enjoy.

Edited by Trauma
Tags addition
  • Like 4
  • Thanks 3
Link to comment
Share on other sites

  • 2 weeks later...
9 hours ago, viettanium said:

how to install this script?

just put it to rc.d folder?

 

Installation in rc.d will not work since this script do not provide start and stop args. As @Olegin spotted you can launch it form the task manager, that's the way i use it.

 

Installation example (from your nas cli) :

sudo curl https://raw.githubusercontent.com/Trauma/cpufreq-userspace-scaler/master/scaler.sh -o /usr/local/bin/scaler.sh && sudo chmod +x /usr/local/bin/scaler.sh

Then run it through a startup triggered task, as root, in your DSM, with the following command :

/usr/local/bin/scaler.sh &

or with parameters :

lowload=100 highload=200 scalingmaxfreq=2000000 scalingminfreq=1500000 /usr/local/bin/scaler.sh &

 

Edited by Trauma
  • Like 2
Link to comment
Share on other sites

35 minutes ago, Trauma said:

 

Installation in rc.d will not work since this script do not provide start and stop args. As @Olegin spotted you can launch it form the task manager, that's the way i use it.

 

Installation example (from your nas cli) :


sudo curl https://raw.githubusercontent.com/Trauma/cpufreq-userspace-scaler/master/scaler.sh -o /usr/local/bin/scaler.sh && sudo chmod +x /usr/local/bin/scaler.sh

Then run it through a startup triggered task, as root, in your DSM, with the following command :


/usr/local/bin/scaler.sh &

or with parameters :


lowload=100 highload=200 scalingmaxfreq=2000000 scalingminfreq=1500000 /usr/local/bin/scaler.sh &

 

my CPU is J1900 (2.0GHz 4 core) which had only three mode:

powersave performance userspace

does this script work or I must modify some text?

Link to comment
Share on other sites

Long answer :

Your CPU don not have only 3 modes, synology kernel for DS918+ provides only three cpufreq governors :

  • powersave > set the cpu to its minimal freq
  • performance > set the cpu to its maximal freq
  • userspace > allow you to specify the desired frequency. This script use this governor to modulate the frequency according to system load (that's basically whats explained in the README).

Short answer :

no need to "modify some text", just RTFM ;)

 

  • Like 2
Link to comment
Share on other sites

6 hours ago, Trauma said:

Long answer :

Your CPU don not have only 3 modes, synology kernel for DS918+ provides only three cpufreq governors :

  • powersave > set the cpu to its minimal freq
  • performance > set the cpu to its maximal freq
  • userspace > allow you to specify the desired frequency. This script use this governor to modulate the frequency according to system load (that's basically whats explained in the README).

Short answer :

no need to "modify some text", just RTFM ;)

 

thank you very much, just put this on Triggered Task at Boot-up and this work like a charm!

from 26W Idle now at 23W.

Edited by viettanium
Link to comment
Share on other sites

  • 2 weeks later...

This is a pretty cool script. I really like the fact that it is made to auto-figure out variables. Seems to work well on machine and scales the CPU as needed. While playing around with the files in "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies". I noticed that my J4105 only shows frequencies uptil 1501MHz, but not the boost frequency of 2500MHz. Not that I need the boost, but I wonder if the kernel restricts it

Link to comment
Share on other sites

On 9/11/2019 at 2:29 AM, Jseinfeld said:

This is a pretty cool script. I really like the fact that it is made to auto-figure out variables.

Thanks !

 

 

On 9/11/2019 at 2:29 AM, Jseinfeld said:

 I noticed that my J4105 only shows frequencies uptil 1501MHz, but not the boost frequency of 2500MHz. Not that I need the boost, but I wonder if the kernel restricts it

Not 100% sure about this but i guess boost frequency is managed by intel_pstate, which seems to be enabled in the kernel, but the default cpu frequency driver is set to cpu_freq. I did not succeed to make it work on my rig. I've tried intel_pstate=enable in the grub cmd_line, but no luck. I've also tried to load a compiled module, and it don't load.

 

I guess some guys here have proven it's actually working, while benchmarking the NAS with turbo boost enabled or disabled in bios (they use geekbench in a docker container I guess).

Edited by Trauma
Link to comment
Share on other sites

  • 3 weeks later...

I have a i3-8350K CPU, on z390 chipset, with jun 1.04b+DS918+DSM6.2.2-24922U3.

My BIOS/CPU supports base frequency at 4.0GHz,  power saving lower frequencies (speedstep) but it does not have turbo mode. It also supports overclocking.

 

I have read here that (Jun 1.04b+DS918+DSM6.2.2-24922U3) is not able to correctly move from the base frequency to a lower one based on idleness.

 

Is this script designed to help solve this issue? (seems YES, but just to confirm)

 

Are you aware of a way to see in real time the frequency the CPU is running at in an xpenology system. geekbench can give you an idea of relative max performance, but not confirm lower idle frequencies.

 

 

Edited by mervincm
clarify Q
Link to comment
Share on other sites

It seems to work as designed for me, if a bit more delayed than I expected. It correctly drops it to 800 MHz when it is completely idle, and up to full speed when it is really busy. It is not very often at the mid frequency (2400) but it is there on occasion, so it is working.

thanks!

 

PS I have not found a way to see an accurate frequency, it always says 4000MHz when it is in fact running at 4600MHz.  It is OC from 4000 to 4600, and I believe the OC is functional based on my geekbench test values, they are too high for a stock speed i3-8350k, but about right ration for a 4600MHz version.  It appears to just be a display issue.

 

Link to comment
Share on other sites

does this look correct? 4c/8t Xeon e3-1265L v3

 

Before:

root@TerraServer:~# grep "MHz" /proc/cpuinfo
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
 

After:

root@TerraServer:~# grep "MHz" /proc/cpuinfo
cpu MHz         : 800.000
cpu MHz         : 800.000
cpu MHz         : 800.000
cpu MHz         : 800.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
cpu MHz         : 2501.000
 

root@TerraServer:~# dmidecode -t processor | grep Speed
        Max Speed: 3800 MHz
        Current Speed: 2500 MHz

 

Is the kernel not HT aware? should I disable it in the BIOS? The DS918+ Celeron J3455 cpu is only 4c/4t, so maybe HT is useless or hampering the scaling in this case?

Edited by Black6spdZ
Link to comment
Share on other sites

18 hours ago, mervincm said:

It seems to work as designed for me, if a bit more delayed than I expected. It correctly drops it to 800 MHz when it is completely idle, and up to full speed when it is really busy. It is not very often at the mid frequency (2400) but it is there on occasion, so it is working.

thanks!

If you want, you can use variables to adjust speed and steps according to you're load profil.

 

18 hours ago, mervincm said:

PS I have not found a way to see an accurate frequency, it always says 4000MHz when it is in fact running at 4600MHz.  It is OC from 4000 to 4600, and I believe the OC is functional based on my geekbench test values, they are too high for a stock speed i3-8350k, but about right ration for a 4600MHz version.  It appears to just be a display issue.

acpi-cpufreq driver gather frequencies from ACPI tables, so it's certainly related to your bios ACPI implementation. Try to tweak cpu and acpi settings in bios, it may help. Maybe this CPU is not completly supported on this mobo (bios update ?).

 

Try this, to see if it's more consistant

cat /sys/devices/system/cpu/cpufreq/policy0/bios_limit

 

4 hours ago, Black6spdZ said:

does this look correct? 4c/8t Xeon e3-1265L v3

.....

Is the kernel not HT aware? should I disable it in the BIOS? The DS918+ Celeron J3455 cpu is only 4c/4t, so maybe HT is useless or hampering the scaling in this case?

Obviously not ! Anyway I'm not sure cpuinfo is totally reliable here. Prefer sysfs informations in my opinion.

 

Try this, to see if it's more consistant

cat $(ls /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq)

Please try this as well and report the output of the command here please (for your cpu it should return "8") :

cat /proc/cpuinfo | grep cores | sort -u | awk '{ print $4 }'

 

Edited by Trauma
  • Like 1
Link to comment
Share on other sites

disabled HT

root@TerraServer:~# grep "MHz" /proc/cpuinfo
cpu MHz         : 800.000
cpu MHz         : 800.000
cpu MHz         : 800.000
cpu MHz         : 800.000

 

not saving any power though even before applying script idle ~50w < kill-a-watt meter

 

e3-1265L v3 + mobo ~8w idle

4x HGST DC HC510 10TB ~5w idle/ea  <spec sheet

2x EVO 850 500GB <1w /ea max idle

LSI sas2308-8i IT ~9.8w <spec sheet

2 sticks ddr3 ~5w

onboard BMC/RAC 6w < power with nas off

 

this look pretty close to anyone's similar setup or past experience?

 

Edited by Black6spdZ
Link to comment
Share on other sites

16 hours ago, Black6spdZ said:

root@TerraServer:~# cat $(ls /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq)
800000
800000
800000
800000
2501000
2501000
2501000
2501000

root@TerraServer:~# cat /proc/cpuinfo | grep cores | sort -u | awk '{ print $4 }'
4
 

Please try this version of the script, and report us if it's OK... or not please :

https://raw.githubusercontent.com/Trauma/cpufreq-userspace-scaler/ht-compat/scaler.sh

  • Like 1
Link to comment
Share on other sites

1 hour ago, Black6spdZ said:

/usr/local/bin/scaler.sh: line 53: echo: write error: Invalid argument

 

maybe only physical cores 0-3 can be changed? is there any way to watch all core frequencies in real-time?

 

Yes it seems like ! It certainly means acpi-cpufreq is not able to control threaded cores.

 

You could use this simple loop to monitor cpu frequency, quick and dirty but works... (CTRL+C to escape):

while true; do cat $(ls /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq); done

 

  • Like 1
Link to comment
Share on other sites

Makes sense that you could only modify physical core speeds.. I'm curious why a modern open source OS *nix can't get it's reporting correct around HT x86 CPU's.. They've only been around over a decade now. On a side note I can't test idle power at least until tomorrow, I decided to move my drives around in my case to optimize cooling and the "pin tape spinup mod" for these drives.. Well one of the drives pin came uncovered and didn't spin up.. Needless to say my volume is rebuilding now 😕 oops

Edited by Black6spdZ
Link to comment
Share on other sites

On 9/30/2019 at 1:19 PM, Trauma said:

If you want, you can use variables to adjust speed and steps according to you're load profil.

 

is there something you can point to better understand the load profiles? The speed is just CPU frequency, so that is simple to understand. 

 

On 9/30/2019 at 1:19 PM, Trauma said:

acpi-cpufreq driver gather frequencies from ACPI tables, so it's certainly related to your bios ACPI implementation. Try to tweak cpu and acpi settings in bios, it may help. Maybe this CPU is not completly supported on this mobo (bios update ?).

 

BIOS support for this CPU was in there from the initial release. The systemboard is a gen newer than the CPU actually. I can play with the BIOS, but Windows tools like CPUz read it correctly (if that matters)

 

On 9/30/2019 at 1:19 PM, Trauma said:

 

Try this, to see if it's more consistant


cat /sys/devices/system/cpu/cpufreq/policy0/bios_limit

 

My results are consistant, they just are not correct. 

 

Thank you!

Link to comment
Share on other sites

On 10/1/2019 at 8:17 PM, Black6spdZ said:

root@TerraServer:~# cat $(ls /sys/devices/system/cpu/cpufreq/policy*/scaling_cur_freq)
800000
800000
800000
800000
2501000
2501000
2501000
2501000

root@TerraServer:~# cat /proc/cpuinfo | grep cores | sort -u | awk '{ print $4 }'
4
 

 

I wonder what order these are listed in? if it is phys,phys,phys,virt,virt,virt,virt , maybe it is just a display issue? virtual HT CPUs can't run at a higher frequency than the core performing the work right?

Even if it is Phys,virt,phys,virt etc. Is that even possible? I know individual cores can go UP from base to turbo, but can individual cores go DOWN from base to speedstep? I understood that was a CPU wide change?

maybe this is all just cosmetic?

 

Speaking of turbo, it lists your max, but your turbo is never used. That is ALOT of untapped CPU, expecially on an L CPU. PS this is why I use the i3s. no turbo :)

 

  

Link to comment
Share on other sites

20 minutes ago, mervincm said:

 

I wonder what order these are listed in? if it is phys,phys,phys,virt,virt,virt,virt , maybe it is just a display issue? virtual HT CPUs can't run at a higher frequency than the core performing the work right?

Even if it is Phys,virt,phys,virt etc. Is that even possible? I know individual cores can go UP from base to turbo, but can individual cores go DOWN from base to speedstep? I understood that was a CPU wide change?

maybe this is all just cosmetic?

 

Speaking of turbo, it lists your max, but your turbo is never used. That is ALOT of untapped CPU, expecially on an L CPU. PS this is why I use the i3s. no turbo :)

 

  

isn't turbo C0 state? wonder why it wouldn't clock up? any sysinfo gui package that can be installed on the web gui?

Link to comment
Share on other sites

I don't know why turbo modes are not supported, but there is quite a bit of chatter about it spread around this forum, and I have yet to find anyone getting it to work on the DSM config I use at least (6.2.2u3 w 1.04b and DS918+)

The best web GUI I have found for performance data on a DSM system is netdata in a docker, but while there is PILES of interesting stuff in real time, precious little on CPU frequency.  

Link to comment
Share on other sites

Netdata is effectively a good too monitor your server.

 

About "phys,phys,phys,virt,virt,virt,virt", seems like it's actually displayed/ordered like this. I also doubt HT core could be higher than physical cores. It's also possible that DSM kernel / drivers are missing something to handle this right (maybe bromowl kernel is working).

 

About "load profil", isn't the readme clear enough ? Do you understand "loadaverage" thing ?

 

 

Link to comment
Share on other sites

  • 1 month later...

So if I have a J3355 and it is at 800mhz on idle and 2000mhz normal and 2500mhz on turbo, my parameters would be:

lowload: 040

midload: 065

highload: 085

scalingminfreq: 800000

scalingmaxfreq: 2000000

 

Is this right? I don't know if it is safe to test speeds (for example putting 400mhx on scalingminfreq)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...