summaryrefslogtreecommitdiff
path: root/psutil/arch
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2022-01-16 20:06:14 +0100
committerGitHub <noreply@github.com>2022-01-16 20:06:14 +0100
commit98b49486f81f085bceda60b01b0a8f69a7008290 (patch)
tree23aead2f5fa0e6ae789f7f167100d493f045031e /psutil/arch
parent01f5f1ecb1b3470c1df2a120f0f6dca7f58088fb (diff)
downloadpsutil-98b49486f81f085bceda60b01b0a8f69a7008290.tar.gz
OpenBSD: add support for CPU frequency (#2057)
Diffstat (limited to 'psutil/arch')
-rw-r--r--psutil/arch/openbsd/cpu.c18
-rw-r--r--psutil/arch/openbsd/cpu.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/psutil/arch/openbsd/cpu.c b/psutil/arch/openbsd/cpu.c
index 2a366fe0..0691fd1f 100644
--- a/psutil/arch/openbsd/cpu.c
+++ b/psutil/arch/openbsd/cpu.c
@@ -89,3 +89,21 @@ psutil_cpu_stats(PyObject *self, PyObject *args) {
uv.forks // forks
);
}
+
+
+PyObject *
+psutil_cpu_freq(PyObject *self, PyObject *args) {
+ int freq;
+ size_t size;
+ int mib[2] = {CTL_HW, HW_CPUSPEED};
+
+ // On VirtualBox I get "sysctl hw.cpuspeed=2593" (never changing),
+ // which appears to be expressed in Mhz.
+ size = sizeof(freq);
+ if (sysctl(mib, 2, &freq, &size, NULL, 0) < 0) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+
+ return Py_BuildValue("i", freq);
+}
diff --git a/psutil/arch/openbsd/cpu.h b/psutil/arch/openbsd/cpu.h
index 6bace0b1..07bf95fd 100644
--- a/psutil/arch/openbsd/cpu.h
+++ b/psutil/arch/openbsd/cpu.h
@@ -7,5 +7,6 @@
#include <Python.h>
+PyObject *psutil_cpu_freq(PyObject* self, PyObject* args);
PyObject *psutil_cpu_stats(PyObject* self, PyObject* args);
PyObject *psutil_per_cpu_times(PyObject *self, PyObject *args);