Introduction to Threads, Multi and Hyperthreads PDF

Summary

This document provides an introduction to threads, multithreading, and hyperthreading. It explains the concepts of threads, thread IDs, program counters, register sets, and stacks. It also describes different threading models like many-to-one, one-to-one, and many-to-many.

Full Transcript

Introduction to Threads, Multi and Hyperthreads Threading the needle to Operation. Threads A thread is a fundamental unit of CPU Utilization It comprises of Thread ID, Program Counter, Register Set and Stack Thread ID - used by the operating...

Introduction to Threads, Multi and Hyperthreads Threading the needle to Operation. Threads A thread is a fundamental unit of CPU Utilization It comprises of Thread ID, Program Counter, Register Set and Stack Thread ID - used by the operating system to identify processes and threads. The thread id is unique globally but the users can capture the thread handle of the process thread through this id. Program Counter - a special register in a computer processor that contains the memory address (location) of the next program instruction to be executed. Before the CPU fetches an instruction from memory, it references the program counter for the correct memory address. Register Set - temporary storage of intermediate data values. Stack - a data structure used by processors in operating systems to manage the execution of programs. The stack is typically implemented in the memory of the processor and is used to store data and return addresses during program execution. Threads Single Threaded Process Multi-Threaded Process Code Data Files Code Data Files Register Stack Register Registers Registers Stack Stack Stack Threads -> Threads single sequence stream within a process. Threads are also called lightweight processes as they possess some of the properties of processes. Every operating system needs Threads. ❑ Threads run in parallel improving the application performance. ❑ Threads can share common data so they do not need to use inter-process communication. Like the processes, threads also have states like ready, executing, blocked, etc. ❑ Priority can be assigned to the threads just like the process, and the highest priority thread is scheduled first. ❑ Each thread has its own Thread Control Block (TCB). Like the process, a context switch occurs for the thread, and register contents are saved in (TCB). Thread Control Block Thread Control Blocks (TCBs) represents threads generated in the system. It contains information about the threads, such as it’s ID and states. Thread ID: It is a unique identifier assigned by the Operating System to the thread when it is being created. It is similar to Process Control Thread states: These are the states of the thread which Block changes as the thread progresses through the system CPU information: It includes everything that the OS needs to know about, such as how far the thread has progressed and what data is being used. Thread Priority: It indicates the weight (or priority) of the thread over other threads which helps the thread scheduler to determine which thread should be selected next from the READY queue. Multithreading and Hyperthreading Many to One User Thread Supported and manage directly by One to One the Operating System USER KERNEL Supported by the user and managed w/out Many to Many kernel support Kernel Thread Models Many to One Model Pros: Maps Many user-level threads to one kernel Thread management is done by the thread K library in user space. Is very efficient Cons: Entire process will be block if a thread makes a blocking system call Due to only 1 thread can access the kernel Kernel User at a time, the multiple threads are unable to run in parallel on the multiprocessor Thread Thread One to One Model Pros: K Maps each user thread to a kernel thread Provides more concurrency than the many-to one K model by allowing another thread to run when a thread makes a blocking system K Also allows multiple thread to run in parallel on multiprocessors K Cons: Creating a user thread requires creating the corresponding kernel thread. Kernel User This can burden the performance on the app and will restrict the number of threads Thread Thread supported in the system. Many to Many Model Pros: K Multiplexes many user-lvl threads to a smaller or equal number of kernel threads. K The number of kernel threads may be specific to either an application or a machine. K Developers can create as many user threads as necessary and can run in parallel on a multiprocessor. K When a thread performs a blocking system call, the kernel can schedule another thread for Kernel User execution. Thread Thread Types of Threads in Operating System User Level Thread Kernel Level Thread a type of thread that is not created using a type of thread that can recognize the system calls. The kernel has no work in the Operating system easily. Kernel Level management of user-level threads. User-level Threads has its own thread table where it threads can be easily implemented by the user. keeps track of the system. The operating System Kernel helps in managing threads. Types of Threads in Operating System User Level Thread Pros: Implementation of the User-Level Thread is easier than Kernel Level Thread. a type of thread that is not created Context Switch Time is less in User Level Thread. using system calls. The kernel has User-Level Thread is more efficient than Kernel-Level no work in the management of Thread. Because of the presence of only Program Counter, Register user-level threads. User-level Set, and Stack Space, it has a simple representation. threads can be easily implemented by the user. Cons: There is a lack of coordination between Thread and Kernel. In case of a page fault, the whole process can be blocked. Types of Threads in Operating System Kernel Level Thread Pros: It has up-to-date information on all threads. Applications that block frequency are to be handled by the a type of thread that can recognize Kernel-Level Threads. the Operating system easily. Kernel Whenever any process requires more time to process, Level Threads has its own thread Kernel-Level Thread provides more time to it. table where it keeps track of the system. The operating System Cons: Kernel helps in managing threads. Kernel-Level Thread is slower than User-Level Thread. Implementation of this type of thread is a little more complex than a user-level thread. What is Hyper-Threading? Before, there was only a single CPU system. Later on, the system improves and the CPU contains the cores. Like dual-core CPU, 4-Core CPU, 8-Core CPU, and so on. What is Hyper-Threading? Core means these are logical CPUs. To again improve the system, Hyper-Threading technology is used What is Hyper-Threading? Hyper-Threading is a technology developed by Intel that allows a single physical processor to act like two separate processors. What is Hyper-Threading? This helps the computer run multiple tasks more efficiently. When Hyper-Threading is enabled, the processor can handle two sets of instructions at the same time, making the computer faster and more responsive, especially when running multiple applications or complex programs. What is Multithreading? Multithreading is a method where a big task is divided into smaller parts called threads, which can be worked on at the same time by different CPU cores. What is Multithreading? This makes processing faster and more efficient. It’s like having multiple people work on different parts of a project at the same time, instead of one person doing everything alone. Difference between Overall, Hyper-Threading improves the performance of multi-threaded applications on systems in modern computers via concurrent execution. What is Hyper-Threading? Cores vs. Threads Cores Workers Workers 10101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 Workers Workers 010101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 Threads Physical vs. Logical Cores Physical Workers Workers Cores Workers Workers Physical vs. Logical Cores 10101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 010101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 Logical Cores Also known as “Threads” Cores vs. Threads 1 2 1 2 10101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 4 3 010101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 4 3 (4 Physical Cores) X (1 Thread/Core) = 4 Logical Cores 010101010101010101010101010101010101010101010101010101 10101010101010101010101010101010101010101010101010101 Cores vs. Threads 6 5 1 2 1 10101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 2 4 010101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 3 4 3 7 8 (4 Physical Cores) X (2 Thread/Core) = 8 Logical Cores 01010101010101010101010101010101010101010101010101010 10101010101010101010101010101010101010101010101010101 01010101010101010101010101010101010101010101010101010 01010101010101010101010101010101010101010101010101010 ACTIVITY 10101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 010101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 010101010101010101010101010101010101010101010101010101010101010101010101010101010100100101111 01010101010101010101010101010101010101010101010101010101010101010101010101010101010010010111 (4 Physical Cores) X (4 Thread/Core) = 16 Logical cores Hyperthreading Simultaneous Multithreading (SMT) Hyperthreaded system allows their processor core’s resources to become multiple logical processors for performance Hyperthreading Parellel Operations Core to core operations a method in computing of running two or more processors, or CPUs, to handle separate parts of an overall task. Breaking up different parts of a task among multiple processors helps reduce the amount of time it takes to run a program. Hyperthreading Process Concurrent Operations Core to Thread, Operate by switching Execution time two or more operations performed at the same time (or within a give interval) the ability of an operating system to execute multiple tasks simultaneously or in an overlapping manner. It is a key feature of modern operating systems that enables efficient use of system resources, responsiveness, scalability, and parallelism. Hyperthreading Enables the processor to execute two threads or 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. Hyperthreading How to check your PC for hyperthreading: Goto CMD > type wmic in the CMD this will appear Wmic – Windows Management Instrumentation Command type in CPU Get NumberOfCores then you’ll know the quantity of cores in your PC, Hyperthreading if you want to know the quantity logical Processors in your PC, simply type: CPU Get NumberOfCores, NumberOfLogicalProcessors Hyperthreading There are many wmic commands to try, Type in the ff. for the full info on your pc wmic cpu list brief wmic cpu list full wmic bios list full wmic memorychip list full wmic diskdrive list full wmic baseboard list full wmic path win32_videocontroller wmic os list full /? Thanks Thank you for Listening to my discussion Instructions for use If you have a free account, in order to use this template, you must credit Slidesgo in your final presentation. Please refer to the next slide to read the instructions for premium users. As a Free user, you are allowed to: - Modify this template. - Use it for both personal and commercial projects. You are not allowed to: - Sublicense, sell or rent any of Slidesgo Content (or a modified version of Slidesgo Content). - Distribute Slidesgo Content unless it has been expressly authorized by Slidesgo. - Include Slidesgo Content in an online or offline database or file. - Offer Slidesgo templates (or modified versions of Slidesgo templates) for download. - Acquire the copyright of Slidesgo Content. For more information about editing slides, please read our FAQs or visit our blog: https://slidesgo.com/faqs and https://slidesgo.com/slidesgo-school Instructions for use (premium users) As a Premium user, you can use this template without attributing Slidesgo. You are allowed to: Modify this template. Use it for both personal and commercial purposes. Share this template in an editable format with people who are not part of your team. You are not allowed to: Sublicense, sell or rent this Slidesgo Template (or a modified version of this Slidesgo Template). Distribute this Slidesgo Template (or a modified version of this Slidesgo Template) or include it in a database or in any other product or service that offers downloadable images, icons or presentations that may be subject to distribution or resale. Use any of the elements that are part of this Slidesgo Template in an isolated and separated way from this Template. Register any of the elements that are part of this template as a trademark or logo, or register it as a work in an intellectual property registry or similar. For more information about editing slides, please read our FAQs or visit our blog: https://slidesgo.com/faqs and https://slidesgo.com/slidesgo-school Infographics You can add and edit some infographics to your presentation to present your data in a visual way. Choose your favourite infographic and insert it in your presentation using Ctrl C + Ctrl V or Cmd C + Cmd V in Mac. Select one of the parts and ungroup it by right-clicking and choosing “Ungroup”. Change the color by clicking on the paint bucket. Then resize the element by clicking and dragging one of the square-shaped points of its bounding box (the cursor should look like a double-headed arrow). Remember to hold Shift while dragging to keep the proportions. Group the elements again by selecting them, right-clicking and choosing “Group”. Repeat the steps above with the other parts and when you’re done editing, copy the end result and paste it into your presentation. Remember to choose the “Keep source formatting” option so that it keeps the design. For more info, please visit our blog.

Use Quizgecko on...
Browser
Browser