cpufreq-userspace-scaler
cpufreq-userspace-scaler copied to clipboard
errors on boot, but OK when manually ran or executed a second time.
I have this script running as root as a scheduled task, user-defined script at boot-up of /usr/local/bin/scaler.sh &
I have it configured to send notification details by email.
When It runs at boot-up, I see Current Status:0 (Normal) Standard output/error:/usr/local/bin/scaler.sh: line61:echo:write error:invalid argument.
If I go to that same scheduled job post-boot and right-click run, it runs properly. Current Status:0 (Normal) Standard output/error:
maybe something is not quite ready yet at boot? ps this cpu was recently changed a few times hex to quad to another hex core cpu, in case that matters.
Try to run the script with bash -x /usr/local/bin/scaler.sh &
in order to get more logs.
The error line61:echo:write error:invalid argument
could mean that ether $maxfreq
or $cpucorecount
aren't defined.
I will try that. What I have been using in the meantime, having the script executed a second time, with the first execution a dependency of the second, works well. My CPU is an intel i9-9900k w HT disabled so 8 cores.
Initial Attempt (what is supposet to work)
task:"scaler" user:root Event:Boot-up User-defined script:/usr/local/bin/scaler.sh &
output.log:/usr/local/bin/scaler.sh: line 61: echo: write error: Invalid argument
script.log:/usr/local/bin/scaler.sh &
->result: script didn't work as all 8 cores remain at 3,601,000
Next Attempt (what does work but I don't know why :) )
task:"scaler" user:root Event:Boot-up User-defined script:/usr/local/bin/scaler.sh &
output.log:/usr/local/bin/scaler.sh: line 61: echo: write error: Invalid argument
script.log:/usr/local/bin/scaler.sh &
task:"2nd scaler" user:root Event:Boot-up Pre-Task:scaler User-defined script:/usr/local/bin/scaler.sh &
output.log:
script.log:/usr/local/bin/scaler.sh &
->result: script did work as all 8 cores dropped quickly to 800,000
Diagnostic Attempt (provide meaningful logs)
task:"scaler" user:root Event:Boot-up User-defined script:bash -x /usr/local/bin/scaler.sh &
output.log:
+ set -euo pipefail
++ sort -u
++ awk '{ print $4 - 1 }'
++ grep cores /proc/cpuinfo
+ cpucorecount=7
++ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+ governor=userspace
+ '[' userspace '!=' userspace ']'
+ IFS=' '
+ read -r -a freqlist
++ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
+ scalingminfreq=800000
+ scalingmaxfreq=3601000
+ '[' userspace = userspace ']'
++ seq 0 7
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ echo 800000
+ echo 3601000
+ true
+ main
++ cut -c 1-2
+ currtemp=60
++ cut -c 1-2
+ maxtemp=86
++ awk -F . '{print $1 substr($2,1,2)}'
+ loadavg=255
+ minfreq=800000
+ midfreq=2200000
+ maxfreq=3601000
+ coolfreq=3200000
+ lowload=050
+ midload=065
+ '[' 60 -lt 86 ']'
++ seq 0 7
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
+ sleep 0.5
+ true
+ main
++ cut -c 1-2
+ currtemp=60
++ cut -c 1-2
+ maxtemp=86
++ awk -F . '{print $1 substr($2,1,2)}'
+ loadavg=255
+ minfreq=800000
+ midfreq=2200000
+ maxfreq=3601000
+ coolfreq=3200000
+ lowload=050
+ midload=065
+ '[' 60 -lt 86 ']'
++ seq 0 7
+ for i in '$(seq 0 "${cpucorecount}")'
+ '[' 255 -le 50 ']'
+ '[' 255 -ge 50 ']'
+ '[' 255 -le 65 ']'
+ '[' 255 -ge 65 ']'
+ echo 3601000
/usr/local/bin/scaler.sh: line 61: echo: write error: Invalid argument
script.log:bash -x /usr/local/bin/scaler.sh &
->result: script didn't work as all 8 cores remain at 3,601,000
I believe the script is simply starting too soon during the boot sequence (not sure what is missing to trigger this). On DSM 7.1 with systemd, I was able to solve this issue issues by adding/changing the following in the service file:
[Unit]
...
After=multi-user.target
Requires=multi-user.target
...
[Install]
WantedBy=syno-bootup-done.target
I believe you can simply prepend a "sleep 60 &&" to the configured boot task to achieve the same (or edit the script to run "sleep 60" as first command). I know it's not the most elegant solution, but it should work reliably, and I'd rather have 60s at boot with no frequency scaling than to have to check and fiddle every time the NAS (re)starts. A more elegant solution would be to check in a while loop until the required directory/files exist, and retry the write ("echo") commands until they work, but not sure it's worth it =)
Thanks @fsvm88. I'll test and integrate the systemd service. I don't think i'll modify the script, for DSM 6.X the sleep tweak in task manager will be fine enough though.