Computer Fundamentals: Operating Systems, Concurrency. Dr Robert Harle

Similar documents
int $0x32 // call interrupt number 50

David DeFlyer Class notes CS162 January 26 th, 2009

CSE 410: Systems Programming

CS510 Operating System Foundations. Jonathan Walpole

Operating Systems: Internals and Design Principles. Chapter 2 Operating System Overview Seventh Edition By William Stallings

THE CPU SPENDS ALMOST ALL of its time fetching instructions from memory

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Chapter 02: Computer Organization. Lesson 07 Operating Systems

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

CSC 2405: Computer Systems II

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

Operating Systemss and Multicore Programming (1DT089)

Introduction to Computer Systems and Operating Systems

Chapter 2 Operating-System Structures

Operating Systems Overview. Chapter 2

Computer System Overview

ELEC 377 Operating Systems. Week 1 Class 2

Introduction to Concurrency (Processes, Threads, Interrupts, etc.)

Introduction. CS3026 Operating Systems Lecture 01

Operating Systems Overview

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Operating Systems (2INC0) 2018/19. Introduction (01) Dr. Tanir Ozcelebi. Courtesy of Prof. Dr. Johan Lukkien. System Architecture and Networking Group

PROCESSES AND THREADS THREADING MODELS. CS124 Operating Systems Winter , Lecture 8

THREADS AND CONCURRENCY

Computer-System Architecture (cont.) Symmetrically Constructed Clusters (cont.) Advantages: 1. Greater computational power by running applications

Computer System Overview OPERATING SYSTEM TOP-LEVEL COMPONENTS. Simplified view: Operating Systems. Slide 1. Slide /S2. Slide 2.

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

W4118 Operating Systems. Junfeng Yang

THREADS & CONCURRENCY

Process Characteristics

Unit A451: Computer systems and programming. Section 3: Software 1 Intro to software

PROVING THINGS ABOUT PROGRAMS

Computer System Overview

ECE 574 Cluster Computing Lecture 8

Operating Systems Overview. Chapter 2

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institute of Technology, Delhi

CSCI 120 Introduction to Computation Operating System (draft)

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Resource Management IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Chapter 4: Multithreaded Programming

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Background: Operating Systems

Introduction to Computing and Systems Architecture

Processes and Virtual Memory Concepts

CS 104 Computer Organization and Design

THE PROCESS ABSTRACTION. CS124 Operating Systems Winter , Lecture 7

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

Introduction to Operating Systems. Chapter Chapter

Chapter 3: Processes

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Introduction to System Programming

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

SMD149 - Operating Systems

Chapter 5 - Input / Output

Scheduling. CS 161: Lecture 4 2/9/17

Disciplina Sistemas de Computação

Lesson 5: Software for embedding in System- Part 2

Advanced Operating Systems (CS 202)

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

Subject Name:Operating system. Subject Code:10EC35. Prepared By:Remya Ramesan and Kala H.S. Department:ECE. Date:

Even coarse architectural trends impact tremendously the design of systems

Introduction to Operating. Chapter Chapter

Starting from. An Introduction to Computing Science by Jeremy Scott LEARNER NOTES

Sistemi in Tempo Reale

OPERATING SYSTEM. Chapter 4: Threads

Process Description and Control

Even coarse architectural trends impact tremendously the design of systems. Even coarse architectural trends impact tremendously the design of systems

I/O Handling. ECE 650 Systems Programming & Engineering Duke University, Spring Based on Operating Systems Concepts, Silberschatz Chapter 13

Chapter 2: Operating-System Structures

Rsyslog: going up from 40K messages per second to 250K. Rainer Gerhards

THREADS & CONCURRENCY

CSE 120 Principles of Operating Systems

Introduction to Operating Systems. Chapter Chapter

Comp 204: Computer Systems and Their Implementation. Lecture 18: Devices

Chapter 5: Threads. Outline

Scheduling, part 2. Don Porter CSE 506

CSCI-GA Operating Systems I/O. Hubertus Franke

Cache Performance and Memory Management: From Absolute Addresses to Demand Paging. Cache Performance

Chapter 2: Operating-System Structures

Devices. Today. Comp 104: Operating Systems Concepts. Operating System An Abstract View 05/01/2017. Devices. Devices

Concurrency. Glossary

18-447: Computer Architecture Lecture 16: Virtual Memory

Note Takers: Chau, Bao Kham (cs162-bb) and Quang Tran (cs162-bc) Topic: Real time system

Storage Systems Dr. K. Gopinath Department of Computer Science and Engineering Indian Institute of Science, Bangalore

Introduction to Asynchronous Programming Fall 2014

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Part I Overview Chapter 1: Introduction

Fundamental Concepts and History

CSE 451: Operating Systems Winter Module 2 Architectural Support for Operating Systems

MULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10

Even coarse architectural trends impact tremendously the design of systems

Introduction to Operating Systems (Part II)

Administrivia. Minute Essay From 4/11

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

Native POSIX Thread Library (NPTL) CSE 506 Don Porter

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

CS162 Operating Systems and Systems Programming Lecture 14. Caching (Finished), Demand Paging

Virtual Memory. Chapter 8

Threads. CS-3013 Operating Systems Hugh C. Lauer. CS-3013, C-Term 2012 Threads 1

Transcription:

Computer Fundamentals: Operating Systems, Concurrency Dr Robert Harle

This Week The roles of the O/S (kernel, timeslicing, scheduling) The notion of threads Concurrency problems Multi-core processors Virtual machines

Traditionally A single program for a single user at a single time

Operating System User Application Hardware

Time sharing A single computer for multiple users each executing a single program

Operating System User User User Application Application Application Operating System Hardware

Microprocessors (early 80s) A dedicated machine for each person running a single program

Operating System User User User Application Application Application Operating System Operating System Operating System Hardware Hardware Hardware

Multitasking (80s+) A dedicated machine for each person running multiple programs

Operating System User Application Application Operating System Hardware Application

OS Functions A modern OS does a lot Abstracts hardware (allows you to write code to e.g. access HDD and takes care of the different HDDs for you) Schedules processes Allocates main memory (to individual processes) Provides library of useful functions (e.g. get system time, load file, etc) Enforces security May provide libraries to create a GUI

The Kernel The kernel is the part of the OS that runs the system Just software Handles process scheduling (see later) Access to hardware Memory management Very complex software when it breaks... game over.

Memory Management The kernel allocates chunks of main memory to each process. It tries to prevent a program from accessing anything outside its allocation

Multitasking by Time-slicing Modern OSes allow us to run many programs at once ( multitask ). Or so it seems. In reality a CPU time-slices: Each running program (or process ) gets a certain slot of time on the CPU We rotate between the running processes with each timeslot This is all handled by the OS, which schedules the processes. It is invisible to the running program. Processes A,B,C running A B C Process D started A B C D A B C D time

Context Switching Every time the OS decides to switch the running task, it has to perform a context switch It saves all the program's context (the Fetch Execute stuff like program counter, register values, etc) to (main) memory It loads in the context for the next program Obviously there is a time cost associated with doing this...

Choosing a Timeslot Size Longer The computer is more efficient: it spends more time doing useful stuff and less time context switching The illusion of running multiple programs simultaneously is broken Appears more responsive More time context switching means the overall efficiency drops Shorter

Relinquishing a Timeslot Early Sometimes a process is stuck waiting for something to happen (e.g. data to be read from disk) The process is blocked Should release (yield) its timeslot How can we know when to unblock it? A blocks and yields A B C A B C D B C D B

Poll We could periodically check ( poll ) to see whether the data is there Essentially keep scheduling the process even though it will mostly be doing pointless checks Esay but obviously inefficient

Interrupts Modern systems support interrupts Just signals that something has happened. An interrupt handler is associated with each interrupt E.g. HDD raises an interrupt to say it's done getting data scheduler unblocks the process Interrupt handler A blocks A B C A B C D B C D A B

Platforms Almost all significant programs make use of the library functions in an OS (e.g. to draw a window) Our machine code needs not only a specific instruction set, but also the relevant operating system (with its libraries) installed So software is typically compiled for a specific platform: a (architecture, OS) pair x86/windows ARM/Windows x86/linux ARM/iOS X86/OSX

Threads and Concurrency!

Threads Sometimes a program needs to do background tasks whilst still performing a foreground task E.g. run an intensive computation but still process mouse events in case the user hits cancel. Processes have threads: effectively sub processes that run and are scheduled independently A1 A2 C A1 A2 B1 B2 B3 A1 A2 C time

Processes vs Threads Threads run independently but share memory Memory Process A Thread 1 Process B Thread 1 Thread 2

Multiple CPUs Ten years ago, each generation of CPUs packed more in and ran faster. But: The more you pack stuff in, the hotter it gets The faster you run it, the hotter it gets And we got down to physical limits anyway!! Some systems had multiple CPUs to get speed up C A B

Multicore CPUs Modern system contain chips with multiple cores: multiple CPUs in a single package Connections shorter faster Lower power Main Memory Main Memory C A1 B A2

The New Challenge Two cores run completely independently, so a single machine really can run two or more applications simultaneously BUT the real interest is how we write reliable programs that use more than one core or thread This is hard because they use the same resources, and they can then interfere with each other Those sticking around for IB CST will start to look at such concurrency issues in far more detail. We will just look at...

Race Conditions c=5 Thread 1 c = c + 1; Main memory Thread 2 c = c - 1;

Race Conditions c=5 Thread 1 LOAD c x ADD #1 x STORE x c Main memory Thread 2 LOAD c x SUB #1 x STORE x c

Race Conditions Thread 1 LOAD c x ADD #1 x STORE x c t Thread 1 Register Thread 2 Thread 2 Main Register Memory 5 6 6 LOAD c x SUB #1 x STORE x c 6 5 5 5 5 6 6 6 5

Race Conditions t Thread 1 Thread 1 Register LOAD c x 5 Thread 2 LOAD c x SUB #1 x STORE x c ADD #1 x STORE x c 6 6 Thread 2 Main Register Memory 5 4 4 5 5 5 4 4 6

Race Conditions Thread 1 t LOAD c x ADD #1 x STORE x c Thread 1 Register Thread 2 Thread 2 Main Register Memory LOAD c x 5 SUB #1 x STORE x c 4 4 5 6 6 5 5 5 6 6 4

Race Conditions When we have two or more threads sharing a piece memory the result can depend on the order of execution Race condition Hard to detect (non-deterministic) Hard to debug Generally just hard

Solving Race Conditions LOAD c x ADD #1 x STORE x c Risky sets of operations like this must be made atomic i.e. no context switching once the code block is started Not trivial much of CST IB devoted to this

Aside: The Value of Immutability If something is immutable, the race conditions go away since you can only read it remember this for OOP

Emulation Go back 20 years and emulators were all the rage: programs on architecture X that simulated architecture Y so that programs for Y could run on X Essentially interpreters, except they had to recreate the entire system. So, for example, they had to run the operating system on which to run the program. Game Console OS PC operating system Now computers are so fast we can run multiple virtual machines on them Allows us to run multiple operating systems simultaneously!

Virtualisation User Application Operating System User Application Application Operating System Operating System Hardware User User Application Application Operating System

Virtualisation This is time-sharing reinvented, with steroids Underpins the internet services we have today Heavy load Windows 7 Light load Windows 7 Windows 7 Windows xp Windows 7 Windows 7 Ubuntu Ubuntu Android

So what have we learnt? Operating systems are complex pieces of software They are really a collection of management processes, each in charge of a different thing Multitasking is faked through timeslicing Multiple cores withn a CPU were introduced to boost performance on multitasking systems All this parallelism leads to lots of tricky concurrency issues that we're still trying to bottom out.