From: Michael Tremer Date: Wed, 23 Nov 2016 22:36:52 +0000 (+0100) Subject: Replace bogomips by fibonnacci benchmark X-Git-Tag: 0.9.28~1296 X-Git-Url: http://git.ipfire.org/?p=pakfire.git;a=commitdiff_plain;h=7e11c4db619ddccf599a35c81bf2580b402dbe24 Replace bogomips by fibonnacci benchmark BogoMIPS cannot be used as an easy way to determine how fast a system is any more since there is only dummy values available in newer kernels. We use a simple fibonnacci function now which is executed for a set amount of time (defaults to one second) and count the number of iterations performed. This is then multiplied by the number of CPU cores. Fibonnacci is a very simple test that relies on the integer unit (no FPU involved) and is not depending on anything else. This will also allow us to quantitatively determine the difference in speed between processors. Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/_pakfiremodule.c b/src/_pakfire/_pakfiremodule.c index 04a321b6..fc2d953c 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/_pakfire/_pakfiremodule.c @@ -40,6 +40,7 @@ #include "util.h" static PyMethodDef pakfireModuleMethods[] = { + {"performance_index", (PyCFunction)performance_index, METH_VARARGS, NULL}, {"version_compare", (PyCFunction)version_compare, METH_VARARGS, NULL}, {"get_capabilities", (PyCFunction)get_capabilities, METH_VARARGS, NULL}, {"set_capabilities", (PyCFunction)set_capabilities, METH_VARARGS, NULL}, diff --git a/src/_pakfire/util.c b/src/_pakfire/util.c index 616e0344..85fc7214 100644 --- a/src/_pakfire/util.c +++ b/src/_pakfire/util.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "constants.h" @@ -83,3 +84,55 @@ PyObject *version_compare(PyObject *self, PyObject *args) { return Py_BuildValue("i", ret); } + +static unsigned int fibonnacci(const clock_t* deadline) { + clock_t now = clock(); + + unsigned long f1 = 1; + unsigned long f2 = 1; + + // Count iterations + unsigned int counter = 0; + + while (now < *deadline) { + unsigned long next = f1 + f2; + f1 = f2; + f2 = next; + + now = clock(); + counter++; + } + + return counter; +} + +PyObject* performance_index(PyObject* self, PyObject* args) { + int seconds = 1; + + if (!PyArg_ParseTuple(args, "|i", &seconds)) { + return NULL; + } + + if (seconds == 0) { + PyErr_SetString(PyExc_ValueError, "Runtime must be one second or longer"); + return NULL; + } + + // Determine the number of online processors + int processors = sysconf(_SC_NPROCESSORS_ONLN); + + // Determine deadline + clock_t deadline = clock(); + deadline += CLOCKS_PER_SEC * seconds; + + // Run Fibonnacci until deadline + unsigned int iterations = fibonnacci(&deadline); + + // Times the result by the number of processors + iterations *= processors; + + // Normalise to a second + iterations /= seconds; + + return PyLong_FromUnsignedLong(iterations); +} diff --git a/src/_pakfire/util.h b/src/_pakfire/util.h index 0322d1c8..97d5bb3a 100644 --- a/src/_pakfire/util.h +++ b/src/_pakfire/util.h @@ -29,5 +29,6 @@ extern PyObject *_personality(PyObject *self, PyObject *args); extern PyObject *_sync(PyObject *self, PyObject *args); extern PyObject *_unshare(PyObject *self, PyObject *args); extern PyObject *version_compare(PyObject *self, PyObject *args); +extern PyObject* performance_index(PyObject* self, PyObject* args); #endif diff --git a/src/pakfire/system.py b/src/pakfire/system.py index f6ff1dc5..758a8d7a 100644 --- a/src/pakfire/system.py +++ b/src/pakfire/system.py @@ -29,6 +29,8 @@ import tempfile import distro import shell +from . import _pakfire + from i18n import _ class System(object): @@ -151,16 +153,8 @@ class System(object): return ret or _("Could not be determined") @property - def cpu_bogomips(self): - cpuinfo = self.parse_cpuinfo() - - for key in ("bogomips", "BogoMIPS"): - bogomips = cpuinfo.get(key, None) - - if bogomips is None: - continue - - return float(bogomips) * self.cpu_count + def cpu_bogomips(self): + return _pakfire.performance_index() def get_loadavg(self): return os.getloadavg()