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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tuna-cmd.py      | 12 +++++++++---
 tuna/cpupower.py | 16 +++++++++++-----
 2 files changed, 20 insertions(+), 8 deletions(-)

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 abbbe0448a8a..da869420eb6f 100644
--- a/tuna/cpupower.py
+++ b/tuna/cpupower.py
@@ -58,6 +58,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()
@@ -65,15 +68,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()
 
 
-- 
2.45.2





[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux