lec 1operating systems1 operating systems lecture 1: introduction review of system architecture and...

43
Lec 1 Operating Systems 1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari William M. Mongan

Upload: lee-hutchinson

Post on 27-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 1

Operating Systems

Lecture 1: IntroductionReview of System Architecture and Concurrent Programming

Maxim Shevertalov

Jay KothariWilliam M. Mongan

Page 2: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 2

Introduction

• What is an Operating System?• How are they designed?• Why study them?

Page 3: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 3

What is an Operating System?

• Facilitation + Performance• Think of Air Traffic Control: they are in charge of lots of airplanes,

and sometimes they tell airplanes to wait their turn.• Despite what we may sometimes think, their intent is not to prevent

us from doing what we want by imposing complicated rules.• Rather, they are there to facilitate aircraft in flight.• On its own, the air traffic controller does not accomplish much; but,

together with the aircraft he supports, he aims to maximize performance for all the participating airplanes (not any one!), while protecting them from one another.

• It’s all about coordination.

Page 4: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 4

What is an Operating System?

• Can we use a computer system without an operating system?

Page 5: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 5

What is an Operating System?

• Can we use a computer system without an operating system?– We would have to directly interface with the computer hardware.– Pros: speed?, control?– Cons: What if we need to run on a different machine? Or change the network

card? Install a new OS? What if new features like multiprocessors or a cluster is introduced to the program?

• The operating system mediates between application (the airplanes) and the shared resources (the runways and airspace) in a way that provides abstraction and generality for the applications.

Page 6: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

What is an Operating System?

• Trusted software interposed between the hardware and application/utilities to improve efficiency and usability

• Most computing systems have some form of operating systems• Hard to use computer systems without OS

Computer HardwareComputer Hardware

Operating SystemOperating System

Applications and UtilitiesApplications and Utilities

Lec 1 Operating Systems 6

Page 7: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 7

Why Study Them?

• Take a deeper at system architecture• Modular, layered software design• All of our software runs on top of it! It is the common

denominator of everything we write. • How often do you make a syscall? Or invoke some system

library?• Learn to build complex systems• Engineering Issues• Business Issues (OS as a government)• Security (viruses, worms, etc.)

Page 8: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Computer System Organization

• Computer-system operation• One or more CPUs, device controllers connect through common bus

providing access to shared memory• Concurrent execution of CPUs and devices competing for memory cycles

MemoryMemory

CPUCPUCPUCPUCPUCPU Disk ControllerDisk Controller USB ControllerUSB Controller GPUGPU

Lec 1 Operating Systems 8

Page 9: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 9

Operating System Design: Modularity

• Process Control: Threads• Synchronization and Scheduling• Protection, Memory Management, Caching• Demand Paging• File Systems• Networking and Distributed Systems• Protection and Security

Page 10: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 10

One Size Fits All? Requirements Dictate Design

Page 11: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Evolution of the OS• In the beginning... Computers

• Cost millions of $$$

• Were hard to operate (performed using console switches)

• Were hard to program (in particular I/O devices)

Lec 1 Operating Systems 11

Page 12: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Utilizing Expensive Hardware

• Expensive computers could not idle; utilization should be very high

• Batch processing was devised• Programming done offline and subroutine were created for common tasks• I/O and processing overlap obtained via buffering and interrupts

Lec 1 Operating Systems 12

Page 13: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Factors in OS Evolution

• Cost of computers (i.e., computer time)• Cost of people (i.e., user time)

user wait time

com

pu

ter

util

iza

tion

time sharing systems

time sharing systems

early batch systems

early batch systems

personal systems

personal systems

Lec 1 Operating Systems 13

Page 14: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Lec 1 Operating Systems 14

Major OS Functions

Page 15: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Major OS Functions

• Control access and provide interfaces• To the OS and devices attached to the system

• Provide interfaces for human-machine and machine-machine transactions

• Manage resources• Mediate resource usage among different tasks

• Implement policies

Lec 1 Operating Systems 15

Page 16: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Major OS Functions

• Control access and provide interfaces• To the OS and devices attached to the system

• Provide interfaces for human-machine and machine-machine transactions

• Manage resources• Mediate resource usage among different tasks

• Implement policies

• Provide abstractions• Hide the peculiarities of the hardware.

• Example: device independent I/O

• Consume resources• OS runs on the system that is being managed… so it is going to consume

resources!

Lec 1 Operating Systems 16

Page 17: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

What is the Access Problem?

• User wants to access OS, why?• User wants to access devices connected to the system• It all starts with recognizing the user’s intent to access!

Lec 1 Operating Systems 17

Page 18: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Access Problem: Handling I/O

• Programmed I/O• The CPU transfers the data from (or to) the device buffers.

• After issuing an I/O operation the CPU continuously checks (polls) for its completion

Lec 1 Operating Systems 18

Page 19: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Access Problem: Handling I/O• Interrupt-driven I/O (slow speed, character device)

• The CPU issues an I/O operation and goes on; Device notifies (interrupts) the CPU as data arrives; CPU processes the data

Lec 1 Operating Systems 19

Page 20: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

How Does the OS Service Interrupts?

Lec 1 Operating Systems 20

Page 21: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Access Problem: Data Processing

• Once data is captured from device (e.g., keyboard) what is next?

• Imagine you want to write a word processor• Capture some keystrokes – for arrow and other control keys

• Capture words (cooked or raw form?)

Lec 1 Operating Systems 21

Page 22: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Accessing Devices vs. OS Services

• OS interposes itself between the hardware and applications/utilities/users

• Controlling access to OS ---> Controls device access

UserUser OSOS DeviceDevice

Lec 1 Operating Systems 22

Page 23: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

How Do You Control Access to the OS?

• Provides a two level architecture:• Trusted mode

• Untrusted mode

• The OS (at least the core part – called Kernel) runs in the trusted mode

• User applications/utilities run in the untrusted mode

Lec 1 Operating Systems 23

Page 24: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

System Call via Trap

• OS provides system calls for accessing OS services from applications

• System calls are special procedure calls • Control transfer

• Switch protection domain

• System calls also:• Validate the call

• Allow authorized actions to take place

Lec 1 Operating Systems 24

Page 25: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

How are Syscalls Processed?

Lec 1 Operating Systems 25

Page 26: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

UNIX Syscall Examples

• Process control

• fork(), exec(), wait(), abort()

• File manipulation

• chmod(), link(), stat(), creat()

• Device manipulation

• open(), close(), ioctl(), select()

• Information maintenance

• time(), acct(), gettimeofday()

• Communications

• socket(), accept(), send(), recv()

Lec 1 Operating Systems 26

Page 27: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

How Does an OS Manage Resources?

Lec 1 Operating Systems 27

Page 28: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Process: Avatar of the Application• A process represented process table entry

Lec 1 Operating Systems 28

Page 29: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Simple Process Model

• Below is a two-state process model• Running (on the CPU)

• Not running (waiting to get the CPU or at I/O)

Lec 1 Operating Systems 29

Page 30: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Resource Management: Processor Time

• Processor time is the primary resource managed by the OS• How it is managed depends on the type of OS:

• Batch vs Time-sharing

• Uniprogramming vs Multiprogramming

Lec 1 Operating Systems 30

Page 31: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Example: Uniprogramming (only one program running on the system)

What is the CPU Utilization?What is the CPU Utilization?

Lec 1 Operating Systems 31

Page 32: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Example: Multiprogramming(multiple programs simultaneously running)

Lec 1 Operating Systems 32

Page 33: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Comparing System Utilization

Lec 1 Operating Systems 33

Page 34: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Process Scheduling

Lec 1 Operating Systems 34

Page 35: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Process Scheduling: Concerns

Lec 1 Operating Systems 35

Page 36: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Process Scheduling Concerns

• Fairness• Give equal and fair access to resources

• Differential responsiveness• Discriminate among different classes of jobs

• Efficiency• Maximize throughput, minimize response time, and accommodate as many

users as possible

Lec 1 Operating Systems 36

Page 37: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Memory Management

• Memory management is key to multiprogramming

• Memory is a space sharing resource

• Memory management is necessary to protect co-residing programs from each other

• Depending on the occupancy pattern, a program would not know the location until load time

• Memory management should provide:

• Protection

• Relocation

Lec 1 Operating Systems 37

Page 38: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

How Does an OS Manage Memory?

• Idea:

• Divide the memory into partitions and allocate them to different processes

• Partitions can be fixed size or variable size

• A process

• Cannot access memory not allocated to it

• Can request more memory from OS

• Can release already held memory to OS

• May only use a small portion of the allocated memory

Lec 1 Operating Systems 38

Page 39: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

How Does an OS Manage Memory?

• We can load more processes than that fitting the memory• Where do the rest go?

Answer: Virtual MemoryAnswer: Virtual Memory

Lec 1 Operating Systems 39

Page 40: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Virtual Memory in Action

• Some memory chunks (pages) are in memory

• Rest in disk• OS is responsible for

retrieving the pages from and flushing the pages to disk

Lec 1 Operating Systems 40

Page 41: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

To Use Storage, We Need a Filesystem

Lec 1 Operating Systems 41

Page 42: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Storage Management: Component View

Lec 1 Operating Systems 42

Page 43: Lec 1Operating Systems1 Operating Systems Lecture 1: Introduction Review of System Architecture and Concurrent Programming Maxim Shevertalov Jay Kothari

Topics Covered

• Fundamentals (Operating Systems Structures)

• Process Control and Threads

• Synchronization and scheduling

• Protection, Address translation, Caching

• Demand Paging

• File Systems

• Networking and Distributed Systems

• Protection and Security

Lec 1 Operating Systems 43