Skip to main content

How A CPU (Central Processing Unit) Works !

Hi, we'll be discussing classical computing, more specifically - how the CPU operates and CPU parallelism. [Music] In the previous video in this series we discussed the shrinking of the transistor, allowing for more powerful and efficient computers, as well as the end of Moore's Law based on the miniaturization of the transistor within the next seven to ten years. Be sure to check it out for some background context for this video. Now in that video when referring to computing performance, we were focused on classical computing based on the CPU.

Classical computing, is essentially the digital computer, almost every computing device on the market today is a classical computer. Classical computers operate in serial, in other words, as mentioned in the first video in the series, Computing Origins, executing various instructions extremely fast in 'order', but to the average user it appears to be running them in parallel, meaning multiple instructions at a time. This is du…

How A CPU (Central Processing Unit) Works !

 Hi, we'll be discussing classical computing, more specifically - how the CPU operates and CPU parallelism. [Music] In the previous video in this series we discussed the shrinking of the transistor, allowing for more powerful and efficient computers, as well as the end of Moore's Law based on the miniaturization of the transistor within the next seven to ten years. Be sure to check it out for some background context for this video. Now in that video when referring to computing performance, we were focused on classical computing based on the CPU.

Classical computing, is essentially the digital computer, almost every computing device on the market today is a classical computer. Classical computers operate in serial, in other words, as mentioned in the first video in the series, Computing Origins, executing various instructions extremely fast in 'order', but to the average user it appears to be running them in parallel, meaning multiple instructions at a time. This is due to many hardware and software optimizations to allow for asynchronous operation. By the end of this video the distinction between parallel and asynchronous operation will become clear, but first let's see how the classical computer works.

As a disclaimer: the concepts we will be discussing are an over generalization of computing architecture, but for the sake of getting an abstracted understanding of classical computing functionality will serve well. Alright so first let's bring in the central processing unit, the CPU is the brains of the computer. Let's also bring in memory, the RAM, this is where the CPU accesses stored information it needs. Now the CPU also has built-in memory, this is called the cache. The cache is considerably smaller than the RAM, with sizes ranging in the order of 32 kilobytes to 8 megabytes. The purpose of the cache is to give the CPU the information it needs immediately.

The CPU and RAM are separate objects, so when the CPU needs information, it takes time, albeit a very small amount of time to read the data from the memory. This time can add considerable delay to computer operation. With the cache being right on the CPU reduces this time to almost nothing. The reason why you don't need much cache storage is because it just needs to store little bits of important information that the CPU will need to use soon or has been using a lot of recently.

There are various methods implemented to determine what goes on to the cache, what should be kept on the cache and when it should be written back on to the RAM. In a typical CPU there are various levels of cache, each with different read and write times and sizes, for the sake of simplicity we'll assume a single cache for our CPU. So now with the basic components out of the way, let's get into how the computer operates.

 When a CPU executes an instruction there are five basic steps that need to be completed: 1) Fetch: Get the instruction from the memory and store in the cache in some cases. 2) Decode: Get the appropriate variables needed for the execution of the instruction. 3) Execute: Compute the result of the instruction. 4) Memory: For instructions that require a memory read/ write operation to be done. 5) Write Back: Write the results of the instruction back into memory. Nearly every instruction goes through the first three and final step, only certain instructions go through the memory steps such as load and stores but for the sake of simplicity we'll assume every instruction requires all five steps.

 Now each step takes one clock cycle, this translates to a CPI, clock cycles per instruction, of five. As a note, most modern processors can execute billions of clock cycles per second, for example, a 3.4 gigahertz processor can execute 3.4 billion clock cycles per second. Now a CPI of 5 is very inefficient, meaning the resources of the CPU are wasted. This is why pipelining was introduced, bringing asynchronous operation into computing. Pipelining essentially makes it so each step can be executed in a different clock cycle, translating to 5 instructions per 5 clock cycles, or in other words, one instruction per clock cycle, a CPI of 1.

 Essentially what pipelining does is take the segmented steps of an instruction and execute them in each clock cycle, since the segmented steps are smaller than the size and less complex than a normal instruction, you can do the steps of other instructions in the same clock cycle. For example, if a step for one instruction is fetching the data, you could begin decoding another, executing another, etc - since the hardware involved for those steps isn't being blocked.

Superscalar pipelines add to this performance further. Think of pipelines as a highway, now typical lane in the highway can execute one instruction per clock cycle. With superscalar processors you add more lanes to the highway, for example, a 2 wide superscalar also referred to as a dual issue machine, has a theoretical CPI of 1/2, two instructions per clock cycle. There are various other methods implemented to make the processor CPI more efficient, such as: unrolling loops, very long instruction words [VLIWs] - which are essentially multiple instructions wrapped into one larger instruction, compiler scheduling an optimization - allowing for out of order execution and more.

 There are also many issues that come along with pipelining that decrease CPI, such as: data hazards, memory hazards, structural hazards and more. All these topics are beyond the scope of this video, but mentioned to satisfy curiosity if you wish to know more about them. So at this point, we now know about the basic design of a CPU, how it communicates with memory, the stages that it executes instructions in, as well as pipelining and superscalar design. Now instead of imagining all of this as a single CPU, let's take it further, all this technology can be embedded on a single core of a processor.

With multiple cores, you take the performance of a single core and multiply it by the core count, for example, in a quad core by four. Multiple cores also have a shared cache as a side note. The use of superscalar pipelines as well as multiple cores are considered hardware level parallelism. The computer industry after years of stagnation is now beginning to divert more focus to hardware level parallelism, by adding more cores to processors.

 This can be demonstrated by consumer processors like AMDs Threadripper line and Intel's i9 processor line, with core counts ranging from 8 to 16 and 10 to 18 respectively. While these may be their higher end consumer processor,  even the low and mid end processors from i3, i5 and i7 are getting buffs, with core counts ranging from quad, hex and octa core. As a side note, supercomputers are the best examples of utilizing hardware parallelism. For example, Intel's Xeon Phi and AMD's Epyc processors have core counts ranging from 24 to 72! With supercomputers having tens of thousands of processors with them.

Now there's one key component that is required in tandem with hardware parallelism to truly use all the resources efficiently, software parallelism. This leads us to the final topic in classical computing will cover, hyperthreading also referred to as multithreading. Instead of being implemented as hardware parallelism this is used as higher level software parallelism. Think of a thread as a sequence of instructions, now with single-threading, that sequence of instructions just flows through the pipeline as normal.

However, with multi-threading, you can segment your application into many threads and specifically choose how you want to execute them. Multi-threading can significantly increase computing performance, by explicitly stating what CPU resources you want to utilize and when. For example, for an application, the user interface, GUI, can be executed on one thread while the logic is executed on another. This is just one example of many instances where multi-threading can be used. Now multi-threading can't just be used for every application.

Since classical computing isn't intrinsically parallel, there can be a lot of issues with concurrency, or in other words, when multiple threads are executing at the same time but depend on the result of each other. Thus, some applications end up being only single threaded. However, many individuals and groups are working on ways to best utilize hardware parallelism through new software practices and rewriting old software.

For example, the latest Firefox updates now are bringing in multi-threading. Also some of the most computationally intensive tasks by default excel at multi-threading, such as: video editing, rendering and data processing - to list a few. Also as exemplified by the gaming industry, a lot of games are now moving into multi-threaded performance.So, in summary, classical computing is asynchronous not truly parallel.

Instructions are still executed in serial, but through the use of hardware and software level parallelism, maximize the utilization of the resources of the computer, making them execute extremely fast; giving the illusion of parallel operation. Also if you want a deeper look into how the CPU works. 

Comments

Popular posts from this blog

How To Install Windows Without Cd Or Pendrive

Hello guys welcome to our blog if you want to install Windows operating system on your computer or laptop without CD and PenDrive, then today's post will be very useful for you. Normally when we install a window, we need a CD or pen drive for it. But today I will tell you how you can install Windows without a CD or pen drive.

But guys, there is a condition here, through this method you can upgrade Windows means if you are on Windows 7 and you want to go to Windows 8 or Windows 10, then you can install Windows without CD or Pendrive. This is to say that if you want to install Windows without CD and PenDrive, then your computer should already have a second window operating system. Only then you will be able to install Windows with this method.

But before that, we know what is the Windows operating system and a little information about whom.?
What Is Windows Operating System
Windows operating system is a computer operating system whose first version Windows 1.0 was launched by Microsoft …

7 Best Free Windows Program (You Should Have!)

If you're like me, you're always on the lookout for cool new software that might be useful to you. So as usual, I've got a new list of awesome programs that you should REALLY know about if you don't already. And of course, these are all free, and will all work on windows. Though many will also be compatible with mac as well. And at the end of the video, if you're interested, I'll have links to other lists I've made of free programs, chrome extensions, that kinda stuff. But enough rambling, let's go.Program No.  1Starting off, a very useful program that I hope most of you have already, called 7-zip. It's an extremely popular program for compressing files and extracting them from all sorts of file containers. It's very similar to the infamous WinRar, except free, and supports more file types. So if you've ever come across a weird file container you've never seen before, this will handle whatever you throw at it. Anything from zip files, to…

What Is USB Type-C ? (The New Version Of USb Cables!)

Ah yes, USB Type-C, the new USB standard that will save us from constantly trying to put a plugin a USB cable the right way. Most of you have heard of it by now if you're not already using it, but you probably don't know all the details. Like, what's the difference between USB-Cand USB 3.1, or are all USB-C cables capable of the same speeds. Well, that's what we're going to talk about today because even though all USB-C connectors look the same, there are a LOT of different types of USB-C you should know about. And believe me, it can get REALLY confusing, I literally did about 5 hours of research for this video, but I'll try to make it easy to understand.

First of all, let's start off very simple, what is USB-C. At it's the most basic level, USB-C just refers to this specific USB plug, plus some specifications for those cables' wiring, and that's it. So just saying "USB-C" only tells you about what the cable looks like, it doesn't d…