From: "John B. Wyatt IV" <jwyatt@redhat.com>
To: Shuah Khan <skhan@linuxfoundation.org>
Cc: "John B. Wyatt IV" <jwyatt@redhat.com>,
linux-pm@vger.kernel.org, Thomas Renninger <trenn@suse.com>,
Shuah Khan <shuah@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org, John Kacur <jkacur@redhat.com>,
Tomas Glozar <tglozar@redhat.com>, Arnaldo Melo <acme@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"John B. Wyatt IV" <sageofredondo@gmail.com>
Subject: [PATCH v2 3/4] Include test_raw_pylibcpupower.py
Date: Tue, 27 Aug 2024 02:24:35 -0400 [thread overview]
Message-ID: <20240827062438.71809-4-jwyatt@redhat.com> (raw)
In-Reply-To: <20240827062438.71809-1-jwyatt@redhat.com>
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>
---
Changes in v2:
- None.
---
.../bindings/python/test_raw_pylibcpupower.py | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100755 tools/power/cpupower/bindings/python/test_raw_pylibcpupower.py
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")
--
2.46.0
next prev parent reply other threads:[~2024-08-27 6:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 6:24 [PATCH v2 0/4] Add SWIG Bindings to libcpupower John B. Wyatt IV
2024-08-27 6:24 ` [PATCH v2 1/4] Add SWIG bindings files for libcpupower John B. Wyatt IV
2024-08-27 6:24 ` [PATCH v2 2/4] Implement dummy function for SWIG to accept the full library definitions John B. Wyatt IV
2024-08-27 6:24 ` John B. Wyatt IV [this message]
2024-08-27 6:24 ` [PATCH v2 4/4] MAINTAINERS: Add Maintainers for SWIG Python bindings John B. Wyatt IV
2024-09-04 12:41 ` [PATCH v2 0/4] Add SWIG Bindings to libcpupower Shuah Khan
2024-09-04 13:26 ` Shuah Khan
2024-09-04 14:13 ` John B. Wyatt IV
2024-09-04 15:52 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240827062438.71809-4-jwyatt@redhat.com \
--to=jwyatt@redhat.com \
--cc=acme@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sageofredondo@gmail.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tglozar@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=trenn@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox