diff mbox series

[v4] tuna: add options to get idle state info

Message ID 20240725162532.1890461-2-ashelat@redhat.com
State New
Headers show
Series [v4] tuna: add options to get idle state info | expand

Commit Message

Anubhav Shelat July 25, 2024, 4:25 p.m. UTC
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.

Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
---
 tuna-cmd.py      | 12 +++++++++---
 tuna/cpupower.py | 18 ++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/tuna-cmd.py b/tuna-cmd.py
index c6ef8bae09a3..b6f94182241f 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -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()
diff --git a/tuna/cpupower.py b/tuna/cpupower.py
index ecb82536d404..0aa9243b7838 100644
--- a/tuna/cpupower.py
+++ b/tuna/cpupower.py
@@ -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()