tuna: Add functionality to set the cstate of specified CPUs when running tuna
PATCH v4 1/3 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 cstate subcommand to tuna-cmd.py. cpupower.py provides the infrastructure to interface with the cpupower command, and the cstate subcommand in tuna-cmd.py lets the user specify the cstate to be set and the cpu list to set it on.
--- tuna-cmd.py | 14 +++++++-- tuna/cpupower.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 tuna/cpupower.py
tuna-cmd.py +11 -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,8 @@ 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'), } parser = HelpMessageParser(description="tuna - Application Tuning Program")
@@ -147,6 +148,7 @@ def gen_parser(): show_threads = subparser.add_parser('show_threads', description='Show thread list', help='Show thread list') show_irqs = subparser.add_parser('show_irqs', description='Show IRQ list', help='Show IRQ list') show_configs = subparser.add_parser('show_configs', description='List preloaded profiles', help='List preloaded profiles') + cstate = subparser.add_parser('cstate', description='Set a cstate on a given CPU list.', help='Set a cstate on a given CPU list.') what_is = subparser.add_parser('what_is', description='Provides help about selected entities', help='Provides help about selected entities') gui = subparser.add_parser('gui', description="Start the GUI", help="Start the GUI")
@@ -219,6 +221,9 @@ def gen_parser(): show_irqs_group.add_argument('-S', '--sockets', **MODS['sockets']) show_irqs.add_argument('-q', '--irqs', **MODS['irqs']) + cstate.add_argument('-c', '--cpus', **MODS['cpus']) + cstate.add_argument('-i', '--cstate', **MODS['cstate']) + what_is.add_argument('thread_list', **POS['thread_list']) gui.add_argument('-d', '--disable_perf', **MODS['disable_perf'])
@@ -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(str(args.cpu_list).strip('[]').replace(' ', ''), args.cstate) + cpupower_controller.enable_idle_state() + if 'irq_list' in vars(args): ps = procfs.pidstats() if tuna.has_threaded_irqs(ps):
tuna/cpupower.py new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v4 1/1 tuna: add options to get idle state info
Added a function in cpupower.py to get idle state info by executing cpupower, and added an option in tuna to run that function from the cstate subcommand.
--- tuna-cmd.py | 12 +++++++++--- tuna/cpupower.py | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-)
tuna-cmd.py +9 -3
@@ -118,6 +118,8 @@ def gen_parser(): "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"), "cstate": dict(dest='cstate', metavar='CSTATE', help='Set cpus in IDLE-LIST to a specific cstate'), + "info": dict(dest='info', default=False, action='store_true', + help='Display information about available CPU idle states.'), } parser = HelpMessageParser(description="tuna - Application Tuning Program")
@@ -223,6 +225,7 @@ def gen_parser(): cstate.add_argument('-c', '--cpus', **MODS['cpus']) cstate.add_argument('-i', '--cstate', **MODS['cstate']) + cstate.add_argument('--info', **MODS['info']) what_is.add_argument('thread_list', **POS['thread_list'])
@@ -671,9 +674,12 @@ 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(str(args.cpu_list).strip('[]').replace(' ', ''), args.cstate) - cpupower_controller.enable_idle_state() + if args.command == 'cstate': + if args.info: + cpupower.Cpupower.get_idle_info() + elif args.cstate: + cpupower_controller = cpupower.Cpupower(str(args.cpu_list).strip('[]').replace(' ', ''), args.cstate) + cpupower_controller.enable_idle_state() if 'irq_list' in vars(args): ps = procfs.pidstats()
tuna/cpupower.py +12 -6
@@ -59,6 +59,9 @@ class Cpupower: f.close() print('Idle state configuration restored') + def get_idle_info(): + subprocess.call(['cpupower', 'idle-info']) + if __name__ == '__main__': parser = argparse.ArgumentParser()
@@ -66,15 +69,18 @@ if __name__ == '__main__': help='List of cpus to perform cpupower-idle-set operation on.') parser.add_argument('-s', '--cstate', default='', help='Specify cstate to enable/disable') - + parser.add_argument('--info', default=False, action='store_true', help='Get idle state information') + args = parser.parse_args() print(args) cpulist = args.cpu_list cstate = args.cstate - cpupower = Cpupower(cpulist, cstate) - - cpupower.enable_idle_state() - time.sleep(10) - cpupower.restore_cstate() + if (cstate): + cpupower = Cpupower(cpulist, cstate) + cpupower.enable_idle_state() + time.sleep(10) + cpupower.restore_cstate() + elif (args.info): + Cpupower.get_idle_info()
Signature · 1 line
2.45.2
PATCH v4 3/3 tuna: require -i option for cstate
In reply to Anubhav ShelatPreviously, user could run cstate subcommand without specifying cstate. Now the option to specify a cstate is required.
--- tuna-cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tuna-cmd.py +1 -1
@@ -224,7 +224,7 @@ def gen_parser(): show_irqs.add_argument('-q', '--irqs', **MODS['irqs']) cstate.add_argument('-c', '--cpus', **MODS['cpus']) - cstate.add_argument('-i', '--cstate', **MODS['cstate']) + cstate.add_argument('-i', '--cstate', **MODS['cstate'], required=True) cstate.add_argument('--info', **MODS['info']) what_is.add_argument('thread_list', **POS['thread_list'])
Signature · 1 line
2.45.2