How to Find the Processor/Chip Architecture on Linux

How to find the processor / chip architecture on Linux

To display kernel architecture: uname -p

To display extended CPU details: cat /proc/cpuinfo

How do I find my CPU topology?

you can use command

lscpu

this will give information

for processor related info

dmidecode -t processor

Programmatically detect CPU architecture at runtime

If you compile your executable for 64bit, the CPU must be 64bit only.

If you compile your executable for 32bit, the CPU may be 32bit or 64bit (if a 64bit CPU is capable of running 32bit code), so you MUST query the CPU to differentiate. Best to get that from the OS when possible, but the CPU may have its own query for that info.

For instance, on an x86 or x86-64 CPU, there is a CPUID instruction available:

  • On Intel CPUs, CPUID's "Processor Info and Feature Bits" query includes an ia64 feature flag (IA64 processor emulating x86).

  • On AMD CPUs, CPUID's "Extended Processor Info and Feature Bits" query includes a long mode feature flag.

CPUID has a "Get vendor ID" query to determine the CPU manufacturer.

How to identify 64 bit processor with cat /proc/cpuinfo

Use the lscpu command.

32bit example output:

$ lscpu
Architecture: i686
CPU op-mode(s): 32-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 4
Core(s) per socket: 1
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 26
Stepping: 5
CPU MHz: 2260.998
BogoMIPS: 4521.99
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 8192K

64bit example:

$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 4
Thread(s) per core: 1
Core(s) per socket: 4
CPU socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 23
Stepping: 6
CPU MHz: 2327.533
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 6144K

How to obtain the number of CPUs/cores in Linux from the command line?


grep -c ^processor /proc/cpuinfo

will count the number of lines starting with "processor" in /proc/cpuinfo

For systems with hyper-threading, you can use

grep ^cpu\\scores /proc/cpuinfo | uniq |  awk '{print $4}'

which should return (for example) 8 (whereas the command above would return 16)

Check architecture for Linux and Mac

To detect bitness of your .NET runtime process (mono process in your case) you can check IntPtr.Size == 8 and to detect bitness of your processor you can parse the output of sysctl hw.cpu64bit_capable command on OSX and the output of cat /proc/cpuinfo | grep "flags" | grep " lm " command on Linux.

How do I find information about the parallel architecture of my CPU?

The sys filesystem knows all about this:

$ ls /sys/devices/system/cpu 
cpu0 cpu2 cpuidle possible sched_mc_power_savings
cpu1 cpu3 online present

$ ls /sys/devices/system/cpu/cpu0/topology/
core_id core_siblings_list thread_siblings
core_siblings physical_package_id thread_siblings_list

Here's the documentation

Using this filesystem, you can find out how many CPUs you have, how many threads they have, which CPUs are next to which other cpus, and which CPUs share caches with which other ones.

For example - Q: which CPUs does cpu0 share it's L2 cache with?

$ cat /sys/devices/system/cpu/cpu0/cache/index2/{type,level,shared_cpu_list}
Unified
2
0-1

A: It shares it's unified L2 cache with cpu1 (and itself).

Another example: Q: which CPUs are in the same physical package as cpu0 (on a larger machine):

cat /sys/devices/system/cpu/cpu0/topology/core_siblings
00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000055

A: cores 0, 2, 4 and 6. (taken from the bit pattern above, lsb=cpu0)


not all linux systems have the sys filesystem in, and it's not always in root. (possibly in proc/sys?). the thread_siblings_list form is not always available, but the thread_siblings (bit pattern) one is.



Related Topics



Leave a reply



Submit