Skip to content

cpu

zeus.device.cpu

Abstraction layer for CPU devices.

The main function of this module is get_cpus, which returns a CPU Manager object specific to the platform.

get_cpus

get_cpus()

Initialize and return a singleton CPU monitoring object for Intel CPUs.

The function returns a CPU management object that abstracts the underlying CPU energy monitoring interface: EMI on Windows, RAPL on Linux.

Raises:

Type Description
ZeusCPUInitError

If no supported CPU energy monitoring interface is available.

Source code in zeus/device/cpu/__init__.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def get_cpus() -> CPUs:
    """Initialize and return a singleton CPU monitoring object for Intel CPUs.

    The function returns a CPU management object that abstracts the underlying
    CPU energy monitoring interface: EMI on Windows, RAPL on Linux.

    Raises:
        ZeusCPUInitError: If no supported CPU energy monitoring interface is available.
    """
    global _cpus
    if _cpus is not None:
        return _cpus
    if emi_is_available():
        _cpus = EMICPUs()
        return _cpus
    if rapl_is_available():
        _cpus = RAPLCPUs()
        return _cpus
    raise ZeusCPUInitError(
        "No supported CPU energy monitoring interface is available. "
        "EMI requires Windows 10+ with an Intel EMI-compatible driver. "
        "RAPL requires Linux with the intel-rapl kernel module."
    )