Multithreading Models & Hyperthreading
Summary
TLDRThis lecture delves into multi-threading, contrasting single-threaded with multi-threaded processes and highlighting the advantages of the latter. It introduces user and kernel threads, and the critical relationship between them in operating systems. The three primary multi-threading models—many-to-one, one-to-one, and many-to-many—are explored, each with its benefits and limitations. The many-to-one model is efficient but can block the entire process with a single blocking call. The one-to-one model allows for more concurrency but can be costly in terms of performance due to kernel thread creation. The many-to-many model offers flexibility and better utilization of multiprocessor systems. Additionally, the lecture covers hyper-threading, or simultaneous multi-threading, a technique by Intel that allows a single physical core to handle multiple threads, enhancing performance. Practical methods to check for hyper-threading on a system are also provided, offering viewers a deeper understanding of modern computing technology.
Takeaways
- 🧵 Multi-threading involves the use of multiple threads within a single process to improve performance and resource utilization.
- 📚 There are two types of threads: user-level threads, managed by the application, and kernel-level threads, directly managed by the operating system.
- 🔗 The relationship between user and kernel threads can be established in three models: many-to-one, one-to-one, and many-to-many.
- 🚫 In the many-to-one model, multiple user threads are mapped to a single kernel thread, which can lead to blocking issues and limit parallel execution on multiprocessors.
- 🔄 The one-to-one model maps each user thread to a unique kernel thread, allowing for better concurrency but can be costly due to the overhead of creating kernel threads.
- ➡️ The many-to-many model offers flexibility by allowing many user threads to be mapped to a smaller or equal number of kernel threads, improving concurrency and parallel execution.
- 💡 Hyper-threading, also known as simultaneous multi-threading, is a technology that allows a single physical processor core to handle two or more threads simultaneously, improving performance.
- 🔧 Hyper-threading can be identified by checking the number of logical processors against the number of physical cores; more logical processors indicate hyper-threading.
- 🛠️ The many-to-many model is often considered the best for establishing the relationship between user and kernel threads, as it combines the advantages of the other models while minimizing their drawbacks.
- 🔎 To determine if a system supports hyper-threading, one can use the 'wmic cpu get number of cores, number of logical processors' command in the command prompt on Windows.
- 🌟 Hyper-threading is a proprietary term by Intel, but the concept of simultaneous multi-threading can be found in various processor technologies to enhance performance.
Q & A
What are the two types of threads discussed in the lecture?
-The two types of threads discussed are user threads and kernel threads. User threads operate at the user level and are managed without direct kernel support, while kernel threads are managed directly by the operating system.
What is the definition of a many-to-one threading model?
-In a many-to-one threading model, many user-level threads are mapped to a single kernel thread. This model allows for efficient thread management in user space but has limitations such as blocking the entire process if a single thread makes a blocking system call.
What are the limitations of the many-to-one threading model?
-The limitations of the many-to-one model include blocking the entire process if one thread makes a blocking system call and the inability to run multiple threads in parallel on a multiprocessor system due to the one-to-one mapping with kernel threads.
How does the one-to-one threading model differ from the many-to-one model?
-The one-to-one threading model maps each user thread to a separate kernel thread, providing more concurrency than the many-to-one model. It allows other threads to continue running even if one thread makes a blocking system call and enables the use of multiprocessor systems.
What is the main disadvantage of the one-to-one threading model?
-The main disadvantage of the one-to-one model is the overhead associated with creating kernel threads. This can be costly and may burden the performance of an application, leading to a restriction on the number of threads supported by the system.
Can you explain the many-to-many threading model?
-The many-to-many threading model multiplexes many user-level threads to a smaller or equal number of kernel threads. It allows developers to create as many user threads as necessary, which can then run in parallel on a multiprocessor system and continue execution even when one thread performs a blocking system call.
What is hyper-threading, and how does it relate to multi-threading?
-Hyper-threading, also known as simultaneous multi-threading, is a technology that allows a single processor core's resources to be virtually divided into multiple logical processors, enabling the execution of multiple threads at the same time. It is a proprietary name given by Intel for this technology.
How does hyper-threading improve system performance?
-Hyper-threading improves system performance by allowing multiple logical processors to execute threads in parallel. This can make efficient use of a processor's resources and increase throughput, as it is almost like having multiple separate processors working together.
How can you determine if your system supports hyper-threading?
-You can determine if your system supports hyper-threading by checking the number of logical processors compared to the number of physical cores. If the number of logical processors is greater than the physical cores, hyper-threading is enabled.
What command can be used in Windows to check the number of cores and logical processors?
-In Windows, you can use the 'wmic cpu get number of cores' command to check the number of physical cores and 'wmic cpu get number of logical processors' to check the number of logical processors, which will help you determine if hyper-threading is enabled.
Outlines
🧵 Introduction to Multi-threading Models
This paragraph introduces the concept of multi-threading and the types of threads: user-level and kernel threads. It explains that user threads operate at the user level and are managed by developers, while kernel threads are directly managed by the operating system. The paragraph sets the stage for a deeper dive into multi-threading models, which are essentially the relationships between user and kernel threads. It outlines three common models: many-to-one, one-to-one, and many-to-many, and promises a detailed exploration of each model's characteristics, benefits, and limitations.
🔗 Many-to-One Model and Its Limitations
The many-to-one model is explored in this paragraph, where multiple user threads are mapped to a single kernel thread. This model is efficient in thread management at the user level, but it has significant limitations. If one thread makes a blocking system call, the entire process is blocked, and the model does not support parallel execution on a multiprocessor system due to the one-to-one mapping with the kernel thread. These constraints make it less suitable for systems requiring high concurrency and parallelism.
🔄 Advantages and Disadvantages of the One-to-One Model
The one-to-one model maps each user thread to a dedicated kernel thread, providing more concurrency than the many-to-one model. It allows for continued execution of other threads even if one makes a blocking system call and supports parallel execution on multiprocessor systems. However, creating a user thread requires the creation of a corresponding kernel thread, which can be costly and impact application performance. Most implementations restrict the number of threads due to the overhead of creating kernel threads, which limits the scalability of this model.
🤹 Many-to-Many Model: The Optimal Multi-threading Approach
The many-to-many model is presented as an improvement over the previous models, allowing for a flexible mapping of many user threads to a smaller or equal number of kernel threads. This model supports the creation of as many user threads as needed, with corresponding kernel threads capable of running in parallel on a multiprocessor system. It addresses the limitations of the many-to-one and one-to-one models by preventing the entire process from being blocked by a single thread's blocking system call and enabling better utilization of multiprocessor systems. This model is widely implemented and considered optimal for multi-threading environments.
🚀 Hyper-Threading: Simultaneous Multi-Threading in Practice
This paragraph delves into hyper-threading, also known as simultaneous multi-threading, a technology that allows a single processor core to handle multiple threads by virtually dividing it into multiple logical processors. Hyper-threading enhances performance by enabling the execution of multiple threads in parallel, akin to having multiple processors. The speaker demonstrates how to check for hyper-threading support in a system using the Windows Management Instrumentation (WMIC) commands, revealing that their Intel Core i3 processor supports hyper-threading with two physical cores and four logical processors.
Mindmap
Keywords
💡Multi-threading
💡User Threads
💡Kernel Threads
💡Many-to-One Model
💡One-to-One Model
💡Many-to-Many Model
💡Hyper-Threading
💡Logical Processors
💡Blocking System Call
💡Concurrency
Highlights
Introduction to multi-threading models and hyper-threading.
Difference between user-level threads and kernel-level threads.
User-level threads operate without direct kernel support.
Kernel threads are directly managed by the operating system.
Necessity of a relationship between user and kernel threads for system functionality.
Three common multi-threading models: many-to-one, one-to-one, and many-to-many.
Many-to-one model maps many user threads to one kernel thread.
Efficiency of thread management in user space in the many-to-one model.
Limitations of the many-to-one model, such as process blocking on a blocking system call.
Inability to utilize multiprocessor systems fully in the many-to-one model.
One-to-one model maps each user thread to a single kernel thread.
Increased concurrency in the one-to-one model, allowing for parallel execution on multiprocessors.
Disadvantages of the one-to-one model include the overhead of creating kernel threads.
Many-to-many model allows for multiplexing of user threads to a smaller or equal number of kernel threads.
Advantages of the many-to-many model include better utilization of multiprocessor systems and handling of blocking system calls.
Hyper-threading, also known as simultaneous multi-threading, allows for multiple logical processors from a single physical core.
Hyper-threading enables processors to execute two threads simultaneously, enhancing performance.
Practical method to check for hyper-threading support using Windows Management Instrumentation (WMIC).
Demonstration of checking for hyper-threading on an Intel Core i3 processor.
Conclusion summarizing the importance of understanding multi-threading models and hyper-threading in modern computing.
Transcripts
in the previous lecture we started
studying about threats and we saw the
difference between single threaded
processes and multi threaded processes
and we also saw the benefits of
multi-threading so in this lecture we'll
be studying about multi-threading models
and hyper threading so before we go into
multi threading models let us understand
the type of threads that we have so
basically there are two types of threats
the first one is user threats and the
second one is kernel threats so user
threads are the threats that are
supported above the kernel and are
managed without the kernel support so
these are the threads that are operating
in user level or which are created by
the users or the developers and then we
have the kernel threats so the kernel
threads are supported and managed
directly by the operating system so
kernel threads are the threads which are
managed directly by the operating system
and not by the user so these are the two
types of threats that we have so when we
started studying about operating system
we saw that the users are constantly
interacting with the system and
operating system is what allows this to
happen so since we have seen that there
are two types of threats the user
threats and kernel threats so for these
two threats to be able to function
together
there must exist a relationship between
the user thread and kernel threats so
ultimately for the system to function
there must exist a relationship between
the user threats and the kernel threats
so we will see how we can establish this
relationship between the user threats
and the kernel threats so that is the
thing that we are going to study in
multi-threading models so
multi-threading models are nothing but
the type of relationships that can be
there between the user threads and
kernel threads so we will see what they
are so there are three common ways of
establishing this relationship and what
is this relationship the relationship
between the user thread and the kernel
threads so let's see what they are the
first one is many to one model the
second one is one to one model and the
third one is many to many models so we
will see each of this models one by one
and we will see how do they function
what are their limitations and which one
among these are the best so
coming to the first model we have the
many to one model so from the name
itself we can understand that there is a
many to one relationship established
between the user threads and the kernel
threads so from this diagram we can see
these things on top they represent the
user threads and then the circle over
here it represents the kernel thread so
we see that many user threads are
associated to one kernel thread or many
user threads are accessing one kernel
thread so that is what we mean by the
many to one model many user threads to
one kernel thread so as I told you in
this model it Maps many user level
threads to one kernel thread and then
the thread management is done by the
thread library in user space so it is
efficient thread management is done in
the user level not in the kernel level
so in that way this is efficient because
we are able to manage the threads in the
user space now let us see what are the
disadvantages or the limitations of this
model so here are the limitations the
entire process will block if a thread
makes a blocking system call so we see
that many user threads are associated or
mapped to one kernel thread and if one
of the thread makes a blocking system
call then the entire process will be
blocked because let's say that all these
threads are associated to one single
process they are the threads of one
single process doing a certain task and
all these threads are mapped to this
kernel thread in the operating system so
let's say that one of the thread makes a
blocking system call so if that thread
makes a blocking system call this kernel
thread will be blocked and if this is
blocked then all of them will be blocked
because they are all mapped to this
single kernel thread so that is one of
the limitations or disadvantage of this
model so if one thread makes a blocking
system call the entire process will be
blocked and then the second limitation
is that because only one thread can
access the kernel at a time multiple
threads are unable to run in parallel on
a multiprocessor so as you see here
since these multiple threads in the user
level are mapped to just one kernel
thread even if we are having a multiple
processor system if you are
a multiprocessor we are not going to be
able to make use of that multiprocessor
system because even though we have
multiprocessor that means even though we
are having more than one processor one
kernel thread will run only in one of
the processor one kernel thread cannot
run in two processors so even though we
have many processors this entire thing
will run only in one of the processors
because they are all mapped to one
kernel thread and one kernel thread will
run only on one of the processor so that
is another limitation of the many-to-one
model all right so now let's go to the
next model and see how is that better
than this and if that has any
limitations as well so the second model
that we have is one-to-one model so from
the name itself even here we can
understand here that one user thread is
mapped to exactly one kernel thread
unlike the Mini to one model here one
user thread is mapped to only one kernel
thread so here this user thread is
mapped to this kernel thread this one to
this one and so on so let us see how
does this work and what are its benefits
and what are its limitations so as I
told you in this model it Maps each user
thread to one kernel thread and then it
provides more concurrency than the
many-to-one model by allowing another
thread to run when a thread makes a
blocking system call so in this case
even if one user thread makes a blocking
system call the entire process will not
be affected unlike the many to one model
so here let's say for example that these
four threads belongs to one process and
then let's say that one of the user
thread makes a blocking system call so
if it does so only this kernel thread
associated with this user thread will be
affected and only this part will be
blocked so the other part of the process
that means these three threats
associated with these three kernel
threads can still run even though this
hat made a blocking system call so that
is one advantage as compared to the many
to one model and also it allows multiple
threads to run in parallel on a multi
processor so in the previous one we saw
that we cannot make use of the
multiprocessor system but in this case
we are able to make use of
multiprocessor systems why because each
user thread is associated to one
so each of this part can run on one of
the processors that we have so suppose
we are having four processors in our
system then each of these threads can
run on one of the four processors so
this one can run on one this on another
one and so on so we are able to make use
of the multi processor architecture that
we have in case of the one-to-one model
so so far we saw that one-to-one model
is having some advantages as compared to
the many to one model now let's see if
it has some disadvantages and if they
have what are they so here are the
disadvantages creating a user thread
requires creating the corresponding
kernel thread so here we see that each
user thread is mapped to one kernel
thread so whenever you are creating a
user thread you have to create the
kernel thread as well so that may become
costly sometimes and because the
overhead of creating kernel threads can
burden the performance of an application
most implementations of this model
restrict the number of threads supported
by the system so the overhead of
creating kernel threads can sometimes be
very heavy on the system or the
application that is running so what
happens is that most of the applications
they will restrict the number of kernel
threads that can be created because in
one system there is a limit of how many
threads can run at a time so if you are
having a multiprocessor system with four
processors then at a time only four
threads can run because each thread will
run on one of the processor so if you
are having a processor with 4 cores that
means you're having 4 processors in your
system and if you are having 5 threads
and trying to make those 5 threads run
at the same time it may not work so the
application may have to restrict the
number of threads that are supported so
that is another disadvantage of this
one-to-one model now let us go to the
next model and see if that is better
than these two that we have discussed
till now so here we come to the last
model which is some many to many model
so here again from the name we can
understand that many user threads are
associated or mapped to many kernel
threads so from the diagram it is very
clear here we have the user threads and
here we have the kernel threads and
these user threads are associated with
this corner treads or their map to this
kernel threat so there is some
many-to-many relationship in this model
so let us see what are the advantages of
this model and if this is better than
the other two that we have discussed so
here as I told you in this model it
multiplexes many user level threats to a
smaller or equal number of kernel
threats so as we see here there is a
mapping between many user level threats
to a smaller or equal number of kernel
threats so here we have four user
threats and they may be mapped to four
or lesser number of kernel threats that
is what we mean by this and then the
number of kernel threats may be specific
to either a particular application or a
particular machine so as I told you
there is a limitation of the number of
threats that we can have in a system so
the number of kernel tress that we can
have in this model it may be specific to
a particular application or a particular
machine depending upon the number of
threats that they support and in this
one developers can create as many user
threats as necessary and the
corresponding kernel threads can run in
parallel on a multiprocessor so here as
we see the developers can create as many
number of user threats as they want and
they will be mapped to the corresponding
number of kernel threats and they can
run in parallel on a multiprocessor so
we have talked about how threads
function in a multiprocessor system so
we can clearly see that in this they can
run on a multiprocessor system because
we are having multiple kernel threads
and also when a thread performs a
blocking system call the kernel can
schedule another thread for execution
here we see that when a user thread
performs a blocking system call the
entire process will not be blocked the
remaining things can be scheduled for
execution when one user thread performs
a blocking system call so these were the
limitations that we had in DES many to
one model and one to one model so in
many to one model we saw that when a
blocking system call is performed the
entire process was blocked but that
problem is solved in many to many model
it was also solved in the one to one
model but in one to one model there were
other problems that we faced like each
user thread could be associated or map
to only one kernel thread but in this
one there is a many-to-many relationship
so in that way
so many too many model is better than
the one-to-one model so we see that this
many-to-many model it is having many
advantages and it is far better than the
many to one model and one-to-one model
so this is the model that is implemented
in most of the systems and this is the
best model that we can have in a
multi-threading system to establish the
relationship between the user thread and
kernel threads now we will discuss
another topic that is hyper threading
which is also known as simultaneous
multi-threading so we have been studying
about multi-threading and we saw how
multi-threading is much better than a
single threaded process we saw its
benefits and we also saw the models in
which the relationship between user
threads and kernel threads are
established in a multi-threading system
so what we mean by simultaneous
multi-threading is that we are having
more than one multi-threading going on
in the same system multi-threading means
multiple threads at the same time and
simultaneous multi-threading means many
of this multi-threading zs-- going on at
the same time so that is what
simultaneous multi-threading is and
hyper threading is the same thing it is
just the proprietary name given by Intel
so intercompany they call it hyper
threading so let us see what is the
advantage of hyper threading or
simultaneous multi-threading and how it
actually works what happens is that in a
hyper threaded system it allows their
processors cores resources to become
multiple logical processors for
performance so what we have is we are
having a micro processor that means we
are having a processor in our system
where all the processing is happening
and in our processors we are having
different cores right we have heard of
single core systems dual core system
quad core systems and so on what happens
is if it is a single core system that
means there is only one processor where
only one processing can take place at a
time that means only one thread can run
at a time and if we are having a dual
core processor that means in your
processor you are having two cores where
two processing can happen at the same
time that means it will support two
threads at the same time so in the same
way quad core means for coarse so four
units of processing that means four
threads can be supported at the same
time so physically depending upon the
number of course you have that
many number of threads it will support
at one time so in this hyper threading
or simultaneous multi-threading what
happens is that the physical cores of
your processors they are virtually or
logically divided into multiple
processors so if you are having one core
it may be logically divided into two
physically it is only one but logically
it may be divided into two so that two
threads may be supported at the same
time similarly if you are having a dual
core system then those two cores may be
logically divided into two each so you
will have a total of four cores where
four different threads can run and the
same time so that is what we mean by
simultaneous multi-threading or hyper
theory so what happens it enables the
processors to execute two threads or a
set of instructions at the same time
since hyper threading allows two streams
to be executed in parallel it is almost
like having two separate processors
working together so this is what I just
explained to you now let us see how can
we find out if your system that you are
using supports simultaneous
multi-threading or hyper threading and
let us see how we can find out if hyper
threading is running in our system
because it is always interesting to
practically see what is happening
instead of just learning the theory so
let us try to find out how this works so
here I just want to show you the
properties of the system that I am using
right now so here I am having a
processor which is of Intel Core i3 and
it belongs to the 2 3 7 0 M model so
this is the processor that I am having
in my system right now so in order to
find out whether my system is
hyper-threaded or not what you have to
do is you have to open your command
prompt so you open up your command
prompt and here you type WM IC so wmic
stands for windows management
instrumentation which is a management
infrastructure that provides you access
to control over a system so if you type
wmic it will open up the windows
management instrumentation console so if
you press ENTER you enter the command
line interface of W M I so here I will
show you the command which will help us
know how many cores are we having in our
system so here there is a command called
CPU
get number of course if you type this
command it will show you the number of
course that you have in your system that
means the number of course in your
processor so we know there are different
types of processors having different
cores and as I told you if you are
having multiple cores means it is a
multiprocessor system so here you see
that I am having two cores in my system
that means there are two threads that
can be supported at the same time so it
is just like having two processors now
we will find out how many logical
processors do I have now if the number
of logical processors is equal to the
number of physical cores that means
there is no hyper threading happening in
my system because I am just having that
many number of course as a physical
course that I have but if I am having
more number of logical cores as compared
to the physical course that we saw here
then that means hyper threading is
happening in our system so in order to
do that there is another command so let
us extend this command here we said get
number of course now we will also say
number of logical processors now if I
press ENTER here what do I see I see
that number of course is 2 which we saw
before and number of logical processors
is 4 so we see that physically we had
only 2 cores but they are divided into
two each and as a total I am having 4
number of logical processors so here we
clearly see that there is hyper
threading I am having four logical cores
that means I can run four threads at the
same time in my system so clearly my
system is hyper threaded so that is how
we can find out how many course we have
and also we can find out if our system
is hyper threaded or not so with that I
hope you understood the concept of hyper
threading so this topic may not be
present in your syllabus or in your
textbooks but this is something good to
know because this is the kind of
technology that we are using today so we
have seen the models of multi-threading
and we also saw hyper threading and how
it works in our system
thank you for watching and see you in
the next one
[Applause]
[Music]
5.0 / 5 (0 votes)