Skip to contentSkip to conversation

Add cpupower idle-state functionality

PATCH Superseded John B. Wyatt IV 3 participants 11 messages Jan 28, 2025 – Feb 19, 2025

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Add cpupower idle-state functionality

This patch series adds idle-state functionality to control cpu power usage and to test idle states.

The number of cpus was needed in the cpupower file; I extracted out the previously local to tuna-cli.py functionality to a separate file so the cpu code can be used in any file in Tuna and reduce duplications. The nics code was similar so it was also extracted to reduce the number of global variables.

Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat

John B. Wyatt IV (2):
tuna: extract cpu and nics determination code into a utils.py file
tuna: Add idle-state control functionality

 tuna-cmd.py      |  67 +++++++++-------
 tuna/cpupower.py | 202 +++++++++++++++++++++++++++++++++++++++++++++++
 tuna/utils.py    |  27 +++++++
 3 files changed, 267 insertions(+), 29 deletions(-)
 create mode 100755 tuna/cpupower.py
 create mode 100644 tuna/utils.py
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/2 tuna: extract cpu and nics determination code into a utils.py file

Extracting the code allows these previously local (global to the file) variables and functions to be used in other files of Tuna. Reducing the number of globals makes the code cleaner and reduces the size of tuna-cmd.py.

---
 tuna-cmd.py   | 34 +++++++---------------------------
 tuna/utils.py | 27 +++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 27 deletions(-)
 create mode 100644 tuna/utils.py
tuna-cmd.py +7 -27
index f37e286..d0323f5 100755
@@ -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, utils
 import logging
 import time
 import shutil
@@ -76,7 +76,6 @@ except:
 
 # FIXME: ETOOMANYGLOBALS, we need a class!
 
-nr_cpus = None
 ps = None
 irqs = None
 
@@ -233,25 +232,6 @@ def gen_parser():
     return parser
 
 
-def get_nr_cpus():
-    """ Get all cpus including disabled cpus """
-    global nr_cpus
-    if nr_cpus:
-        return nr_cpus
-    nr_cpus = os.sysconf('SC_NPROCESSORS_CONF')
-    return nr_cpus
-
-nics = None
-
-
-def get_nics():
-    global nics
-    if nics:
-        return nics
-    nics = ethtool.get_active_devices()
-    return nics
-
-
 def thread_help(tid):
     global ps
     if not ps:
@@ -277,7 +257,7 @@ def save(cpu_list, thread_list, filename):
         if (cpu_list and not set(kt.affinity).intersection(set(cpu_list))) or \
            (thread_list and kt.pid not in thread_list):
             del kthreads[name]
-    tuna.generate_rtgroups(filename, kthreads, get_nr_cpus())
+    tuna.generate_rtgroups(filename, kthreads, utils.get_nr_cpus())
 
 
 def ps_show_header(has_ctxt_switch_info, cgroups=False):
@@ -328,7 +308,7 @@ def format_affinity(affinity):
     if len(affinity) <= 4:
         return ",".join(str(a) for a in affinity)
 
-    return ",".join(str(hex(a)) for a in procfs.hexbitmask(affinity, get_nr_cpus()))
+    return ",".join(str(hex(a)) for a in procfs.hexbitmask(affinity, utils.get_nr_cpus()))
 
 def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
                    sock_inode_re, cgroups, columns=None, compact=True):
@@ -351,7 +331,7 @@ def ps_show_thread(pid, affect_children, ps, has_ctxt_switch_info, sock_inodes,
                 irqs = procfs.interrupts()
             users = irqs[tuna.irq_thread_number(cmd)]["users"]
             for u in users:
-                if u in get_nics():
+                if u in utils.get_nics():
                     users[users.index(u)] = "%s(%s)" % (
                         u, ethtool.get_module(u))
             users = ",".join(users)
@@ -486,7 +466,7 @@ def do_ps(thread_list, cpu_list, irq_list, show_uthreads, show_kthreads,
 
 
 def find_drivers_by_users(users):
-    nics = get_nics()
+    nics = utils.get_nics()
     drivers = []
     for u in users:
         try:
@@ -689,10 +669,10 @@ def main():
         apply_config(args.profilename)
 
     elif args.command in ['include', 'I']:
-        tuna.include_cpus(args.cpu_list, get_nr_cpus())
+        tuna.include_cpus(args.cpu_list, utils.get_nr_cpus())
 
     elif args.command in ['isolate', 'i']:
-        tuna.isolate_cpus(args.cpu_list, get_nr_cpus())
+        tuna.isolate_cpus(args.cpu_list, utils.get_nr_cpus())
 
     elif args.command in ['run', 'r']:
 
tuna/utils.py new file +27 -0
new file mode 100644
index 0000000..9010df3
@@ -0,0 +1,27 @@
+# Copyright (C) 2024 John B. Wyatt IV
+# SPDX-License-Identifier: GPL-2.0-only
+
+import os
+
+import tuna.new_eth as ethtool
+
+# Collect a few globals and functions so they can be reused in other modules
+nr_cpus = None
+nics = None
+
+def get_nr_cpus():
+    """ Get all cpus including disabled cpus """
+    global nr_cpus
+    if nr_cpus != None:
+        return nr_cpus
+    nr_cpus = os.sysconf('SC_NPROCESSORS_CONF')
+    return nr_cpus
+
+def get_nics():
+    global nics
+    if nics != None:
+        return nics
+    nics = ethtool.get_active_devices()
+    return nics
+
+
Signature · 1 line
2.48.1
#2 lore raw

PATCH 2/2 tuna: Add idle-state control functionality

In reply to John B. Wyatt IV

Allows Tuna to control cpu idle-state functionality on the system, including querying, enabling, disabling of cpu idle-states to control power usage or to test functionality.

This requires cpupower, a utility in the Linux kernel repository and the cpupower Python bindings added in Linux 6.12 to control cpu idle-states. If cpupower is missing Tuna as a whole will continue to function and idle-set functionality will error out.

---
 tuna-cmd.py      |  33 +++++++-
 tuna/cpupower.py | 202 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 233 insertions(+), 2 deletions(-)
 create mode 100755 tuna/cpupower.py
tuna-cmd.py +31 -2
index d0323f5..81d0f48 100755
@@ -25,6 +25,7 @@ from tuna import tuna, sysfs, utils
 import logging
 import time
 import shutil
+import tuna.cpupower as cpw
 
 def get_loglevel(level):
     if level.isdigit() and int(level) in range(0,5):
@@ -115,8 +116,12 @@ 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"),
+            "idle_state_disabled_status": dict(dest='idle_state_disabled_status', metavar='IDLESTATEDISABLEDSTATUS', type=int, help='Print if cpu idle state of the cpus in CPU-LIST is enabled or disabled. If CPU-LIST is not specified, default to all cpus.'),
+            "idle_info": dict(dest='idle_info', action='store_const', const=True, help='Print general idle information on cpus in CPU-LIST. If CPU-LIST is not specified, default to all cpus.'),
+            "disable_idle_state": dict(dest='disable_idle_state', metavar='IDLESTATEINDEX', type=int, help='Disable cpus in CPU-LIST\'s cpu idle (cpu sleep state). If CPU-LIST is not specified, default to all cpus.'),
+            "enable_idle_state": dict(dest='enable_idle_state', metavar='IDLESTATEINDEX', type=int, help='Enable cpus in CPU-LIST\'s cpu idle (cpu sleep state). If CPU-LIST is not specified, default to all cpus.')
+    }
 
     parser = HelpMessageParser(description="tuna - Application Tuning Program")
 
@@ -147,6 +152,10 @@ def gen_parser():
     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')
 
+    idle_set = subparser.add_parser('idle-set',
+                                    description='Query and set all idle states on a given CPU list. Requires libcpupower to be installed',
+                                    help='Set all idle states 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")
 
@@ -218,6 +227,13 @@ def gen_parser():
     show_irqs_group.add_argument('-S', '--sockets', **MODS['sockets'])
     show_irqs.add_argument('-q', '--irqs', **MODS['irqs'])
 
+    idle_set_group = idle_set.add_mutually_exclusive_group(required=True)
+    idle_set.add_argument('-c', '--cpus', **MODS['cpus'])
+    idle_set_group.add_argument('-s', '--status', **MODS['idle_state_disabled_status'])
+    idle_set_group.add_argument('-i', '--idle-info', **MODS['idle_info'])
+    idle_set_group.add_argument('-d', '--disable', **MODS['disable_idle_state'])
+    idle_set_group.add_argument('-e', '--enable', **MODS['enable_idle_state'])
+
     what_is.add_argument('thread_list', **POS['thread_list'])
 
     gui.add_argument('-d', '--disable_perf', **MODS['disable_perf'])
@@ -635,6 +651,19 @@ def main():
         my_logger.addHandler(add_handler("DEBUG", tofile=False))
         my_logger.info("Debug option set")
 
+    if args.command == 'idle-set':
+        if not cpw.have_cpupower:
+            print(f"Error: libcpupower bindings are not detected; need {cpw.cpupower_required_kernel} at a minimum.")
+            sys.exit(1)
+
+        if not args.cpu_list or args.cpu_list == []:
+            args.cpu_list = cpw.Cpupower().get_all_cpu_list()
+
+        my_cpupower = cpw.Cpupower(args.cpu_list)
+        ret = my_cpupower.idle_state_handler(args)
+        if ret > 0:
+            sys.exit(ret)
+
     if args.loglevel:
         if not args.debug:
             my_logger = setup_logging("my_logger")
tuna/cpupower.py new file +202 -0

202 lines not on this page · raw message

Signature · 1 line
2.48.1
#3 lore raw

Re: [PATCH 2/2] tuna: Add idle-state control functionality

Quoted 45 lines · John B. Wyatt IV

Allows Tuna to control cpu idle-state functionality on the system, including querying, enabling, disabling of cpu idle-states to control power usage or to test functionality.

This requires cpupower, a utility in the Linux kernel repository and the cpupower Python bindings added in Linux 6.12 to control cpu idle-states. If cpupower is missing Tuna as a whole will continue to function and idle-set functionality will error out.

---
 tuna-cmd.py      |  33 +++++++-
 tuna/cpupower.py | 202 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 233 insertions(+), 2 deletions(-)
 create mode 100755 tuna/cpupower.py
tuna-cmd.py +7 -2
index d0323f5..81d0f48 100755
@@ -25,6 +25,7 @@ from tuna import tuna, sysfs, utils
 import logging
 import time
 import shutil
+import tuna.cpupower as cpw
 
 def get_loglevel(level):
     if level.isdigit() and int(level) in range(0,5):
@@ -115,8 +116,12 @@ 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"),
+            "idle_state_disabled_status": dict(dest='idle_state_disabled_status', metavar='IDLESTATEDISABLEDSTATUS', type=int, help='Print if cpu idle state of the cpus in CPU-LIST is enabled or disabled. If CPU-LIST is not specified, default to all cpus.'),
+            "idle_info": dict(dest='idle_info', action='store_const', const=True, help='Print general idle information on cpus in CPU-LIST. If CPU-LIST is not specified, default to all cpus.'),
+            "disable_idle_state": dict(dest='disable_idle_state', metavar='IDLESTATEINDEX', type=int, help='Disable cpus in CPU-LIST\'s cpu idle (cpu sleep state). If CPU-LIST is not specified, default to all cpus.'),
+            "enable_idle_state": dict(dest='enable_idle_state', metavar='IDLESTATEINDEX', type=int, help='Enable cpus in CPU-LIST\'s cpu idle (cpu sleep state). If CPU-LIST is not specified, default to all cpus.')
+    }
 
     parser = HelpMessageParser(description="tuna - Application Tuning Program")
 

tuna-cmd.py def gen_parser(): · line 157

Quoted 6 lines
tuna-cmd.py +3 -0
@@ -147,6 +152,10 @@ def gen_parser():
     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')
 
+    idle_set = subparser.add_parser('idle-set',
+                                    description='Query and set all idle states on a given CPU list. Requires libcpupower to be installed',
+                                    help='Set all idle states on a given CPU-LIST.')

idle_state would be a better name (or idle-state, but underscores are already used elsewhere...), since it can both set and get.

It also mostly operates on individual states (-i being the exception), not all at once. How about just:

Manage CPU idle state disabling (requires libcpupower)

Also, don't forget to update the man page.

Quoted 6 lines
tuna-cmd.py +2 -0
@@ -635,6 +651,19 @@ def main():
         my_logger.addHandler(add_handler("DEBUG", tofile=False))
         my_logger.info("Debug option set")
 
+    if args.command == 'idle-set':
+        if not cpw.have_cpupower:

tuna-cmd.py def main(): · line 665

Quoted 10 lines
tuna-cmd.py +10 -0
+            print(f"Error: libcpupower bindings are not detected; need {cpw.cpupower_required_kernel} at a minimum.")
+            sys.exit(1)
+
+        if not args.cpu_list or args.cpu_list == []:
+            args.cpu_list = cpw.Cpupower().get_all_cpu_list()
+
+        my_cpupower = cpw.Cpupower(args.cpu_list)
+        ret = my_cpupower.idle_state_handler(args)
+        if ret > 0:
+            sys.exit(ret)

Why not just pass in cpu_list as is, and have cpw understand what an empty or absent list is? And it looks like it already partially does check for None... If the user specifically does something like --cpu '' should we really treat that as equivalent to not specifing --cpu? I don't see other commands doing this.

Especially if you're going to delegate all other option parsing... Why is cpulist special? Just do something like:

elif args.command == 'idle_state'
cpw.idle_state(args)

tuna-cmd.py def main(): · line 669

Quoted 3 lines
tuna-cmd.py +0 -0
     if args.loglevel:
         if not args.debug:
             my_logger = setup_logging("my_logger")

Why did you put the new command before log handling, rather than with all the other commands?

Quoted 7 lines
tuna/cpupower.py new file +1 -0
new file mode 100755
index 0000000..b09dc2f
@@ -0,0 +1,202 @@
+# Copyright (C) 2024 John B. Wyatt IV

tuna/cpupower.py line 11

Quoted 10 lines
tuna/cpupower.py new file +10 -0
+# SPDX-License-Identifier: GPL-2.0-only
+
+from typing import List
+import tuna.utils as utils
+
+cpupower_required_kernel = "6.12"
+have_cpupower = None
+
+
+import raw_pylibcpupower as cpw

This is a bit confusing since you import this module as cpw elsewhere...

Also, I got this even without trying to use the new functionality:

$ ./tuna-cmd.py 
Traceback (most recent call last):
  File "/home/crwood/git/tuna/./tuna-cmd.py", line 28, in <module>
    import tuna.cpupower as cpw
  File "/home/crwood/git/tuna/tuna/cpupower.py", line 11, in <module>
    import raw_pylibcpupower as cpw
ModuleNotFoundError: No module named 'raw_pylibcpupower'

Maybe something like:

try:
import raw_pylibcpupower as lcpw
lcpw.cpufreq_get_available_frequencies(0)
except:
lcpw = None

tuna/cpupower.py line 33

Quoted 2 lines
tuna/cpupower.py new file +2 -0
+        You must use have_cpupower variable to determine if the bindings were
+        detected in your code."""

Instead of doing to the class/module user what SWIG did to the binding user, why not just throw an exception if the binding is missing? This will automatically happen if lcpw is None, though you may want a friendlier error message in the main entry point.

tuna/cpupower.py line 42

Quoted 9 lines
tuna/cpupower.py new file +9 -0
+        def __init__(self, cpulist=None):
+            if cpulist == None:
+                self.__cpulist = self.get_all_cpu_list()
+            else:
+                self.__cpulist = cpulist
+
+        @classmethod
+        def get_all_cpu_list(cls):
+            return list(range(cls.get_idle_info()["all_cpus"]))

Is this really idle-state-specific? Maybe just something like this in tuna/utils.py:

def get_all_cpu_list():
return list(range(get_nr_cpus()))

We shouldn't need to get all the idle state information just to get a cpu list.

And all these class methods make me wonder why this is a class to begin with, rather than just module functions.

tuna/cpupower.py line 62

Quoted 3 lines
tuna/cpupower.py new file +3 -0
+
+        @classmethod
+        def get_idle_info(cls, cpu=0):

Why is cpu 0 special?

Quoted 12 lines
tuna/cpupower.py new file +12 -0
+            idle_states, idle_states_amt = cls.get_idle_states(cpu)
+            idle_states_list = []
+            for idle_state in range(0, len(idle_states)):
+                idle_states_list.append(
+                    {
+                        "CPU ID": cpu,
+                        "Idle State Name": idle_states[idle_state],
+                        "Flags/Description": cpw.cpuidle_state_desc(cpu, idle_state),
+                        "Latency": cpw.cpuidle_state_latency(cpu, idle_state),
+                        "Usage": cpw.cpuidle_state_usage(cpu, idle_state),
+                        "Duration": cpw.cpuidle_state_time(cpu, idle_state)
+                    }

tuna/cpupower.py line 84

Quoted 10 lines
tuna/cpupower.py new file +10 -0
+                )
+            idle_info = {
+                "all_cpus": utils.get_nr_cpus(),
+                "CPUidle-driver": cpw.cpuidle_get_driver(),
+                "CPUidle-governor": cpw.cpuidle_get_governor(),
+                "idle-states-count": idle_states_amt,
+                "available-idle-states": idle_states,
+                "cpu-states": idle_states_list
+            }
+            return idle_info

This seems overly complicated. Why do you bundle all this stuff up just to extract it elsewhere? The call to get the data is simpler than the data structure lookup.

tuna/cpupower.py line 87

Quoted 3 lines
tuna/cpupower.py new file +3 -0
+
+        @classmethod
+        def print_idle_info(cls, cpu_list=[0]):

The only thing that instantiating this class does is to store a cpu list, and here you're passing it into a class method instead...

tuna/cpupower.py line 113

Quoted 4 lines
tuna/cpupower.py new file +4 -0
+        def idle_state_handler(self, args) -> int:
+            if args.idle_state_disabled_status != None:
+                cstate_index = args.idle_state_disabled_status
+                cstate_list, cstate_amt = self.get_idle_states(args.cpu_list[0]) # Assumption, that all cpus have the same idle state

The API doesn't make that assumption, so why should we? Systems exist with heterogeneous CPUs... could be a reason to support looking up states by name, if and when there are systems we care about that actually have different cpuidle states.

And you don't need this lookup anyay -- libcpupower already does the bounds check, and you can get the name inside the loop.

tuna/cpupower.py line 116

Quoted 3 lines
tuna/cpupower.py new file +3 -0
+                if cstate_index < 0 or cstate_index >= cstate_amt:
+                    print(f"Invalid idle state range. Total for this cpu is {cstate_amt}")
+                    return 1

"this cpu"?

Quoted 47 lines
tuna/cpupower.py new file +47 -0
+                cstate_name = cstate_list[cstate_index]
+                ret = self.is_disabled_idle_state(cstate_index)
+                for i, e in enumerate(ret):
+                    match e:
+                        case 1:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is disabled.")
+                        case 0:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is enabled.")
+                        case -1:
+                            print(f"Idlestate not available")
+                        case -2:
+                            print(f"Disabling is not supported by the kernel")
+                        case _:
+                            print(f"Not documented: {e}")
+            elif args.idle_info != None:
+                self.print_idle_info(args.cpu_list)
+                return 0
+            elif args.disable_idle_state != None:
+                cstate_index = args.disable_idle_state
+                cstate_list, cstate_amt = self.get_idle_states(args.cpu_list[0]) # Assumption, that all cpus have the same idle state
+                if cstate_index < 0 or cstate_index >= cstate_amt:
+                    print(f"Invalid idle state range. Total for this cpu is {cstate_amt}")
+                    return 1
+                cstate_name = cstate_list[cstate_index]
+                ret = self.disable_idle_state(cstate_index, 1)
+                for i, e in enumerate(ret):
+                    match e:
+                        case 0:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is disabled.")
+                        case -1:
+                            print(f"Idlestate not available")
+                        case -2:
+                            print(f"Disabling is not supported by the kernel")
+                        case -3:
+                            print(f"No write access to disable/enable C-states: try using sudo")
+                        case _:
+                            print(f"Not documented: {e}")
+            elif args.enable_idle_state != None:
+                cstate_index = args.enable_idle_state
+                cstate_list, cstate_amt = self.get_idle_states(args.cpu_list[0]) # Assumption, that all cpus have the same idle state
+                if cstate_index < 0 or cstate_index >= cstate_amt:
+                    print(f"Invalid idle state range. Total for this cpu is {cstate_amt}")
+                    return 1
+                cstate_name = cstate_list[cstate_index]
+                ret = self.disable_idle_state(cstate_index, 0)
+                for i, e in enumerate(ret):
+                    match e:

tuna/cpupower.py line 173

Quoted 10 lines
tuna/cpupower.py new file +10 -0
+                        case 0:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is enabled.")
+                        case -1:
+                            print(f"Idlestate not available")
+                        case -2:
+                            print(f"Disabling is not supported by the kernel")
+                        case -3:
+                            print(f"No write access to disable/enable C-states: try using sudo")
+                        case _:
+                            print(f"Not documented: {e}")

Factor out the error messages so they're not duplicated between suboperations. Actually, pretty much the whole thing is duplicated between enable/disable...

Do we want to print anything at all on success? It looks like tuna generally follows the Unix philosophy of not doing so.

And the error messages are a bit vague... imagine running a script and something deep inside it spits out "Disabling is not supported by the kernel". Disabling what?

tuna/cpupower.py line 176

Quoted 3 lines
tuna/cpupower.py new file +3 -0
+            else:
+                print(args)
+                print("idle-set error: you should not get here!")

"you should not get here" is not a useful error message... jut throw an exception.

-Crystal

#4 lore raw

Re: [PATCH 2/2] tuna: Add idle-state control functionality

Quoted 49 lines · Crystal Wood
Quoted 48 lines · John B. Wyatt IV

Allows Tuna to control cpu idle-state functionality on the system, including querying, enabling, disabling of cpu idle-states to control power usage or to test functionality.

This requires cpupower, a utility in the Linux kernel repository and the cpupower Python bindings added in Linux 6.12 to control cpu idle-states. If cpupower is missing Tuna as a whole will continue to function and idle-set functionality will error out.

---
 tuna-cmd.py      |  33 +++++++-
 tuna/cpupower.py | 202 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 233 insertions(+), 2 deletions(-)
 create mode 100755 tuna/cpupower.py
tuna-cmd.py +7 -2
index d0323f5..81d0f48 100755
@@ -25,6 +25,7 @@ from tuna import tuna, sysfs, utils
 import logging
 import time
 import shutil
+import tuna.cpupower as cpw
 
 def get_loglevel(level):
     if level.isdigit() and int(level) in range(0,5):
@@ -115,8 +116,12 @@ 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"),
+            "idle_state_disabled_status": dict(dest='idle_state_disabled_status', metavar='IDLESTATEDISABLEDSTATUS', type=int, help='Print if cpu idle state of the cpus in CPU-LIST is enabled or disabled. If CPU-LIST is not specified, default to all cpus.'),
+            "idle_info": dict(dest='idle_info', action='store_const', const=True, help='Print general idle information on cpus in CPU-LIST. If CPU-LIST is not specified, default to all cpus.'),
+            "disable_idle_state": dict(dest='disable_idle_state', metavar='IDLESTATEINDEX', type=int, help='Disable cpus in CPU-LIST\'s cpu idle (cpu sleep state). If CPU-LIST is not specified, default to all cpus.'),
+            "enable_idle_state": dict(dest='enable_idle_state', metavar='IDLESTATEINDEX', type=int, help='Enable cpus in CPU-LIST\'s cpu idle (cpu sleep state). If CPU-LIST is not specified, default to all cpus.')
+    }
 
     parser = HelpMessageParser(description="tuna - Application Tuning Program")
 
@@ -147,6 +152,10 @@ def gen_parser():
     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')
 
Quoted 6 lines

tuna-cmd.py def gen_parser(): · line 157

Quoted 3 lines
tuna-cmd.py +3 -0
+    idle_set = subparser.add_parser('idle-set',
+                                    description='Query and set all idle states on a given CPU list. Requires libcpupower to be installed',
+                                    help='Set all idle states on a given CPU-LIST.')

idle_state would be a better name (or idle-state, but underscores are already used elsewhere...), since it can both set and get.

Being used elsewhere is why I used it. Nothing else to add.

Quoted 5 lines

It also mostly operates on individual states (-i being the exception), not all at once. How about just:

Manage CPU idle state disabling (requires libcpupower)

Will do.

Quoted 2 lines

Also, don't forget to update the man page.

The man page will be in a future patch.

Quoted 15 lines
Quoted 15 lines
tuna-cmd.py +10 -0
@@ -635,6 +651,19 @@ def main():
         my_logger.addHandler(add_handler("DEBUG", tofile=False))
         my_logger.info("Debug option set")
 
+    if args.command == 'idle-set':
+        if not cpw.have_cpupower:
+            print(f"Error: libcpupower bindings are not detected; need {cpw.cpupower_required_kernel} at a minimum.")
+            sys.exit(1)
+
+        if not args.cpu_list or args.cpu_list == []:
+            args.cpu_list = cpw.Cpupower().get_all_cpu_list()
+
+        my_cpupower = cpw.Cpupower(args.cpu_list)
+        ret = my_cpupower.idle_state_handler(args)
Quoted 8 lines

tuna-cmd.py def main(): · line 665

Quoted 2 lines
tuna-cmd.py +2 -0
+        if ret > 0:
+            sys.exit(ret)

Why not just pass in cpu_list as is, and have cpw understand what an empty or absent list is? And it looks like it already partially does check for None... If the user specifically does something like --cpu '' should we really treat that as equivalent to not specifing --cpu? I don't see other commands doing this.

Will move the logic to the class.

I do not understand what you wrote for the second part with checking for --cpu. Would you please rephase?

Note I am still learning argparse; if you know of a better way, an example would be welcome. :-)

Quoted 7 lines

Especially if you're going to delegate all other option parsing... Why is cpulist special? Just do something like:

elif args.command == 'idle_state'
cpw.idle_state(args)

Quoted 6 lines

tuna-cmd.py def main(): · line 669

Quoted 3 lines
tuna-cmd.py +0 -0
     if args.loglevel:
         if not args.debug:
             my_logger = setup_logging("my_logger")

Why did you put the new command before log handling, rather than with all the other commands?

Will amend this. Looks like I misapplied a commit hunk.

Quoted 24 lines
Quoted 8 lines
tuna/cpupower.py new file +1 -0
new file mode 100755
index 0000000..b09dc2f
@@ -0,0 +1,202 @@
+# Copyright (C) 2024 John B. Wyatt IV

tuna/cpupower.py line 11

Quoted 10 lines
tuna/cpupower.py new file +10 -0
+# SPDX-License-Identifier: GPL-2.0-only
+
+from typing import List
+import tuna.utils as utils
+
+cpupower_required_kernel = "6.12"
+have_cpupower = None
+
+
+import raw_pylibcpupower as cpw

This is a bit confusing since you import this module as cpw elsewhere...

Also, I got this even without trying to use the new functionality:

Quoted 8 lines
$ ./tuna-cmd.py 
Traceback (most recent call last):
  File "/home/crwood/git/tuna/./tuna-cmd.py", line 28, in <module>
    import tuna.cpupower as cpw
  File "/home/crwood/git/tuna/tuna/cpupower.py", line 11, in <module>
    import raw_pylibcpupower as cpw
ModuleNotFoundError: No module named 'raw_pylibcpupower'

This was pointed out to me in a separate email. I have already fixed it for the v2 I will send.

Quoted 7 lines

Maybe something like:

try:
import raw_pylibcpupower as lcpw
lcpw.cpufreq_get_available_frequencies(0)
except:
lcpw = None

pylint does not like a module to be dynamically imported this way, but I found a workaround using importlib. pylint's messaging is very valuable so I rather not have to disable it. It gives a warning every time cpw is used otherwise.

Quoted 8 lines

tuna/cpupower.py line 33

Quoted 3 lines
tuna/cpupower.py new file +2 -0
+        You must use have_cpupower variable to determine if the bindings were
+        detected in your code."""

Instead of doing to the class/module user what SWIG did to the binding user, why not just throw an exception if the binding is missing? This will automatically happen if lcpw is None, though you may want a friendlier error message in the main entry point.

Please see above.

Quoted 11 lines

tuna/cpupower.py line 42

Quoted 10 lines
tuna/cpupower.py new file +9 -0
+        def __init__(self, cpulist=None):
+            if cpulist == None:
+                self.__cpulist = self.get_all_cpu_list()
+            else:
+                self.__cpulist = cpulist
+
+        @classmethod
+        def get_all_cpu_list(cls):
+            return list(range(cls.get_idle_info()["all_cpus"]))
Quoted 2 lines

Is this really idle-state-specific? Maybe just something like this in tuna/utils.py:

It is in the cpupower.py file, not an idle-state.py file. The only part specific to idle-state is idle-set is the only user.

I was thinking of that, but that can be a future patch. I wanted this implementation to be kept simple.

Quoted 6 lines

def get_all_cpu_list():
return list(range(get_nr_cpus()))

We shouldn't need to get all the idle state information just to get a cpu list.

I mimicked the way cpupower reports this information. The information is useful to report. I am not sure what your objection is.

Quoted 3 lines

And all these class methods make me wonder why this is a class to begin with, rather than just module functions.

I plan to add future functionality down the road; a class would be appropriate for handling this.

Quoted 6 lines

tuna/cpupower.py line 62

Quoted 4 lines
tuna/cpupower.py new file +3 -0
+
+        @classmethod
+        def get_idle_info(cls, cpu=0):

Why is cpu 0 special?

cpupower itself for this functionality picks a random cpu thread to report. I choose cpu 0 as a stopgap until I find/upstream better functionality to handle this. I did not feel a random cpu was any better.

Quoted 24 lines
Quoted 13 lines
tuna/cpupower.py new file +12 -0
+            idle_states, idle_states_amt = cls.get_idle_states(cpu)
+            idle_states_list = []
+            for idle_state in range(0, len(idle_states)):
+                idle_states_list.append(
+                    {
+                        "CPU ID": cpu,
+                        "Idle State Name": idle_states[idle_state],
+                        "Flags/Description": cpw.cpuidle_state_desc(cpu, idle_state),
+                        "Latency": cpw.cpuidle_state_latency(cpu, idle_state),
+                        "Usage": cpw.cpuidle_state_usage(cpu, idle_state),
+                        "Duration": cpw.cpuidle_state_time(cpu, idle_state)
+                    }

tuna/cpupower.py line 84

Quoted 10 lines
tuna/cpupower.py new file +10 -0
+                )
+            idle_info = {
+                "all_cpus": utils.get_nr_cpus(),
+                "CPUidle-driver": cpw.cpuidle_get_driver(),
+                "CPUidle-governor": cpw.cpuidle_get_governor(),
+                "idle-states-count": idle_states_amt,
+                "available-idle-states": idle_states,
+                "cpu-states": idle_states_list
+            }
+            return idle_info
Quoted 3 lines

This seems overly complicated. Why do you bundle all this stuff up just to extract it elsewhere? The call to get the data is simpler than the data structure lookup.

I do not understand. There are multiple calls to get the data.

As I said above, I was mimicking how cpupower reports this information. I thought it would be useful to report. I wrap this data up into a hashmap that I hope may be useful to export as json for scripting in the future.

Quoted 7 lines

tuna/cpupower.py line 87

Quoted 4 lines
tuna/cpupower.py new file +3 -0
+
+        @classmethod
+        def print_idle_info(cls, cpu_list=[0]):

The only thing that instantiating this class does is to store a cpu list, and here you're passing it into a class method instead...

Yes, please see above.

Quoted 10 lines

tuna/cpupower.py line 113

Quoted 5 lines
tuna/cpupower.py new file +4 -0
+        def idle_state_handler(self, args) -> int:
+            if args.idle_state_disabled_status != None:
+                cstate_index = args.idle_state_disabled_status
+                cstate_list, cstate_amt = self.get_idle_states(args.cpu_list[0]) # Assumption, that all cpus have the same idle state

The API doesn't make that assumption, so why should we? Systems exist with heterogeneous CPUs... could be a reason to support looking up states by name, if and when there are systems we care about that actually have different cpuidle states.

Heterogeneous CPU support will come in a future patch once I have upstreamed some more work.

Note that the libcpupower API offers a way to get the number of cores of a system (get_cpu_topology()), but the code to do this is commented out (see the missing curly brace?) and returns a 0 for the number of cores currently.

https://elixir.bootlin.com/linux/v6.13.3/source/tools/power/cpupower/lib/cpupower.c#L206-L213

Quoted 3 lines

And you don't need this lookup anyay -- libcpupower already does the bounds check, and you can get the name inside the loop.

I will check on that.

Quoted 6 lines

tuna/cpupower.py line 116

Quoted 4 lines
tuna/cpupower.py new file +3 -0
+                if cstate_index < 0 or cstate_index >= cstate_amt:
+                    print(f"Invalid idle state range. Total for this cpu is {cstate_amt}")
+                    return 1

"this cpu"?

Will amend.

Quoted 59 lines
Quoted 48 lines
tuna/cpupower.py new file +47 -0
+                cstate_name = cstate_list[cstate_index]
+                ret = self.is_disabled_idle_state(cstate_index)
+                for i, e in enumerate(ret):
+                    match e:
+                        case 1:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is disabled.")
+                        case 0:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is enabled.")
+                        case -1:
+                            print(f"Idlestate not available")
+                        case -2:
+                            print(f"Disabling is not supported by the kernel")
+                        case _:
+                            print(f"Not documented: {e}")
+            elif args.idle_info != None:
+                self.print_idle_info(args.cpu_list)
+                return 0
+            elif args.disable_idle_state != None:
+                cstate_index = args.disable_idle_state
+                cstate_list, cstate_amt = self.get_idle_states(args.cpu_list[0]) # Assumption, that all cpus have the same idle state
+                if cstate_index < 0 or cstate_index >= cstate_amt:
+                    print(f"Invalid idle state range. Total for this cpu is {cstate_amt}")
+                    return 1
+                cstate_name = cstate_list[cstate_index]
+                ret = self.disable_idle_state(cstate_index, 1)
+                for i, e in enumerate(ret):
+                    match e:
+                        case 0:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is disabled.")
+                        case -1:
+                            print(f"Idlestate not available")
+                        case -2:
+                            print(f"Disabling is not supported by the kernel")
+                        case -3:
+                            print(f"No write access to disable/enable C-states: try using sudo")
+                        case _:
+                            print(f"Not documented: {e}")
+            elif args.enable_idle_state != None:
+                cstate_index = args.enable_idle_state
+                cstate_list, cstate_amt = self.get_idle_states(args.cpu_list[0]) # Assumption, that all cpus have the same idle state
+                if cstate_index < 0 or cstate_index >= cstate_amt:
+                    print(f"Invalid idle state range. Total for this cpu is {cstate_amt}")
+                    return 1
+                cstate_name = cstate_list[cstate_index]
+                ret = self.disable_idle_state(cstate_index, 0)
+                for i, e in enumerate(ret):
+                    match e:

tuna/cpupower.py line 173

Quoted 10 lines
tuna/cpupower.py new file +10 -0
+                        case 0:
+                            print(f"CPU: {args.cpu_list[i]} Idle state \"{cstate_name}\" is enabled.")
+                        case -1:
+                            print(f"Idlestate not available")
+                        case -2:
+                            print(f"Disabling is not supported by the kernel")
+                        case -3:
+                            print(f"No write access to disable/enable C-states: try using sudo")
+                        case _:
+                            print(f"Not documented: {e}")
Quoted 3 lines

Factor out the error messages so they're not duplicated between suboperations. Actually, pretty much the whole thing is duplicated between enable/disable...

Will do.

Quoted 3 lines

Do we want to print anything at all on success? It looks like tuna generally follows the Unix philosophy of not doing so.

Good point. That will also make it easier to script.

Quoted 11 lines

And the error messages are a bit vague... imagine running a script and something deep inside it spits out "Disabling is not supported by the kernel". Disabling what?

tuna/cpupower.py line 176

Quoted 3 lines
tuna/cpupower.py new file +3 -0
+            else:
+                print(args)
+                print("idle-set error: you should not get here!")

"you should not get here" is not a useful error message... jut throw an exception.

Will amend.

Signature · 4 lines
Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat
#5 lore raw
In reply to John B. Wyatt IV
Quoted 18 lines · John B. Wyatt IV

This patch series adds idle-state functionality to control cpu power usage and to test idle states.

The number of cpus was needed in the cpupower file; I extracted out the previously local to tuna-cli.py functionality to a separate file so the cpu code can be used in any file in Tuna and reduce duplications. The nics code was similar so it was also extracted to reduce the number of global variables.

Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat

John B. Wyatt IV (2):
tuna: extract cpu and nics determination code into a utils.py file
tuna: Add idle-state control functionality

Quoted 12 lines
 tuna-cmd.py      |  67 +++++++++-------
 tuna/cpupower.py | 202 +++++++++++++++++++++++++++++++++++++++++++++++
 tuna/utils.py    |  27 +++++++
 3 files changed, 267 insertions(+), 29 deletions(-)
 create mode 100755 tuna/cpupower.py
 create mode 100644 tuna/utils.py
Signature · 1 line
2.48.1

./tuna-cmd.py idle-set -h
usage: tuna-cmd.py idle-set [-h] [-c CPU-LIST]
(-s IDLESTATEDISABLEDSTATUS | -i | -d
IDLESTATEINDEX | -e IDLESTATEINDEX)

Query and set all idle states on a given CPU list. Requires libcpupower to be
installed

options:
-h, --help show this help message and exit
-c CPU-LIST, --cpus CPU-LIST
CPU-LIST affected by commands
-s IDLESTATEDISABLEDSTATUS, --status IDLESTATEDISABLEDSTATUS
Print if cpu idle state of the cpus in CPU-LIST is enabled or disabled. If CPU-LIST is not specified, default to all cpus.
-i, --idle-info Print general idle information on cpus in
CPU-LIST. If
CPU-LIST is not specified, default to all cpus.
-d IDLESTATEINDEX, --disable IDLESTATEINDEX
Disable cpus in CPU-LIST's cpu idle (cpu sleep
state).
If CPU-LIST is not specified, default to all cpus.
-e IDLESTATEINDEX, --enable IDLESTATEINDEX
Enable cpus in CPU-LIST's cpu idle (cpu sleep
state).
If CPU-LIST is not specified, default to all cpus.

These names are kind of awkward, isn't IDLESTATE good enough, why IDLESTATEINDEX?

For the -s option, why do we need to put the IDLESTATEDISABLEDSTATUS, if we omit that can't we just get a result like running "cpupower idle-info"? Could you rename IDLESTATEDISABLEDSTATUS to just IDLESTATE_STATUS?

Thanks

John Kacur

#6 lore raw
Quoted 62 lines · John Kacur
Quoted 18 lines · John B. Wyatt IV

This patch series adds idle-state functionality to control cpu power usage and to test idle states.

The number of cpus was needed in the cpupower file; I extracted out the previously local to tuna-cli.py functionality to a separate file so the cpu code can be used in any file in Tuna and reduce duplications. The nics code was similar so it was also extracted to reduce the number of global variables.

Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat

John B. Wyatt IV (2):
tuna: extract cpu and nics determination code into a utils.py file
tuna: Add idle-state control functionality

Quoted 12 lines
 tuna-cmd.py      |  67 +++++++++-------
 tuna/cpupower.py | 202 +++++++++++++++++++++++++++++++++++++++++++++++
 tuna/utils.py    |  27 +++++++
 3 files changed, 267 insertions(+), 29 deletions(-)
 create mode 100755 tuna/cpupower.py
 create mode 100644 tuna/utils.py
Signature · 1 line
2.48.1

./tuna-cmd.py idle-set -h
usage: tuna-cmd.py idle-set [-h] [-c CPU-LIST]
(-s IDLESTATEDISABLEDSTATUS | -i | -d
IDLESTATEINDEX | -e IDLESTATEINDEX)

Query and set all idle states on a given CPU list. Requires libcpupower to be
installed

options:
-h, --help show this help message and exit
-c CPU-LIST, --cpus CPU-LIST
CPU-LIST affected by commands
-s IDLESTATEDISABLEDSTATUS, --status IDLESTATEDISABLEDSTATUS
Print if cpu idle state of the cpus in CPU-LIST is enabled or disabled. If CPU-LIST is not specified, default to all cpus.
-i, --idle-info Print general idle information on cpus in
CPU-LIST. If
CPU-LIST is not specified, default to all cpus.
-d IDLESTATEINDEX, --disable IDLESTATEINDEX
Disable cpus in CPU-LIST's cpu idle (cpu sleep
state).
If CPU-LIST is not specified, default to all cpus.
-e IDLESTATEINDEX, --enable IDLESTATEINDEX
Enable cpus in CPU-LIST's cpu idle (cpu sleep
state).
If CPU-LIST is not specified, default to all cpus.

Quoted 6 lines

These names are kind of awkward, isn't IDLESTATE good enough, why IDLESTATEINDEX?

For the -s option, why do we need to put the IDLESTATEDISABLEDSTATUS, if we omit that can't we just get a result like running "cpupower idle-info"? Could you rename IDLESTATEDISABLEDSTATUS to just IDLESTATE_STATUS?

This was confusing to me too, but it looks like the argument is actually a particular idle state, not the status of that state. So it should be "IDLESTATE" just like -d and -e. Or better, "IDLE-STATE" like "CPU- LIST".

-Crystal

#7 lore raw
Quoted 5 lines · Crystal Wood
Quoted 3 lines · John Kacur

For the -s option, why do we need to put the IDLESTATEDISABLEDSTATUS, if we omit that can't we just get a result like running "cpupower idle-info"? Could you rename IDLESTATEDISABLEDSTATUS to just IDLESTATE_STATUS?

Quoted 7 lines

This was confusing to me too, but it looks like the argument is actually a particular idle state, not the status of that state. So it should be "IDLESTATE" just like -d and -e. Or better, "IDLE-STATE" like "CPU- LIST".

-Crystal

Apologies for not answering you earlier John. Did not see this email until Crystal's email.

If there is no objections I will go with Crystal's suggestion.

Here is the current printout for the patch series I will send (note I changed a few items to address confusion). Please let me know if this addresses everyone's concerns:

options:
-h, --help show this help message and exit
-i, --idle-info Print general idle information on cpus in CPU-LIST. If CPU-LIST is not specified, default to all cpus.
-s IDLE-STATE, --status IDLE-STATE
Print the idle-state (cpu sleep state) of the cpus in CPU-LIST as enabled or disabled. The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-d IDLE-STATE, --disable IDLE-STATE
Disable cpus in CPU-LIST's idle-state (cpu sleep state). The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-e IDLE-STATE, --enable IDLE-STATE
Enable cpus in CPU-LIST's idle-state (cpu sleep state). The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-c CPU-LIST, --cpus CPU-LIST
CPU-LIST affected by commands

Signature · 4 lines
Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat
#8 lore raw
Quoted 11 lines · John B. Wyatt IV
Quoted 10 lines · Crystal Wood
Quoted 3 lines · John Kacur

For the -s option, why do we need to put the IDLESTATEDISABLEDSTATUS, if we omit that can't we just get a result like running "cpupower idle-info"? Could you rename IDLESTATEDISABLEDSTATUS to just IDLESTATE_STATUS?

This was confusing to me too, but it looks like the argument is actually a particular idle state, not the status of that state. So it should be "IDLESTATE" just like -d and -e. Or better, "IDLE-STATE" like "CPU- LIST".

Quoted 7 lines
Quoted 2 lines

-Crystal

Apologies for not answering you earlier John. Did not see this email until Crystal's email.

If there is no objections I will go with Crystal's suggestion.

No objection, just as long as it is legible, that looks a lot better!

John

Quoted 28 lines

Here is the current printout for the patch series I will send (note I changed a few items to address confusion). Please let me know if this addresses everyone's concerns:

options:
-h, --help show this help message and exit
-i, --idle-info Print general idle information on cpus in CPU-LIST. If CPU-LIST is not specified, default to all cpus.
-s IDLE-STATE, --status IDLE-STATE
Print the idle-state (cpu sleep state) of the cpus in CPU-LIST as enabled or disabled. The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-d IDLE-STATE, --disable IDLE-STATE
Disable cpus in CPU-LIST's idle-state (cpu sleep state). The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-e IDLE-STATE, --enable IDLE-STATE
Enable cpus in CPU-LIST's idle-state (cpu sleep state). The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-c CPU-LIST, --cpus CPU-LIST
CPU-LIST affected by commands

Signature · 4 lines
Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat
#9 lore raw
In reply to John B. Wyatt IV
Quoted 23 lines · John B. Wyatt IV
Quoted 5 lines · Crystal Wood
Quoted 3 lines · John Kacur

For the -s option, why do we need to put the IDLESTATEDISABLEDSTATUS, if we omit that can't we just get a result like running "cpupower idle-info"? Could you rename IDLESTATEDISABLEDSTATUS to just IDLESTATE_STATUS?

Quoted 7 lines

This was confusing to me too, but it looks like the argument is actually a particular idle state, not the status of that state. So it should be "IDLESTATE" just like -d and -e. Or better, "IDLE-STATE" like "CPU- LIST".

-Crystal

Apologies for not answering you earlier John. Did not see this email until Crystal's email.

If there is no objections I will go with Crystal's suggestion.

Here is the current printout for the patch series I will send (note I changed a few items to address confusion). Please let me know if this addresses everyone's concerns:

Quoted 12 lines

options:
-h, --help show this help message and exit
-i, --idle-info Print general idle information on cpus in CPU-LIST. If CPU-LIST is not specified, default to all cpus.
-s IDLE-STATE, --status IDLE-STATE
Print the idle-state (cpu sleep state) of the cpus in CPU-LIST as enabled or disabled. The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-d IDLE-STATE, --disable IDLE-STATE
Disable cpus in CPU-LIST's idle-state (cpu sleep state). The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.
-e IDLE-STATE, --enable IDLE-STATE
Enable cpus in CPU-LIST's idle-state (cpu sleep state). The argument is the index of the idle-state of the cpu as reported by -i. If CPU-LIST is not specified, default to all cpus.

We could simplify the description as:

-i, --idle-info Print general idle information for the selected CPUs,
including index values for IDLE-STATE.
-s IDLE-STATE, --status IDLE-STATE
Print whether IDLE-STATE is enabled on the selected CPUs.
-d IDLE-STATE, --disable IDLE-STATE
Disable IDLE-STATE on the selected CPUs
-e IDLE-STATE, --enable IDLE-STATE
Enable IDLE-STATE on the selected CPUs
-c CPU-LIST, --cpus CPU-LIST
Specify the list of CPUs to act on. If omitted, act on all CPUs.

-Crystal

#10 lore raw
Quoted 15 lines · Crystal Wood

We could simplify the description as:

-i, --idle-info Print general idle information for the selected CPUs,
including index values for IDLE-STATE.
-s IDLE-STATE, --status IDLE-STATE
Print whether IDLE-STATE is enabled on the selected CPUs.
-d IDLE-STATE, --disable IDLE-STATE
Disable IDLE-STATE on the selected CPUs
-e IDLE-STATE, --enable IDLE-STATE
Enable IDLE-STATE on the selected CPUs
-c CPU-LIST, --cpus CPU-LIST
Specify the list of CPUs to act on. If omitted, act on all CPUs.

Will do. Thank you Crystal.

Signature · 4 lines
Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat