summaryrefslogtreecommitdiffstats
path: root/tools/power
diff options
context:
space:
mode:
authorJohn B. Wyatt IV <jwyatt@redhat.com>2024-09-05 04:19:10 +0200
committerShuah Khan <skhan@linuxfoundation.org>2024-09-06 02:50:07 +0200
commit660475266b744ab02695c6f3cdf28b120b884125 (patch)
tree5f4a19610d5586b5bc058129247b09844a623722 /tools/power
parentpm:cpupower: Add SWIG bindings files for libcpupower (diff)
downloadlinux-660475266b744ab02695c6f3cdf28b120b884125.tar.xz
linux-660475266b744ab02695c6f3cdf28b120b884125.zip
pm:cpupower: Include test_raw_pylibcpupower.py
This script demonstrates how to make use of, and tests, the bindings. In the future, this script could become part of a larger test suite to test the bindings and libcpupower. Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com> Signed-off-by: John B. Wyatt IV <sageofredondo@gmail.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'tools/power')
-rwxr-xr-xtools/power/cpupower/bindings/python/test_raw_pylibcpupower.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py b/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py
new file mode 100755
index 000000000000..3d6f62b9556a
--- /dev/null
+++ b/tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0-only
+
+import raw_pylibcpupower as p
+
+# Simple function call
+
+"""
+Get cstate count
+"""
+cpu_cstates_count = p.cpuidle_state_count(0)
+if cpu_cstates_count > -1:
+ print(f"CPU 0 has {cpu_cstates_count} c-states")
+else:
+ print(f"cstate count error: return code: {cpu_cstates_count}")
+
+"""
+Disable cstate (will fail if the above is 0, 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 _:
+ print(f"Not documented")
+
+
+# Pointer example
+
+topo = p.cpupower_topology()
+total_cpus = p.get_cpu_topology(topo)
+if total_cpus > 0:
+ print(f"Number of total cpus: {total_cpus} and number of cores: {topo.cores}")
+else:
+ print(f"Error: could not get cpu topology")