Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROPOSAL] psutil.cpu_info() (extended CPU information) #1894

Open
giampaolo opened this issue Dec 19, 2020 · 1 comment
Open

[PROPOSAL] psutil.cpu_info() (extended CPU information) #1894

giampaolo opened this issue Dec 19, 2020 · 1 comment

Comments

@giampaolo
Copy link
Owner

giampaolo commented Dec 19, 2020

This is a generic / exploration ticket, currently useful only for collecting information on how to get CPU info on different platforms, and which I will update from time to time. The idea is to provide a psutil.cpu_info() API returning a dict (EDIT or namedtuple?) with variable keys, depending on what's available. By observing lscpu output on Linux, the idea is to have something roughly like this:

>>> psutil.cpu_info()
{"model_name": "Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz",
 "arch": "x86_64",
 "op_modes": "32-bit, 64-bit",
 "logical_cpus": 8,
 "cores_per_socket": 4,
 "sockets": 1,
 "threads_per_core": 2,
 "cores_per_sockets": 4,
 "numa_nodes": 1,
 "vendor": "GenuineIntel",
 "l1d_cache": "32000",
 "l1i_cache": "32000",
 "l2_cache": "256000",
 "l3_cache": "6144000",
 "flags": "fpu vme de pse tsc msr pae ..."}}

Note that the information re. the number of cores/sockets, etc. intersect with another proposal I made in #1392 (comment), where I (roughly) suggest a re-adaptation of psutil's cpu_count() API. That must be taken info consideration as possibly we would end up with 2 ways of doing the same thing, but cpu_count() should be preferred as "more standard":

psutil.cpu_count(kind="logical")  
psutil.cpu_count(kind="cores")
psutil.cpu_count(kind="sockets")  
psutil.cpu_count(kind="usable")
psutil.cpu_count(kind="numa")

The number of CPU types is not strictly related with this proposal though. The point of cpu_info() is the provide more "human readable", non-strictly-standardized information.

Minimum information

According to lscpu on Linux and sysctl.h on macOS, it seems to me the bare minimum info we should provide on all platforms should be the following (but didn't check Windows yet):

  • model name
  • L1I cache size
  • L1D cache size
  • L3 cache size
  • number of sockets
  • byte order (little/big endian)
  • flags / features

Platform notes / implementations

Linux

  • lscpu.c source code
  • cat /proc/cpuinfo output
  • lscpu output
  • lscpu -J (JSON) output, in case we'll end up parsing it (likely)

macOS

  • sysctl.h interface
  • sysctl -a | grep machdep.cp output:
machdep.cpu.max_basic: 22
machdep.cpu.max_ext: 2147483656
machdep.cpu.vendor: GenuineIntel
machdep.cpu.brand_string: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
machdep.cpu.family: 6
machdep.cpu.model: 30
machdep.cpu.extmodel: 1
machdep.cpu.extfamily: 0
machdep.cpu.stepping: 5
machdep.cpu.feature_bits: 9266193621400157183
machdep.cpu.extfeature_bits: 1241917688064
machdep.cpu.signature: 67301
machdep.cpu.brand: 0
machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH MMX FXSR SSE SSE2 HTT SSE3 SSSE3 CX16 SSE4.1 SSE4.2 POPCNT VMM
machdep.cpu.extfeatures: SYSCALL XD EM64T LAHF LZCNT PREFETCHW RDTSCP TSCI
machdep.cpu.logical_per_package: 2
machdep.cpu.cores_per_package: 2
machdep.cpu.microcode_version: 0
machdep.cpu.processor_flag: 1
machdep.cpu.mwait.linesize_min: 0
machdep.cpu.mwait.linesize_max: 0
machdep.cpu.mwait.extensions: 3
machdep.cpu.mwait.sub_Cstates: 0
machdep.cpu.thermal.sensor: 0
machdep.cpu.thermal.dynamic_acceleration: 0
machdep.cpu.thermal.invariant_APIC_timer: 0
machdep.cpu.thermal.thresholds: 0
machdep.cpu.thermal.ACNT_MCNT: 0
machdep.cpu.thermal.core_power_limits: 0
machdep.cpu.thermal.fine_grain_clock_mod: 0
machdep.cpu.thermal.package_thermal_intr: 0
machdep.cpu.thermal.hardware_feedback: 0
machdep.cpu.thermal.energy_policy: 0
machdep.cpu.xsave.extended_state: 0 0 0 0
machdep.cpu.xsave.extended_state1: 0 0 0 0
machdep.cpu.arch_perf.version: 0
machdep.cpu.arch_perf.number: 0
machdep.cpu.arch_perf.width: 0
machdep.cpu.arch_perf.events_number: 0
machdep.cpu.arch_perf.events: 0
machdep.cpu.arch_perf.fixed_number: 0
machdep.cpu.arch_perf.fixed_width: 0
machdep.cpu.cache.linesize: 64
machdep.cpu.cache.L2_associativity: 4
machdep.cpu.cache.size: 256
machdep.cpu.tlb.inst.large: 8
machdep.cpu.tlb.data.small: 64
machdep.cpu.tlb.data.small_level1: 64
machdep.cpu.address_bits.physical: 39
machdep.cpu.address_bits.virtual: 48
machdep.cpu.core_count: 2
machdep.cpu.thread_count: 2
machdep.cpu.tsc_ccc.numerator: 0
machdep.cpu.tsc_ccc.denominator: 0

Windows

TODO

FreeBSD

Other platforms

Considerations / open questions

  • in case there's more than 1 physical CPU on the system, the API may return a list of dicts (cpu_info(percpu=True)), but that would be a mess in terms of implementation and probably not portable, so it should not be supported.
@Sub-7
Copy link

Sub-7 commented Jan 21, 2021

Json output of the core load would be nice.

psutil.cpu_percent(interval=1, percpu=True)
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

@giampaolo giampaolo changed the title [PROPOSAL] extended CPU information - cpu_info() [PROPOSAL] psutil.cpu_info() (extended CPU information) Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants