If I tell you I'm multitasking, don't believe me, the best that I can do as a weak pitiful human
is to quickly switch my attention from one single thing to another. But is that how your CPU works?
Actually, no. Your CPU relies on a strategy called scheduling, where the operating system
will decide what sets of instructions or threads will get put through the CPU first,
second, third, and so on. Understanding scheduling is crucial to understanding
exactly how modern multi-core CPUs work. So we got a little bit of help for this video,
and we'd like to thank our friends at Intel for their assistance as we run through this thought
experiment. Each thread that your computer is working on gets assigned a value called priority,
so a thread with a higher priority value will be further ahead in line to get processed by your
CPU. Developers can assign priority values when they write a program, and Windows can change a
thread's priority based on how many system resources it needs and what the exact nature
of the instructions are. For example, if a thread is tied to what you're inputting with a keyboard
and mouse, such as clicking buttons in your web browser or aiming your weapon in a game,
it's likely going to get a higher priority. By contrast, background activities that aren't
time sensitive, those will get a lower priority. Similarly, developers can assign another value
called quality of service, or QOS, to each thread. QOS is a way for devs to signal to Windows
how much processor power a thread might need, and while Windows doesn't treat it as important
as priority, QOS is still a factor that the operating system will take into account when it
comes to scheduling. QOS is especially relevant when it comes to power management, as the OS can
use QOS to request a certain frequency from the CPU, and the CPU's hardware can decide
if it can ramp up to that frequency while staying within power limits. That's especially useful
on laptops. Which is all very cool, but in terms of our guy doing two things at once analogy,
priority and QOS pertain more to what I'm choosing to do, like texting while watching a movie,
rather than how I'm juggling those two tasks. So let's drill down into that. Traditionally,
CPU threads would go through one at a time, like my brain, but this isn't how modern multicore
systems operate, especially considering some newer chips even have different kinds of cores
all on one package. One goal in scheduling on multicore is not to context switch more than is
necessary. And context switching is just another fancy term for moving a thread from one core
onto a different one. In general, you want each thread to start and finish on one single core,
and you want to load balance across cores so that none of them are getting overwhelmed.
And there's been a lot of tweaking over the years to figure out how to do this easily
and efficiently, such as with libraries, which are software resources that sit between the
program and the operating system and allow multi-threading without making a developer do
a ton of extra coding. On newer chips, how exactly threading works out across cores becomes even more
important because of hybrid chips like Intel's Alder Lake lineup. These chips have higher performance,
or P cores, and lower performance, but more power saving, E cores. It might be confusing as to why
they put E cores on a desktop CPU where you aren't worried about your battery running out,
but because E cores are physically smaller, you can actually pack more of them onto a chip,
meaning you can in some cases get better performance if the scheduler can spread a program out
across many E cores compared to a smaller number of P cores. Now, even though the Windows scheduler
will still use P cores first by default if they're not busy, it can then use an E core for a second
thread before using the slower hyperthreading feature of a P core. We're also getting to the
point where, although Windows is still making final decisions on scheduling, there are now
hardware assist features on newer CPUs that will actually give advice to Windows, so a CPU can look
at the incoming workload and then advise Windows on the best current core for a certain thread,
depending on whether Windows wants more performance or better power efficiency.
So there's a lot that goes into deciding who gets to go first when it comes to your CPU,
and a multi-core model can legitimately multitask. Also, my wife can do it somehow.
If you guys enjoyed this video, check out our other videos, leave a comment if you have a suggestion for a future fastest Techquickie,
and don't forget to subscribe.