Carnegie Mellon 15-213/18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) 1998 - 2010. All Rights Reserved. All work contained herein is copyrighted and used by permission of the authors. Contact [email protected]for permission or for more information. 27 th (and last) Lecture, 29 April 2010 Multi-Core Architectures
34
Embed
Carnegie Mellon 15-213/18-243: Introduction to Computer Systems Instructors: Bill Nace and Gregory Kesden (c) 1998 - 2010. All Rights Reserved. All work.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Carnegie Mellon
15-213/18-243: Introduction to Computer Systems
Instructors: Bill Nace and Gregory Kesden
(c) 1998 - 2010. All Rights Reserved. All work contained herein is copyrighted and used by permission of the authors. Contact [email protected] for permission or for more information.
27th (and last) Lecture, 29 April 2010
Multi-Core Architectures
Carnegie Mellon
Today Thread safety Multi-core Parallelism on multi-core
Carnegie Mellon
Crucial concept: Thread Safety Functions called from a thread (without external
synchronization) must be thread-safe Meaning: it must always produce correct results when called repeatedly
from multiple concurrent threads
Some examples of thread-unsafe activities: Failing to protect shared variables Relying on persistent state across invocations Returning a pointer to a static variable Calling a thread-unsafe functions
Carnegie Mellon
Thread-Unsafe Functions (Class 1) Failing to protect shared variables
Fix: Use P and V semaphore operations Example: goodcnt.c Issue: Synchronization operations will slow down code
e.g., badcnt requires 0.5s, goodcnt requires 7.9s
Carnegie Mellon
Thread-Unsafe Functions (Class 2) Relying on persistent state across multiple function invocations
Example: Random number generator (RNG) that relies on static state
/* rand: return pseudo-random integer on 0..32767 */ static unsigned int next = 1; int rand(void) { next = next*1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } /* srand: set seed for rand() */ void srand(unsigned int seed) { next = seed; }
/* rand: return pseudo-random integer on 0..32767 */ static unsigned int next = 1; int rand(void) { next = next*1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } /* srand: set seed for rand() */ void srand(unsigned int seed) { next = seed; }
Carnegie Mellon
Making Thread-Safe RNG Pass state as part of argument
and, thereby, eliminate static state
Consequence: programmer using rand_r must maintain seed
Threads Summary Threads provide another mechanism for writing
concurrent programs Threads are growing in popularity
Somewhat cheaper than processes Easy to share data between threads
However, the ease of sharing has a cost: Easy to introduce subtle synchronization errors
Which are very, very, very, very, very difficult to discover Tread carefully with threads!
For more info: D. Butenhof, “Programming with Posix Threads”, Addison-Wesley, 1997
Carnegie Mellon
Today Thread safety Multi-core Parallelism on multi-core
Carnegie Mellon
Why Multi-Core? Traditionally, single core performance is improved
by increasing the clock frequency... ...and making deeply pipelined circuits... Which leads to...
Heat problems Speed of light problems Difficult design and verification Large design teams Big fans, heat sinks Expensive air-conditioning on server farms
Increasing clock frequency no longer the way to go forward
Carnegie Mellon
Single Core Computer
mainmemory
I/O bridge
Bus Interface
ALU
register file
CPU chip
system bus memory bus
disk controller
graphicsadapter
USBcontroller
mouse keyboard monitordisk
I/O bus
Expansion slots
networkadapter
network
Carnegie Mellon
Single Core CPU Chip
Bus Interface
ALU
register file
CPU chipThe single core
system bus
Carnegie Mellon
Multi-Core Architecture Somewhat recent trend in computer architecture Replicate many cores on a single die
ALU
register file
ALU
register file
ALU
register file
Core 1
Bus Interface
Core 2 Core n
Multi-core Chip
Carnegie Mellon
Within each core, threads are time-sliced (just like on a uniprocessor)
Carnegie Mellon
Interaction With the Operating System
OS perceives each core as a separate processor OS scheduler maps threads/processes to different
cores Most major OS support multi-core today:
Mac OS X, Linux, Windows, …
Carnegie Mellon
Today Thread safety Multi-core Parallelism on multi-core
Carnegie Mellon
Instruction-Level Parallelism Parallelism at the machine-instruction level Achieved in the processor with