tuna: Add functionality to set the cstate of specified CPUs when running tuna
PATCH v2 1/1 tuna: Add functionality to set the cstate of specified CPUs when running tuna
We would like to be able to set the cstate of CPUs while running tuna.
This patch adds the file cpupower.py and options to tuna-cmd.py. This allows the user to execute the cpupower command from tuna, allowing the user to set the cstate on a given list or cpus. Once tuna exits, the original cstate configuration will be restored.
This will let the user to test balancing power consumption and performance.
Signed-off-by Anubhav Shelat <[email protected]>
--- tuna-cmd.py | 17 +++++++++-- tuna/cpupower.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 tuna/cpupower.py
tuna-cmd.py +14 -3
@@ -21,7 +21,7 @@ from functools import reduce import tuna.new_eth as ethtool import tuna.tuna_sched as tuna_sched import procfs -from tuna import tuna, sysfs +from tuna import tuna, sysfs, cpupower import logging import time import shutil
@@ -116,7 +116,10 @@ def gen_parser(): "disable_perf": dict(action='store_true', help="Explicitly disable usage of perf in GUI for process view"), "refresh": dict(default=2500, metavar='MSEC', type=int, help="Refresh the GUI every MSEC milliseconds"), "priority": dict(default=(None, None), metavar="POLICY:RTPRIO", type=tuna.get_policy_and_rtprio, help="Set thread scheduler tunables: POLICY and RTPRIO"), - "background": dict(action='store_true', help="Run command as background task") + "background": dict(action='store_true', help="Run command as background task"), + "cstate": dict(dest='cstate', metavar='CSTATE', help='Set cpus in IDLE-LIST to a specific cstate'), + "idle_list": dict(dest="idle_list", metavar='IDLE-LIST', + help='CPU list to set idle states on (default: all cpus).') } parser = HelpMessageParser(description="tuna - Application Tuning Program")
@@ -125,6 +128,8 @@ def gen_parser(): parser.add_argument('-v', '--version', **MODS['version']) parser.add_argument('-L', '--logging', **MODS['logging']) parser.add_argument('-D', '--debug', **MODS['debug']) + parser.add_argument('-i', '--cstate', **MODS['cstate']) + parser.add_argument('-l', '--idle-list', **MODS['idle_list']) subparser = parser.add_subparsers(dest='command')
@@ -649,7 +654,6 @@ def main(): parser = gen_parser() # Set all necessary defaults for gui subparser if no arguments provided args = parser.parse_args() if len(sys.argv) > 1 else parser.parse_args(['gui']) - if args.debug: my_logger = setup_logging("my_logger") my_logger.addHandler(add_handler("DEBUG", tofile=False))
@@ -667,6 +671,10 @@ def main(): print("Valid log levels: NOTSET, DEBUG, INFO, WARNING, ERROR") print("Log levels may be specified numerically (0-4)\n") + if args.cstate: + cpupower_controller = cpupower.Cpupower(args.idle_list, args.cstate) + cpupower_controller.enable_idle_state() + if 'irq_list' in vars(args): ps = procfs.pidstats() if tuna.has_threaded_irqs(ps):
@@ -760,6 +768,9 @@ def main(): except KeyboardInterrupt: pass + if cpupower_controller: + cpupower_controller.restore_cstate() + if __name__ == '__main__': main()
tuna/cpupower.py new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.45.2