Skip to content

Instantly share code, notes, and snippets.

@nariox
Created February 25, 2020 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nariox/11e5284373eb4c858f817e060911ec03 to your computer and use it in GitHub Desktop.
Save nariox/11e5284373eb4c858f817e060911ec03 to your computer and use it in GitHub Desktop.
Script to set power UUID to "adaptive performance" (or any other UUID when supplied in the argument)
#!/bin/bash
set -eu
die() {
echo "$1" >&2
exit 1
}
main() {
local uuid="$1"; shift
echo $uuid
# Ensure we have the device node
if [[ ! -d /sys/devices/platform/INT3400:00/ ]]; then
die "INT3400 device not found"
fi
# Ensure we have the thermal zone...
local zone
for zone in /sys/class/thermal/thermal_zone?; do
if [[ -f "$zone/type" ]] && [[ "$(cat $zone/type)" = "INT3400 Thermal" ]]; then
break
fi
done
if [[ -z "${zone:-}" ]]; then
die "Could not find 'INT3400 Thermal' thermal zone"
fi
# ... and that we can enable/disable it (which is only true when the right
# kernel patches are present).
if [[ ! -f "$zone/mode" ]]; then
die "Thermal zone 'mode' not found; are the kernel patches applied?"
fi
# Ensure the given UUID exists in the `available_uuids` set.
if ! grep -q "^$uuid$" "/sys/devices/platform/INT3400:00/uuids/available_uuids" 2>&1 >/dev/null; then
die "UUID '$uuid' is not supported by the device"
fi
# Okay, all set! Disable zone, set UUID, then enable.
echo disabled > "$zone/mode"
echo "$uuid" > "/sys/devices/platform/INT3400:00/uuids/current_uuid"
echo enabled > "$zone/mode"
echo "Set UUID to: $uuid" >&2
# Ensure that the UUID set properly by reading it back.
if [[ "$(cat /sys/devices/platform/INT3400:00/uuids/current_uuid)" != "$uuid" ]]; then
die "UUID did not set correctly"
fi
echo "Success" >&2
}
if [ -z "$*" ]; then
main "63BE270F-1C11-48FD-A6F7-3AF253FF3E2D"
else
main "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment