DEV Community

Cover image for Understanding Processors : babies to beast
Aadityansha
Aadityansha

Posted on

Understanding Processors : babies to beast

Transistor

Let's begin with basics , the very basic but curial part on which everything of modern computation is based on (i.e Transistors)

Processors aka Cpu are nothing but billions and billions of these small* transistors* on a silicon chip ( or silicon base )

But What are Transistors? πŸ€”

Transistor

Consider Transtors as a switch which can do on and off electricity flow or say regulate the flow of electron through the chip Just as a switch do for Electrical bulb

↓

However in the meantime of regulating the flow of electron ( (or say switch on and off )) they able to perform the calculation which is represent by 0 (off or no current flow) and 1 ((on or current flow))

↓

By combining this billions and billions of transistor we can make them perform complex calculation and can able to perform the computer task easily (becuz at the end of the day any task you perform on your device they end up converting into 0s and 1s and then getting calculated by the processor and then response is then again converted back into human readable language )

Now We are ready to deep dive into the working of processor

The CPU (Central Processing Unit) is the brain of your computer.

It:

1.Executes instructions (like add, multiply, move data, compare even at large scale ).

2.Decides which tasks to run and in what order.

3.Controls communication between memory, storage, and other hardware.

The Basic working cycle of Cpu but important

((Just read it i'll give a simple analogy below))

Every CPU instruction runs in this Fetch β†’ Decode β†’ Execute β†’ Writeback cycle: (This is also called clock , Don't worry i'll explain)

1.Fetch : Get the instruction from memory (RAM or cache).

↓

2.Decode : Understand what the instruction means (e.g. add, move, jump).

↓

3.Execute : Perform the actual work β€” arithmetic, logic, memory access, etc.

↓

4.Writeback : Store the result back into registers or memory.


Simple Analogy: Let's suppose you are playing a game in which you fire a bullet to the opponent then:

1.you fired a bullet this information will be send to your cpu (or say Fetched by the Cpu)

↓

2.Cpu will then decode the instruction into it's 0s and 1s so that it can calculate your opponent's health, position etc

↓

3.it'll execute the operation or say perform the calculation to find the opponent health your bullet speed distance etc.. to calculate the final result

↓

4.Writeback: It'll then send this information to your game that (hey i have calculated everything and it's a headshot with damage 100%)

Since it's a complete cycle of Fetch β†’ Decode β†’ Execute β†’ Writeback it creates a clock or circle


And here comes our next part: (Clock-speed)

Clock speed means how fast the CPU cycles instructions (i.e how fast the cpu completing each cycle of instruction )

1 GHz = 1 billion cycles per second

Higher GHz = faster per-core performance (usually)

That's why most gaming phone brand mention the clock speed as their one of the crucial aspects

However GHz alone doesn't define performance β€” architecture, cache, and cores matter more. (will talk about it later) But what matter more is the IPC


IPC (Instructions Per Cycle)

IPC stands for how many instructions a CPU can do per clock cycle. Higher IPC β†’ more efficient core ( discussed below) .

Even with the same GHz, a CPU with higher IPC performs better. (which means that in same cycle or clock the one with more ipc can perform or execute more instruction than one with less ipc)


What's a Core?

Core is simply the brain which handel the operations , more the core (i.e brain) more efficiently and rapidly it would handle the operation

CPUs are multi-core, meaning multiple independent brains inside one chip, to handle multiple operation at same time (i.e talking on call , playing game and downloading movies all at same time
)

A dual-core CPU = 2 cores

A quad-core CPU = 4 cores

An octa-core CPU = 8 cores

So, it's a simple analogy that more core means more efficient and more operation at same time right ?

The answer again is No , the core are facilitated (i.e helped , just trying to sound cool πŸ˜…) by something called thread


Thread

Think of thread as same brain doing multiple task at same time (just as you chatting to your girlfreind and your female best friend simultaneously or at same time with your single brain )

Since as we discussed the Cpu has multiple brain or core , facilitating them with thread would help each of them to handle multiple task at same time

4 cores, 8 threads means each core or brian will have 2 thread

It means that each of the brain ( or core) will able to perform two task simultaneously , it means overall they can perform 8 task simultaneously


TDP (Thermal Design Power)

TDP = how much heat a CPU produces under load, measured in watts (W)

Low TDP β†’ cool and power-efficient (e.g., laptops)

High TDP β†’ more performance but needs better cooling


Fabrication Process (nm)

you might have heard of*3nm processor , 2nm processor* these kind of brand marketing by smartphone or laptop companies for demonstrating theri device performance , But what it actually means πŸ€”?

↓

As we talked about transistors and we also know that more the transistor would be more the calculation or execution of instruction would be done by the cpu effectively and rapidly which will increase the performance of the device

↓

But to fit more transistor on that small size chip we need to reduce the size of transistors (But wait πŸ˜• we can also increase the size of chip can't we ?)

The simple answer is sadly No .

Reason:

1.Cost explodes

Larger chips = more material and energy to manufacture

↓

Fewer chips fit on a manufacturing wafer (i.e machine to make chip)

↓

Also would require more silicon to produce large chip which will drastically increase the price

↓

2.Heat problems : Big chip generate more heat

↓

3.Physical limitations

  1. phone, laptop, or server has limited space

  2. Bigger chips don't fit in slim devices

  3. Harder to connect to other components

Therefore companies always tries to reduce the transistor size to 3nm , 2nm etc in order to fit more of them on chip so that performance can be increase

However there again is a limitation

Too much of reduction in transistor size would led to leakage of electron , as we have already discussed that transistor regulate electron flow too small transistor wouldn't able to prevent electron from flowing (companies are working on shifting on other element like carbon )


Now we have enough knowledge to understand the components of Cpu (aka processor)

Components of CPU

1. Register

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Hold immedtiate data to         β”‚
β”‚  perform the action              β”‚               
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Analogy : Let's recall our bullet game example to understand this
Register holds the distance ,speed,postion of opponent to calculate the damage in our game example


2. Alu(Arithmetic Logic Unit)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Perform or execute the action   β”‚
β”‚  like doing arethemitic          β”‚
β”‚  operation and logic building    β”‚               
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Analogy : So based on that data (stored data in register about distance , velocity etc ..) it'll then calculate the damage


3. Control unit

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         CONTROL UNIT 🧠           β”‚
β”‚  It's the brain, the core which  β”‚
β”‚  takes the decision              β”‚               
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Analogy : control unit handel with the decision making part like ( Ok the user has clicked the fire button now let's make a decision based on the calculation Done by Alu that with 20% of damage how much health has reduced of opponent)


4. Cache

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Hold other immediate data which β”‚
β”‚  are important but not as        β”‚
β”‚  important as data in Register   β”‚               
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Analogy : So in this game there are lot more things will be going on , like ( game menu game lobby , map , Dress color , gun skin etc.. )these data are needed but not as immediate as the data for damage or bullet shot .

Also data like connecting user with his teammate , transferring his voice to his teammate (and getting their msg as well )


Cache (L1, L2, L3) in depth

Before diving to cache let's understand How your App start whenever you open it

↓
Basically when a user start an App it get loaded from Rom (or Harddrive or SSD or Memory) to Ram

↓
It means that whenever an App is running it uses the storages more specifically the memory of Ram

↓

Analogy: Let's get back to our game example, when you started the game it get loaded from your Device harddrive or SSD or Rom to your Ram

↓

However some portion of that game from Ram also get loaded into Cpu or processor for fast calculation

↓
For instance: In your house you have a library room (Just as Rom or harddisk)

then your study room (The Ram where you keep your require 10-12 books )

then table Processor/Cpu (where you keep the instant needed book which you are reading at that moment )

Wait 🫷 , you have your hand as well in which you have the book which you are reading now , What is it then πŸ€”? Just keep in mind I'll cover soon


CPU cache: tiny ultra-fast memory inside CPU for storing frequently used data

Analogy: Like while playing the game there's a lot many things stored inside your Ram (like the game characters, diffrent menus , event , different maps you have downloaded everything)

↓

But you don't require all of them during having a battle, right ?

↓

Thus , the necessary information get stored inside the cpu (Just as the table) for fast processing so that the processor doesn't have to go to Ram (room book shelf) to ask for information (such as what's current position of player , communion with teammates , which gun he has etc ...)
That's what Cache is storing necessary information for fast processing

Cache Parts

Basically each core (brain) has it's own 2 cache (tiny memory) called L1 and L2

↓

Informations are stored inside these cache based on priority

↓

The more closet cache to each core is L1: stores very tiny data 10-12kb
(Ultra necessary information)

and a bit away is L2: stores tiny data 100kb-1mbkb (also necessary but after L1)

(will give you a better example just read it)

Then their is L3: stores relatively large data 10-15mb cache which is a shared cache , it is only one memory but shared by all the cores


                Response time  | size     | Position from core
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”--------------------------------------------
β”‚   L1 Cache   β”‚ β†’ Fastest  ⚑ | Smallest | Closest to core
β”‚  (per core)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   L2 Cache   β”‚ β†’ A bit slower πŸ‡ | Larger | Still per core
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   L3 Cache   β”‚ β†’ Shared among cores 🐒 | Biggest | bit away
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Remember: We talked about Register which stores game info like calculation speed etc
And do you remember we talked about the hand which has the book being read by the person at that instant?

Yes, that's exactly what a Register is! It holds the information needed to respond immediately β€” like the person holding that one book in their hand right now ( basically the ultra-urgent stuff that you need RIGHT NOW to not get destroyed in the game )

It stores:
(
Player's current position,
Opponent's position,
Bullet velocity,
Distance to target,
etc .. )

Now Let's Sum Up all with an Analogy

The Game Scenario: Opening & Playing

Step 1: Game Opens
(Game gets fetched from Hard drive/ROM β†’ loaded into RAM)

↓

Step 2: Match Starts
(Information gets distributed across the memory hierarchy based on urgency)

Memory Distribution During a Squad Fight

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            HARDWARE MEMORY HIERARCHY                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  REGISTER (In your HAND)                                β”‚
β”‚  Ultra-Immediate Data (being processed RIGHT NOW)       β”‚
β”‚  ───────────────────────────────────────────────────────│
β”‚  β€’ Player's current position                            β”‚
β”‚  β€’ Opponent's position                                  β”‚
β”‚  β€’ Bullet speed                                         β”‚
β”‚  β€’ Distance to target                                   β”‚
β”‚  β€’ Real-time damage calculations                        β”‚
β”‚  β€’ Current instruction being executed                   β”‚
β”‚                                                          β”‚
β”‚  Size: Tiny (bytes)  Speed: Instant                     β”‚
β”‚  ( basically the book you're reading at THIS moment )   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L1 CACHE (On your TABLE)                               β”‚
β”‚  Necessary Data for Immediate Use (per core)            β”‚
β”‚  ───────────────────────────────────────────────────────│
β”‚  β€’ User's current gun                                   β”‚
β”‚  β€’ Current ammunition count                             β”‚
β”‚  β€’ Health kit status                                    β”‚
β”‚  β€’ Voice messages/commands from teammate                β”‚
β”‚  β€’ Knocked/downed player info                           β”‚
β”‚  β€’ Current active ability/skill                         β”‚
β”‚  β€’ Real-time teammate positions                         β”‚
β”‚                                                          β”‚
β”‚  Size: 10-12 KB  Speed: Ultra Fast                      β”‚
β”‚  ( stuff you need very soon but not RIGHT NOW )         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L2 CACHE (In your ROOM)                                β”‚
β”‚  Secondary Important Data (per core)                    β”‚
β”‚  ───────────────────────────────────────────────────────│
β”‚  β€’ Total players remaining in match                     β”‚
β”‚  β€’ Current backpack items                               β”‚
β”‚  β€’ The map/room of the current fight                    β”‚
β”‚  β€’ Enemy team roster info                               β”‚
β”‚  β€’ Available loot nearby                                β”‚
β”‚  β€’ Cooldown timers for abilities                        β”‚
β”‚  β€’ Recent event log                                     β”‚
β”‚                                                          β”‚
β”‚  Size: 100 KB - 1 MB  Speed: Fast                       β”‚
β”‚  ( good to know but doesn't affect your next move )     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  L3 CACHE (In your LIBRARY)                             β”‚
β”‚  General Game Data (SHARED by all cores)                β”‚
β”‚  ───────────────────────────────────────────────────────│
β”‚  β€’ Map layouts & design                                 β”‚
β”‚  β€’ Character skins & cosmetics                          β”‚
β”‚  β€’ Gun specifications & stats                           β”‚
β”‚  β€’ Clothes/outfit data                                  β”‚
β”‚  β€’ Other players' info (all squad members)              β”‚
β”‚  β€’ Game settings & configuration                        β”‚
β”‚  β€’ Texture & audio data                                 β”‚
β”‚                                                          β”‚
β”‚  Size: 10-15 MB  Speed: Slower but shared               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  RAM (Your STUDY ROOM)                                  β”‚
β”‚  All Active Game Data                                   β”‚
β”‚  ───────────────────────────────────────────────────────│
β”‚  β€’ Entire game world state                              β”‚
β”‚  β€’ All loaded assets                                    β”‚
β”‚  β€’ All player data                                      β”‚
β”‚  β€’ Sound files                                          β”‚
β”‚  β€’ Game menus & UI                                      β”‚
β”‚                                                          β”‚
β”‚  Size: 2-8 GB  Speed: Slow                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  STORAGE (Your HARDDRIVE)                               β”‚
β”‚  Entire Game File      and other device data            β”‚
β”‚  ───────────────────────────────────────────────────────│
β”‚  β€’ Complete game installation                           β”‚
β”‚  β€’ All game assets not in memory                        |
β”‚ β€’ All other movies , Apps , songs etc                   |
β”‚  β€’ Save files & settings                                β”‚
β”‚                                                         β”‚
β”‚  Size: 100+ GB  Speed: Very Slow                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Enter fullscreen mode Exit fullscreen mode

I hope this is enough for the basics , i have rewritten it 3 times because each time i continue to write and the electricity switch off i had to rewrite things again which was frustrating πŸ˜…

Hope you all liked it and feel free to suggest improvements and share your thoughts on my social handel . If i get better feedback i would soon write it's second part

X

Linkdin

Thankyou

Top comments (0)