Last active
May 25, 2022 00:24
-
-
Save highercomve/5d4f1aab54e1286edbadf7eb285c598a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
cmd=`basename $0` | |
usage() { | |
echo "USAGE: $cmd power time_window" | |
echo " power: Power Limit in watts (PL1,PL2)" | |
echo " time_window: PL1 time window in sec (default: 28 max:128)" | |
exit 0 | |
} | |
if [ "$1" == "" ]; then | |
usage | |
fi | |
powercount=$(echo $1 | tr "," "\n" | wc -l) | |
if [ "$powercount" == 2 ]; then | |
pl1w=$(echo $1 | tr "," "\n" | head -n 1 | tail -n 1) | |
pl2w=$(echo $1 | tr "," "\n" | head -n 2 | tail -n 1) | |
pl1=$(( 1000000 * $pl1w )) | |
pl2=$(( 1000000 * $pl2w )) | |
else | |
pl1=$(( 1000000 * $1 )) | |
pl2=$(( 1000000 * $1 )) | |
fi | |
[ "$UID" -eq 0 ] || exec sudo "$0" "$@" | |
powercap-set -p intel-rapl -z 0 -c 0 -l $pl1 | |
if [ "$2" != "" ]; then | |
time=$(( 1000000 * $2 )) | |
powercap-set -p intel-rapl -z 0 -c 1 -l $pl2 -s $time | |
else | |
powercap-set -p intel-rapl -z 0 -c 1 -l $pl2 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment