Concurrent Programing: Why you should care, deeply. Don Porter Portions courtesy Emmett Witchel

Similar documents
Processes. Criteria for Comparing Scheduling Algorithms

File Systems: Fundamentals

CS 5523: Operating Systems

Cyber-Physical Systems Scheduling

Final Review. Chenyang Lu. CSE 467S Embedded Compu5ng Systems

Last Time. Bit banged SPI I2C LIN Ethernet. u Embedded networks. Ø Characteristics Ø Requirements Ø Simple embedded LANs

Operating Systems. Chenyang Lu

Optimization Strategies

CS 2461: Computer Architecture I

VLSI Design I; A. Milenkovic 1

Maps, Hash Tables and Dictionaries

Maps and Hash Tables. EECS 2011 Prof. J. Elder - 1 -

Performance & Energy

Philips Lifeline. Ø Chenyang Lu 1

Adaptive QoS Control for Real-Time Systems

HPCG on Tianhe2. Yutong Lu 1,Chao Yang 2, Yunfei Du 1

CS 5523 Operating Systems: Synchronization in Distributed Systems

Wednesday, January 4, electronic components

Chapter Seven: Energy

TinyOS and nesc. Ø TinyOS: OS for wireless sensor networks. Ø nesc: programming language for TinyOS.

CSE 520S Real-Time Systems

Critiques. Ø Critique #1

Servilla: Service Provisioning in Wireless Sensor Networks. Chenyang Lu

VELA round suspended T5 direct/indirect

Batch binary Edwards. D. J. Bernstein University of Illinois at Chicago NSF ITR

CS 5523 Operating Systems: Intro to Distributed Systems

Outline. Your Project Proposal an evolving plan. Project Proposal Guidelines (2 files) ECE496 Design Project Preparing Your Project Proposal

Ø Project Description. Ø Design Criteria. Ø Design Overview. Ø Design Components. Ø Schedule. Ø Testing Criteria. Background Design Implementation

Choosing the Right Monitor for Your Application

Case5:08-cv PSG Document514 Filed08/21/13 Page1 of 18

Downloaded from: justpaste.it/vlxf

Case 5:18-cv Document 1 Filed 02/03/18 Page 1 of 27

Real-Time CORBA. Chenyang Lu CSE 520S

Liveness: The Readers / Writers Problem

ARKANSAS SECRETARY OF STATE. Rules on Vote Centers

From Meander Designs to a Routing Application Using a Shape Grammar to Cellular Automata Methodology

Frequency-dependent fading bad for narrowband signals. Spread the narrowband signal into a broadband signal. dp/df. (iii)

Case 1:17-cv Document 1 Filed 12/11/17 Page 1 of 17 IN THE UNITED STATES DISTRICT COURT FOR THE WESTERN DISTRICT OF TEXAS AUSTIN DIVISION

12 Economic alternatives as strategies

AME 514. Applications of Combustion

edelivery Agreement and Disclosure

Read the Directions sheets for step-by-step instructions.

Suggested Model Directions for Clinical Negligence cases before Master Ungley and Master Yoxall

Deadlock. deadlock analysis - primitive processes, parallel composition, avoidance

Systematic Policy and Forward Guidance

APPENDIX C M E M O R A N D U M FROM: Advance Authorization for Investigative, Expert or Other Services. Case Name & Designation.

A Bloom Filter Based Scalable Data Integrity Check Tool for Large-scale Dataset

Review: Background on Bits. PFTD: What is Computer Science? Scale and Bits: Binary Digits. BIT: Binary Digit. Understanding scale, what does it mean?

An Electronic Voting System for a Legislative Assembly

PLS 103 Lecture 3 1. Today we talk about the Missouri legislature. What we re doing in this section we

SMS based Voting System

Virtual Memory and Address Translation

The Impact of Military Technological Development on NATO Cooperation

Computer Power Management Rules. Ø Jim Kardach, re-red chief power architect, Intel h6p://

County of Collier CLERK OF THE CIRCUIT COURT COLLIER COUNTY COURTHOUSE

A Micro-Benchmark Evaluation of Catamount and Cray Linux Environment (CLE) Performance

PART 5 BUILDING REGULATIONS AND CODES CHAPTER 1 BUILDING CODES AND REGULATIONS CHAPTER 2 PLUMBING CODE

Installation Instructions HM2085-PLM Strain Gage Input Module

Paper No Entered: September 29, 2016 UNITED STATES PATENT AND TRADEMARK OFFICE

Introduction to Artificial Intelligence CSCE , Fall 2017 URL:

Kosovo Passport Europe s first Passport with certified SAC. Labinot Carreti, Head of Sales Europe / CIS / North Africa Montreal, 07th of October 2014

Luciano Nicastro

We should share our secrets

4th International Industrial Supercomputing Workshop Supercomputing for industry and SMEs in the Netherlands

Parliamentary Tools for the Convention Delegate

IBM Cognos Open Mic Cognos Analytics 11 Part nd June, IBM Corporation

UNITED STATES DISTRICT COURT CENTRAL DISTRICT OF CALIFORNIA CIVIL MINUTES GENERAL

IC Chapter 6. Dealer License Plates

Last Time. Embedded systems introduction

HENRIETTA HANKIN BRANCH OF THE CHESTER COUNTY LIBRARY MEETING ROOM USE POLICY

Product Description

EXPERIENCE MAXIMUM QUALITY

Political Economy of Structural Reform: reforms among resurgent populism

ARKANSAS SECRETARY OF STATE

Case3:10-cv JW Document81 Filed06/12/12 Page1 of 23 SAN FRANCISCO DIVISION

Post War America Chapter 27

Overview of the Design Process. Avoid Bad Design, Use UCD Evidence-based Design Hypothesis testing!

The problems with a paper based voting

ENGLISH SEMINAR OF INTELLECTUAL PROPERTY BY IP GRADUATE SCHOOL UNION. Patent Law. August 2, 2016

Awodele, 0.,1 Ajayi, 0.B.,2 and Ajayi, LA. 3

Computational Architecture. The Social Organization of Distributed Cognition. A foundational metaphor. Two Physical Symbol Systems?

Real-Time Wireless Control Networks for Cyber-Physical Systems

Digital research data in the Sigma2 prospective

NVM EXPRESS, INC. INTELLECTUAL PROPERTY POLICY. Approved as of _November 21_, 2015 ( Effective Date ) by the Board of Directors of NVM Express

The purchase of new voting equipment

LEGAL NOTICE REQUEST FOR BID SEALED BID For. Digital Forensic Computers. For ST. CHARLES COUNTY GOVERNMENT ST.

Case 1:18-cv TWP-MPB Document 1 Filed 01/04/18 Page 1 of 17 PageID #: 1

DevOps Course Content

Dynamic Opening Statements How to Establish Credibility and Persuade From the Beginning

A. To provide general standards for all signs within the Borough and specific standards for signs in various zoning districts;

Event Based Sequential Program Development: Application to Constructing a Pointer Program

Department of Mechanical Engineering

Efficient, Cost Effective and Sustainable Self-Delivery of Asphalt for Small Works

Voting Criteria April

Cadac SoundGrid I/O. User Guide

Real- Time Wireless Control Networks for Cyber- Physical Systems

Supreme Court of Florida

COMP 635: WIRELESS & MOBILE COMMUNICATIONS COURSE INTRODUCTION. Jasleen Kaur. Fall 2017

CITY OF ESCONDIDO. Planning Commission and Staff Seating AGENDA PLANNING COMMISSION. 201 North Broadway City Hall Council Chambers. 7:00 p.m.

Ensuring That Traffic Signs Are Visible at Night: Federal Regulations

Transcription:

Concurrent Programing: Why you should care, deeply Don Porter Portions courtesy Emmett Witchel 1

Uniprocessor Performance Not Scaling Performance (vs. VAX-11/780) 10000 1000 100 10 1 20% /year 52% /year 25% /year 1978 1980 1982 1984 1986 1988 1990 1992 1994 1996 1998 2000 2002 2004 2006 Graph by Dave Patterson 2

Power and heat lay waste to processor makers! Intel P4 (2000-2007) Ø 1.3GHz to 3.8GHz, 31 stage pipeline Ø Prescott in 02/04 was too hot. Needed 5.2GHz to beat 2.6GHz Athalon! Intel Pentium Core, (2006-) Ø 1.06GHz to 3GHz, 14 stage pipeline Ø Based on mobile (Pentium M) micro-architecture Power efficient! 2% of electricity in the U.S. feeds computers Ø Doubled in last 5 years 3

What about Moore s law?! Number of transistors double every 24 months Ø Not performance! 4

Architectural trends that favor multicore! Power is a first class design constraint Ø Performance per watt the important metric! Leakage power significant with small transisitors Ø Chip dissipates power even when idle!! Small transistors fail more frequently Ø Lower yield, or CPUs that fail?! Wires are slow Ø Light in vacuum can travel ~1m in 1 cycle at 3GHz Ø Motivates multicore designs (simpler, lower-power cores)! Quantum effects! Motivates multicore designs (simpler, lower-power cores) 5

Multicores are here, and coming fast! 4 cores in 2007 16 cores in 2009 80 cores in 20?? AMD Quad Core Sun Rock Intel TeraFLOP [AMD] quad-core processors are just the beginning. http://www.amd.com Intel has more than 15 multi-core related projects underway http://www.intel.com 6

Multicore programming will be in demand! Hardware manufacturers betting big on multicore! Software developers are needed! Writing concurrent programs is not easy! You will learn how to do it in this class 7

Concurrency Problem! Order of thread execution is non-deterministic Ø Multiprocessing A system may contain multiple processors è cooperating threads/processes can execute simultaneously Ø Multi-programming Thread/process execution can be interleaved because of timeslicing! Operations often consist of multiple, visible steps Ø Example: x = x + 1 is not a single operation read x from memory into a register increment register store register back to memory! Goal: Thread 2 read increment store Ø Ensure that your concurrent program works under ALL possible interleaving 8

Questions! Do the following either completely succeed or completely fail?! Writing an 8-bit byte to memory Ø A. Yes B. No! Creating a file Ø A. Yes B. No! Writing a 512-byte disk sector Ø A. Yes B. No 9

Sharing among threads increases performance int a = 1, b = 2; main() { } CreateThread(fn1, 4); CreateThread(fn2, 5); fn1(int arg1) { } if(a) b++; fn2(int arg1) { a = arg1; } What are the values of a & b at the end of execution? 10

Sharing among theads increases performance, but can lead to problems!! int a = 1, b = 2; main() { } CreateThread(fn1, 4); CreateThread(fn2, 5); fn1(int arg1) { } if(a) b++; fn2(int arg1) { a = 0; } What are the values of a & b at the end of execution? 11

Some More Examples! What are the possible values of x in these cases? Thread1: x = 1; Thread2: x = 2; Initially y = 10; Thread1: x = y + 1; Thread2: y = y * 2; Initially x = 0; Thread1: x = x + 1; Thread2: x = x + 2; 12

Critical Sections! A critical section is an abstraction Ø Consists of a number of consecutive program instructions Ø Usually, crit sec are mutually exclusive and can wait/signal Later, we will talk about atomicity and isolation! Critical sections are used frequently in an OS to protect data structures (e.g., queues, shared variables, lists, )! A critical section implementation must be: Ø Correct: the system behaves as if only 1 thread can execute in the critical section at any given time Ø Efficient: getting into and out of critical section must be fast. Critical sections should be as short as possible. Ø Concurrency control: a good implementation allows maximum concurrency while preserving correctness Ø Flexible: a good implementation must have as few restrictions as practically possible 13

The Need For Mutual Exclusion! Running multiple processes/threads in parallel increases performance! Some computer resources cannot be accessed by multiple threads at the same time Ø E.g., a printer can t print two documents at once! Mutual exclusion is the term to indicate that some resource can only be used by one thread at a time Ø Active thread excludes its peers! For shared memory architectures, data structures are often mutually exclusive Ø Two threads adding to a linked list can corrupt the list 14

Exclusion Problems, Real Life Example! Imagine multiple chefs in the same kitchen Ø Each chef follows a different recipe! Chef 1 Ø Grab butter, grab salt, do other stuff! Chef 2 Ø Grab salt, grab butter, do other stuff! What if Chef 1 grabs the butter and Chef 2 grabs the salt? Ø Yell at each other (not a computer science solution) Ø Chef 1 grabs salt from Chef 2 (preempt resource) Ø Chefs all grab ingredients in the same order Current best solution, but difficult as recipes get complex Ingredient like cheese might be sans refrigeration for a while 15

The Need To Wait! Very often, synchronization consists of one thread waiting for another to make a condition true Ø Master tells worker a request has arrived Ø Cleaning thread waits until all lanes are colored! Until condition is true, thread can sleep Ø Ties synchronization to scheduling! Mutual exclusion for data structure Ø Code can wait (await) Ø Another thread signals (notify) 16

Example 2: Traverse a singly- linked list! Suppose we want to find an element in a singly linked list, and move it to the head! Visual intuition: lhead lprev lptr 17

Example 2: Traverse a singly- linked list! Suppose we want to find an element in a singly linked list, and move it to the head! Visual intuition: lhead lprev lptr 18

Even more real life, linked lists lprev = NULL; for(lptr = lhead; lptr; lptr = lptr->next) { if(lptr->val == target){ // Already head?, break if(lprev == NULL) break; // Move cell to head lprev->next = lptr->next; lptr->next = lhead; lhead = lptr; break; } lprev = lptr; }! Where is the critical section? 19

Even more real life, linked lists // Move cell to head lprev->next = lptr->next; lptr->next = lhead lhead = lptr; lhead Thread 1 Thread 2 lprev elt lptr lprev->next = lptr->next; lptr->next = lhead; lhead = lptr; lhead lprev! A critical section often needs to be larger than it first appears Ø The 3 key lines are not enough of a critical section elt lptr 20

Even more real life, linked lists Thread 1 Thread 2 if(lptr->val == target){ elt = lptr; // Already head?, break if(lprev == NULL) break; // Move cell to head lprev->next = lptr->next; // lptr no longer in list for(lptr = lhead; lptr; lptr = lptr->next) { if(lptr->val == target){! Putting entire search in a critical section reduces concurrency, but it is safe. 21

Safety and Liveness! Safety property : nothing bad happens Ø holds in every finite execution prefix Windows never crashes a program never terminates with a wrong answer! Liveness property: something good eventually happens Ø no partial execution is irremediable Windows always reboots a program eventually terminates! Every property is a combination of a safety property and a liveness property - (Alpern and Schneider) 22

Safety and liveness for critical sections! At most k threads are concurrently in the critical section Ø A. Safety Ø B. Liveness Ø C. Both! A thread that wants to enter the critical section will eventually succeed Ø A. Safety Ø B. Liveness Ø C. Both! Bounded waiting: If a thread i is in entry section, then there is a bound on the number of times that other threads are allowed to enter the critical section (only 1 thread is alowed in at a time) before thread i s request is granted. Ø A. Safety B. Liveness C. Both 23