Userspace Synchronization

Slides:



Advertisements
Similar presentations
Chapter 6: Process Synchronization
Advertisements

Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Jonathan Walpole Computer Science Portland State University
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Computer Science 162 Discussion Section Week 3. Agenda Project 1 released! Locks, Semaphores, and condition variables Producer-consumer – Example (locks,
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
CS510 Concurrent Systems Introduction to Concurrency.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
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.
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.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
CSE 425: Concurrency II Semaphores and Mutexes Can avoid bad inter-leavings by acquiring locks –Guard access to a shared resource to take turns using it.
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.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
CSE 153 Design of Operating Systems Winter 2015 Lecture 5: Synchronization.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Synchronization.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
Read-Copy-Update Synchronization in the Linux Kernel 1 David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
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.
December 1, 2006©2006 Craig Zilles1 Threads & Atomic Operations in Hardware  Previously, we introduced multi-core parallelism & cache coherence —Today.
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
Chapter 5: Process Synchronization – Part 3
PARALLEL PROGRAM CHALLENGES
Chapter 5: Process Synchronization
Synchronization.
Threads Cannot Be Implemented As a Library
Atomic Operations in Hardware
Atomic Operations in Hardware
SYNCHRONIZATION IN LINUX
Overview of the Lab 2 Assignment: Linux Scheduler Profiling
Overview of the Lab 3 Assignment: Kernel Module Concurrent Memory Use
Monitors Chapter 7.
Kernel Synchronization II
Threading And Parallel Programming Constructs
Module 7a: Classic Synchronization
Jonathan Walpole Computer Science Portland State University
Kernel Structure and Infrastructure
Lecture 2 Part 2 Process Synchronization
Monitors Chapter 7.
Top Half / Bottom Half Processing
Kernel Synchronization I
Monitors Chapter 7.
Semester Review Brian Kocoloski
Kernel Synchronization II
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CSE 451: Operating Systems Autumn 2004 Module 6 Synchronization
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2004 Module 6 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
Kernel Tracing David Ferry, Chris Gill, Brian Kocoloski
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Chapter 6: Synchronization Tools
Atomicity, Mutex, and Locks
Processes David Ferry, Chris Gill, Brian Kocoloski
Process/Thread Synchronization (Part 2)
More concurrency issues
Presentation transcript:

Userspace Synchronization Chris Gill, Brian Kocoloski CSE 422S - Operating Systems Organization Washington University in St. Louis St. Louis, MO 63143

CSE 422S – Operating Systems Organization Atomic Operations Today, we will be exploring atomic hardware operations and synchronization in more detail Important atomic functions: __atomic_compare_exchange() – set a variable to a new value if its old value is something we expect it to be __atomic_add_fetch() – add to a variable and return its new value __atomic_sub_fetch() – subtract from a variable and return its new value CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Compare/Exchange Syntax: cmp_exchg(ptr, expected, desired) Parameters ptr : pointer to an integer valued expected: value that ptr should have now desired: value that we want to set ptr to Semantics: (of course, this is executed atomically) if (*ptr == expected) { *ptr = desired; return true; } else { return false; } CSE 422S – Operating Systems Organization

Spinlock via Compare/Exchange Syntax: cmp_exchg(ptr, expected, desired) Lock: Repeatedly invoke cmp_exchg(ptr, UNLOCKED, LOCKED) If it fails, that means the value of ptr is not unlocked, so need to try again If it succeeds, value is set to LOCKED to prevent concurrent access Unlock: Invoke cmp_exchg(ptr, LOCKED, UNLOCKED) Has to succeed – if not, the lock was never acquired CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Spinlocks vs Futexes Spinlocks via cmp/xchg function correctly, but waste CPU cycles via spinning In cases of longer critical sections, it is desirable to be able to put processes/threads to sleep Similar to kernel-level mutexes/semaphores Fast userspace mutexes (futexes) are a new feature to improve lock performance CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Futexes Two components: (1) an atomic integer variable in userspace (2) a system call to sleep/wake up contending processes Can be used to synchronize multiple processes or threads In multiprocess settings, processes must explicitly share memory via something like mmap() In multithread settings, threads implicitly share memory In their simplest form, futexes offer primitive operations on which other (sleep) lock mechanisms can be built Semaphores, condition variables, readers/writer locks, etc. CSE 422S – Operating Systems Organization

Futex Example <On whiteboard> CSE 422S – Operating Systems Organization

Futex Example <On whiteboard> Takeaways: Common case code path – (no lock contention) – is optimized by not requiring any system calls Uncommon case - (lock contention) – does not waste CPU cycles by spinning, but rather sleeps/wakes up via system calls CSE 422S – Operating Systems Organization

CSE 422S – Operating Systems Organization Today’s Studio Implement userspace spinlocks and mutexes Some Programming Considerations Volatile variables are often important Inform compiler (and someone reading the code) that a variable’s value may change unexpectedly) Read type declarations right-to-left in C and C++ E.g., volatile int * is a pointer to an int that’s volatile (the int value, not the pointer, may change) OpenMP is for parallel programming Pragmas built into gcc, to support concurrent execution of functions, barrier synchronization before and after parallel-for loops, etc. CSE 422S – Operating Systems Organization