chap1

48
Operating Systems Introduction Xiaoyu Zhang 1

Upload: adisi

Post on 21-Nov-2014

212 views

Category:

Education


4 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Chap1

Operating SystemsIntroduction

Xiaoyu Zhang

1

Page 2: Chap1

Computing Devices Everywhere

2

Page 3: Chap1

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

3

Page 4: Chap1

How do we tame complexity?• Every piece of computer hardware different– Different CPU

• Pentium, PowerPC, MIPS, …– Different amounts of memory, disk, …– Different types of devices

• Mice, Keyboards, Sensors, Cameras, Fingerprint readers– Different networking environment

• Cable, DSL, Wireless, Firewalls,…

• Questions:– Does the programmer need to write a single program

that performs many independent activities?– Does every program have to be altered for every piece

of hardware?– Does a faulty program crash everything?– Does every program have access to all hardware?

4

Page 5: Chap1

Four Components of a Computer System

An operating system is the interface between the user and the hardware.

Definition: An operating system implements a virtual machine that is (hopefully) easier and safer to program and use than the raw hardware.

5

Page 6: Chap1

Operating System

• Services (Resource management): The OS provides standard services (the interface) which the hardware implements. These services include the file system, virtual memory, networking, CPU scheduling, etc.

• Coordination (Control): The OS coordinates multiple applications and users to achieve fairness and efficiency (throughput). Examples: concurrency, protection, networking, and security.

• The OS design goal is to make the machine convenient to use (a software engineering problem) and efficient (a system and engineering problem).

Application

Operating System

HardwarePhysical Machine Interface

Virtual Machine Interface

6

Page 7: Chap1

Virtual Machines: Layers of OSs• Useful for OS development

– When OS crashes, restricted to one VM– Can aid testing programs on other OSs

7

Page 8: Chap1

Virtual Machines• Software emulation of an abstract machine– Make it look like hardware has features you want– Programs from one hardware & OS work on another one

• Programming simplicity– Each process thinks it has all memory/CPU time– Each process thinks it owns all devices– Different Devices appear to have same interface– Device Interfaces more powerful than raw hardware

• Bitmapped display windowing system• Ethernet card reliable, ordered, networking (TCP/IP)

• Fault Isolation– Processes unable to directly impact other processes– Bugs cannot crash whole machine

• Protection and Portability

8

Page 9: Chap1

Summary of Operating System Principles

• OS as juggler: providing the illusion of a dedicated machine with infinite memory and CPU.

• OS as government: protecting users from each other, allocating resources efficiently and fairly, and providing secure and safe communication.

• OS as complex system: keeping OS design and implementation as simple as possible is the key to getting the OS to work.

• OS as history teacher: learning from past to predict the future, i.e., OS design tradeoffs change with technology.

9

Page 10: Chap1

What is an Operating System,… Really?

• Most Likely:– Memory Management– I/O Management– CPU Scheduling– Communications? (Does Email belong in OS?)

• What about?– File System?– Multimedia Support?– User Interface?– Internet Browser?

• Is this only interesting to Academics??

10

Page 11: Chap1

Operating System Definition (cont)• No universally accepted definition

• “Everything a vendor ships when you order an operating system” is good approximation– But varies wildly

• “The one program running at all times on the computer” is the kernel. Everything else is either a system program (ships with the operating system) or an application program

11

Page 12: Chap1

Why Study Operating Systems?

• Abstraction: How to get the OS to give users an illusion of infinite memory, CPUs, resources, world wide computing, etc.

• System Design: How to make tradeoffs between – performance and the convenience of OS abstractions, – performance and the simplicity of OS design, and – putting functionality in hardware or software.

• As systems change the OS must adapt (e.g., new hardware, software).

12

Page 13: Chap1

Why Study Operating Systems?• The operating system makes the computer work - it is a key

abstraction layer for applications. • Understanding operating systems will enable you to use your

computer more effectively. They are an excellent example of system design issues whose results and ideas you will apply in all aspects of experimental computer science.

• Background: To understand this course you must have a solid basic understanding of hardware (CS 331: CPU instruction sets, memory hierarchies, I/O systems, etc.) and solid programming skills (complex data structures, debugging, etc., e.g. what you learned in CS 311)

• Obviously, you cannot understand the implications of how components intersect without understanding the components.

13

Page 14: Chap1

What if we didn’t have an Operating System?

• Source CodeCompilerObject CodeHardware• How do you get object code onto the hardware?• How do you print out the answer?• Once upon a time, had to Toggle in program in

binary and read out answer from LED’s!

Altair 808014

Page 15: Chap1

Simple OS: What if only one application?

• Examples:– Very early computers– Early PCs– Embedded controllers (elevators, cars, etc)

• OS becomes just a library of standard services– Standard device drivers– Interrupt handlers– Math libraries

15

Page 16: Chap1

MS-DOS Layer Structure

16

Page 17: Chap1

More complex OS: Multiple Apps

• Full Coordination and Protection– Manage interactions between different users– Multiple programs running simultaneously– Multiplex and protect Hardware Resources

• CPU, Memory, I/O devices like disks, printers, etc

• Facilitator– Still provides Standard libraries, facilities

• Would this complexity make sense if there were only one application that you cared about?

17

Page 18: Chap1

Interrupt Driven O.S.• Most modern operating systems are interrupt driven.

– Start-up: 1) Load O.S. (kernel) and start it running.– 2) O.S. waits for an event (an interrupt).

• Definition of interrupt:– An interrupt is a method to ensure that the CPU takes note of an

event.

• Types of interrupt:– Hardware interrupts (e.g. from an I/O device)– Software interrupt (from an executing process. System Call)

• Also called a trap or an exception• Generated to signal error (e.g. divide by zero)• or to request service from OS (e.g. I/O).

Page 19: Chap1

Interrupt Handling

• The operating system preserves the state of the CPU by storing registers and the program counter.

• The O.S. determines which type of interrupt has occurred.– Separate segments of code determine what action should

be taken for each type of interrupt.• The OS executes the sequence of commands

associated with the given interrupt.• The OS recovers the stored information from the

original process and continues execution.

Page 20: Chap1

Example: Protecting Processes from Each Other

• Problem: Run multiple applications in such a way that they are protected from one another

• Goal: – Keep User Programs from Crashing OS– Keep User Programs from Crashing each other– [Keep Parts of OS from crashing other parts?]

• (Some of the required) Mechanisms:– Address Translation– Dual Mode Operation

• Simple Policy:– Programs are not allowed to read/write memory of other

Programs or of Operating System

20

Page 21: Chap1

CPU MMU

VirtualAddresses

PhysicalAddresses

Address Translation• Address Space

– A group of memory addresses usable by something – Each program (process) and kernel has potentially different

address spaces.• Address Translation:

– Translate from Virtual Addresses (emitted by CPU) into Physical Addresses (of memory)

– Mapping often performed in Hardware by Memory Management Unit (MMU)

21

Page 22: Chap1

Example of Address Translation

Prog 1Virtual

AddressSpace 1

Prog 2Virtual

AddressSpace 2

CodeDataHeapStack

CodeDataHeapStack

Data 2

Stack 1

Heap 1

OS heap & Stacks

Code 1

Stack 2

Data 1

Heap 2

Code 2

OS code

OS dataTranslation Map 1 Translation Map 2

Physical Address Space 22

Page 23: Chap1

Dual Mode Operation• Hardware provides at least two modes:

– “Kernel” mode (or “supervisor” or “protected”)– “User” mode: Normal programs executed

• Some instructions/ops prohibited in user mode:– Example: cannot modify page tables in user mode

• Attempt to modify Exception generated • Transitions from user mode to kernel mode:

– System Calls, Interrupts, Other exceptions

24

Page 24: Chap1

UNIX System Structure

User Mode

Kernel Mode

Hardware

Applications

Standard Libs

25

Page 25: Chap1

“In conclusion…”• Operating systems provide a virtual machine

abstraction to handle diverse hardware• Operating systems simplify application

development by providing standard services • Operating systems coordinate resources and

protect users from each other• Operating systems can provide an array of fault

containment, fault tolerance, and fault recovery

26

Page 26: Chap1

Moore’s Law Change Drives OS Change

Typical academic computer 1981 vs 2006

0.2$4,000$25,000

0.1 110s

23216

110,0001 Gb/s9600 b/s

100,0001TB10MB

32,7684GB128KB

1,280

6—40

3200x4

0.25—0.5

10

3—10

Factor20061981

Price

#users/machine

# addr bits

Net bandwidth

Disk capacity

DRAM capacity

CPU MHz,

Cycles/inst

27

Page 27: Chap1

Moore’s law effects• Nothing like this in any other area of business• Transportation in over 200 years:

– 2 orders of magnitude from horseback @10mph to Concorde @1000mph

– Computers do this every decade!• What does this mean for us?

– Techniques have to vary over time to adapt to changing tradeoffs• I place a lot more emphasis on principles

– The key concepts underlying computer systems– Less emphasis on facts that are likely to change over the next few

years…• Let’s examine the way changes in $/MIPS has radically

changed how OS’s work

28

Page 28: Chap1

Dawn of timeENIAC: (1945—1955)

• “The machine designed by Drs. Eckert and Mauchly was a monstrosity. When it was finished, the ENIAC filled an entire room, weighed thirty tons, and consumed two hundred kilowatts of power.”

• http://ei.cs.vt.edu/~history/ENIAC.Richey.HTML29

Page 29: Chap1

History Phase 1 (1948—1970)Hardware Expensive, Humans Cheap• When computers cost millions of $’s, optimize for

more efficient use of the hardware!– Lack of interaction between user and computer

• User at console: one user at a time• Batch monitor: load program, run, print

• Optimize to better use hardware– When user thinking at console, computer idleBAD!– Feed computer batches and make users wait

• No protection: what if batch program has bug?

30

Page 30: Chap1

History Phase 1½ (late 60s/early 70s)• Data channels, Interrupts: overlap I/O and compute

– DMA – Direct Memory Access for I/O devices– I/O can be completed asynchronously

• Multiprogramming: several programs run simultaneously– Small jobs not delayed by large jobs– More overlap between I/O and CPU– Need memory protection between programs and/or OS

• Complexity gets out of hand: – Multics: announced in 1963, ran in 1969

• 1777 people “contributed to Multics” (30-40 core dev)• Turing award lecture from Fernando Corbató (key researcher): “On

building systems that will fail”– OS 360: released with 1000 known bugs (APARs)

• “Anomalous Program Activity Report”• OS finally becomes an important science:

– How to deal with complexity???– UNIX based on Multics, but vastly simplified

31

Page 31: Chap1

History Phase 2 (1970 – 1985)Hardware Cheaper, Humans Expensive• Computers available for tens of thousands of dollars instead of millions• OS Technology maturing/stabilizing• Interactive timesharing:

– Use cheap terminals (~$1000) to let multiple users interact with the system at the same time

– Sacrifice CPU time to get better response time– Users do debugging, editing, and email online

• Problem: Thrashing– Performance very non-linear

response with load– Thrashing caused by many

factors including• Swapping, queueing

Users

Resp

on

se

time

32

Page 32: Chap1

History Phase 3 (1981— )Hardware Very Cheap, Humans Very Expensive• Computer costs $1K, Programmer costs $100K/year– If you can make someone 1% more efficient by giving

them a computer, it’s worth it!– Use computers to make people more efficient

• Personal computing: – Computers cheap, so give everyone a PC

• Limited Hardware Resources Initially:– OS becomes a subroutine library– One application at a time (MSDOS, CP/M, …)

• Eventually PCs become powerful:– OS regains all the complexity of a “big” OS– multiprogramming, memory protection, etc (NT,OS/2)

• Question: As hardware gets cheaper does need for OS go away?

33

Page 33: Chap1

History Phase 3 (con’t)Graphical User Interfaces

• Xerox Star: 1981– Originally a research

project (Alto)– First “mice”, “windows”

• Apple Lisa/Machintosh: 1984– “Look and Feel” suit 1988

• Microsoft Windows:– Win 1.0 (1985)– Win 3.1 (1990)– Win 95 (1995)– Win NT (1993)– Win 2000 (2000)– Win XP (2001)– Win Vista (2007)

Xero

x S

tar

Win

dow

s 3

.1

34

Page 34: Chap1

History Phase 4 (1989—): Distributed Systems

• Networking (Local Area Networking)– Different machines share resources– Printers, File Servers, Web Servers– Client – Server Model

• Services– Computing– File Storage

35

Page 35: Chap1

History Phase 5 (1995—): Mobile Systems

• Ubiquitous Mobile Devices– Laptops, PDAs, phones– Small, portable, and inexpensive

• Recently twice as many smart phones as PDAs• Many computers/person!

– Limited capabilities (memory, CPU, power, etc…)• Wireless/Wide Area Networking

– Leveraging the infrastructure– Huge distributed pool of resources extend devices– Traditional computers split into pieces. Wireless keyboards/mice,

CPU distributed, storage remote• Peer-to-peer systems

– Many devices with equal responsibilities work together– Components of “Operating System” spread across globe

36

Page 36: Chap1

History of OS: Summary• Change is continuous and OSs should adapt– Not: look how stupid batch processing was– But: Made sense at the time

• Situation today is much like the late 60s [poll]– Small OS: 100K lines– Large OS: >10M lines (5M for the browser!)

• 100-1000 people-years• Complexity still reigns– NT under development from early 90’s to late 90’s

• Never worked very well– Jury still out on Windows 2000/XP– Windows Vista (aka “Longhorn”) delayed many times

• Latest release date of 2005, 2006, 2007 (finally)

37

Page 37: Chap1

Now for a quick tour of OS Structures

38

Page 38: Chap1

Operating System Structure• Multiprogramming needed for efficiency

– Single user cannot keep CPU and I/O devices busy at all times– Multiprogramming organizes jobs (code and data) so CPU always has one to

execute– A subset of total jobs in system is kept in memory– One job selected and run via job scheduling– When it has to wait (for I/O for example), OS switches to another job

• Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing– Response time should be < 1 second– Each user has at least one program executing in memory process– If several jobs ready to run at the same time CPU scheduling– If processes don’t fit in memory, swapping moves them in and out to run– Virtual memory allows execution of processes not completely in memory

39

Page 39: Chap1

Operating System Services(What things does the OS do?)

• Services that (more-or-less) map onto components– Program execution

• How do you execute concurrent sequences of instructions?– I/O operations

• Standardized interfaces to extremely diverse devices– File system manipulation

• How do you read/write/preserve files?• Looming concern: How do you even find files???

– Communications• Networking protocols/Interface with CyberSpace?

• Control capabilities– Error detection & recovery– Resource allocation– Accounting– Protection

40

Page 40: Chap1

Operating Systems Components(What are the pieces of the OS)

• Process Management• Main-Memory Management• I/O System management• File Management• Networking• User Interfaces

41

Page 41: Chap1

Process Management• A process is a program in execution. It is a unit of work within the system.

Program is a passive entity, process is an active entity.• Process needs resources to accomplish its task

– CPU, memory, I/O, files– Initialization data

• Process termination requires reclaim of any reusable resources• Single-threaded process has one program counter specifying location of

next instruction to execute– Process executes instructions sequentially, one at a time, until

completion• Multi-threaded process has one program counter per thread• Typically system has many processes, some user, some operating system

running concurrently on one or more CPUs– Concurrency by multiplexing the CPUs among the processes / threads

42

Page 42: Chap1

Process Management ActivitiesThe operating system is responsible for the following

activities in connection with process management:• Creating and deleting both user and system

processes• Suspending and resuming processes• Providing mechanisms for process synchronization• Providing mechanisms for process communication• Providing mechanisms for deadlock handling

43

Page 43: Chap1

Memory Management• All data in memory before and after processing• All instructions in memory in order to execute• Memory management determines what is in memory

when– Optimizing CPU utilization and computer response to users

• Memory management activities– Keeping track of which parts of memory are currently

being used and by whom– Deciding which processes (or parts thereof) and data to

move into and out of memory– Allocating and deallocating memory space as needed

44

Page 44: Chap1

Storage Management• OS provides uniform, logical view of information storage

– Abstracts physical properties to logical storage unit - file– Each medium is controlled by device (i.e., disk drive, tape drive)

• Varying properties include access speed, capacity, data-transfer rate, access method (sequential or random)

• File-System management– Files usually organized into directories– Access control on most systems to determine who can access what– OS activities include

• Creating and deleting files and directories• Primitives to manipulate files and dirs• Mapping files onto secondary storage• Backup files onto stable (non-volatile) storage media

45

Page 45: Chap1

Mass-Storage Management• Usually disks used to store data that does not fit in main memory or data that

must be kept for a “long” period of time.• Proper management is of central importance• Entire speed of computer operation hinges on disk subsystem and its algorithms• OS activities

– Free-space management– Storage allocation– Disk scheduling

• Some storage need not be fast– Tertiary storage includes optical storage, magnetic tape– Still must be managed– Varies between WORM (write-once, read-many-times) and RW (read-write)

46

Page 46: Chap1

I/O Subsystem• One purpose of OS is to hide peculiarities of

hardware devices from the user• I/O subsystem responsible for– Memory management of I/O including

• buffering (storing data temporarily while it is being transferred),

• caching (storing parts of data in faster storage for performance),

• spooling (the overlapping of output of one job with input of other jobs)

– General device-driver interface– Drivers for specific hardware devices

47

Page 47: Chap1

Protection and Security• Protection – any mechanism for controlling access of

processes or users to resources defined by the OS• Security – defense of the system against internal and external

attacks– Huge range, including denial-of-service, worms, viruses, identity

theft, theft of service• Systems generally first distinguish among users, to determine

who can do what– User identities (user IDs, security IDs) include name and associated

number, one per user– User ID then associated with all files, processes of that user to

determine access control– Group identifier (group ID) allows set of users to be defined and

controls managed, then also associated with each process, file– Privilege escalation allows user to change to effective ID with more

rights

48

Page 48: Chap1

Conclusion• Rapid Change in Hardware Leads to changing OS– Batch Multiprogramming Timeshare Graphical

UI Ubiquitous Devices Cyberspace/Metaverse/??• OS features migrated from mainframes PCs• Standard Components and Services– Process Control– Main Memory– I/O– File System– UI

• Complexity is always out of control– However, “Resistance is NOT Useless!”

49