seanmonstar / num_cpus

Get the number of CPUs in Rust
Apache License 2.0
582 stars 91 forks source link

Returns 13 cores on AWS 16 core instance #102

Closed JakkuSakura closed 4 years ago

JakkuSakura commented 4 years ago

A simple wrap for num_cpus and lstopo

pub fn get_logical_processor_number() -> i32 { num_cpus::get() as i32 }
physical core numbers number: 8 (lstopo) logical core number: 13(num_cpus)
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          16
On-line CPU(s) list:             0-15
Thread(s) per core:              2
Core(s) per socket:              8
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz
Stepping:                        4
CPU MHz:                         3374.405
BogoMIPS:                        5999.98
Hypervisor vendor:               KVM
Virtualization type:             full
L1d cache:                       256 KiB
L1i cache:                       256 KiB
L2 cache:                        8 MiB
L3 cache:                        24.8 MiB
NUMA node0 CPU(s):               0-15
Vulnerability Itlb multihit:     KVM: Vulnerable
Vulnerability L1tf:              Mitigation; PTE Inversion
Vulnerability Mds:               Vulnerable: Clear CPU buffers attempted, no microcode; SMT
                                  Host state unknown
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sa
                                 nitization
Vulnerability Spectre v2:        Mitigation; Full generic retpoline, STIBP disabled, RSB fi
                                 lling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Vulnerable: Clear CPU buffers attempted, no microcode; SMT
                                  Host state unknown
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca c
                                 mov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx p
                                 dpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nons
                                 top_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq ssse
                                 3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_dead
                                 line_timer aes xsave avx f16c rdrand hypervisor lahf_lm ab
                                 m 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi
                                 1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq
                                  rdseed adx smap clflushopt clwb avx512cd avx512bw avx512v
                                 l xsaveopt xsavec xgetbv1 xsaves ida arat pku ospke
seanmonstar commented 4 years ago

Interesting. Do you know if cgroups or CPU affinity has been set for the process?

For the logical CPUs, num_cpus checks sched_getaffinity, and if that fails, it checks _SC_NPROCESSORS_ONLN.

JakkuSakura commented 4 years ago

Oh, I forgot that I have already isolated 3 cores for my realtime application using tuned. Is there an option to get the real logical core number?

seanmonstar commented 4 years ago

Nope. num_cpus assumes if you're asking for the number of logical CPUs, you're likely asking how many the process has access to.