Detect CPU via "cpuid" instruction instead of "/proc/cpuinfo".
The following discussion from !65 (closed) should be addressed:
-
@clemenci started a discussion: This is not found on CentOS7 with Kernel 3.10, but is seems it can be observed with a more recent Kernel (see https://gist.github.com/hiroi10/70c972730e4057946f36544b0547e467).
Shall we move from
cpuinfoflags to something more precise? (To be noted that the list of supported CPUs varies with the version of GCC, so we cannot rely on the host compiler).
For the record, I found a couple of interesting resources:
-
https://github.com/flababah/cpuid.py
- pure Python, but requires we can set the executable bit of a memory buffer (often disabled for security reasons)
-
https://github.com/FlightDataServices/PyCPUID
- mixes C and Python so it does not have the
cpuid.pyproblem, but it's more difficult to install and does not support Python 3 (we might submit a PR)
- mixes C and Python so it does not have the
One could write a tiny dynamic library (see https://stackoverflow.com/a/4823889) and call it from Python with ctypes. The .so could be distributed as a binary (it's very portable), or we take the PyCPUID approach, in which case I would try to just fix the Python 3 issue.
I experimented a bit with a mix of the approaches, and it is actually relatively easy to have something minimal that fits our needs.