Skip to contentSkip to conversation

pm: cpupower: bindings: improve test script

PATCH In review John B. Wyatt IV 2 participants 4 messages Sep 30, 2024 – Oct 2, 2024 CPU power monitoring

lore
Share & tools
lore

John B. Wyatt IV

author maintainer
#0 lore raw

cover pm: cpupower: bindings: improve test script

Improve test_raw_pylibcpupower.py with some cleanup and catching more states. This includes confirming states have been disabled and a notice to use sudo.

John B. Wyatt IV (2):
pm: cpupower: bindings: Improve disable c_state block
pm: cpupower: bindings: Add test to confirm cpu state is disabled

 .../bindings/python/test_raw_pylibcpupower.py | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)
Signature · 1 line
2.46.2
author maintainer
#1 lore raw

PATCH 1/2 pm: cpupower: bindings: Improve disable c_state block

This commit fixes a bad comment, removes an unneeded code block, and catches a few more states that cpuidle_state_disable with the test script. Part of the motivation for this commit was I kept forgetting to use sudo.

---
 .../bindings/python/test_raw_pylibcpupower.py        | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py +6 -6
index 3d6f62b9556a..bb2b26db8b10 100755
@@ -15,21 +15,21 @@ else:
     print(f"cstate count error: return code: {cpu_cstates_count}")
 
 """
-Disable cstate (will fail if the above is 0, ex: a virtual machine)
+Disable cstate (will fail if the above returns is under 1, ex: a virtual machine)
 """
 cstate_disabled = p.cpuidle_state_disable(0, 0, 1)
-if cpu_cstates_count == 0:
-    print(f"CPU 0 has {cpu_cstates_count} c-states")
-else:
-    print(f"cstate count error: return code: {cpu_cstates_count}")
 
 match cstate_disabled:
     case 0:
         print(f"CPU state 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")
+        print(f"Not documented: {cstate_disabled}")
 
 
 # Pointer example
Signature · 1 line
2.46.2
author maintainer
#2 lore raw

PATCH 2/2 pm: cpupower: bindings: Add test to confirm cpu state is disabled

In reply to John B. Wyatt IV

Add a simple test to confirm and print out the cpu state.

---
 .../bindings/python/test_raw_pylibcpupower.py    | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py +16 -0
index bb2b26db8b10..ca5aa46c9b20 100755
@@ -31,6 +31,22 @@ match cstate_disabled:
     case _:
         print(f"Not documented: {cstate_disabled}")
 
+"""
+Test cstate is disabled
+"""
+is_cstate_disabled = p.cpuidle_is_state_disabled(0, 0)
+
+match is_cstate_disabled:
+    case 1:
+        print(f"CPU is disabled")
+    case 0:
+        print(f"CPU is enabled")
+    case -1:
+        print(f"Idlestate not available")
+    case -2:
+        print(f"Disabling is not supported by kernel")
+    case _:
+        print(f"Not documented: {is_cstate_disabled}")
 
 # Pointer example
 
Signature · 1 line
2.46.2
maintainer
#3 lore raw
In reply to John B. Wyatt IV
Quoted 11 lines · John B. Wyatt IV

Improve test_raw_pylibcpupower.py with some cleanup and catching more states. This includes confirming states have been disabled and a notice to use sudo.

John B. Wyatt IV (2):
pm: cpupower: bindings: Improve disable c_state block
pm: cpupower: bindings: Add test to confirm cpu state is disabled

  .../bindings/python/test_raw_pylibcpupower.py | 28 +++++++++++++++----
  1 file changed, 22 insertions(+), 6 deletions(-)

Applied these two patches to
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux.git/log/?h=cpupower

They will be included in my next pull request to PM maintainer.

thanks,
-- Shuah