CPU Basics: Processor Internals, Operation, Cores, Threads and Clock Speed Explained

by Mayank
Processor

When we go to the store to purchase a new Laptop or smartphone, we usually get intrigued when we hear the words “quad-core” or “hexa-core.” We also hear phrases like “4 cores clocked at 1.8 GHz each”. You may have wondered what these words and phrases really mean and why they are essential.

In this post I will explain to you in the simplest way possible some of these common terms which are widely used. So even though you don’t know much about processors and their architecture, you’ll pretty easily understand the jargon.

Contents

  1. What is a CPU?
  2. What lies inside of a CPU?
  3. A Top to Bottom Overview
  4. Clock Speed of a CPU
  5. What is a CPU Core?
  6. What is a Thread?
  7. Putting it all together

Let’s first take a brief look at what CPU really means and how it works.

What is a CPU?

A CPU ( Central Processing Unit), usually called a processor, is the real brain of a computer. It’s essentially an electronic circuit that executes the instructions given to it. Such instructions that contain several Arithmetic/Logic and Input/Output operations are generated from a program. These programs are written by the programmers who build apps for your PC or smartphones.

An Intel i9-9900K processor.
Photo by Christian Wiediger on Unsplash

What lies inside the CPU?

The CPU consists of billions of transistors that are fabricated or printed on a single rectangular piece of semiconductor material also called an Integrated Circuit (IC) or die. This die is enclosed in a case as seen in the below picture. This is the actual CPU or processor that your PC or smartphone has.

The back view of a CPU. These golden pins line up with holes in your motherboard’s CPU socket.

The purpose of these transistors is switching. Each transistor is switched on and off a million or a billion times per second. Just think of these transistors as a light switch in your home that you turn on and off very quickly. These transistors are connected together to form millions of digital circuits called logic gates (AND, OR, NOT are the basic logic gates). When a transistor turns ON, a 1 signal is generated, and when it turns OFF, a 0 signal is produced, and different combinations of these signals form logic gates. These gates are combined to form functional units (like registers, ALU etc). These functional units then form the architecture of the CPU.

The inside view of a Motorola 68040 processor from the 1990. Now

An architecture is the backbone of a particular CPU. Every bit of instruction is executed using the CPU architecture. Processor architecture is a wide subject and I won’t get into explaining it. The architecture implementation for every CPU manufacturer is different (Intel x86, AMD Ryzen, ARM are some popular ones).

Note: Transistors are the building blocks for the logic gates. Logic gates create flip flops, and flip flops build complex circuits like registers, ALU (Arithmetic and Logic Unit) etc. That is why at the lowest level, the processors are made up of transistors.

Fact: Before the introduction of integrated circuits ( ICs), computers had to be physically rewired to perform different tasks. If you were born in that era, you had to wire the components to make a simple addition, then rewire it to make a division. The ENIAC is an example of such a computer.

The ENIAC computer from the time when ICs didn’t exist

Don’t worry too much about the internal stuff, though. Just think of it like this:

The CPU contains a lot of puzzle pieces (transistors) and there are different ways to connect them. Once the pieces are connected in a particular way, you’ll get a functional unit. Several of these functional units are connected in a particular way to make a complete architecture. A program talks to the operating system which then talks to the architecture through the specific instructions stored in the program.

A Top to Bottom Overview

Okay, so we’ve taken a look at the inside of a CPU. But how do you talk to the CPU? Let’s take a deep dive into this process from top to bottom.

  • Let’s say you’ve opened an app on your laptop. Now, a group of programmers would have written this application as a program so it can run on your computer. This program runs internally and everything is handled by your operating system.
  • Built into the operating system is a bunch of tools to make sense of this program (such as compilers, parsers, assemblers and some complex operating system magic like process scheduling, creating processes and threads, etc.) to translate the program into real instructions that a CPU can understand. These instructions guide the CPU to do something.
  • The CPU architecture then fetches, decodes and executes these instructions (instruction cycle). There is a clock pulse that allocates time for the execution of each instruction.
  • The result of the execution is obtained in the main memory ( RAM) from where the operating system takes it and shows it to you.

Note: This is just a very small explanation of how the CPU works. The actual process is much bigger and more complex, but this description is enough for you to get acquainted with the process.

Clock Speed of a CPU

In the above section, I told you about how transistors quickly turn on and off and make logic gates and functional units. But how does a transistor know when to switch on and when to turn off? The CPU clock pulse is the answer to this question. Every CPU that exists today has a Clock Generator near it. Clock signals or pulses are generated by the clock generator. A clock signal is either high (1) or low (0).

A desktop PC clock generator

The clock speed measures how many pulses or cycles can be generated in a second. It is measured in MHz and GHz (where Megahertz is a million pulses per second and Gigahertz is a billion pulses per second). Each cycle consists of either a single instruction or a number of instructions. All this depends on the architecture of the CPU. In some architectures an instruction may be processed in a single cycle but it may take several cycles or pulses to process the same instruction in other architectures.

Note: While higher clock speed means better performance, certain factors like cache architecture are often considered to calculate the processor’s actual performance. So the next time you are buying a new laptop or a smartphone, make sure that you don’t just consider higher clock speed as the only factor for your purchase.

What is a CPU Core?

After designing a CPU, the manufacturers realized that although the clock speed (explained above) of the CPUs was quite high (ranging from a few MHz to a few GHz), the CPU could serve only one process at a time, therefore all the CPU power could not be utilized. The solution was to make use of multiple CPUs. The problems with using multiple CPUs are:

  • We would need multiple sockets on the motherboard to fit both CPUs
  • We would need separate cooling units for both CPUs.
  • This would increase the cost of the whole computer system.
  • The power consumption will be very high.

Note: Multiple CPUs are used today to perform very complicated tasks. With multiple CPUs, you can run multiple processes at a time in parallel. Computers with multiple processors are mostly used as servers.

A desktop motherboard with 2 CPUs in it. The two heat sinks are fitted on the top of each CPU for cooling

With the advent of improved manufacturing techniques, we were able to pack more CPU transistors on a CPU of the same size and build more complex systems. Such innovations brought with them a concept where manufacturers packed multiple CPUs within a single CPU which used just a single socket. Each CPU inside of a processor is then called a “Core”. So a dual-core processor has two CPUs or cores in it. We went even further with quad-core processors (4 cores), hexa-core processors (6 cores) and octa-core processors (8 cores). We even went bonkers with 16, 32 and 64 core CPUs!

AMD Ryzen Threadripper 3990X
The AMD Ryzen Threadripper 3990X has a whopping 64 cores

The benefit of doing so is that now the computer’s operating system can think of a dual-core CPU as two different CPUs and provide the two CPUs with separate processes, or distribute a task between the two cores. The other advantage of using multiple cores is that the latency is reduced considerably as the cores can interact more effectively because they are on the same chip. The below image of the Windows Task Manager explains it better:

This CPU has 4 cores in it

What is a Thread?

You may have heard the term “Threads” floating around if you’re into computers. Look at the image above. You will see the word “Logical Processors” written just below “Cores”. Logical Processors and Threads are the same. The term is quite self-explanatory if you break it down. Logical means virtual or not physically present in hardware form. So a logical processor or thread does not exist physically rather it is created virtually.

Threads divide a single physical core of the CPU into two virtual cores. This means that if you have a dual-core CPU (i.e. 2 cores) then it will have 4 threads. In the above image you can see I have a quad-core CPU (i.e. 4 cores) so my CPU has 8 threads. Similarly, an 8 core CPU will have 16 threads and so on.

Processes and Threads

A process is created every time you open an application on your computer. Multiple processes can share a single core at a time along with memory resources such as RAM. This is called multi-tasking. The CPU core can only execute a single process at a time, but it can quickly switch between processes. A powerful operating system tool called the “Process Scheduler” manages the switching between processes.

A thread is created by a process every time an application is opened. The more applications you open, the more processes you run, resulting in more threads being created. Threads are also managed by an operating system scheduler. A single process can also distribute a task to multiple threads called multi-threading.

The number of processes and threads currently active on my PC

Got confused? Let’s make it easier:

  • Let’s say you want to open Google Chrome on your PC.
  • The program is an executable file. In this case it will be chrome.exe
  • A process is created when you double-click on the Chrome icon.
  • Thread is the smallest unit in the process. When the Chrome process is running, one thread of the process could display your current tab, and the second thread could display your other tabs.

Putting it all together

Wow that was a long article! Now before you go let’s summarize everything from the above sections. The block diagram below will help you.

The block diagram of the complete execution process
  • When you open an application, it starts as a program.
  • The program is compiled or interpreted in binary form (1 or 0) that the CPU can understand.
  • The program is loaded in the RAM or volatile memory.
  • The program is then converted to one or more running processes. This is done through the operating system.
  • Processes are independent of each other.
  • Each process then creates one or multiple threads depending on the requirements.
  • As a process contains multiple threads that share the same memory block, threads can easily communicate with each other.
  • The CPU executes these threads and loads the execution result into the memory from where the operating system displays it to you.
  • Every execution is synchronized by a CPU clock. The clock speed measures how many cycles or pulses are generated in a second.

We love to hear from you

Are you still confused? Got some questions? Feel free to comment below. Also, feel free to suggest more topics for future blog posts.

Related Posts

Leave a Comment