This repository has no description
1.5 kB
80 lines
1#!/usr/bin/env bash
2
3set -euo pipefail
4
5# Power profiles in watts (stapm/sustained limit)
6PROFILE_LOW=3
7PROFILE_NORMAL=15
8PROFILE_HIGH=28
9
10usage() {
11 cat <<EOF
12Usage: power-profile <profile|watts>
13
14Profiles:
15 low - ${PROFILE_LOW}W TDP (battery saving)
16 normal - ${PROFILE_NORMAL}W TDP (balanced)
17 high - ${PROFILE_HIGH}W TDP (performance)
18
19Or specify watts directly:
20 power-profile 10 # Set 10W TDP
21
22Burst limits are automatically calculated:
23 slow = stapm × 1.2
24 fast = stapm × 1.5
25
26Examples:
27 power-profile low
28 power-profile normal
29 power-profile high
30 power-profile 5
31EOF
32}
33
34set_tdp() {
35 local stapm=$1
36 # Calculate burst limits (using integer math, *10 then /10 to simulate decimals)
37 local slow=$(( (stapm * 12) / 10 ))
38 local fast=$(( (stapm * 15) / 10 ))
39
40 local stapm_mw=$((stapm * 1000))
41 local slow_mw=$((slow * 1000))
42 local fast_mw=$((fast * 1000))
43
44 echo "Setting power profile:"
45 echo " STAPM (sustained): ${stapm}W"
46 echo " Slow limit: ${slow}W"
47 echo " Fast limit: ${fast}W"
48 ryzenadj --stapm-limit="$stapm_mw" --slow-limit="$slow_mw" --fast-limit="$fast_mw"
49 echo "Done."
50}
51
52if [[ $# -ne 1 ]]; then
53 usage
54 exit 1
55fi
56
57case "$1" in
58 low)
59 set_tdp "$PROFILE_LOW"
60 ;;
61 normal)
62 set_tdp "$PROFILE_NORMAL"
63 ;;
64 high)
65 set_tdp "$PROFILE_HIGH"
66 ;;
67 -h|--help|help)
68 usage
69 exit 0
70 ;;
71 *)
72 if [[ "$1" =~ ^[0-9]+$ ]]; then
73 set_tdp "$1"
74 else
75 echo "Error: Unknown profile '$1'"
76 usage
77 exit 1
78 fi
79 ;;
80esac