Multi-core Architectures. Dr. Yingwu Zhu

Similar documents
Multi-core Architectures. Dr. Yingwu Zhu

CSE 392/CS 378: High-performance Computing - Principles and Practice


COSC 6385 Computer Architecture. - Multi-Processors (IV) Simultaneous multi-threading and multi-core processors

COSC 6385 Computer Architecture. - Thread Level Parallelism (III)

CSC501 Operating Systems Principles. OS Structure

COSC 6385 Computer Architecture - Thread Level Parallelism (I)

A Thread is an independent stream of instructions that can be schedule to run as such by the OS. Think of a thread as a procedure that runs

Introducing Multi-core Computing / Hyperthreading

Multiple Issue and Static Scheduling. Multiple Issue. MSc Informatics Eng. Beyond Instruction-Level Parallelism

COSC 6385 Computer Architecture - Thread Level Parallelism (III)

Multiprocessors and Thread-Level Parallelism. Department of Electrical & Electronics Engineering, Amrita School of Engineering

WHY PARALLEL PROCESSING? (CE-401)

Simultaneous Multithreading on Pentium 4

Multi-threaded processors. Hung-Wei Tseng x Dean Tullsen

Advanced Processor Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Computer Systems Architecture

Serial. Parallel. CIT 668: System Architecture 2/14/2011. Topics. Serial and Parallel Computation. Parallel Computing

Advanced Processor Architecture

Lecture 26: Parallel Processing. Spring 2018 Jason Tang

THREAD LEVEL PARALLELISM

TDT Coarse-Grained Multithreading. Review on ILP. Multi-threaded execution. Contents. Fine-Grained Multithreading

Module 18: "TLP on Chip: HT/SMT and CMP" Lecture 39: "Simultaneous Multithreading and Chip-multiprocessing" TLP on Chip: HT/SMT and CMP SMT

Parallelism in Hardware

Lecture 26: Multiprocessing continued Computer Architecture and Systems Programming ( )

Hyperthreading Technology

Multithreading: Exploiting Thread-Level Parallelism within a Processor

Today. SMP architecture. SMP architecture. Lecture 26: Multiprocessing continued Computer Architecture and Systems Programming ( )

Multiprocessors. Flynn Taxonomy. Classifying Multiprocessors. why would you want a multiprocessor? more is better? Cache Cache Cache.

Computer Architecture: Multi-Core Processors: Why? Prof. Onur Mutlu Carnegie Mellon University

Multi-core Programming Evolution

Computer Systems Architecture

Superscalar Processors

Shared Symmetric Memory Systems

MULTIPROCESSORS AND THREAD-LEVEL. B649 Parallel Architectures and Programming

Multiprocessors and Locking

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 18 Multicore Computers

MULTIPROCESSORS AND THREAD-LEVEL PARALLELISM. B649 Parallel Architectures and Programming

Multicore Hardware and Parallelism

Multithreaded Processors. Department of Electrical Engineering Stanford University

Advanced d Processor Architecture. Computer Systems Laboratory Sungkyunkwan University

Motivation for Parallelism. Motivation for Parallelism. ILP Example: Loop Unrolling. Types of Parallelism

Non-uniform memory access machine or (NUMA) is a system where the memory access time to any region of memory is not the same for all processors.

EN164: Design of Computing Systems Topic 08: Parallel Processor Design (introduction)

Handout 3 Multiprocessor and thread level parallelism

Computer Architecture Spring 2016

Computer Architecture: Multi-Core Processors: Why? Onur Mutlu & Seth Copen Goldstein Carnegie Mellon University 9/11/13

Multiprocessors & Thread Level Parallelism

Computing architectures Part 2 TMA4280 Introduction to Supercomputing

Lect. 2: Types of Parallelism

ROEVER ENGINEERING COLLEGE DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Outline Marquette University

Twos Complement Signed Numbers. IT 3123 Hardware and Software Concepts. Reminder: Moore s Law. The Need for Speed. Parallelism.

Parallel Processing. Computer Architecture. Computer Architecture. Outline. Multiple Processor Organization

Comp. Org II, Spring

Parallel Architecture. Hwansoo Han

Processor Performance and Parallelism Y. K. Malaiya

INSTITUTO SUPERIOR TÉCNICO. Architectures for Embedded Computing

CS 654 Computer Architecture Summary. Peter Kemper

Parallel Processing & Multicore computers

COSC4201 Multiprocessors

Spring 2011 Parallel Computer Architecture Lecture 4: Multi-core. Prof. Onur Mutlu Carnegie Mellon University

Comp. Org II, Spring

Exam-2 Scope. 3. Shared memory architecture, distributed memory architecture, SMP, Distributed Shared Memory and Directory based coherence

CS420/520 Computer Architecture I

Modern Processor Architectures. L25: Modern Compiler Design

Computer and Information Sciences College / Computer Science Department CS 207 D. Computer Architecture. Lecture 9: Multiprocessors

CPI < 1? How? What if dynamic branch prediction is wrong? Multiple issue processors: Speculative Tomasulo Processor

Data/Thread Level Speculation (TLS) in the Stanford Hydra Chip Multiprocessor (CMP)

RISC Processors and Parallel Processing. Section and 3.3.6

CSC 252: Computer Organization Spring 2018: Lecture 26

Data/Thread Level Speculation (TLS) in the Stanford Hydra Chip Multiprocessor (CMP)

Chapter 07: Instruction Level Parallelism VLIW, Vector, Array and Multithreaded Processors. Lesson 06: Multithreaded Processors

Control Hazards. Branch Prediction

Multiprocessor Cache Coherence. Chapter 5. Memory System is Coherent If... From ILP to TLP. Enforcing Cache Coherence. Multiprocessor Types

ENGN1640: Design of Computing Systems Topic 06: Advanced Processor Design

Lecture Topics. Announcements. Today: Advanced Scheduling (Stallings, chapter ) Next: Deadlock (Stallings, chapter

COSC4201. Multiprocessors and Thread Level Parallelism. Prof. Mokhtar Aboelaze York University

CSE502 Graduate Computer Architecture. Lec 22 Goodbye to Computer Architecture and Review

Online Course Evaluation. What we will do in the last week?

Hyperthreading 3/25/2008. Hyperthreading. ftp://download.intel.com/technology/itj/2002/volume06issue01/art01_hyper/vol6iss1_art01.

EC 513 Computer Architecture

Chap. 4 Multiprocessors and Thread-Level Parallelism

Chapter 4 Threads, SMP, and

Objective. We will study software systems that permit applications programs to exploit the power of modern high-performance computers.

Lecture 9: MIMD Architectures

UNIT I (Two Marks Questions & Answers)

Multiprocessor Support

CPI IPC. 1 - One At Best 1 - One At best. Multiple issue processors: VLIW (Very Long Instruction Word) Speculative Tomasulo Processor

CS377P Programming for Performance Multicore Performance Multithreading

Parallel Processors. The dream of computer architects since 1950s: replicate processors to add performance vs. design a faster processor

Modern Processor Architectures (A compiler writer s perspective) L25: Modern Compiler Design

Chapter Seven. Idea: create powerful computers by connecting many smaller ones

Computer Architecture 计算机体系结构. Lecture 9. CMP and Multicore System 第九讲 片上多处理器与多核系统. Chao Li, PhD. 李超博士

Data/Thread Level Speculation (TLS) in the Stanford Hydra Chip Multiprocessor (CMP)

Limitations of parallel processing

Chapter 18 Parallel Processing

A Multiprocessor system generally means that more than one instruction stream is being executed in parallel.

Computer Architecture Crash course

CS425 Computer Systems Architecture

Transcription:

Multi-core Architectures Dr. Yingwu Zhu

Outline Parallel computing? Multi-core architectures Memory hierarchy Vs. SMT Cache coherence

What is parallel computing? Using multiple processors in parallel to solve problems more quickly than with a single processor

Examples of parallel computing A cluster computer that contains multiple PCs combined together with a high speed network A shared memory multiprocessor (SMP*) by connecting multiple processors to a single memory system A Chip Multi-Processor (CMP) contains multiple processors (called cores) on a single chip Concurrent execution comes from desire for performance!

Single-core computer

Single-core CPU chip the single core A register file is an array of processor registers in a central processing unit (CPU)

Multi-core architectures Replicate multiple processor cores on a single die Core 1 Core 2 Core 3 Core 4 Multi-core CPU chip

Multi-core CPU chip The cores fit on a single processor socket Also called CMP (Chip Multi-Processor) core core core core 1 2 3 4

The cores run in parallel thread 1 thread 2 thread 3 thread 4 core core core core 1 2 3 4

Within each core, threads are timesliced (like on a uniprocessor) Several threads Several threads Several threads Several threads core core core core 1 2 3 4

Interaction with OS OS perceives each core as a separate processor OS scheduler maps threads/processes to different cores Most major OS support multi-core today: Windows, Linux, Mac OS X,

Why multi-core? Difficult to make single-core clock frequencies even higher Deeply pipelined circuits: heat problems speed of light problems difficult design and verification large design teams necessary server farms need expensive air-conditioning Many new applications are multithreaded General trend in computer architecture (shift towards more parallelism)

Instruction-level parallelism Parallelism at the machine-instruction level The processor can re-order, pipeline instructions, split them into microinstructions, do aggressive branch prediction, etc. Instruction-level parallelism enabled rapid increases in processor speeds over the last 15 years

Thread-level parallelism (TLP) This is parallelism on a more coarser scale Server can serve each client in a separate thread (Web server, database server) A computer game can do AI, graphics, and physics in three separate threads Single-core superscalar processors cannot fully exploit TLP Multi-core architectures are the next step in processor evolution: explicitly exploiting TLP

General context: multiprocessors Multiprocessor is any computer with several processors SIMD Single instruction, multiple data Modern graphics cards MIMD Multiple instructions, multiple data Lemieux cluster, Pittsburgh supercomputing center

SIMD vs. MIMD MIMD = Multiple Instruction, Multiple Data traditional parallel processing N processors all doing their own thing SIMD = Singe Instruction, Multiple Data All processors do exactly the same thing Simple hardware

Multiprocessor memory types Shared memory: In this model, there is one (large) common shared memory for all processors Distributed memory: In this model, each processor has its own (small) local memory, and its content is not replicated anywhere else

Multi-core processor is a special kind of a multiprocessor: All processors are on the same chip Multi-core processors are MIMD: Different cores execute different threads (Multiple Instructions), operating on different parts of memory (Multiple Data). Multi-core is a shared memory multiprocessor: All cores share the same memory

What applications benefit from multi-core? Database servers Web servers (Web commerce) Compilers Multimedia applications Scientific applications, CAD/CAM In general, applications with Thread-level parallelism (as opposed to instruction-level parallelism) Each can run on its own core

More examples Editing a photo while recording a TV show through a digital video recorder Downloading software while running an antivirus program Anything that can be threaded today will map efficiently to multi-core BUT: some applications difficult to parallelize 20

Single superscalar core Equipped with SMT Simultaneous MultiThreading

Bus L2 Cache and Control Simultaneous multithreading: complementary to multi-cores Problem addressed: The processor pipeline can get stalled: Waiting for the result of a long floating point (or integer) operation Waiting for data to arrive from memory Other execution units wait unused! Integer BTB L1 D-Cache D-TLB Schedulers Uop queues Rename/Alloc Trace Cache Decoder BTB and I-TLB Floating Point Source: Intel ucode ROM

Simultaneous multithreading (SMT) Permits multiple independent threads to execute SIMULTANEOUSLY on the SAME core Weaving together multiple threads on the same core Example: if one thread is waiting for a floating point operation to complete, another thread can use the integer units

Bus L2 Cache and Control Without SMT, only a single thread can run at any given time L1 D-Cache D-TLB Integer Floating Point BTB Schedulers Uop queues Rename/Alloc Trace Cache Decoder ucode ROM BTB and I-TLB Thread 1: floating point

Bus L2 Cache and Control Without SMT, only a single thread can run at any given time L1 D-Cache D-TLB Integer Floating Point BTB Schedulers Uop queues Rename/Alloc Trace Cache Decoder ucode ROM BTB and I-TLB Thread 2: integer operation

Bus L2 Cache and Control SMT processor: both threads can run concurrently L1 D-Cache D-TLB Integer Floating Point BTB Schedulers Uop queues Rename/Alloc Trace Cache Decoder ucode ROM BTB and I-TLB Thread 2: integer operation Thread 1: floating point

Bus L2 Cache and Control But: Can t simultaneously use the same functional unit L1 D-Cache D-TLB Integer Floating Point BTB Schedulers Uop queues Rename/Alloc Trace Cache ucode ROM Decoder BTB and I-TLB Thread 1 Thread 2 IMPOSSIBLE This scenario is impossible with SMT on a single core (assuming a single integer unit)

SMT not a true parallel processor Enables better threading (e.g. up to 30%) OS and applications perceive each simultaneous thread as a separate virtual processor The chip has only a single copy of each resource Compare to multi-core: each core has its own copy of resources

Bus Bus L2 Cache and Control L2 Cache and Control Multi-core: threads can run on separate cores L1 D-Cache D-TLB L1 D-Cache D-TLB Integer Floating Point Integer Floating Point Schedulers Schedulers Uop queues Uop queues Rename/Alloc Rename/Alloc BTB Trace Cache Decoder ucode ROM BTB Trace Cache Decoder ucode ROM BTB and I-TLB BTB and I-TLB Thread 1 Thread 2

Bus Bus L2 Cache and Control L2 Cache and Control Multi-core: threads can run on separate cores L1 D-Cache D-TLB L1 D-Cache D-TLB Integer Floating Point Integer Floating Point Schedulers Schedulers Uop queues Uop queues Rename/Alloc Rename/Alloc BTB Trace Cache Decoder ucode ROM BTB Trace Cache Decoder ucode ROM BTB and I-TLB BTB and I-TLB Thread 3 Thread 4

Combining Multi-core and SMT Cores can be SMT-enabled (or not) The different combinations: Single-core, non-smt: standard uniprocessor Single-core, with SMT Multi-core, non-smt Multi-core, with SMT The number of SMT threads: 2, 4, or sometimes 8 simultaneous threads Intel calls them hyper-threads

Bus Bus L2 Cache and Control L2 Cache and Control SMT Dual-core: all four threads can run concurrently L1 D-Cache D-TLB L1 D-Cache D-TLB Integer Floating Point Integer Floating Point Schedulers Schedulers Uop queues Uop queues Rename/Alloc Rename/Alloc BTB Trace Cache Decoder ucode ROM BTB Trace Cache Decoder ucode ROM BTB and I-TLB BTB and I-TLB Thread 1 Thread 3 Thread 2 Thread 4

Comparison: multi-core vs SMT Advantages/disadvantages?

Comparison: multi-core vs SMT Multi-core: Since there are several cores, each is smaller and not as powerful (but also easier to design and manufacture) However, great with thread-level parallelism SMT Can have one large and fast superscalar core Great performance on a single thread Mostly still only exploits instruction-level parallelism

The memory hierarchy If simultaneous multithreading only: all s shared Multi-core chips: L1 s private L2 s private in some architectures and shared in others Memory is always shared

C O R E 1 C O R E 0 Fish machines Dual-core Intel Xeon processors hyper-threads Each core is hyper-threaded Private L1 s Shared L2 s L1 L2 memory L1

C O R E 1 C O R E 0 C O R E 1 C O R E 0 Designs with private L2 s L1 L1 L1 L1 L2 L2 L2 L2 memory L3 memory L3 Both L1 and L2 are private Examples: AMD Opteron, AMD Athlon, Intel Pentium D A design with L3 s Example: Intel Itanium 2

Private vs shared s? Advantages/disadvantages?

Private vs shared s Advantages of private: They are closer to core, so faster access Reduces contention Advantages of shared: Threads on different cores can share the same data More space available if a single (or a few) high-performance thread runs on the system

The coherence problem Since we have private s: How to keep the data consistent across s? Each core should perceive the memory as a monolithic array, shared by all the cores

The coherence problem Suppose variable x initially contains 15213 Core 1 Core 2 Core 3 Core 4 multi-core chip Main memory x=15213

The coherence problem Core 1 reads x Core 1 Core 2 Core 3 Core 4 x=15213 multi-core chip Main memory x=15213

The coherence problem Core 2 reads x Core 1 Core 2 Core 3 Core 4 x=15213 x=15213 multi-core chip Main memory x=15213

The coherence problem Core 1 writes to x, setting it to 21660 Core 1 Core 2 Core 3 Core 4 x=21660 x=15213 multi-core chip Main memory x=21660 assuming write-through s

The coherence problem Core 2 attempts to read x gets a stale copy Core 1 Core 2 Core 3 Core 4 x=21660 x=15213 multi-core chip Main memory x=21660

Solutions for coherence This is a general problem with multiprocessors, not limited just to multi-core There exist many solution algorithms, coherence protocols, etc. A simple solution: invalidation-based protocol with snooping

Inter-core bus Core 1 Core 2 Core 3 Core 4 multi-core chip Main memory inter-core bus

Invalidation protocol with snooping Invalidation: If a core writes to a data item, all other copies of this data item in other s are invalidated Snooping: All cores continuously snoop (monitor) the bus connecting the cores. Snooping is the process where the individual s monitor address lines for accesses to memory locations that they have d. When a write operation is observed to a location that a has a copy of, the controller invalidates its own copy of the snooped memory location.

The coherence problem Revisited: Cores 1 and 2 have both read x Core 1 Core 2 Core 3 Core 4 x=15213 x=15213 multi-core chip Main memory x=15213

The coherence problem Core 1 writes to x, setting it to 21660 Core 1 Core 2 Core 3 Core 4 x=21660 x=15213 sends invalidation request Main memory x=21660 INVALIDATED assuming write-through s multi-core chip inter-core bus

The coherence problem After invalidation: Core 1 Core 2 Core 3 Core 4 x=21660 multi-core chip Main memory x=21660

The coherence problem Core 2 reads x. Cache misses, and loads the new copy. Core 1 Core 2 Core 3 Core 4 x=21660 x=21660 multi-core chip Main memory x=21660

Alternative to invalidate protocol: update Core 1 writes x=21660: protocol Core 1 Core 2 Core 3 Core 4 x=21660 x=21660 UPDATED broadcasts updated value Main memory x=21660 assuming write-through s multi-core chip inter-core bus

Which do you think is better? Invalidation or update?

Invalidation vs update Multiple writes to the same location invalidation: only the first time update: must broadcast each write (which includes new variable value) Invalidation generally performs better: it generates less bus traffic

Programming for multi-core Programmers must use threads or processes Spread the workload across multiple cores Write parallel algorithms OS will map threads/processes to cores

Thread safety very important Pre-emptive context switching: context switch can happen AT ANY TIME True concurrency, not just uniprocessor timeslicing Concurrency bugs exposed much faster with multi-core

However: Need to use synchronization even if only time-slicing on a uniprocessor int counter=0; void thread1() { int temp1=counter; counter = temp1 + 1; } void thread2() { int temp2=counter; counter = temp2 + 1; }

Need to use synchronization even if only timeslicing on a uniprocessor temp1=counter; counter = temp1 + 1; temp2=counter; counter = temp2 + 1 gives counter=2 temp1=counter; temp2=counter; counter = temp1 + 1; counter = temp2 + 1 gives counter=1

Assigning threads to the cores Each thread/process has an affinity mask Affinity mask specifies what cores the thread is allowed to run on Different threads can have different masks Affinities are inherited across fork()

Affinity masks are bit vectors Example: 4-way multi-core, without SMT 1 1 0 1 core 3 core 2 core 1 core 0 Process/thread is allowed to run on cores 0,2,3, but not on core 1

Affinity masks when multi-core and SMT combined Separate bits for each simultaneous thread Example: 4-way multi-core, 2 threads per core 1 1 0 0 1 0 1 1 core 3 core 2 core 1 core 0 thread 1 thread 0 thread 1 thread 0 thread 1 thread 0 thread 1 thread 0 Core 2 can t run the process Core 1 can only use one simultaneous thread

Default Affinities Default affinity mask is all 1s: all threads can run on all processors Then, the OS scheduler decides what threads run on what core OS scheduler detects skewed workloads, migrating threads to less busy processors

Process migration is costly Need to restart the execution pipeline Cached data is invalidated OS scheduler tries to avoid migration as much as possible: it tends to keeps a thread on the same core This is called soft affinity

Hard affinities The programmer can prescribe her own affinities (hard affinities) Rule of thumb: use the default scheduler unless a good reason not to

When to set your own affinities Two (or more) threads share data-structures in memory map to same core so that can share Real-time threads: Example: a thread running a robot controller: - must not be context switched, or else robot can go unstable - dedicate an entire core just to this thread Source: Sensable.com

Kernel scheduler API #include <sched.h> int sched_getaffinity(pid_t pid, unsigned int len, unsigned long * mask); Retrieves the current affinity mask of process pid and stores it into space pointed to by mask. len is the system word size: sizeof(unsigned int long)

Kernel scheduler API #include <sched.h> int sched_setaffinity(pid_t pid, unsigned int len, unsigned long * mask); Sets the current affinity mask of process pid to *mask len is the system word size: sizeof(unsigned int long) To query affinity of a running process: $ taskset -p 3935 pid 3935's current affinity mask: f

Windows Task Manager core 2 core 1

Legal licensing issues Will software vendors charge a separate license per each core or only a single license per chip? Microsoft, Red Hat Linux, Suse Linux will license their OS per chip, not per core

Conclusions Multi-core chips an important new trend in computer architecture Several new multi-core chips in design phases Parallel programming techniques likely to gain importance

Acknowledgement Some slides are adapted from Jernej Barbic