Mostly finish TDP script

This commit is contained in:
Quad 2021-05-20 12:40:52 +02:00
parent 609712d4bd
commit 348bc0de07
1 changed files with 46 additions and 14 deletions

View File

@ -2,9 +2,10 @@
# Global vars/settings
command_name=$(basename $0)
rapl_base="/sys/class/powercap/intel-rapl:0"
pl1_path="${rapl_base}/constraint_0_power_limit_uw"
pl2_path="${rapl_base}/constraint_1_power_limit_uw"
#rapl_path="/sys/class/powercap/intel-rapl:0"
rapl_path="testfolder"
pl1_path="${rapl_path}/constraint_0_power_limit_uw"
pl2_path="${rapl_path}/constraint_1_power_limit_uw"
# Set up help text
help_text="${command_name}: GDP Win 3 TDP management script
@ -77,16 +78,47 @@ w_to_uw () {
fi
}
# Common checks/tasks
is_detailed () {
if [[ "$@" == *"--detail"* ]] || [[ "$@" == *"-d"* ]]; then
exit 0
else
exit 1
fi
}
set_pl () {
if [ $1 -eq 1 ] || [ $1 -eq 2 ] || [ ! -z $2 ]; then
if [ $1 -eq 1 ]; then
pl_path=$pl1_path
elif [ $1 -eq 2 ]; then
pl_path=$pl2_path
fi
echo $(w_to_uw $2) > $pl_path
echo $pl_path
else
exit 1
fi
}
get_pl () {
if [ $1 -eq 1 ]; then
cat $pl1_path
elif [ $1 -eq 2 ]; then
cat $pl2_path
fi
}
# Retrieves current TDP and prints it
check_tdp () {
if [[ "$@" == *"--detail"* ]] || [[ "$@" == *"-d"* ]]; then
local detailed=yes
fi
if [ -z "$1" ] || ( is_detailed $@ ); then
local pl1=$(uw_to_w $(get_pl 1))
local pl2=$(uw_to_w $(get_pl 2))
if [ -z "$1" ]; then
echo "PL1 is $(uw_to_w 10000000)W" # Placeholder
if [ $detailed == "yes" ]; then
echo "PL2 is $(uw_to_w 12000000)W" # Placeholder
echo "PL1 is ${pl1}W" # Placeholder
if ( is_detailed $@ ); then
echo "PL2 is ${pl2}W" # Placeholder
fi
elif [ "$1" == "--help" ]; then
print_help "check"
@ -116,15 +148,15 @@ set_tdp () {
else
#PL1
local watts=$1
local uwatts=$(w_to_uw $watts)
set_pl 1 $watts
#PL2
local watts2=$(expr $watts + 2)
local uwatts2=$(w_to_uw $watts2)
set_pl 2 $watts2
echo $uwatts
echo "PL1 is now ${watts}W (Long-term)"
if [[ "$@" == *"--detail"* ]] || [[ "$@" == *"-d"* ]]; then
if ( is_detailed $@ ); then
echo "PL2 is now ${watts2}W (Short-term)"
fi
fi