Linux Kernel Development Chapter 8. Kernel Synchronization Introduction Geum-Seo Koo 2007. 04. 27 - Fri. Operating System Lab.

Slides:



Advertisements
Similar presentations
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
Advertisements

Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Mutual Exclusion.
Bilgisayar Mühendisliği Bölümü GYTE - Bilgisayar Mühendisliği Bölümü Multithreading the SunOS Kernel J. R. Eykholt, S. R. Kleiman, S. Barton, R. Faulkner,
IT Systems Multiprocessor System EN230-1 Justin Champion C208 –
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Computer Systems/Operating Systems - Class 8
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Multithreading The objectives of this chapter are:
Review: Process Management Objective: –Enable fair multi-user, multiprocess computing on limited physical resources –Security and efficiency Process: running.
CS533 Concepts of Operating Systems Class 4 Linux Kernel Locking Issues.
CS510 Concurrent Systems Class 1
Chapter 11 Operating Systems
1 Concurrency: Deadlock and Starvation Chapter 6.
CS533 - Concepts of Operating Systems 1 CS533 Concepts of Operating Systems Class 8 Synchronization on Multiprocessors.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
1 Thread II Slides courtesy of Dr. Nilanjan Banerjee.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
OPERATING SYSTEMS CPU SCHEDULING.  Introduction to CPU scheduling Introduction to CPU scheduling  Dispatcher Dispatcher  Terms used in CPU scheduling.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Solution to Dining Philosophers. Each philosopher I invokes the operations pickup() and putdown() in the following sequence: dp.pickup(i) EAT dp.putdown(i)
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Development of a Resource Locking Algorithm for a Kernel Debugging User-space API Library TJHSST Computer Systems Lab Timothy Wismer.
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Operating Systems CSE 411 Multi-processor Operating Systems Multi-processor Operating Systems Dec Lecture 30 Instructor: Bhuvan Urgaonkar.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Kernel Locking Techniques by Robert Love presented by Scott Price.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Concurrency & Dynamic Programming.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Multithreading The objectives of this chapter are: To understand the purpose of multithreading To describe Java's multithreading mechanism.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Unit 4: Processes, Threads & Deadlocks June 2012 Kaplan University 1.
Implementing Lock. From the Previous Lecture  The “too much milk” example shows that writing concurrent programs directly with load and store instructions.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Pitfalls: Time Dependent Behaviors CS433 Spring 2001 Laxmikant Kale.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Kernel Synchronization David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
Multithreading / Concurrency
Background on the need for Synchronization
G.Anuradha Reference: William Stallings
Threads, SMP, and Microkernels
COT 5611 Operating Systems Design Principles Spring 2014
COP 4600 Operating Systems Fall 2010
Chapter 2: The Linux System Part 3
Jonathan Walpole Computer Science Portland State University
Background and Motivation
Coordination Lecture 5.
Implementing Mutual Exclusion
Kernel Synchronization I
Implementing Mutual Exclusion
Kernel Synchronization II
CS333 Intro to Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Presentation transcript:

Linux Kernel Development Chapter 8. Kernel Synchronization Introduction Geum-Seo Koo Fri. Operating System Lab.

ClCu03 2 Introduction In a shared memory application Shared source are protected from concurrent access Because if multiple threads of execution access and manipulate the data Properly protecting shared resources can be tough Multiprocessing support implies that Kernel code can simultaneously run on two or more processors This chapter discusses The issues of concurrency and synchronization, as they exist in an operating system kernel

ClCu03 3 Critical Regions and Race Conditions Critical Regions Code paths that access and manipulate shared data Usually unsafe for multiple threads of execution to access the same resource simultaneously Race Condition(bug) If it is possible for two threads of execution to be simultaneously in the same critical region Synchronization Ensuring that unsafe concurrency is prevented and that race conditions do not occur

ClCu03 4 Why do we need protection? An ATM(Automated Teller Machine) int total = get_total_from_account(); /* total funds in account */ int withdrawal = get_withdrawal_amount(); /* amount user asked to withdrawal */ /* check whether the user has enough funds in her account */ if (total <withdrawal) error(“You do not have that much money!”) /* the user has enough money: deduct the withdrawal amount from her total */ total -= withdrawal; update_total_funds(total); spit_out_money(withdrawal); /* give the user their money */ P1 LOAD total(105)... SUB withdrawal(100)... STORE total(5) P2 LOAD total(105)... SUB withdrawal(10)... STORE total(95) Never happen total: 105

ClCu03 5 A specific computing example: i++; Thread 2 - get i(8) increment i(8->9) write back i(9) The Single Variable Thread 1 get i (7) increment i(7 -> 8) write back i(8) - Thread 1 get i (7) increment i(7 -> 8) - write back i(8) -- Thread 2 get i(7) - increment i(7->8) - write back i(8) Thread 1 increment i(7 -> 8) - Or: - increment i(8->9) Thread 2 - increment i(8->9) increment i(7->8) - The desired outcomeA possible outcome Possible outcome

ClCu03 6 Locking A lock provides Such a mechanism; it works much like a lock on a door Thread 1 try to lock the queue Succeeded: acquired lock access queue... unlock the queue... Thread 2 try to lock the queue failed: waiting.. waiting... succeeded: acquired lock access queue... unlock the queue the lock prevents concurrency

ClCu03 7 What Causes Concurrency, Anyway? The kernel has similar causes of concurrency Interrupts can occur asynchronously at almost any time, interrupting the currently executing code Softirqs and tasklets can raise or schedule a softirq or tasklet at almost any time Kernel preemption one task in the kernel can preempt another Sleeping and synchronization with user-space can sleep and thus invoke the scheduler, resulting in the running of a new process Symmetrical multiprocessing can be executing kernel code at exactly the same time

ClCu03 8 So, How Do I Know What Needs Protecting? Whenever you write kernel code, you should ask yourself these questions: Is the data global? Is the data shared between process context and interrupt context? If a process is preempted while accessing this data, can the newly scheduled process access the same data? Can the current process sleep(block) on anything? What prevent the data from being freed out from under me? What happens if this function is called again on another processor? What am I going to do about it?

ClCu03 9 Deadlocks A condition involving one or more threads of execution and one or more resources Each thread is waiting for one of the resources But all the resources are already held a four-way traffic stop self-deadlock

ClCu03 10 Deadlocks Deadly embrace or the ABBA deadlock Prevention of deadlock: a few simple rules Lock ordering is vital Prevent starvation Do not double acquire the same lock Complexity in your locking scheme invites deadlocks Thread 1 acquire lock A try to acquire lock B wait for lock B Thread 2 acquire lock B try to acquire lock A wait for lock A

ClCu03 11 Contention and Scalability Lock Contention Used to describe a lock that is currently in use, but that another thread is trying to acquire Scalability A measurement of how well a system can be expanded With a large number of processes, processors, and memory Kernel 2.6 Kernel locking is very fine-grained and scalability is very good

ClCu03 12 Locking and Your Code Whenever you write kernel code Whether it is a new system call or a rewirtten driver, protecting data from concurrent access needs to be a primary concern Linux kernel provides to ensure that your code is race and deadlock free