diff --git a/environment/env.go b/environment/env.go index 25079b4..6dc3f0e 100644 --- a/environment/env.go +++ b/environment/env.go @@ -1,7 +1,10 @@ package environment -// Environment Variables that are used. +// Environment Variables and that are used. // These environment variables need to be set before launching elektron. -// Environment Variable to store the password for username="rapl" on the nodes in the cluster. +// Password for username="rapl" on the nodes in the cluster. var RaplPassword = "RAPL_PSSWD" + +// Location of the script that sets the powercap value for a host. +var RaplThrottleScriptLocation = "RAPL_PKG_THROTTLE_SCRIPT_LOCATION" diff --git a/rapl/cap.go b/rapl/cap.go index dd57a49..a981ddc 100644 --- a/rapl/cap.go +++ b/rapl/cap.go @@ -33,7 +33,7 @@ func Cap(host, username string, percentage float64) error { return errors.Wrap(err, "Failed to create session") } - err = session.Run("sudo /misc/shared_data/rdelval1/RAPL_PKG_Throttle.py " + strconv.FormatFloat(percentage, 'f', 2, 64)) + err = session.Run("sudo " + os.Getenv(elekEnv.RaplThrottleScriptLocation) + "/RAPL_PKG_Throttle.py" + strconv.FormatFloat(percentage, 'f', 2, 64)) if err != nil { return errors.Wrap(err, "Failed to run RAPL script") } diff --git a/scripts/RAPL_PKG_Throttle.py b/scripts/RAPL_PKG_Throttle.py new file mode 100644 index 0000000..34e58b1 --- /dev/null +++ b/scripts/RAPL_PKG_Throttle.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 +import sys +import os +import math + +def main(): + POWER_CAP_DIR = "/sys/class/powercap/" + + if not len(sys.argv) == 2: + print(sys.argv[0] + " ") + exit(-1) + + if not os.path.exists(POWER_CAP_DIR): + print("Powercap framework not installed exist") + exit(-1) + + throttle_percent = float(sys.argv[1])/100.0 + + if throttle_percent > 1.0 or throttle_percent < 0: + print("Percent must be between 0 and 100") + exit(-1) + +# print(throttle_percent) + + + + for directory in os.listdir(POWER_CAP_DIR): + if len(directory.split(':')) == 2: + max_watts = open(POWER_CAP_DIR + directory + '/constraint_0_max_power_uw', 'r') + rapl_cap_watts = open(POWER_CAP_DIR + directory + '/constraint_0_power_limit_uw', 'w') #0=longer window, 1=shorter window + + rapl_cap_watts.write(str(math.ceil(float(max_watts.read())*throttle_percent))) + + +main()