| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2e55c6a commit bb27766
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,21 +4,73 @@ CPUPATH=/sys/devices/system/cpu | |||
| 4 | 4 | ||
| 5 | 5 | MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}') | |
| 6 | 6 | ||
| 7 | + [ "$(uname -s || true)" = "Linux" ] || \ | ||
| 8 | + echo "Warning: This script supports Linux only." >&2 | ||
| 9 | + | ||
| 10 | + [ "$(id -u || true)" = "0" ] || \ | ||
| 11 | + echo "Warning: This script typically needs root access to modify CPU governor. Consider running it with sudo." >&2 | ||
| 12 | + | ||
| 13 | + get_default_governor() { | ||
| 14 | + case "$(cat "$CPUPATH/cpu0/cpufreq/scaling_available_governors")" in | ||
| 15 | + *"schedutil"*) echo "schedutil" ;; | ||
| 16 | + *"ondemand"*) echo "ondemand" ;; | ||
| 17 | + *"conservative"*) echo "conservative";; | ||
| 18 | + *) echo "powersave" ;; | ||
| 19 | + esac | ||
| 20 | + | ||
| 21 | + } | ||
| 22 | + | ||
| 7 | 23 | set_governor() { | |
| 8 | - echo "Setting CPU frequency governor to \"$1\"" | ||
| 24 | + governor_name="$1" | ||
| 25 | + | ||
| 26 | + echo "Setting governor for all CPU cores to \"$governor_name\"..." | ||
| 27 | + | ||
| 9 | 28 | i=0 | |
| 10 | 29 | while [ "$i" -le "$MAXID" ]; do | |
| 11 | 30 | echo "$1" > "$CPUPATH/cpu$i/cpufreq/scaling_governor" | |
| 12 | 31 | i=$((i + 1)) | |
| 13 | 32 | done | |
| 33 | + | ||
| 34 | + echo "Done." | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + usage() { | ||
| 38 | + default_gov=$(get_default_governor) | ||
| 39 | + echo "CPU Governor Management Script" | ||
| 40 | + echo "----------------------------------------------------------------------------" | ||
| 41 | + echo "Usage: $0 [command]" | ||
| 42 | + echo | ||
| 43 | + echo "Commands:" | ||
| 44 | + echo " fast Sets the governor to 'performance' for maximum speed." | ||
| 45 | + echo " (Warning: Increases heat/power use. Use for short-term tasks.)" | ||
| 46 | + echo | ||
| 47 | + echo " reset Resets the governor to the system's recommended default ('$default_gov')." | ||
| 48 | + echo | ||
| 49 | + echo " get Shows the current CPU governor for ALL cores." | ||
| 50 | + echo "----------------------------------------------------------------------------" | ||
| 14 | 51 | } | |
| 15 | 52 | ||
| 16 | 53 | case "$1" in | |
| 17 | 54 | fast | performance) | |
| 55 | + echo "Warning: The 'performance' mode locks the CPU at its highest speed." | ||
| 56 | + echo "It is highly recommended to 'reset' after your task is complete." | ||
| 18 | 57 | set_governor "performance" | |
| 19 | 58 | ;; | |
| 59 | + | ||
| 60 | + reset | default) | ||
| 61 | + default_governor=$(get_default_governor) | ||
| 62 | + set_governor "$default_governor" | ||
| 63 | + ;; | ||
| 64 | + | ||
| 65 | + get | status) | ||
| 66 | + echo "Current governor status for all cores:" | ||
| 67 | + grep . "$CPUPATH"/cpu*/cpufreq/scaling_governor | ||
| 68 | + ;; | ||
| 69 | + | ||
| 20 | 70 | *) | |
| 21 | - echo "Usage: $0 fast" | ||
| 71 | + usage | ||
| 22 | 72 | exit 1 | |
| 23 | 73 | ;; | |
| 24 | 74 | esac | |
| 75 | + | ||
| 76 | + exit 0 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments