14 1 Embedded Software Lab. Embedded Software Lab Daejun Park, Eunsoo Park Lecture 8 Synchronization.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Synchronization and Deadlocks
Global Environment Model. MUTUAL EXCLUSION PROBLEM The operations used by processes to access to common resources (critical sections) must be mutually.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
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.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
CS533 Concepts of Operating Systems Class 4 Linux Kernel Locking Issues.
CS510 Concurrent Systems Class 1
Semaphores, mutexes and condition variables. semaphores Two types – Binary – 0 or 1 – Counting 0 to n Wait – decrements > 0 forces a wait Post or signal.
Monitors CSCI 444/544 Operating Systems Fall 2008.
CS510 Concurrent Systems Class 1 Linux Kernel Locking Techniques.
CS533 Concepts of Operating Systems Class 17 Linux Kernel Locking Techniques.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
CS533 Concepts of Operating Systems Linux Kernel Locking Techniques.
Computer Science 162 Discussion Section Week 3. Agenda Project 1 released! Locks, Semaphores, and condition variables Producer-consumer – Example (locks,
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Implementing Synchronization. Synchronization 101 Synchronization constrains the set of possible interleavings: Threads “agree” to stay out of each other’s.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Kernel Locking Techniques by Robert Love presented by Scott Price.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
CS533 Concepts of Operating Systems Jonathan Walpole.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Kernel Synchronization in Linux Uni-processor and Multi-processor Environment By Kathryn Bean and Wafa’ Jaffal (Group A3)
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Lecture 6 Page 1 CS 111 Summer 2013 Concurrency Solutions and Deadlock CS 111 Operating Systems Peter Reiher.
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.
Linux Kernel Development Chapter 8. Kernel Synchronization Introduction Geum-Seo Koo Fri. Operating System Lab.
CS162 Section 2. True/False A thread needs to own a semaphore, meaning the thread has called semaphore.P(), before it can call semaphore.V() False: Any.
Kernel Synchronization David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
CSE 120 Principles of Operating
Process Synchronization
CSNB334 Advanced Operating Systems 4
Background on the need for Synchronization
Semaphores and Condition Variables
Chapter 5: Process Synchronization
Introduction to Operating Systems
Inter-Process Communication and Synchronization
Topic 6 (Textbook - Chapter 5) Process Synchronization
Lecture 2 Part 2 Process Synchronization
Another Means Of Thread Synchronization
Computer Science & Engineering Electrical Engineering
Kernel Synchronization I
NT Synchronization Primitives
CS510 Concurrent Systems Class 1a
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
CS510 Concurrent Systems Jonathan Walpole.
Linux Kernel Locking Techniques
Monitors and Inter-Process Communication
EECE.4810/EECE.5730 Operating Systems
CSE 542: Operating Systems
Presentation transcript:

14 1 Embedded Software Lab. Embedded Software Lab Daejun Park, Eunsoo Park Lecture 8 Synchronization

14 2 Embedded Software Lab. Race Condition  Prevention : Synchronization –Some code (Critical Region)could be interleaved  Not serialized. Kernel Synchronization

14 3 Embedded Software Lab. Spin Lock –When access a shared data or enter a critical region –If locked, spin around repeatedly executing loop – busy wait –Kernel preemption is disabled in every critical region protected by spin locks spinlock_t –slock 1 : unlocked state 0 이하 : locked state –break_lock Flag signaling that process is busy waiting for the lock

14 4 Embedded Software Lab. Spin Lock spin_lock() macro –Disable kernel preemption – preempt_disable() –Check slock –If slock=1, exit  Success to acquire spin lock. –If slock=0, preempt_enable() –Set break_lock=1 –Wait cycle while(spin_is_locked(slp) && slp->break_lock) cpu_relax();

14 5 Embedded Software Lab. Semaphore Allow waiters to sleep struct semaphore –count >0 : free =0 : busy, no waiting process <0 : busy, waiting process –wait Address of wait queue list –sleepers Flag whether processes are sleeping

14 6 Embedded Software Lab. Semaphore Releasing semaphores – up() –count++ and check if count>0 –count<=0 : wake up one sleeping process Getting semaphores – down() –count-- and check if count<0 –count>=0 : acquire resource –count=1, sleepers=0 : semaphore open –count=0, sleepers=0 : semaphore close, no sleeping process –count=-1, sleepers=1 : semaphore close, sleeping process

14 7 Embedded Software Lab. spinlock 을 사용하는 kernel 코드를 찾아 조사 –initialization 부분 –lock 부분 –unlock 부분 –critical section 에 대해 경쟁하는 부분 example(inode->i_lock) –initialization 부분 inode_init_always() –lock & unlock 부분, critical section iget_locked() –spin_lock(&inode->i_lock); –inode->i_state = I_NEW; –hlist_add_head(&inode->i_hash, head); –spin_unlock(&inode->i_lock); 실습