From 733d81ed05e90e27a08f838ad020f41d8aef7bc2 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sat, 13 Nov 2021 14:50:42 +0100 Subject: [PATCH] v7.8 + DietPi-Set_CPU | Assure the script always exists with no error code + DietPi-Set_CPU | Only obtain dietpi.txt settings when required and always perform valid min/max integer checks with a fallback default value + DietPi-Set_CPU | Exit early if CPU governor tunables are present but not writable, e.g. within a container + RC up --- .update/version | 2 +- dietpi.txt | 8 ++-- dietpi/dietpi-autostart | 2 +- dietpi/func/dietpi-globals | 2 +- dietpi/func/dietpi-set_cpu | 87 ++++++++++++++++++++------------------ 5 files changed, 52 insertions(+), 49 deletions(-) diff --git a/.update/version b/.update/version index a93855de66..b8ecff269d 100644 --- a/.update/version +++ b/.update/version @@ -1,7 +1,7 @@ # Available DietPi version G_REMOTE_VERSION_CORE=7 G_REMOTE_VERSION_SUB=8 -G_REMOTE_VERSION_RC=1 +G_REMOTE_VERSION_RC=2 # Minimum DietPi version to allow update G_MIN_VERSION_CORE=6 G_MIN_VERSION_SUB=0 diff --git a/dietpi.txt b/dietpi.txt index 600288b84e..e73af71bab 100644 --- a/dietpi.txt +++ b/dietpi.txt @@ -27,7 +27,7 @@ AUTO_SETUP_TIMEZONE=Europe/London AUTO_SETUP_NET_ETHERNET_ENABLED=1 AUTO_SETUP_NET_WIFI_ENABLED=0 -# Force ethernet speeds: 0=automatic speed | 10 = 10Mbit | 100 = 100Mbit etc +# Force Ethernet speeds: 0=automatic speed | 10 = 10Mbit | 100 = 100Mbit etc # - This is mainly aimed at PINE A64 which may have an HW issue that causes unstable 1Gbit link. AUTO_SETUP_NET_ETH_FORCE_SPEED=0 @@ -105,7 +105,7 @@ AUTO_SETUP_DESKTOP_INDEX=0 # - It won't be installed if no desktop is installed and a manual browser selection will override it. AUTO_SETUP_BROWSER_INDEX=-1 -# DietPi-Autostart: 0=Console | 7=Console autologin | 1=Kodi | 2=Desktop autologin | 16=Desktop | 4=OpenTyrian | 5=DietPi-Cloudshell | 6=Amiberry fast boot | 8=Amiberry standard boot | 9=DDX-Rebirth | 10=CAVA Spectrum | 11=Chromium kiosk | 14=Custom autostart service +# DietPi-Autostart: 0=Console | 7=Console autologin | 1=Kodi | 2=Desktop autologin | 16=Desktop | 4=OpenTyrian | 5=DietPi-CloudShell | 6=Amiberry fast boot | 8=Amiberry standard boot | 9=DDX-Rebirth | 10=CAVA Spectrum | 11=Chromium kiosk | 14=Custom script (background) | 17=Custom script (foreground) # - This will be effective on 2nd boot, after firstrun update and installs have been done. # - Related software titles must be installed either on firstrun installs or via AUTO_SETUP_AUTOMATED=1 + AUTO_SETUP_INSTALL_SOFTWARE_ID (see below). AUTO_SETUP_AUTOSTART_TARGET_INDEX=0 @@ -148,9 +148,9 @@ SURVEY_OPTED_IN=-1 CONFIG_CPU_GOVERNOR=schedutil # Ondemand Sampling Rate | Min value: 10000 microseconds (10ms) CONFIG_CPU_ONDEMAND_SAMPLE_RATE=25000 -# Ondemand Sampling Down Factor: Samling Rate * Down Factor / 1000 = ms (40 = 1000ms when sampling rate is 25000) +# Ondemand Sampling Down Factor: Sampling Rate * Down Factor / 1000 = ms (40 = 1000ms when sampling rate is 25000) CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=40 -# Throttle Up Percentage: Percentage of average CPU usage during samling rate at which CPU will be throttled up/down +# Throttle Up Percentage: Percentage of average CPU usage during sampling rate at which CPU will be throttled up/down CONFIG_CPU_USAGE_THROTTLE_UP=50 # CPU Frequency Limits: Disabled=disabled diff --git a/dietpi/dietpi-autostart b/dietpi/dietpi-autostart index c07e76363f..16c7456dd3 100644 --- a/dietpi/dietpi-autostart +++ b/dietpi/dietpi-autostart @@ -219,7 +219,7 @@ _EOF_ '' '●─ Other ' '14' ': Custom script (background, no autologin)' '17' ': Custom script (foreground, with autologin)' - '5' ': DietPi-Cloudshell' + '5' ': DietPi-CloudShell' ) diff --git a/dietpi/func/dietpi-globals b/dietpi/func/dietpi-globals index a4d63d7a47..1ee34c5149 100644 --- a/dietpi/func/dietpi-globals +++ b/dietpi/func/dietpi-globals @@ -57,7 +57,7 @@ # - Assign defaults/code version as fallback [[ $G_DIETPI_VERSION_CORE ]] || G_DIETPI_VERSION_CORE=7 [[ $G_DIETPI_VERSION_SUB ]] || G_DIETPI_VERSION_SUB=8 - [[ $G_DIETPI_VERSION_RC ]] || G_DIETPI_VERSION_RC=1 + [[ $G_DIETPI_VERSION_RC ]] || G_DIETPI_VERSION_RC=2 [[ $G_GITBRANCH ]] || G_GITBRANCH='master' [[ $G_GITOWNER ]] || G_GITOWNER='MichaIng' # - Save current version and Git branch diff --git a/dietpi/func/dietpi-set_cpu b/dietpi/func/dietpi-set_cpu index 097c442bd4..004a77d5c8 100644 --- a/dietpi/func/dietpi-set_cpu +++ b/dietpi/func/dietpi-set_cpu @@ -10,17 +10,22 @@ # # Info: # - Location: /boot/dietpi/func/dietpi-set_cpu - # - Runs at boot, called by /boot/dietpi/preboot + # - Runs at boot, called by dietpi-preboot.service > /boot/dietpi/preboot # - Applies CPU governor: ondemand, powersave, performance, etc. # - Applies CPU governor settings: throttle up percent etc. #//////////////////////////////////// # Exit if not supported - if [[ ! -f '/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors' ]]; then - - echo 'DietPi-CPU_set | CPU governors are not supported on this device. Aborting...' - exit - + if [[ ! -w '/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors' ]] + then + + if [[ -f '/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors' ]] + then + echo 'DietPi-CPU_set | CPU governors cannot be changed on this system. This is probably a container guest. Aborting...' + else + echo 'DietPi-CPU_set | CPU governors are not available on this system. This is probably a virtual machine. Aborting...' + fi + exit 0 fi # Import DietPi-Globals -------------------------------------------------------------- @@ -37,35 +42,33 @@ local available_governors=$( /sys/devices/system/cpu/intel_pstate/no_turbo @@ -118,7 +119,7 @@ fi - # Standard via kernel (MHz) + # Linux CPUfreq: kHz elif [[ -f '/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq' ]]; then # Reset to defaults if no/invalid entry @@ -131,7 +132,6 @@ for i in /sys/devices/system/cpu/cpu[0-9]*/cpufreq do - if (( $converted_khz_value_min > 0 )); then echo "$converted_khz_value_min" > "$i/scaling_min_freq" @@ -151,7 +151,6 @@ mawk '{print $NF}' "$i/scaling_available_frequencies" > "$i/scaling_max_freq" fi - done else @@ -162,14 +161,15 @@ fi - local cpu_throttle_up_percent=$(sed -n '/^[[:blank:]]*CONFIG_CPU_USAGE_THROTTLE_UP=/{s/[^=]*=//p;q}' /boot/dietpi.txt) - # Set CPU governor interactive settings if [[ $CPU_GOVERNOR == 'interactive' ]]; then - # Set hispeed_load, if available on system (eg: XU4 kernel lacks this feature) + # Set hispeed_load if supported by system (e.g. Odroid XU4 kernel lacks this feature) if [[ -f '/sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load' ]]; then + local cpu_throttle_up_percent=$(sed -n '/^[[:blank:]]*CONFIG_CPU_USAGE_THROTTLE_UP=/{s/[^=]*=//p;q}' /boot/dietpi.txt) + disable_error=1 G_CHECK_VALIDINT "$cpu_throttle_up_percent" 1 100 || cpu_throttle_up_percent=50 + G_DIETPI-NOTIFY 2 "Setting go_hispeed_load: $cpu_throttle_up_percent %" echo "$cpu_throttle_up_percent" > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load @@ -182,12 +182,16 @@ # Set CPU governor ondemand settings elif [[ $CPU_GOVERNOR == 'ondemand' ]]; then + local cpu_throttle_up_percent=$(sed -n '/^[[:blank:]]*CONFIG_CPU_USAGE_THROTTLE_UP=/{s/[^=]*=//p;q}' /boot/dietpi.txt) local cpu_ondemand_sampling_rate=$(sed -n '/^[[:blank:]]*CONFIG_CPU_ONDEMAND_SAMPLE_RATE=/{s/[^=]*=//p;q}' /boot/dietpi.txt) local cpu_ondemand_sampling_down_factor=$(sed -n '/^[[:blank:]]*CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=/{s/[^=]*=//p;q}' /boot/dietpi.txt) + disable_error=1 G_CHECK_VALIDINT "$cpu_throttle_up_percent" 1 100 || cpu_throttle_up_percent=50 + disable_error=1 G_CHECK_VALIDINT "$cpu_ondemand_sampling_rate" 10000 || cpu_ondemand_sampling_rate=25000 + disable_error=1 G_CHECK_VALIDINT "$cpu_ondemand_sampling_down_factor" 1 100 || cpu_ondemand_sampling_down_factor=40 G_DIETPI-NOTIFY 2 "Setting up_threshold: $cpu_throttle_up_percent %" G_DIETPI-NOTIFY 2 "Setting sampling_rate: $cpu_ondemand_sampling_rate microseconds" - G_DIETPI-NOTIFY 2 "Setting sampling_down_factor: $cpu_ondemand_sampling_down_factor" + G_DIETPI-NOTIFY 2 "Setting sampling_down_factor: $cpu_ondemand_sampling_down_factor x" # Check for different possible locations # - All @@ -197,17 +201,15 @@ echo "$cpu_ondemand_sampling_rate" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate echo "$cpu_ondemand_sampling_down_factor" > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor - # - XU4 3.x kernel + # - Odroid XU4 3.x kernel elif [[ -f '/sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold' ]]; then # Apply to all cores for i in /sys/devices/system/cpu/cpu[0-9]*/cpufreq/ondemand do - echo "$cpu_throttle_up_percent" > "$i/up_threshold" echo "$cpu_ondemand_sampling_rate" > "$i/sampling_rate" echo "$cpu_ondemand_sampling_down_factor" > "$i/sampling_down_factor" - done else @@ -219,9 +221,12 @@ # Set CPU governor conservative settings elif [[ $CPU_GOVERNOR == 'conservative' ]]; then + local cpu_throttle_up_percent=$(sed -n '/^[[:blank:]]*CONFIG_CPU_USAGE_THROTTLE_UP=/{s/[^=]*=//p;q}' /boot/dietpi.txt) + disable_error=1 G_CHECK_VALIDINT "$cpu_throttle_up_percent" 1 100 || cpu_throttle_up_percent=50 + G_DIETPI-NOTIFY 2 "Setting up_threshold: $cpu_throttle_up_percent %" - # XU3/4 different path (must apply to each core) + # Odroid XU4: Must apply to each core if [[ $G_HW_MODEL != 11 && -f '/sys/devices/system/cpu/cpufreq/conservative/up_threshold' ]]; then echo "$cpu_throttle_up_percent" > /sys/devices/system/cpu/cpufreq/conservative/up_threshold @@ -230,9 +235,7 @@ for i in /sys/devices/system/cpu/cpu[0-9]*/cpufreq/conservative do - echo "$cpu_throttle_up_percent" > "$i/up_threshold" - done else @@ -253,12 +256,12 @@ #----------------------------------------------------------------------------------- Check_CPU_Gov_Available - # Apply CPU0 gov to all cores (if required) + # Apply CPU governor to all cores Apply_CPU_Gov G_DIETPI-NOTIFY 0 "Applied CPU governor settings: $CPU_GOVERNOR" #----------------------------------------------------------------------------------- - exit + exit 0 #----------------------------------------------------------------------------------- }