Module Cpuid
Detect CPU features.
v0.1.2 — homepage
Overview
Cpuid provides runtime detection of CPU features through the x86 CPUID instruction. Detection discovers the CPU vendor
and a set of feature flag
s.
The flag names reflect the Linux convention, except in uppercase. Only the features reported by the CPU are included (i.e. there are no synthetic flags).
Limitations
Cpuid currently relies on an x86-specific feature. The library runs on ARM processors, but calls return an error
.
The only CPUID-leaves consulted for feature flags are 0x1
, 0x7:0
and 0x80000001
. Hence, the reported features are a subset of what Linux would report.
Number of cores is CPUID 0xb:1
EBX
. This only works on Intel CPUs after around 2010, and fails under virtualization.
Cpuid
type error
=[
|
`Unsupported
]
type nonrec 'a result
= ('a, error) Stdlib.result
type vendor
=[
|
`AMD
|
`Centaur
|
`Cyrix
|
`Intel
|
`Transmeta
|
`NSC
|
`NexGen
|
`Rise
|
`SiS
|
`UMC
|
`VIA
|
`Vortex
|
`KVM
|
`Hyper_V
|
`Parallels
|
`VMware
|
`Xen
|
`UNKNOWN
]
The CPU manufacturer, the type of virtual environment, or
`UNKNOWN
.
type flag
=[
]
CPU flags signify presence of individual features.
Consult the interface file for the meaning of individual flags.
val pp_error : Stdlib.Format.formatter -> error -> unit
pp_error ppf e
formats theerror
e
to the formatterppf
.
val pp_vendor : Stdlib.Format.formatter -> vendor -> unit
pp_vendor ppf v
formats thevendor
v
to the formatterppf
.
val pp_flag : Stdlib.Format.formatter -> flag -> unit
pp_flag ppf f
formats theflag
f
to the formatterppf
.
Queries
val model : unit -> (int * int * int) result
model ()
is the CPU's family, model and stepping, or anerror
.
val cores : unit -> int result
cores ()
is the number of available logical cores.Note Do not take
cores ()
too seriously. See limitations.