Skip to main content

Finding how many processors

I wanted to find out the processor details in my laptop and I found out that there are several ways to check. For example, see The RedHat community discussion on Figuring out CPUs and Sockets.

In this blog post, I'm listing few commands to find out details about CPUs.

I'm using Ubuntu in my Lenovo ThinkPad T530 laptop and following commands should be working any Linux system.

Display information about CPU architecture


$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 58
Model name: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
Stepping: 9
CPU MHz: 1199.988
CPU max MHz: 3600.0000
CPU min MHz: 1200.0000
BogoMIPS: 5787.10
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 4096K
NUMA node0 CPU(s): 0-3


$ lscpu -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ
0 0 0 0 0:0:0:0 yes 3600.0000 1200.0000
1 0 0 0 0:0:0:0 yes 3600.0000 1200.0000
2 0 0 1 1:1:1:0 yes 3600.0000 1200.0000
3 0 0 1 1:1:1:0 yes 3600.0000 1200.0000

The lscpu command reads /proc/cpuinfo file to get the CPU architecture details. So, you can also read it get more info.

$ cat /proc/cpuinfo

The lshw (list hardware) is another command to get CPU details.

$ sudo lshw -class processor


There is a GUI tool named "hardinfo", which can show details about various hardware components.

$ sudo apt-get install hardinfo
$ hardinfo


The dmidecode is another tool to find out hardware details. Following is an example to find processor details. The value "4" is the Dmi Type for the processor.

$ sudo dmidecode -t 4


The cpuid tool can dump CPUID information for each CPU.

$ sudo apt-get install cpuid
$ cpuid


The inxi is also another tool to check hardware information on Linux.

$ sudo apt-get install inxi
# Show full CPU output, including per CPU clockspeed and CPU max speed
$ inxi -C


Finding number of processors


# Print the number of processing units available
$ nproc
4


$ cat /proc/cpuinfo | grep processor | wc -l
4


Finding number of Physical CPUs


$ cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l
1


Finding number of cores per socket


$ lscpu | grep 'socket'
Core(s) per socket: 2


$ cat /proc/cpuinfo | grep "cpu cores" | uniq
cpu cores : 2

Finding number of threads per core


$ lscpu | grep -i thread
Thread(s) per core: 2


Summary


It's important to know about the CPUs when we are doing performance tests. A physical CPU is inserted into a single CPU socket. There should be multiple CPU sockets to support multiple CPUs. However modern CPUs support multiple cores and hyper-threading. See: CPU Basics: Multiple CPUs, Cores, and Hyper-Threading Explained

We can use following formula to calculate the number of logical processors we see in our system.

Number of Logical Processors = Number of Sockets x Number of Cores per CPU x Threads per Core

In my Laptop, there is one physical processor with two cores and each core has two threads. So, I have 4 logical processors. :)





Comments

Popular posts from this blog

Java Mission Control & Java Flight Recorder

Last year, I got two opportunities to talk about Java Mission Control & Java Flight Recorder. I first talked about " Using Java Mission Control & Java Flight Recorder " as an internal tech talk at WSO2 . I must thank Srinath for giving me that opportunity. After that, Prabath also invited me to do a talk at Java Colombo Meetup . Prabath, Thank you for inviting me and giving me the opportunity to talk at the Java Colombo Meetup! I'm also very excited to see that Marcus Hirt , the Team Lead for Java Mission Control has mentioned about the Java Colombo Meetup in his blog post: " My Favourite JMC Quotes ". It's so nice to see "Sri Lanka" was mentioned in his blog post! :) From Marcus' Blog Here are the slides used at the meetup. Java Colombo Meetup: Java Mission Control & Java Flight Recorder from Isuru Perera Marcus Hirt's blog posts really helped me to understand JMC & JFR concepts and his tutorials were very helpful...

Flame Graphs with Java Flight Recordings

Flame Graphs Brendon D. Gregg , who is a computer performance analyst , has created  Flame Graphs to visualize stack traces in an interactive way. You must watch his talk at USENIX/LISA13 , titled Blazing Performance with Flame Graphs , which explains Flame Graphs in detail. There can be different types of flame graphs and I'm focusing on  CPU Flame Graphs  with Java in this blog post. Please look at the Flame Graphs Description  to understand the Flame Graph visualization. CPU Flame Graphs and Java Stack Traces As  Brendon  mentioned in his talk, understanding why CPUs are busy is very important when analyzing performance.  CPU Flame Graphs  is a good way to identify hot methods from sampled stack traces. In order to generate CPU Flame Graphs for Java Stack Traces , we need a way to get sample stack traces. Brendon has given examples to use jstack  and Google's lightweight-java-profiler . Please refer to his perl program on g...