Skip to contentSkip to conversation

rteval: Added functionality to allow user to set the cstate of specified cpus when running rteval

PATCH Superseded Anubhav Shelat 1 participant 1 message Jul 16, 2024

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rteval: Added functionality to allow user to set the cstate of specified cpus when running rteval

We would like to be able to set the cstates of CPUs while running rteval.

This patch adds the file cpupower.py and options '--idle-set' and '--cpulist' within rteval to use cpupower.

cpupower.py provides the infrastructure to interface with the cpupower command, and the options in rteval-cmd let the user specify the cstate to be set and the CPUs to set it on.

---
 rteval-cmd         | 25 +++++++++++++-
 rteval/cpupower.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 1 deletion(-)
 create mode 100644 rteval/cpupower.py
rteval-cmd +24 -1
index 5cb6d7a44523..c1324aa3e612 100755
@@ -29,6 +29,7 @@ from rteval.Log import Log
 from rteval import RtEval, rtevalConfig
 from rteval.modules.loads import LoadModules
 from rteval.modules.measurement import MeasurementModules
+from rteval import cpupower
 from rteval.version import RTEVAL_VERSION
 from rteval.systopology import SysTopology, parse_cpulist_from_config
 from rteval.modules.loads.kcompile import ModuleParameters
@@ -146,7 +147,11 @@ def parse_options(cfg, parser, cmdargs):
     parser.add_argument("-S", "--source-download", nargs="*", dest="rteval___srcdownload",
                         type=str, default=None, metavar="KERNEL_VERSION",
                         help='download a source kernel from kernel.org and exit')
-
+    parser.add_argument("-c", "--cpulist", dest="rteval___cpulist", metavar="CPULIST",
+                        default=str([i for i in range(os.cpu_count())]).strip('[]'),
+                        help='specify list of cpus whose idle state to modify')
+    parser.add_argument('--idle-set', dest='rteval___cstate', metavar='CSTATE',
+                        default=None, help='cstate to enable for this rteval run')
 
     if not cmdargs:
         cmdargs = ["--help"]
@@ -169,6 +174,12 @@ def parse_options(cfg, parser, cmdargs):
         cmd_args = cmdargs[ind+1:]
         cmdargs = cmdargs[:ind+1]
 
+    # if --cpulist is specified, make sure --idle-set is too
+    if ((sys.argv.count('-c')+sys.argv.count('--cpulist')) > 0) and \
+    (sys.argv.count('--cpulist') == 0):
+        print('--cpulist must be used with --idle-set')
+        cmdargs = ["--help"]
+
     cmd_opts = parser.parse_args(args=cmdargs)
 
     # if no kernel version was provided for --source-download, set version to default
@@ -263,6 +274,9 @@ if __name__ == '__main__':
                 | (rtevcfg.debugging and Log.DEBUG)
         logger.SetLogVerbosity(loglev)
 
+        # check if cpupower is being used
+        if sys.argv.count('--idle-set') > 0:
+            rtevcfg.update({'usingCpupower': True})
         # Load modules
         loadmods = LoadModules(config, logger=logger)
         measuremods = MeasurementModules(config, logger=logger)
@@ -394,6 +408,11 @@ if __name__ == '__main__':
         if not os.path.isdir(rtevcfg.workdir):
             raise RuntimeError(f"work directory {rtevcfg.workdir} does not exist")
 
+        # if idle-set has been specified, enable idlestate in rtecfg.cpulist
+        cpupower_controller = None
+        if rtevcfg.cstate:
+            cpupower_controller = cpupower.Cpupower(rtevcfg.cpulist, rtevcfg.cstate)
+            cpupower_controller.enable_idle_state()
 
         rteval = RtEval(config, loadmods, measuremods, logger)
         rteval.Prepare(rtevcfg.onlyload)
@@ -413,6 +432,10 @@ if __name__ == '__main__':
             ec = rteval.Measure()
             logger.log(Log.DEBUG, f"exiting with exit code: {ec}")
 
+        # reset idlestate
+        if rtevcfg.cstate:
+            cpupower_controller.restore_cstate()
+
         sys.exit(ec)
     except KeyboardInterrupt:
         sys.exit(0)
rteval/cpupower.py new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.45.2