CS2106 Introduction to OS - GitHub

56
1 CS2106 Introduction to OS Lecture 1

Transcript of CS2106 Introduction to OS - GitHub

1

CS2106Introduction to OS

Lecture 1

Overviewn Operating Systems basic concepts:

q What is OS?q Brief History

n Motivation for OSq Overview of Modern OSes

n Operating System Structuresq OS componentsq Types of kernels

n Virtual Machines2[ CS2106 L1 - AY2122 S2 ]

What is OS?n Incorrect/Incomplete definition:

q It is the desktop when you boot up your PCq The "thing" that stores your gamesq Windows! (or Mac! ) (or Linux!)

n One simple definition:q A program that acts as an intermediary between a computer user

and the computer hardwareq OS manages hardware and software resources and provides

essential services to other programs

3[ CS2106 L1 - AY2122 S2 ]

Illustration: What is an OS?

n A simplified view:q Will be refined as we move along

n The most general version:q Hardware (not only a computer!)q User (can be application programs or an actual person! )

4

Hardware

Operating System

User

[ CS2106 L1 - AY2122 S2 ]

Example of Common OSn On Computer:

q Windows 10/9/8/XPq Mac OS Xq Linux distros: Ubuntu, Redhat, CentOS, Debianq Solaris

n On Smartphone:q iOS, Android, Windows Mobile

n Other hardware with OS:q Game console: PS4, Xbox, Wii U, PSP vista, …q Home appliance: Blueray/DVD Player, Mio TV console, …

5[ CS2106 L1 - AY2122 S2 ]

BRIEF HISTORY OF OSTo invent the future, you must understand the past

6[ CS2106 L1 - AY2122 S2 ]

Brief History of OSn Essentially, OS evolves with:

q Computer hardwareq User application and usage pattern

n The "first" computers:q Electronic Numerical Integrator And Computer (ENIAC)

n 1945n Program controlled by cables and switches

q Harvard Mark I:n 1944n Program controlled by punched paper tape

7[ CS2106 L1 - AY2122 S2 ]

OS for the first computersn OS Type:

q NO OS

8

Hardware

User Program

n Programs directly interact with hardwareq Reprogram by changing physical configuration of hardware

n Advantage:q Minimal overhead

n Disadvantages:q Not portable, inflexibleq Inefficient use of computer resources!

[ CS2106 L1 - AY2122 S2 ]

Mainframes: The "Big Iron"n Commonly used by large corporations in 60s, 70s

n Common features:q No interactive interfaceq Accept programs in the form of:

n Paper tape, magnetic tape, punch card q Support batch processing onlyq Very costly

n Usually "rented" instead of owned

n Example:q IBM 360

n Cost: 5 billion USD in 1964 to develop, 130K to buy

9[ CS2106 L1 - AY2122 S2 ]

OS for Mainframes

n Batch OS:q Execute user program (a.k.a. job) one at a time

n Load job from storage media, execute, collect resultn User Job:

q Still interact with hardware directlyq With additional information for the OS

n Resource requiredn Job specification

10

Hardware

User Program

OS

n OS Type:q Batch OS

[ CS2106 L1 - AY2122 S2 ]

OS for Mainframes: Improvementsn Simple batch processing is inefficient:

q CPU idle when perform I/O

n One possible improvement:q Multiprogramming:

n Loads multiple jobs and runs other jobs when I/O needs to be donen Overlaps computation with I/O

n Another OS development in 1970s:q Time-Sharing OS

11[ CS2106 L1 - AY2122 S2 ]

Time-Sharing OSn Features:

q Allow multiple users to interact with machine using terminals (teletypes)q User job scheduling

n Illusion of Concurrencyq Memory management

n Famous Examples:q CTSS developed at MIT 1960sq Multics (1970s)

n Considered as the parent of Unixq Pushed the state of art in virtual memory, security

n Similar to Unix servers today, but more primitive

12[ CS2106 L1 - AY2122 S2 ]

Time-sharing OS: Illustration

n OS manages the sharing of:q CPU time, memory and storage

n Virtualization of hardware:q Each program executes as if it has all the resources to itself

13

Hardware

UP

OS

UP …. UP

☺ ☺☺ Multiple Users

Programs initiated by user

[ CS2106 L1 - AY2122 S2 ]

Minicomputer and Unixn Minicomputer follows the mainframe:

q A "mini" version of mainframe:n Smaller and cheaper

q Example:n Digital Equipment Corp (DEC) PDP-11

n Famous OS:q Unix

n Developed by AT&T employees, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna

n Ken Thompson and Dennis Ritchieq Invented the C programming language as well!!

14[ CS2106 L1 - AY2122 S2 ]

Personal Computern Apple II PC:

q First successfully produced mass home computerq Designed by Steve Wozniak (alone!)

n IBM PC:q The first generic PCq PC becoming truly a collection of commodity hardware componentsq Leads to dominance of Microsoft OS in PCs: MSDOS then Windows

15[ CS2106 L1 - AY2122 S2 ]

OS on Personal Computern Machine (can be) dedicated to user, not timeshared between

multiple usersq Give rise to personal OS

n Several Models:q Windows model:

n Single user at a time but possibly more than 1 user can accessn Dedicated machine

q Unix model: n One user at the workstation but other users can access remotelyn General time-sharing model

16[ CS2106 L1 - AY2122 S2 ]

MOTIVATION FOR OPERATING SYSTEMSWhy do we need OS?

17[ CS2106 L1 - AY2122 S2 ]

Motivation for OS: Abstractionn Large variation in hardware configurations

n Example (Hard disk):q Different capacity (500MB, 320GB, 1.5TB, etc)q Different capabilities:

n Rotation per minutes (RPM)n Access (read/write) speedn Etc

n However, hardware in the same category has well defined and common functionalityq Example (hard disk): store and retrieve information

18[ CS2106 L1 - AY2122 S2 ]

Motivation for OS: Abstractionn Operating System serves as an abstraction:

q Hide the different low-level detailsq Present the common high-level functionality to users

n Users can perform essential tasks through operating systemq No need to worry about low-level details

n Provides:q Efficiency and portability

19[ CS2106 L1 - AY2122 S2 ]

Motivation for OS: Resource Allocatorn Program execution requires multiple resources:

q CPU, memory, I/O devices etc

n For better utilization of resources, multiple programs should be allowed to execute simultaneously

n OS is a resource allocatorq Manages all resources

n CPU, Memory, Input/Output devices

q Arbitrate potentially conflicting requestsn for efficient and fair resource use

20[ CS2106 L1 - AY2122 S2 ]

Motivation for OS: Control Programn Program can misuse the computer:

q Accidentally: due to coding bugsq Maliciously: virus, malware etc

n Multiple users can share the computer:q Tricky to ensure separate user space

n OS is a control programq Controls execution of programs

n Prevent errors and improper use of the computern Provides security and protection

21[ CS2106 L1 - AY2122 S2 ]

Motivation for OS: Summaryn Manage resources and coordination

q process synchronization, resource sharingn Simplify programming

q abstraction of hardware, convenient servicesn Enforce usage policiesn Security and protectionn User Program Portability:

q Across different hardware n Efficiency

q Sophisticated implementations q Optimized for particular usage and hardware

22[ CS2106 L1 - AY2122 S2 ]

OVERVIEW OF MODERN OSThe families of modern OS

23[ CS2106 L1 - AY2122 S2 ]

Modern OS: Overview

24

PC

Mobile Real-Time Embedded

[ CS2106 L1 - AY2122 S2 ]

OS STRUCTURECommon Architecture for OS

25[ CS2106 L1 - AY2122 S2 ]

Operating System Structuresn We have identified the major capabilities of an OS

q i.e., the specification of the OS

n Let us now consider:q The best way to provides these capabilitiesq i.e., the implementations of the OS

n Operating system structure:q Organization of the various componentsq Important factors:

n Flexibilityn Robustnessn Maintainability

26[ CS2106 L1 - AY2122 S2 ]

Illustration: High level view of OS

n Operating System is essentially a softwareq Runs in kernel mode: Have complete access to all hardware resources

n Other software executes in user modeq With limited (or controlled) access to hardware resources

27

Hardware

Operating System

User Interface

PowerPoint Chrome DOTA

Hardware

Software

Kernel Mode

User Mode

[ CS2106 L1 - AY2122 S2 ]

Illustration: Generic OS Components

n A: OS executing machine instructionsn B: normal machine instructions executed (program/library code)n C: calling OS using system call interfacen D: user program calls library coden E: system processes

q Provide high level services, usually part of OS

28

Hardware

System Processes

OS

Library

User Programs

A B B

C

D

E

C

[ CS2106 L1 - AY2122 S2 ]

OS as a Programn OS is also known as the kernel

q Just another program with some special featuresn Deals with hardware issuesn Provides system call interfacen Special code for interrupt handlers, device drivers

n Kernel code has to be different than normal programs:q no use of system call in kernel code q can’t use normal librariesq no normal I/O

n Consider this:q Normal programs use OS: what does OS use? J

29[ CS2106 L1 - AY2122 S2 ]

Implementing Operating Systemn Programming Language:

q Historically in assembly/machine code

q Now in HLLs:n Especially C/C++

q Heavily hardware architecture dependent

n Common code organization:1. Machine independent HLL2. Machine dependent HLL3. Machine dependent assembly

coden Challenges:

q “No one else” to rely on for nice services

q Debugging is hardq Complexityq Enormous Codebase

30[ CS2106 L1 - AY2122 S2 ]

OS Structuresn Several ways to structure an OS:

q Monolithicq Microkernelq Layeredq Client-Server q Exokernelq Split kernelq etc

n We will cover the first two in details:q They represent the whole range of possibilitiesq Most other approaches are variant or improvement

31[ CS2106 L1 - AY2122 S2 ]

Monolithic OS n Kernel is:

q One BIG special programn Various services and components are integral part

q Good SE principles is still possible with:n modularizationn separation of interfaces and implementation

n This is the traditional approach taken by:q Most Unix variants, Windows NT/XP

n Advantages:q Well understoodq Good performance

n Disadvantages:q Highly coupled componentsq Usually devolved into very complicated internal structure

32[ CS2106 L1 - AY2122 S2 ]

Monolithic Kernel Illustration

33

Hardware

User Programs

OS Process Management

Memory Management File System

Device Driver

System Call Interface

Kernel Mode

User Mode

Generic Architecture of Monolithic OS Components

[ CS2106 L1 - AY2122 S2 ]

Microkernel OSn Kernel is:

q Very small and cleanq Only provides basic and essential facilities:

n Inter-Process Communication (IPC)n Address space managementn Thread managementn etc

n Higher level services: q Built on top of the basic facilitiesq Run as server process outside of the OSq Use IPC to communicate

n Advantages:q Kernel is generally more robust and more extendibleq Better isolation and protection between kernel and high level services

n Disadvantages:q Lower Performance

34[ CS2106 L1 - AY2122 S2 ]

Microkernel Components

35

Hardware

User Programs

OS

Process Management

Memory Management

File System

Device Driver

Kernel Mode

User Mode

Generic Architecture of Microkernel OS Components

IPC Scheduling Interrupt Handler …

[ CS2106 L1 - AY2122 S2 ]

Other Operating System Structuren Layered Systems:

q Generalization of monolithic systemq Organize the components into hierarchy of layers

n Upper layers make use of the lower layersn Lowest layer is the hardwaren Highest layer is the user interface

n Client-Server Modelq Variation of microkernelq Two classes of processes:

n Client process request service from server processn Server Process built on top of the microkerneln Client and Server process can be on separate machine!

36[ CS2106 L1 - AY2122 S2 ]

VIRTUAL MACHINESWays of running OSes

37[ CS2106 L1 - AY2122 S2 ]

Motivation: Why Virtual Machinesn Operating system assumes total control of the hardware:

q What if we want to run several OSes on the same hardware at the same time?

n Operating system is hard to debug / monitor:q How do we observe the working of the OS?q How do we test a potentially destructive implementation?

38[ CS2106 L1 - AY2122 S2 ]

Definition: Virtual Machinen Virtual Machine:

q A software emulation of hardwareq Virtualization of underlying hardware

n Illusion of complete hardware to level above: memory, CPU, hard disk etc…q Normal (primitive) operating system can then run on top of the virtual

machine

n Also known as Hypervisor q Two classes of implementations shown next

39[ CS2106 L1 - AY2122 S2 ]

Type 1 Hypervisor

n Type 1 hypervisor:q Provides individual virtual machines to guest OSesq eg. IBM VM/370

40

Hardware

OS1

UP

Type 1 Hypervisor

OS2 OS3

UPUP UP

[ CS2106 L1 - AY2122 S2 ]

Type 2 Hypervisor

n Type 2 hypervisor OSq Runs in host OS q Guest OS runs inside Virtual Machineq e.g. VMware

41

Hardware

Guest OS

UP

Type 2 Hypervisor

UP UP

Host Operating System

[ CS2106 L1 - AY2122 S2 ]

Summaryn Definition of Operating System

n Roles of Operating System

n Common Operating System families

n Operating System structure

42[ CS2106 L1 - AY2122 S2 ]

Referencen Modern Operating System (4th Edition)

q By Andrew S.Tanenbaumq Published by Pearson

n Operating System Concepts (9th Edition)q By Abraham Silberschatz, Peter Baer Galvin & Greg Gagneq Published by McGraw Hill

43[ CS2106 L1 - AY2122 S2 ]

FYI: MODERN OS FAMILY(AS OF 2016)

44[ CS2106 L1 - AY2122 S2 ]

Modern OS: An Overviewn Several dominant desktop OSes:

q Microsoft Windows familyq Unix and its variantsq Mac OS family

n Specialized OSes:q Real-time OSq Embedded System OSq Mobile OSq Distributed OS

45[ CS2106 L1 - AY2122 S2 ]

Microsoft OS Familyn 16-bit:

q MS-DOS (various versions, v1.0 in 1985)q Windows 1.X – 3.X, Windows 9X, Windows ME (2000)

n 32-bit:q Windows NT (32-bit, v3.1 in 1994)q Windows 2000, XP, 2003, Vista, 7, 8, 10 (2015)

n 64-bit:q Windows XP (2005), Vista, 7, 8, 10 (2015)

n Mostly on PC (Intel Processors) platformsn Proprietary

q some sources available under conditionsn Complex architecture, internals info not widely available

46[ CS2106 L1 - AY2122 S2 ]

Microsoft OS: Complexityn Win NT 3.1: (shipped 1993)

q Dev Team Size: 200q 6 Millions LOC (Line of Code)q Complete build time is 5 hours on ~486/50

n Win 2000: (shipped 1999)q Dev Team Size: 1400q 29 Millions LOC (about 50Gb of disk space)q Complete build time: 8 hours on 4-way PIII Xeon 550 with 50Gb disk and 512k

RAM

n Windows 7: (shipped 2009)q Dev Team Size: ~2500 (split into 25 teams of ~100)q ~40 Millions LOC

47[ CS2106 L1 - AY2122 S2 ]

Unix and its Variantsn Many Unix Variants:

q Unix System V versionsq Berkeley System Distribution (BSD)q Sun Solarisq SGI IRIX, IBM AIX, Digital Unix, HP-UX, ...q Linuxq MacOS X (BSD + Mach + Apple)

n Programming Interface (API) mostly the same, fundamentals aresame but small differences exist

n Simple architecture, internals well understood, good documentation, research papersn Linux + BSD open sourcen Non-proprietary, POSIX standardsn Implementations on many processors architectures:

q x86, powerpc, m68k, mips, arm, sparc, alpha, ...

48[ CS2106 L1 - AY2122 S2 ]

Unix Variants: Rough timeline

49"Unix history-simple" by Eraserhead1, Infinity0, Sav_vas - Levenez Unix History

Diagram, Information on the history of IBM's AIX on ibm.com[ CS2106 L1 - AY2122 S2 ]

Linux Distributions (Distros)n Most popular form of linux OS

q E.g. Ubuntu, Fedora, SuSe, BSD, Debian, CentOS, etc

n Essentially a software collection with:q Linux kernelq Common software:

n Desktop management, browser, media player etc

q Development tools/librariesn gnu libraries, compilers etc

q Device driversq Package manager

50[ CS2106 L1 - AY2122 S2 ]

Mackintosh OS Timeline

51[ CS2106 L1 - AY2122 S2 ]

Characteristics of Modern PC OSn Multitasking:

q Concurrent execution of programsn On multiple cores

n Multi/single user: q Unix usually multi-userq Windows usually single-user at a time

n Wide range of computer hardware: q Single PC/notebook q Shared memory systems with 10-100s of processors q Machine clusters with 100-1000s of processors q Distributed computing on Internet with >10K machines

52[ CS2106 L1 - AY2122 S2 ]

Real Time OSn OS for computer systems with time constraints:

q periodicity, deadlines

n Examples: q Critical Systems: aircraft flight system, nuclear power plant, radar systemq Consumer appliances: mobile phones, mp3, video players

n Hard real time: q Timing requirements must be respected, eg. control system

n Soft real time: q Some timing constraints can be missed

n May need formally verified systems

53[ CS2106 L1 - AY2122 S2 ]

Embedded OSn OS for specialized devices and appliances

n Examples: q (Older) Smartphones, microwave oven, car, smart cards, game consoles,

etc

n Special consideration required for:q power usage, real-time requirement and memory limitations

n Usually:q Not general purpose: cannot run any applicationq Cannot be modified: Mostly stored in Read-Only Memory (ROM)

54[ CS2106 L1 - AY2122 S2 ]

Mobile OSn OS for smartphones, tablets, PDAs, or other mobile devices

n Examples:q Android, iOS, Windows Phone, etc.

n Characteristics:q Essentially a customized version of PC OSq Common features: Touchscreen, Cellular, (Video) Camera, etc…

55[ CS2106 L1 - AY2122 S2 ]

Distributed OSn OS for computers/processors connected using network

q Loosely or Tightly coupled

n Loosely coupled: q Autonomous nodes, network may be wide areaq Communication is asynchronous q Reliability issues:

n communication may not be reliable, nodes may failq Resources are distributed

n eg., distributed filesystem, P2P storage

n Tightly coupled:q Specialized node (e.g., Computing nodes) that shares other resources (e.g. Memory /

Harddisk etc), nodes in close proximityq Examples:

n Tembusu2 cluster compute nodes: q ~100 Intel Xeon nodes running CentOS

56[ CS2106 L1 - AY2122 S2 ]