Skip to content

Commit

Permalink
update-amd-tdp
Browse files Browse the repository at this point in the history
Update es_features.yml

Update tdp_hooks.sh

Update batocera-amd-tdp
  • Loading branch information
Mikhailzrick committed Jan 5, 2025
1 parent 06616e7 commit e92d6fd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 64 deletions.
10 changes: 2 additions & 8 deletions board/batocera/x86/fsoverlay/etc/pm/sleep.d/99resume_tdp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ case "$1" in
else
TDP_SETTING=$(printf "%.0f" "$(/usr/bin/batocera-settings-get global.tdp)")
if [ -z "${TDP_SETTING}" ]; then
TDP_SETTING="$(/usr/bin/batocera-settings-get-master system.cpu.tdp)"

if [ -n "${TDP_SETTING}" ]; then
set_tdp "${TDP_SETTING}"
else
echo "TDP setting is not defined, cannot set TDP."
exit 1
fi
echo "TDP setting is not defined, cannot set TDP."
exit 1
else
handle_tdp "${TDP_SETTING}"
fi
Expand Down
108 changes: 55 additions & 53 deletions package/batocera/core/batocera-configgen/scripts/tdp_hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ fi

# set the final tdp value
set_tdp() {
echo "Game ${2} requested setting AMD Mobile Processor TDP to ${1} Watts" >> $log
TDP_VALUE=$1
ROM_NAME=$2

if [ -z "${ROM_NAME}" ]; then
echo "Setting AMD Mobile Processor TDP to ${1} Watts" >> $log
else
echo "Game ${2} requested setting AMD Mobile Processor TDP to ${1} Watts" >> $log
fi

/usr/bin/batocera-amd-tdp $1
}

Expand All @@ -40,69 +48,63 @@ handle_tdp() {
fi
}

# Check for events
EVENT=$1
SYSTEM_NAME=$2
ROM_PATH=$5

# Get the rom name from ROM_PATH
ROM_NAME=$(basename "$ROM_PATH")

# exit accordingly if the event is neither gameStart nor gameStop
if [ "$EVENT" != "gameStart" ] && [ "$EVENT" != "gameStop" ]; then
exit 0
fi

# handle gameStop event
if [ "$EVENT" == "gameStop" ]; then
# set either user global setting or default tdp
TDP_SETTING=$(printf "%.0f" "$(/usr/bin/batocera-settings-get global.tdp)")
if [ -z "${TDP_SETTING}" ]; then
TDP_SETTING="$(/usr/bin/batocera-settings-get system.cpu.tdp)"

if [ -n "$TDP_SETTING" ]; then
set_tdp "${TDP_SETTING}" "STOP"
else
handle_game_stop() {
if [ "$EVENT" == "gameStop" ]; then
# set user global setting
TDP_SETTING=$(printf "%.0f" "$(/usr/bin/batocera-settings-get global.tdp)")
if [ -z "${TDP_SETTING}" ]; then
echo "No TDP setting defined, cannot set TDP." >> $log
exit 1
fi
handle_tdp "${TDP_SETTING}" "STOP"
exit 0
fi
handle_tdp "${TDP_SETTING}" "STOP"
exit 0
fi
}

# run through determining the desired TDP setting
# check for user set system specific setting
if [ -n "${SYSTEM_NAME}" ]; then
# check for rom specific config
TDP_SETTING=$(/usr/bin/batocera-settings-get "${SYSTEM_NAME}[\"${ROM_NAME}\"].tdp")
if [ -z "${TDP_SETTING}" ]; then
TDP_SETTING="$(/usr/bin/batocera-settings-get ${SYSTEM_NAME}.tdp)"
handle_game_start() {
local SYSTEM_NAME="$1"
local ROM_PATH="$2"

# Extract the base game name
ROM_NAME="${ROM_PATH##*/}"

# check for user set system specific setting
if [ -n "${SYSTEM_NAME}" ]; then
# check for rom specific config
TDP_SETTING=$(/usr/bin/batocera-settings-get "${SYSTEM_NAME}[\"${ROM_NAME}\"].tdp")
if [ -z "${TDP_SETTING}" ]; then
TDP_SETTING="$(/usr/bin/batocera-settings-get ${SYSTEM_NAME}.tdp)"
fi
fi
fi

# If no user set system specific setting check for user set global setting
if [ -z "${TDP_SETTING}" ]; then
TDP_SETTING=$(printf "%.0f" "$(/usr/bin/batocera-settings-get global.tdp)")
fi
# If no user set system specific setting check for user set global setting
if [ -z "${TDP_SETTING}" ]; then
TDP_SETTING=$(printf "%.0f" "$(/usr/bin/batocera-settings-get global.tdp)")
fi

# If no value is found ensure tdp is default before exiting
if [ -z "${TDP_SETTING}" ]; then
TDP_SETTING="$(/usr/bin/batocera-settings-get-master system.cpu.tdp)"
# now apply TDP percentage accordingly
if [ -n "${TDP_SETTING}" ]; then
set_tdp "${TDP_SETTING}" "${ROM_NAME}"
handle_tdp "${TDP_SETTING}" "${ROM_NAME}"
else
echo "No TDP setting defined, cannot set TDP." >> $log
exit 1
fi
exit 0
fi
fi
}

# now apply TDP percentage accordingly
if [ -n "${TDP_SETTING}" ]; then
handle_tdp "${TDP_SETTING}" "${ROM_NAME}"
else
echo "No TDP setting defined, cannot set TDP." >> $log
exit 1
fi
# Check for events
SYSTEM_NAME="$2"
ROM_PATH="$5"

case "$1" in
gameStart)
handle_game_start "$SYSTEM_NAME" "$ROM_PATH"
;;
gameStop)
handle_game_stop
;;
*)
exit 0
;;
esac

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ fi
# Calculate WATTS based on TDP
WATTS=$((TDP * 1000))

if [ "$WATTS" -le 90000 ]; then
WATTS_FAST=$((WATTS * 110 / 100)) # 110% TDP for fast-limit if less than 90, allowing for short and mild dynamic frequenmcy increases
else
WATTS_FAST=$WATTS
fi

# Set TDP using ryzenadj
if /usr/bin/ryzenadj --stapm-limit="${WATTS}" --fast-limit="${WATTS}" --slow-limit="$((WATTS * 80 / 100))" --tctl-temp=95; then
if /usr/bin/ryzenadj --stapm-limit="${WATTS}" --fast-limit="${WATTS_FAST}" --slow-limit="$((WATTS * 90 / 100))"; then
echo "TDP of $TDP Watts has been set" >> "$log"
else
echo "Error setting TDP. Please check the logs for more information." >> "$log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ shared:
group: POWER OPTIONS
prompt: RYZEN THERMAL DESIGN POWER
description: Adjust the percentage of power (watts) provided to a Ryzen Mobile Series CPU based on it's default max value. Caution, setting wattage too high could damage your device.
preset: slider
preset_parameters: 10 130 5 100 %
preset: sliderauto
preset_parameters: 10 130 5 %
videomode:
prompt: VIDEO MODE
description: Set the display's resolution. Does not affect the rendering resolution.
Expand Down

0 comments on commit e92d6fd

Please sign in to comment.