Part A Interrupts and Exceptions Kernel preemption CSC-256/456 Operating Systems

Size: px
Start display at page:

Download "Part A Interrupts and Exceptions Kernel preemption CSC-256/456 Operating Systems"

Transcription

1 In-Kernel Synchronization Outline Part A Interrupts and Exceptions Kernel preemption CSC-256/456 Operating Systems Common in-kernel synchronization primitives Applicability of synchronization mechanisms Tuesday, November 27, 2007 Examples in the kernel Konstantinos Menychtas Part B Transactional Memory, a new synchronization model TxLinux * Our case study is Linux * Outline Reasons for synchronization Part A Kernel is reentrant Interrupts and Exceptions Interleaved control-paths Kernel preemption Common in-kernel synchronization primitives Applicability of synchronization mechanisms Asynchronous events Limited resources distribution Examples in the kernel Can be a non monolithic application Part B SMP / Multicore / Manycore Transactional Memory, a new synchronization model Distributed / Multithreaded TxLinux

2 Interrupt signals Implied interrupt signals priorities Interrupts = asynchronous (other devices) Maskable ( IRQs ) Non-maskable (ex. hardware failure) Exceptions = synchronous (by the CPU) Programmed, aka software interrupts (ex. buffer overflow) Processor-detected: faults, traps, aborts Most exceptions at user mode Exceptions can interrupt exceptions page fault may occur in kernel-mode depth at most two (1. system call, 2.page fault) Interrupts in any mode Can interrupt both interrupts and exceptions Cannot be interrupted by exceptions Handling nested execution They try to avoid causing page faults implicitly prioritized Deferrable Functions Policy and Kernel Preemption Enable asynchronous processing, hide latency (ex. Network interrupt handling) Remember TinyOS tasks (vs event handlers) Softirqs statically allocated concurrent (spin-locked) Clever waiter policy Customer = user, Boss = Interrupt Signals Customer service is my priority (user mode) Unless some boss has a request (kernel mode) Every boss wants instant service reentrant Tasklets on top of softirqs (HI_SOFTirq, TASKLET_SOFTirq) dynamic same type tasklets always serialized Kernel preemption = process switch while in kernel mode Forced, in addition to planned switch Replacement not necessarily to switch to user mode Lower dispatch latency higher interactivity

3 Preemption conditions Outline Only when executing an exception handler Part A Only when preemption is enabled Interrupts and Exceptions When kernel control path termination (usually interrupt handler) exception handler re-enables kernel preemption deferrable functions are enabled Kernel preemption Common in-kernel synchronization primitives Applicability of synchronization mechanisms Examples in the kernel Part B Kernel preemption is optional Transactional Memory, a new synchronization model TxLinux Need for synchronization Synchronization Primitives Critical region in control path must run path to completion Race condition execution depends on nesting order Synchronization not necessary IRQ line disabling Implied priority (ex. interrupt handling never interrupted) non-simultaneous execution (ex. tasklets)

4 Per-CPU variables Atomic operations Array of data structs with 1 element / CPU To avoid read-modify-write race conditions When data can be split Hardware memory arbiter serializes them Memory alignment cache line alignment Order undetermined No protection against asynchronous functions atomic_t Prone to race conditions single, chip-level instruction Kernel preemption disabling necessary hardware support Atomic operations, ex. atomic_sub_and_test Atomic bit handling functions, ex. test_and_set_bit Optimization and Memory Barriers Spin-locks (+ RW-spin-locks) The problems Hardware optimizations (ex. dual-issue) Compiler optimizations (ex. loop unrolling) Solutions: Use barriers to avoid synchronization issues Optimization barrier asm volatile( ::: memory ) Memory barrier certain instructions act like that anyway (ex. I/O ports) special hardware [smp_] mb(), rmb(), wmb() Poll until condition Can be faster than rescheduling spinlock_t slock (<=0/1) break_lock (SMP) spin_lock_irq() disables IRQs while held Read/Write rwlock_t : 2^23 R + 1-bit unlock flag

5 Seqlocks Read-Copy Update As of 2.6 linux kernel For data structures mostly read seqlock_t Lock-free spinlock_t creates copy of the protected data structure int sequence Many writers, many readers Biased, in favor of (single) writer, R/W spinlocks Writer never waits seqlock.sequence is increased both at lock / unlock writing only when sequence is odd Suitable when not acting on pointers read by readers and when multiple reads are OK Only dynamically allocated, pointer referenced data structures No kernel control path can sleep inside RCU Free copies on every tick a tasklet executes callbacks (memory-manager-like) Semaphores Completions In-kernel!= System V struct semaphore atomic_t count wait (wait queue list address) sleepers Suspends unsuccessful acquire (down) attempters To be used only by functions allowed to sleep not interrupt handlers not deferrable functions Read/Write semaphores (like rw spinlocks) wake-up one writer / many readers Mutexes (binary semaphores, as of ) Similar to semaphore Specifically for subtle synchronization in SMPs process A at CPU 1 inits semaphore and downs process B at CPU 2 ups semaphore at the same time A tries to destroy semaphore Allows classic semaphore to stay optimized spinlock used to ensure complete() and wait_for_completion()

6 Local Interrupt Disabling Disabling and Enabling Deferrable Functions Allows easy synchronization with concurrent processes at the same CPU Deferrable functions execute unpredictably (mostly when hardware interrupt handlers finish) Does not handle access to data structures by other protect data structures they access against race conditions CPUs Disable softirqs without disabling interrupts addressed by coupling with spinlocks User softirq counter local_irq_disable : uses asm cli() do_softirq never executes when counter > 0 Extra care in interrupt re-enabling take care of nested handling by saving eflags Outline Synchronizing Access Part A Always keep concurrency level high Interrupts and Exceptions number of I/O devices / CPUs Kernel preemption Common in-kernel synchronization primitives Spin-locks, RW-locks, SEQlocks, RCU, local interrupt/softirq disabling stop kernel preemption Applicability of synchronization mechanisms Examples in the kernel Part B Spinlocks can have even more negative effect busy waiting cache tainting Transactional Memory, a new synchronization model TxLinux How to be more clever (examples) atomic_t memory barrier lists (favorite kernel data structure)

7 Choosing the best Protect against exceptions ex. System call service routines Semaphores suffice to synch on unavailable resources works well in UP or SMP environments Kernel preemption does not cause problems unless for per-cpu variables Protect against interrupts Protect against deferrable functions Interrupt handlers are serialized to themselves We need synch for data structures accessed by different handlers Can we lock this struct? Spin-lock : if interrupted, cannot unlock Semaphore : can block the process In UP, disable interrupts in critical regions In SMPs, disable them and acquire spin-lock if locked, interrupt handler on other CPU will release it Lots of macros to couple spinlocks+interrupt disable No synchronization is required in UP a deferrable function is always serialized Synch is required for SMPs multiple softirqs on different CPUs spin-lock one kind of tasklet no more than one run concurrently different kinds of tasklets spin-lock

8 Protect against exceptions and interrupts Protect against exceptions and deferrable functions Consider data structure accessed by both exceptions (ex system calls service routines) and interrupt handlers Interrupt handlers are not reentrant Can be treated like interrupts+exceptions Deferrable functions are activated by interrupts No exception can be raised while they run Disable local interrupts access data structure without interrupts SMPs disable+spin-locks to synch with >1 CPUs or disable+semaphores don't block interrupts! (down_trylock) Couple them with spin-locks+local disable for SMPs local_bh_disable() disables local deferrable functions preferable Protect against interrupts and deferrable functions Protect against everyone Like interrupts+exceptions Solution is the intersection: disable local interrupts + take spin-lock Interrupt can be raised while deferrable function running No deferrable function can stop an interrupt handler Disable local interrupts during deferrable function + spin-lock for SMPs

9 Outline Examples Part A Interrupts and Exceptions Kernel preemption Common in-kernel synchronization primitives Applicability of synchronization mechanisms Examples in the kernel Part B Transactional Memory, a new synchronization model TxLinux Reference counters : atomic_t BKL (Big Kernel Lock) [redundant] : semaphore (used to be spin-lock) reentrant lock_depth counter : how many times acquired per process descriptor per-cpu automatically released on schedule() temporarily set depth=-1 when preempting to avoid corruption More examples Outline Slab-list semaphore : kernels pool for dynamic memory protect (non-block) access (kmem_cache_ create/shrink/reap) never invoke them inside interrupt handler Inode semaphore : i_sem per inode concurrent access to file is a definite source of synchronization issues perform semaphore acquire request in predetermined order to avoid deadlocks (ex. rename) Part A Interrupts and Exceptions Kernel preemption Common in-kernel synchronization primitives Applicability of synchronization mechanisms Examples in the kernel Part B Transactional Memory, a new synchronization model TxLinux

10 Recap A relative comparison We saw Blocking Non-blocking 9 different concurrency control mechanisms 7 in-kernel situations which demand extra care Blocking synchronization ex. spin_lock_t (interrupt disabling) Non-blocking synchronization hardware: compare_and_swap, load_linked store_conditional ex. atomic_t programmability large granularity large synch cost unscalable performance small granularity scalability hard to program Is there any alternative model? Can the kernel take advantage of another model? Transactional Memory Example Atomic Transaction Atomic : operation cannot be broken down to smaller pieces (ex. CAS, non-ex. ADD ) (object is of type shared object ) Transaction : either commit or abort think of money withdrawal: you wouldn't want the bank to charge you for the money you tried to withdray, but never did because its ATM broke.. Atomic Memory Transactions Herlihy (Brown), Shavit and Toitou (Tel-Aviv) Cambridge, Texas (TMLinux), Rochester :)...

11 Questions for TM Atomic memory transactions Blocking or non-blocking? When should we lock the transactional object? When should the updates appear to memory? Whom to promote on conflicts? How should we handle doomed transactions? How should we handle nested transactions? How do we handle memory, since we don't know when to free? Atomic transactions on memory as if it was a database Software or Hardware or Hybrid Granularity level : from cache line to object Scalability Performance Programmability (working on it) Arbitrary granularity Transactional Memory in the Kernel MetaTM/TxLinux Could an OS kernel benefit from TM? What assumptions of TM should we take care of to utilize it in-kernel? how do TM systems it handle interrupts Take Linux: large, mature, well tuned concurrent program TM can be an extra concurrency abstraction for user-level programmers TM in the kernel can benefit from staying close to hardware (hybrid) Use MetaTM HTM Study the workload, propose or incorporate relative ideas from other TM systems (ex contention management) Rewrite Linux using the new TM model TxLinux Evaluate We 'll stick to the problems faced and suggested ideas

12 Bringing TM to Linux Interrupts Single thread of control multiple active transactions transaction stacking Communicate hints to the hardware (HTM) to help conflict management Can the front-end of a TM library benefit from analogous hints? Conflicts in STMs are exceptions anyway! But the kernel is more complex... Non-deterministic, very frequent, undefined origin / request / status How to pair interrupts with TM don't use TM inside interrupt handlers abort first transaction and re-execute after handler nest transactions treat the interrupt as context switch per CPU data struct, interrupts disabling, blocking operations... Stacked transactions (xpush, xpop) no nesting relationship, though like context switch Stacked Transactions Issues Contention management If, while executing T1, interrupt starts T2, and they conflict, there is a livelock Solution: Abort T1 Stack memory might change during the sequence start T, call calle return, interrupt, handler return, T restart conflict with interrupt after calle return RW-spinlocks favor readers SEQlocks favor writers RCU favors readers even more How do we handle conflicts in the light of such conflicting observations? T restarts interrupt due to overwritten stack frame Solution: ignore proper parts from transaction's set SizeMatters policy : restart the smallest transaction. Revert to time-stamps after a while to avoid livelock. backoff is essential

13 Special cases Some (of the) results Not all in-kernel synchronization should be replaced per-cpu : no synchronization issues, substitution might cause performance loss Blocking (semaphores, completions, mutexes) Dominant cost is waiting or queueing? Will we get smaller code footprint with TM? Different behavior if holding lock or not I/O Much I/O while spin-locks held (1/3!) potential performance gains Understanding the Linux Kernel, by Daniel P. Bovet, Marco Cesati TxLinux: Using and Managing Hardware TransactionalMemory in an Operating System and MetaTM/TxLinux: Transactional Memory For An Operating System, by Rossbach, Ramadan et. al (University of Texas at Austin) Unlocking Concurrency: Multicore Programming with Transactional Memory, by Adl-Tabatabai, Kozyrakis, Saha. ACM Queue, vol. 4, no. 10, December 2006 Lowering the Overhead of Nonblocking Software Transactional Memory, by Marathe, Spear, Scott et al ( University of Rochester, RSTM!) THANK YOU Disclaimer: All work presented is work of the respective authors (see ) All copyrighted material (ex. images) also belongs to the respective authors.

Prof. Dr. Hasan Hüseyin

Prof. Dr. Hasan Hüseyin Department of Electrical And Computer Engineering Istanbul, Turkey ECE519 Advanced Operating Systems Kernel Concurrency Mechanisms By Mabruka Khlifa Karkeb Student Id: 163103069 Prof. Dr. Hasan Hüseyin

More information

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10 MULTITHREADING AND SYNCHRONIZATION CS124 Operating Systems Fall 2017-2018, Lecture 10 2 Critical Sections Race conditions can be avoided by preventing multiple control paths from accessing shared state

More information

Operating System Design and Implementation

Operating System Design and Implementation Operating System Design and Implementation Kernel Synchronization Shiao Li Tsao Why Kernel Synchroni zation Semaphor es and Mutexes Atomic Operation s Other mechanis ms Spin Lock Summary 國立交通大學資訊工程學系曹孝櫟老師

More information

Dealing with Issues for Interprocess Communication

Dealing with Issues for Interprocess Communication Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed

More information

Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux

Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux 1 Computer Core Practice1: Operating System Week10. locking Protocol & Atomic Operation in Linux Jhuyeong Jhin and Injung Hwang Race Condition & Critical Region 2 Race Condition Result may change according

More information

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs CSE 451: Operating Systems Winter 2005 Lecture 7 Synchronization Steve Gribble Synchronization Threads cooperate in multithreaded programs to share resources, access shared data structures e.g., threads

More information

Linux Synchronization Mechanisms in Driver Development. Dr. B. Thangaraju & S. Parimala

Linux Synchronization Mechanisms in Driver Development. Dr. B. Thangaraju & S. Parimala Linux Synchronization Mechanisms in Driver Development Dr. B. Thangaraju & S. Parimala Agenda Sources of race conditions ~ 11,000+ critical regions in 2.6 kernel Locking mechanisms in driver development

More information

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization Hank Levy Levy@cs.washington.edu 412 Sieg Hall Synchronization Threads cooperate in multithreaded programs to share resources, access shared

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Spring 2018 Lecture 15: Multicore Geoffrey M. Voelker Multicore Operating Systems We have generally discussed operating systems concepts independent of the number

More information

Synchronization I. Jo, Heeseung

Synchronization I. Jo, Heeseung Synchronization I Jo, Heeseung Today's Topics Synchronization problem Locks 2 Synchronization Threads cooperate in multithreaded programs To share resources, access shared data structures Also, to coordinate

More information

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4 Temporal relations CSE 451: Operating Systems Autumn 2010 Module 7 Synchronization Instructions executed by a single thread are totally ordered A < B < C < Absent synchronization, instructions executed

More information

Kernel Synchronization I. Changwoo Min

Kernel Synchronization I. Changwoo Min 1 Kernel Synchronization I Changwoo Min 2 Summary of last lectures Tools: building, exploring, and debugging Linux kernel Core kernel infrastructure syscall, module, kernel data structures Process management

More information

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1 This Lecture Overview Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4 COSC440 Lecture 3: Interrupts 1 Three reasons for interrupts System calls Program/hardware faults External device interrupts

More information

RCU in the Linux Kernel: One Decade Later

RCU in the Linux Kernel: One Decade Later RCU in the Linux Kernel: One Decade Later by: Paul E. Mckenney, Silas Boyd-Wickizer, Jonathan Walpole Slides by David Kennedy (and sources) RCU Usage in Linux During this same time period, the usage of

More information

Lecture 9: Multiprocessor OSs & Synchronization. CSC 469H1F Fall 2006 Angela Demke Brown

Lecture 9: Multiprocessor OSs & Synchronization. CSC 469H1F Fall 2006 Angela Demke Brown Lecture 9: Multiprocessor OSs & Synchronization CSC 469H1F Fall 2006 Angela Demke Brown The Problem Coordinated management of shared resources Resources may be accessed by multiple threads Need to control

More information

Operating Systems. Synchronization

Operating Systems. Synchronization Operating Systems Fall 2014 Synchronization Myungjin Lee myungjin.lee@ed.ac.uk 1 Temporal relations Instructions executed by a single thread are totally ordered A < B < C < Absent synchronization, instructions

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS

More information

Advance Operating Systems (CS202) Locks Discussion

Advance Operating Systems (CS202) Locks Discussion Advance Operating Systems (CS202) Locks Discussion Threads Locks Spin Locks Array-based Locks MCS Locks Sequential Locks Road Map Threads Global variables and static objects are shared Stored in the static

More information

MetaTM/TxLinux: Transactional Memory For An Operating System

MetaTM/TxLinux: Transactional Memory For An Operating System MetaTM/TxLinux: Transactional Memory For An Operating System Hany E. Ramadan, Christopher J. Rossbach, Donald E. Porter, Owen S. Hofmann, Aditya Bhandari, and Emmett Witchel Department of Computer Sciences,

More information

Lecture 5: Synchronization w/locks

Lecture 5: Synchronization w/locks Lecture 5: Synchronization w/locks CSE 120: Principles of Operating Systems Alex C. Snoeren Lab 1 Due 10/19 Threads Are Made to Share Global variables and static objects are shared Stored in the static

More information

NPTEL Course Jan K. Gopinath Indian Institute of Science

NPTEL Course Jan K. Gopinath Indian Institute of Science Storage Systems NPTEL Course Jan 2012 (Lecture 18) K. Gopinath Indian Institute of Science Spinlocks & Semaphores Shared data betw different parts of code in kernel most common: access to data structures

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization Administrivia Homework 1 Due today by the end of day Hopefully you have started on project 1 by now? Kernel-level threads (preemptable

More information

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts. CPSC/ECE 3220 Fall 2017 Exam 1 Name: 1. Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.) Referee / Illusionist / Glue. Circle only one of R, I, or G.

More information

Linux kernel synchronization. Don Porter CSE 506

Linux kernel synchronization. Don Porter CSE 506 Linux kernel synchronization Don Porter CSE 506 The old days Early/simple OSes (like JOS): No need for synchronization All kernel requests wait until completion even disk requests Heavily restrict when

More information

Lecture 10: Avoiding Locks

Lecture 10: Avoiding Locks Lecture 10: Avoiding Locks CSC 469H1F Fall 2006 Angela Demke Brown (with thanks to Paul McKenney) Locking: A necessary evil? Locks are an easy to understand solution to critical section problem Protect

More information

Interprocess Communication By: Kaushik Vaghani

Interprocess Communication By: Kaushik Vaghani Interprocess Communication By: Kaushik Vaghani Background Race Condition: A situation where several processes access and manipulate the same data concurrently and the outcome of execution depends on the

More information

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition Module 6: Process Synchronization 6.1 Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores

More information

KERNEL THREAD IMPLEMENTATION DETAILS. CS124 Operating Systems Winter , Lecture 9

KERNEL THREAD IMPLEMENTATION DETAILS. CS124 Operating Systems Winter , Lecture 9 KERNEL THREAD IMPLEMENTATION DETAILS CS124 Operating Systems Winter 2015-2016, Lecture 9 2 Last Time: Kernel Threads OS kernel must provide a multitasking implementation Kernel threads are the minimal

More information

Problem Set 2. CS347: Operating Systems

Problem Set 2. CS347: Operating Systems CS347: Operating Systems Problem Set 2 1. Consider a clinic with one doctor and a very large waiting room (of infinite capacity). Any patient entering the clinic will wait in the waiting room until the

More information

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

Multiprocessor Systems. Chapter 8, 8.1

Multiprocessor Systems. Chapter 8, 8.1 Multiprocessor Systems Chapter 8, 8.1 1 Learning Outcomes An understanding of the structure and limits of multiprocessor hardware. An appreciation of approaches to operating system support for multiprocessor

More information

Application Programming

Application Programming Multicore Application Programming For Windows, Linux, and Oracle Solaris Darryl Gove AAddison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris

More information

Atomic Transac1ons. Atomic Transactions. Q1: What if network fails before deposit? Q2: What if sequence is interrupted by another sequence?

Atomic Transac1ons. Atomic Transactions. Q1: What if network fails before deposit? Q2: What if sequence is interrupted by another sequence? CPSC-4/6: Operang Systems Atomic Transactions The Transaction Model / Primitives Serializability Implementation Serialization Graphs 2-Phase Locking Optimistic Concurrency Control Transactional Memory

More information

Linux kernel synchronization

Linux kernel synchronization Linux kernel synchronization Don Porter CSE 56 Memory Management Logical Diagram Binary Memory Formats Allocators Threads Today s Lecture Synchronization System Calls RCU in the kernel File System Networking

More information

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Operating Systems Lecture 4 - Concurrency and Synchronization Adrien Krähenbühl Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Mutual exclusion Hardware solutions Semaphores IPC: Message passing

More information

Chapter 6 Concurrency: Deadlock and Starvation

Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles Chapter 6 Concurrency: Deadlock and Starvation Seventh Edition By William Stallings Operating Systems: Internals and Design Principles When two trains

More information

Synchronization for Concurrent Tasks

Synchronization for Concurrent Tasks Synchronization for Concurrent Tasks Minsoo Ryu Department of Computer Science and Engineering 2 1 Race Condition and Critical Section Page X 2 Synchronization in the Linux Kernel Page X 3 Other Synchronization

More information

Utilizing Linux Kernel Components in K42 K42 Team modified October 2001

Utilizing Linux Kernel Components in K42 K42 Team modified October 2001 K42 Team modified October 2001 This paper discusses how K42 uses Linux-kernel components to support a wide range of hardware, a full-featured TCP/IP stack and Linux file-systems. An examination of the

More information

Concurrency: Deadlock and Starvation

Concurrency: Deadlock and Starvation Concurrency: Deadlock and Starvation Chapter 6 E&CE 354: Processes 1 Deadlock Deadlock = situation in which every process from a set is permanently blocked, i.e. cannot proceed with execution Common cause:

More information

METATM/TXLINUX: TRANSACTIONAL MEMORY FOR AN OPERATING SYSTEM

METATM/TXLINUX: TRANSACTIONAL MEMORY FOR AN OPERATING SYSTEM ... METATM/TXLINUX: TRANSACTIONAL MEMORY FOR AN OPERATING SYSTEM... HARDWARE TRANSACTIONAL MEMORY CAN REDUCE SYNCHRONIZATION COMPLEXITY WHILE RETAINING HIGH PERFORMANCE. METATM MODELS CHANGES TO THE X86

More information

Real Time Linux patches: history and usage

Real Time Linux patches: history and usage Real Time Linux patches: history and usage Presentation first given at: FOSDEM 2006 Embedded Development Room See www.fosdem.org Klaas van Gend Field Application Engineer for Europe Why Linux in Real-Time

More information

Kernel Scalability. Adam Belay

Kernel Scalability. Adam Belay Kernel Scalability Adam Belay Motivation Modern CPUs are predominantly multicore Applications rely heavily on kernel for networking, filesystem, etc. If kernel can t scale across many

More information

- Knowledge of basic computer architecture and organization, ECE 445

- Knowledge of basic computer architecture and organization, ECE 445 ECE 446: Device Driver Development Fall 2014 Wednesdays 7:20-10 PM Office hours: Wednesdays 6:15-7:15 PM or by appointment, Adjunct office Engineering Building room 3707/3708 Last updated: 8/24/14 Instructor:

More information

CSL373/CSL633 Major Exam Solutions Operating Systems Sem II, May 6, 2013 Answer all 8 questions Max. Marks: 56

CSL373/CSL633 Major Exam Solutions Operating Systems Sem II, May 6, 2013 Answer all 8 questions Max. Marks: 56 CSL373/CSL633 Major Exam Solutions Operating Systems Sem II, 2012 13 May 6, 2013 Answer all 8 questions Max. Marks: 56 1. True or False. Give reasons and/or brief explanation. No marks for incomplete/wrong

More information

Kernel Korner Kernel Locking Techniques

Kernel Korner Kernel Locking Techniques Kernel Korner Kernel Locking Techniques Robert explains the various locking primitives in the Linux kernel, why you need them and how kernel developers can use them to write safe code. by Robert Love Proper

More information

Synchronization COMPSCI 386

Synchronization COMPSCI 386 Synchronization COMPSCI 386 Obvious? // push an item onto the stack while (top == SIZE) ; stack[top++] = item; // pop an item off the stack while (top == 0) ; item = stack[top--]; PRODUCER CONSUMER Suppose

More information

Module 1. Introduction:

Module 1. Introduction: Module 1 Introduction: Operating system is the most fundamental of all the system programs. It is a layer of software on top of the hardware which constitutes the system and manages all parts of the system.

More information

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3 Operating Systems Antonio Vivace - 2016 revision 4 Licensed under GPLv3 Process Synchronization Background A cooperating process can share directly a logical address space (code, data) or share data through

More information

CSE 4/521 Introduction to Operating Systems

CSE 4/521 Introduction to Operating Systems CSE 4/521 Introduction to Operating Systems Lecture 7 Process Synchronization II (Classic Problems of Synchronization, Synchronization Examples) Summer 2018 Overview Objective: 1. To examine several classical

More information

More on Synchronization and Deadlock

More on Synchronization and Deadlock Examples of OS Kernel Synchronization More on Synchronization and Deadlock Two processes making system calls to read/write on the same file, leading to possible race condition on the file system data structures

More information

How Linux RT_PREEMPT Works

How Linux RT_PREEMPT Works How Linux RT_PREEMPT Works A common observation about real time systems is that the cost of the increased determinism of real time is decreased throughput and increased average latency. This presentation

More information

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University CS 571 Operating Systems Midterm Review Angelos Stavrou, George Mason University Class Midterm: Grading 2 Grading Midterm: 25% Theory Part 60% (1h 30m) Programming Part 40% (1h) Theory Part (Closed Books):

More information

Timers 1 / 46. Jiffies. Potent and Evil Magic

Timers 1 / 46. Jiffies. Potent and Evil Magic Timers 1 / 46 Jiffies Each timer tick, a variable called jiffies is incremented It is thus (roughly) the number of HZ since system boot A 32-bit counter incremented at 1000 Hz wraps around in about 50

More information

Tasks. Task Implementation and management

Tasks. Task Implementation and management Tasks Task Implementation and management Tasks Vocab Absolute time - real world time Relative time - time referenced to some event Interval - any slice of time characterized by start & end times Duration

More information

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall

Operating Systems: William Stallings. Starvation. Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings Chapter 6 Concurrency: Deadlock and Starvation Patricia Roy Manatee Community College, Venice, FL 2008, Prentice Hall Deadlock

More information

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Synchronization I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Synchronization problem Locks 2 Synchronization Threads cooperate

More information

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem? What is the Race Condition? And what is its solution? Race Condition: Where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular

More information

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Lesson 6: Process Synchronization

Lesson 6: Process Synchronization Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

More information

The Art and Science of Memory Allocation

The Art and Science of Memory Allocation Logical Diagram The Art and Science of Memory Allocation Don Porter CSE 506 Binary Formats RCU Memory Management Memory Allocators CPU Scheduler User System Calls Kernel Today s Lecture File System Networking

More information

Virtual Machine Design

Virtual Machine Design Virtual Machine Design Lecture 4: Multithreading and Synchronization Antero Taivalsaari September 2003 Session #2026: J2MEPlatform, Connected Limited Device Configuration (CLDC) Lecture Goals Give an overview

More information

The Kernel Abstraction

The Kernel Abstraction The Kernel Abstraction Debugging as Engineering Much of your time in this course will be spent debugging In industry, 50% of software dev is debugging Even more for kernel development How do you reduce

More information

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011 Synchronization CS61, Lecture 18 Prof. Stephen Chong November 3, 2011 Announcements Assignment 5 Tell us your group by Sunday Nov 6 Due Thursday Nov 17 Talks of interest in next two days Towards Predictable,

More information

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; } Semaphore Semaphore S integer variable Two standard operations modify S: wait() and signal() Originally called P() and V() Can only be accessed via two indivisible (atomic) operations wait (S) { while

More information

Advanced Operating Systems (CS 202) Memory Consistency, Cache Coherence and Synchronization

Advanced Operating Systems (CS 202) Memory Consistency, Cache Coherence and Synchronization Advanced Operating Systems (CS 202) Memory Consistency, Cache Coherence and Synchronization (some cache coherence slides adapted from Ian Watson; some memory consistency slides from Sarita Adve) Classic

More information

Concurrency: a crash course

Concurrency: a crash course Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Concurrency: a crash course Concurrent computing Applications designed as a collection of computational units that may execute

More information

SMD149 - Operating Systems

SMD149 - Operating Systems SMD149 - Operating Systems Roland Parviainen November 3, 2005 1 / 45 Outline Overview 2 / 45 Process (tasks) are necessary for concurrency Instance of a program in execution Next invocation of the program

More information

Chapter 6: Process Synchronization. Module 6: Process Synchronization

Chapter 6: Process Synchronization. Module 6: Process Synchronization Chapter 6: Process Synchronization Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

Synchronization for Concurrent Tasks

Synchronization for Concurrent Tasks Synchronization for Concurrent Tasks Minsoo Ryu Department of Computer Science and Engineering 2 1 Race Condition and Critical Section Page X 2 Algorithmic Approaches Page X 3 Hardware Support Page X 4

More information

CONCURRENT ACCESS TO SHARED DATA STRUCTURES. CS124 Operating Systems Fall , Lecture 11

CONCURRENT ACCESS TO SHARED DATA STRUCTURES. CS124 Operating Systems Fall , Lecture 11 CONCURRENT ACCESS TO SHARED DATA STRUCTURES CS124 Operating Systems Fall 2017-2018, Lecture 11 2 Last Time: Synchronization Last time, discussed a variety of multithreading issues Frequently have shared

More information

CHAPTER 6: PROCESS SYNCHRONIZATION

CHAPTER 6: PROCESS SYNCHRONIZATION CHAPTER 6: PROCESS SYNCHRONIZATION The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. TOPICS Background

More information

Last Time. Think carefully about whether you use a heap Look carefully for stack overflow Especially when you have multiple threads

Last Time. Think carefully about whether you use a heap Look carefully for stack overflow Especially when you have multiple threads Last Time Cost of nearly full resources RAM is limited Think carefully about whether you use a heap Look carefully for stack overflow Especially when you have multiple threads Embedded C Extensions for

More information

Multiprocessor System. Multiprocessor Systems. Bus Based UMA. Types of Multiprocessors (MPs) Cache Consistency. Bus Based UMA. Chapter 8, 8.

Multiprocessor System. Multiprocessor Systems. Bus Based UMA. Types of Multiprocessors (MPs) Cache Consistency. Bus Based UMA. Chapter 8, 8. Multiprocessor System Multiprocessor Systems Chapter 8, 8.1 We will look at shared-memory multiprocessors More than one processor sharing the same memory A single CPU can only go so fast Use more than

More information

Module 6: Process Synchronization

Module 6: Process Synchronization Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization Examples Atomic

More information

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Multiprocessors and Locking

Multiprocessors and Locking Types of Multiprocessors (MPs) Uniform memory-access (UMA) MP Access to all memory occurs at the same speed for all processors. Multiprocessors and Locking COMP9242 2008/S2 Week 12 Part 1 Non-uniform memory-access

More information

Sistemas Operacionais I. Valeria Menezes Bastos

Sistemas Operacionais I. Valeria Menezes Bastos Sistemas Operacionais I Valeria Menezes Bastos Operating Systems: Internals and Design Principles Chapter 1 Computer System Overview Eighth Edition By William Stallings Summary Basic Elements Evolution

More information

Multiprocessor Systems. COMP s1

Multiprocessor Systems. COMP s1 Multiprocessor Systems 1 Multiprocessor System We will look at shared-memory multiprocessors More than one processor sharing the same memory A single CPU can only go so fast Use more than one CPU to improve

More information

Main Points of the Computer Organization and System Software Module

Main Points of the Computer Organization and System Software Module Main Points of the Computer Organization and System Software Module You can find below the topics we have covered during the COSS module. Reading the relevant parts of the textbooks is essential for a

More information

TxLinux: Using and Managing Hardware Transactional Memory in an Operating System

TxLinux: Using and Managing Hardware Transactional Memory in an Operating System Appears in SOSP 2007 TxLinux: Using and Managing Hardware Transactional Memory in an Operating System Christopher J. Rossbach, Owen S. Hofmann, Donald E. Porter, Hany E. Ramadan, Aditya Bhandari, and Emmett

More information

To Everyone... iii To Educators... v To Students... vi Acknowledgments... vii Final Words... ix References... x. 1 ADialogueontheBook 1

To Everyone... iii To Educators... v To Students... vi Acknowledgments... vii Final Words... ix References... x. 1 ADialogueontheBook 1 Contents To Everyone.............................. iii To Educators.............................. v To Students............................... vi Acknowledgments........................... vii Final Words..............................

More information

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4 Motivation Threads Chapter 4 Most modern applications are multithreaded Threads run within application Multiple tasks with the application can be implemented by separate Update display Fetch data Spell

More information

Concurrency Race Conditions and Deadlocks

Concurrency Race Conditions and Deadlocks Concurrency Race Conditions and Deadlocks Kartik Gopalan Chapters 2 (2.3) and 6 Tanenbaum s Modern OS Sequential Loosely, doing many things, but one after another E.g. Finish one assignment, then another

More information

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Processes Prof. James L. Frankel Harvard University Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Process Model Each process consists of a sequential program

More information

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack

Recap: Thread. What is it? What does it need (thread private)? What for? How to implement? Independent flow of control. Stack What is it? Recap: Thread Independent flow of control What does it need (thread private)? Stack What for? Lightweight programming construct for concurrent activities How to implement? Kernel thread vs.

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

More information

Concurrency Bugs in the Network Stack of NetBSD

Concurrency Bugs in the Network Stack of NetBSD Concurrency Bugs in the Network Stack of NetBSD Ryota Ozaki ozaki-r@{iij.ad.jp,netbsd.org} AsiaBSDCon 2018 BoF Table of Contents Brief overview of NetBSD internals Examples of deadlocks Examples of race

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 11 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel Feedback Queue: Q0, Q1,

More information

Kernels and Locking. Luca Abeni

Kernels and Locking. Luca Abeni Kernels and Locking Luca Abeni luca.abeni@santannapisa.it Critical Sections in Kernel Code Old Linux kernels used to be non-preemptable... Kernel Big critical section Mutual exclusion was not a problem...

More information

Operating System Design Issues. I/O Management

Operating System Design Issues. I/O Management I/O Management Chapter 5 Operating System Design Issues Efficiency Most I/O devices slow compared to main memory (and the CPU) Use of multiprogramming allows for some processes to be waiting on I/O while

More information

Locking: A necessary evil? Lecture 10: Avoiding Locks. Priority Inversion. Deadlock

Locking: A necessary evil? Lecture 10: Avoiding Locks. Priority Inversion. Deadlock Locking: necessary evil? Lecture 10: voiding Locks CSC 469H1F Fall 2006 ngela Demke Brown (with thanks to Paul McKenney) Locks are an easy to understand solution to critical section problem Protect shared

More information

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7 THE PROCESS ABSTRACTION CS124 Operating Systems Winter 2015-2016, Lecture 7 2 The Process Abstraction Most modern OSes include the notion of a process Term is short for a sequential process Frequently

More information

Lecture 9: Midterm Review

Lecture 9: Midterm Review Project 1 Due at Midnight Lecture 9: Midterm Review CSE 120: Principles of Operating Systems Alex C. Snoeren Midterm Everything we ve covered is fair game Readings, lectures, homework, and Nachos Yes,

More information

CS533 Concepts of Operating Systems. Jonathan Walpole

CS533 Concepts of Operating Systems. Jonathan Walpole CS533 Concepts of Operating Systems Jonathan Walpole Introduction to Threads and Concurrency Why is Concurrency Important? Why study threads and concurrent programming in an OS class? What is a thread?

More information

Linux - Not real-time!

Linux - Not real-time! Linux - Not real-time! Date: 16.01.2015 Author(s): Michal Koziel www.bitvis.no 1 Abstract A system is said to be real-time if it can respond to external triggers and perform periodic tasks with deterministic

More information

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) Dept. of Computer Science & Engineering Chentao Wu wuct@cs.sjtu.edu.cn Download lectures ftp://public.sjtu.edu.cn User:

More information

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018 SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T 2. 3. 8 A N D 2. 3. 1 0 S P R I N G 2018 INTER-PROCESS COMMUNICATION 1. How a process pass information to another process

More information

CMSC421: Principles of Operating Systems

CMSC421: Principles of Operating Systems CMSC421: Principles of Operating Systems Nilanjan Banerjee Assistant Professor, University of Maryland Baltimore County nilanb@umbc.edu http://www.csee.umbc.edu/~nilanb/teaching/421/ Principles of Operating

More information

Read-Copy Update (RCU) Don Porter CSE 506

Read-Copy Update (RCU) Don Porter CSE 506 Read-Copy Update (RCU) Don Porter CSE 506 RCU in a nutshell ò Think about data structures that are mostly read, occasionally written ò Like the Linux dcache ò RW locks allow concurrent reads ò Still require

More information

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Process Synchronization, Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores

More information