Skip to content

Commit

Permalink
Add support for multiple CPUS and raw data manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
zacikpa committed Jul 2, 2024
1 parent 4f8d741 commit bfd8c90
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 90 deletions.
12 changes: 9 additions & 3 deletions python/docs/api/info.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
Classes storing CPU information
===============================

.. autoclass:: libcpuid.cpuid.CPUID
.. autoclass:: libcpuid.cpu_id.CPUID
:members:

.. autoclass:: libcpuid.x86.X86ID
.. autoclass:: libcpuid.cpu_id.X86ID
:members:

.. autoclass:: libcpuid.arm.ARMID
.. autoclass:: libcpuid.cpu_id.ARMID
:members:

.. autoclass:: libcpuid.system_id.SystemID
:members:

.. autoclass:: libcpuid.sgx.SGX
:members:

.. autoclass:: libcpuid.sgx.EPC
:members:
8 changes: 8 additions & 0 deletions python/docs/api/raw.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Raw CPU data manipulation
===============================

.. autoclass:: libcpuid.cpu_raw_data.CPURawData
:members:

.. autoclass:: libcpuid.cpu_raw_data.CPURawDataArray
:members:
1 change: 1 addition & 0 deletions python/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ to the libcpuid C library.
api/libcpuid
api/info
api/enums
api/raw
38 changes: 26 additions & 12 deletions python/src/libcpuid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
ffi,
lib,
)
from libcpuid import _cpuid_builder, cpuid, enums
from libcpuid._utils import c_string_to_str, LibCPUIDError
from libcpuid import cpu_id, system_id, cpu_raw_data, enums
from libcpuid.utils import c_string_to_str, LibCPUIDError


def version() -> str:
Expand All @@ -34,20 +34,34 @@ def get_vendor() -> enums.CPUVendor:
return enums.CPUVendor.UNKNOWN


def cpu_identify() -> cpuid.CPUID:
"""Identifies the CPU and returns a :class:`cpuid.CPUID` instance."""
return _cpuid_builder.CPUIDBuilder.from_current_cpu()
def cpu_identify() -> cpu_id.CPUID:
"""Identifies the CPU and returns a :class:`cpu_id.CPUID` instance."""
return cpu_id.CPUIDBuilder.build_from_current_cpu()


def cpu_identify_all() -> system_id.SystemID:
"""Identify all system CPUs and returns a :class:`system_id.SystemID` instance."""
return system_id.SystemIDBuilder.build_from_all_cpus()


def cpuid_get_raw_data() -> cpu_raw_data.CPURawData:
"""Obtains the raw CPUID data from the current CPU."""
return cpu_raw_data.CPURawDataBuilder.build_from_current_cpu()


def cpuid_get_all_raw_data() -> cpu_raw_data.CPURawDataArray:
"""Obtains the raw CPUID data from all CPUs."""
return cpu_raw_data.CPURawDataBuilder.build_array_from_all_cpus()


def get_cpu_list(vendor: enums.CPUVendor) -> list[str]:
"""Gets a list of CPU :meth:`codenames <cpuid.CPUID.cpu_codename>` for a specific vendor."""
raw_cpu_list = ffi.new("struct cpu_list_t *")
lib.cpuid_get_cpu_list(vendor, raw_cpu_list)
if raw_cpu_list.num_entries == 0:
"""Gets a list of CPU :meth:`codenames <cpu_id.CPUID.cpu_codename>` for a specific vendor."""
c_cpu_list = ffi.new("struct cpu_list_t *")
lib.cpuid_get_cpu_list(vendor, c_cpu_list)
if c_cpu_list.num_entries == 0:
raise LibCPUIDError(c_string_to_str(lib.cpuid_error()))
cpu_list = [
c_string_to_str(name)
for name in raw_cpu_list.names[0 : raw_cpu_list.num_entries]
c_string_to_str(name) for name in c_cpu_list.names[0 : c_cpu_list.num_entries]
]
lib.cpuid_free_cpu_list(raw_cpu_list)
lib.cpuid_free_cpu_list(c_cpu_list)
return cpu_list
Loading

0 comments on commit bfd8c90

Please sign in to comment.