Skip to content

Instantly share code, notes, and snippets.

@mcoffin
Last active July 9, 2020 17:31
Show Gist options
  • Save mcoffin/c566b2cca56cde290d1af37f4110f5cf to your computer and use it in GitHub Desktop.
Save mcoffin/c566b2cca56cde290d1af37f4110f5cf to your computer and use it in GitHub Desktop.
pp_od_clk_voltage management script
#!/bin/bash
set -e
set -o pipefail
color_clocks() {
local esc=$(printf '\033')
sed -E "s/^([A-Z_]+):\$/${esc}[1;36m\1${esc}[0;0m:/g"
}
commit_clocks() {
if [ ! -z "$1" ]; then
pushd "$1" 1> /dev/null
fi
if [ ! -e ./pp_od_clk_voltage ]; then
printf "Could not find \"pp_od_clk_voltage\" in \"%s\"\n" "$(pwd)" >&2
return 1
fi
sudo sh -c 'echo c > pp_od_clk_voltage'
if [ ! -z "$1" ]; then
popd 1> /dev/null
fi
}
card=card0
while getopts ":c:" opt; do
case ${opt} in
c)
card="$OPTARG"
card_override=1
;;
\?)
echo "Unknown argument: -$OPTARG" >&2
exit 1
;;
:)
printf "Invalid argument: -%s requires an argument\n" "$OPTARG" >&2
exit 1
;;
esac
done
card_override=${card_override:-0}
shift $((OPTIND -1))
if [ ! -e ./pp_od_clk_voltage ]; then
card_override=1
fi
if [ $card_override -gt 0 ]; then
cd /sys/class/drm/$card/device
fi
if [ ! -e ./pp_od_clk_voltage ]; then
printf "Could not find \"pp_od_clk_voltage\" in \"%s\"\n" "$(pwd)" >&2
exit 1
fi
while [ $# -gt 0 ]; do
echo "$1" | sudo tee pp_od_clk_voltage 1>/dev/null
shift
done
commit_clocks
color_clocks < pp_od_clk_voltage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment