Update 'scripts/tdp'

This commit is contained in:
Quad 2021-05-20 12:10:29 +02:00
parent f59fb295fc
commit 609712d4bd
1 changed files with 32 additions and 8 deletions

View File

@ -1,7 +1,12 @@
#! /usr/bin/bash
# Set up help text
# 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"
# Set up help text
help_text="${command_name}: GDP Win 3 TDP management script
This script checks and sets the TDP using intel_rapl
@ -55,14 +60,33 @@ print_unknown () {
}
# End of help text
# Conversion tools
uw_to_w () {
if ! [[ $1 =~ ^-?[0-9]+$ ]]; then
exit
else
echo $(expr $1 / 1000000)
fi
}
w_to_uw () {
if ! [[ $1 =~ ^-?[0-9]+$ ]]; then
exit
else
echo $(expr $1 '*' 1000000)
fi
}
# Retrieves current TDP and prints it
check_tdp () {
if [[ "$@" == *"--detail"* ]] || [[ "$@" == *"-d"* ]]; then
echo "Placeholder"
echo "Extra placeholder"
local detailed=yes
fi
elif [ -z "$1" ]; then
echo "Placeholder"
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
elif [ "$1" == "--help" ]; then
print_help "check"
@ -72,7 +96,7 @@ check_tdp () {
fi
}
# Sets TDP to number provided as first argument
# Sets PL1 to number provided as first argument, and PL2 2W higher
set_tdp () {
if [ -z "$1" ]; then
echo "Please specify wattage"
@ -92,11 +116,11 @@ set_tdp () {
else
#PL1
local watts=$1
local uwatts=$(expr $watts '*' 1000000)
local uwatts=$(w_to_uw $watts)
#PL2
local watts2=$(expr $watts + 2)
local uwatts2=$(expr $watts2 '*' 1000000)
local uwatts2=$(w_to_uw $watts2)
echo $uwatts
echo "PL1 is now ${watts}W (Long-term)"