Multi Threading
Multi Threading
Multi Threading
[hide]This article has multiple issues. Please help improve it or discuss these issues o
Contents
[hide]
1 Overview
o 1.1 Advantages
o 1.2 Disadvantages
2 Types of multithreading
o 2.1 Block multi-threading
2.1.1 Concept
2.1.2 Terminology
2.1.3 Hardware cost
2.1.4 Examples
o 2.2 Interleaved multi-threading
2.2.1 Terminology
2.2.2 Hardware costs
o 2.3 Simultaneous multi-threading
2.3.1 Concept
2.3.2 Terminology
2.3.3 Hardware costs
2.3.4 Examples
3 Implementation specifics
4 See also
5 References
Overview[edit]
The multithreading paradigm has become more popular as efforts to further
exploit instruction level parallelism have stalled since the late 1990s. This allowed the
concept of throughput computing to re-emerge to prominence from the more
specialized field of transaction processing:
The two major techniques for throughput computing are multiprocessing and
multithreading.
Advantages[edit]
Some advantages include:
If a thread gets a lot of cache misses, the other thread(s) can continue, taking
advantage of the unused computing resources, which thus can lead to faster
overall execution, as these resources would have been idle if only a single
thread was executed.
If a thread cannot use all the computing resources of the CPU (because
instructions depend on each other's result), running another thread can avoid
leaving these idle.
If several threads work on the same set of data, they can actually share their
cache, leading to better cache usage or synchronization on its values.
Disadvantages[edit]
Multiple threads can interfere with each other when sharing hardware resources
such as caches or translation lookaside buffers (TLBs).
Execution times of a single thread are not improved but can be degraded, even
when only one thread is executing. This is due to slower frequencies and/or
additional pipeline stages that are necessary to accommodate thread-switching
hardware.
Hardware support for multithreading is more visible to software, thus requiring
more changes to both application programs and operating systems than
multiprocessing.
Types of multithreading[edit]
Block multi-threading[edit]
Concept[edit]
The simplest type of multi-threading occurs when one thread runs until it is blocked
by an event that normally would create a long latency stall. Such a stall might be a
cache-miss that has to access off-chip memory, which might take hundreds of CPU
cycles for the data to return. Instead of waiting for the stall to resolve, a threaded
processor would switch execution to another thread that was ready to run. Only when
the data for the previous thread had arrived, would the previous thread be placed back
on the list of ready-to-run threads.
For example:
In order to switch efficiently between active threads, each active thread needs to have
its own register set. For example, to quickly switch between two threads, the register
hardware needs to be instantiated twice.
Examples[edit]
Interleaved multi-threading[edit]
Main article: barrel processor
1. Cycle i+1: an instruction from thread B is issued
2. Cycle i+2: an instruction from thread C is issued
The purpose of interleaved multithreading is to remove all data dependency stalls
from the execution pipeline. Since one thread is relatively independent from other
threads, there's less chance of one instruction in one pipe stage needing an output from
an older instruction in the pipeline.
Conceptually, it is similar to pre-emptive multi-tasking used in operating systems.
One can make the analogy that the time-slice given to each active thread is one CPU
cycle.
Terminology[edit]
This type of multithreading was first called Barrel processing, in which the staves of a
barrel represent the pipeline stages and their executing threads. Interleaved or Preemptive or Fine-grained or time-sliced multithreading are more modern terminology.
Hardware costs[edit]