64
1 Agustin Araya CS149 Operating Systems

1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

Embed Size (px)

Citation preview

Page 1: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

1

Agustin Araya

CS149

Operating Systems

Page 2: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

2

...

• Running programs

==> Process management

• Managing main memory

==> Memory management

• Manipulating files (... hard disk)

==> Storage management

What Are the Major Pieces of Functionality of an OS?

Page 3: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

3

• Dealing with I/O devices (e.g., printers, keyboard...)

==> Managing I/O systems

• Providing security

• Dealing with distributed systems

(Cont.)

Page 4: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

4

What is an Operating System?

• A program that acts as an intermediary between a user of a computer and the computer hardware

Page 5: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

5

Operating System Goals

1 To execute user programs and make it easy for the user to solve problems (with the help of a computer)

...another way of saying it: make the computer system convenient to use

2 To use the computer hardware in an efficient manner

Page 6: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

6

A Look Behind the Scene...

|

Page 7: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

7

A Look Behind the Scene...

|

Page 8: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

8

A Look Behind the Scene...

|OS

Page 9: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

9

What Do We Mean by a Computer System?

• We just said that a goal of an OS is to make computer systems easy to use...

• But what is a computer system?

Page 10: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

10

(Cont.)

• A computer system consists of four major components...

• Hardware• provides basic computing resources• e.g.: CPU, memory, I/O devices

• Operating system• controls and coordinates use of hardware

among various applications and users

Page 11: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

11

(Cont.)

• System and Application programs

...define the ways in which the system resources are used to solve the computing problems of the users

...e.g.: word processors, compilers, web browsers, database systems, video games

• Users• e.g.: people, machines, other computers

Page 12: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

12

The Four Components of a Computer System

Page 13: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

13

Page 14: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

14

Important design issue: what to put in the OS and what to leave as system program

Page 15: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

15

Unix systems: small OS...

Microsoft's OSs: very large OS...

Page 16: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

16

Operating System Definitions

• OS is a resource allocator• manages all resources• decides between conflicting requests for

efficient and fair resource use• OS is a control program

• controls execution of programs to prevent errors and improper use of the computer

Page 17: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

17

• OS is a resource allocator• manages all resources• decides between conflicting requests for efficient

and fair resource use• OS is a control program

• controls execution of programs to prevent errors and improper use of the computer

Operating System DefinitionsE.g.: several programs need to run. They compete for the CPU, for memory

Page 18: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

18

(Cont.)

• No universally accepted definition of what an OS is composed of

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

• Another definition: The OS is “the one program running at all times on the computer” (the kernel)• everything else is either a system program

(ships with the operating system) or an application program

Page 19: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

19

What should be part of the kernel?

Should the kernel be as small as possible (a micro-kernel)?

Page 20: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

20

• A user using a personal computer (PC)...

• A user using a mainframe

• by means of a terminal

• other users are simultaneously connected

• A user using a workstation, more powerful than a PC

• connected to servers

• some resources are shared (e.g., print servers)

• A user using a PDA (personal digital assistant)

Different Situations

Page 21: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

21

• A user using a personal computer (PC)...

• A user using a mainframe

• by means of a terminal

• other users are simultaneously connected

• A user using a workstation, more powerful than a PC

• connected to servers

• some resources are shared (e.g., print servers)

• A user using a PDA (personal digital assistant)

Different Situations which are the OS goals for each situation?

Page 22: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

22

• A user using a personal computer (PC)...

• A user using a mainframe

• by means of a terminal

• other users are simultaneously connected

• A user using a workstation, more powerful than a PC

• connected to servers

• some resources are shared (e.g., print servers)

• A user using a PDA (personal digital assistant)

Different Situationsease of use(+resource utilization)

Page 23: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

23

• A user using a personal computer (PC)...

• A user using a mainframe

• by means of a terminal

• other users are simultaneously connected

• A user using a workstation, more powerful than a PC

• connected to servers

• some resources are shared (e.g., print servers)

• A user using a PDA (personal digital assistant)

Different Situations

maximize resource utilization

S

Page 24: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

24

• A user using a personal computer (PC)...

• A user using a mainframe

• by means of a terminal

• other users are simultaneously connected

• A user using a workstation, more powerful than a PC

• connected to servers

• some resources are shared (e.g., print servers)

• A user using a PDA (personal digital assistant)

Different Situations

ease of use and resource utilization

S

Page 25: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

25

• A user using a personal computer (PC)...

• A user using a mainframe

• by means of a terminal

• other users are simultaneously connected

• A user using a workstation, more powerful than a PC

• connected to servers

• some resources are shared (e.g., print servers)

• A user using a PDA (personal digital assistant)

Different Situations

ease of use, battery performance

S

Page 26: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

26

==>

Different situations lead to different OS goals

(Cont.)

Page 27: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

27

• Background knowledge for understanding OSs...

• Review of some basic concepts in computer organization

Computer System Organization

Page 28: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

28

Computer System Organization (the h/w components)

Page 29: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

29

Computer System Organization (the h/w components)The OS is a

program that manages these components

Page 30: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

30

Computer System Organization (the h/w components)From an OS point

of view, we are interested in an abstract view of these components

Page 31: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

31

Computer System Organization

devicecontrollers(hardware)

Page 32: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

32

Computer System OrganizationThe OS interactswith the controllers, rather than with the devices themselves

Page 33: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

33

Computer System Organization

execute concurrentlyexecute concurrently

Page 34: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

34

(Cont.)

• Computers have evolved toward increasing concurrency

• because it leads to higher resource utilization

Page 35: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

35

Computer System Organization

Bus

Page 36: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

36

Computer System Organization

shared memory

Page 37: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

37

• Suppose a program requests to read (or write) data from (to) a file

• How is the information transferred from the file (in hard disk) to the appropriate addresses of the memory allocated to the program (or vice versa)?

• The OS will perform key steps of this process...

Note: In this context, interactions with I/O devices refer to interactions with I/O device controllers

Interactions of the I/O Devices withCPU (Processor), Memory, and OS

Page 38: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

38

• If the user (who activated the program) can only read the file, but not write on it

...the OS needs to ensure the program can only use the appropriate functionality of the I/O device

• The OS does not allow the program to directly access the device

...rather, it provides appropriate commands (abstractions)

...and corresponding routines for executing those commands on the I/O device

OS Responsibilities with Respect to I/O Devices

Page 39: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

39

• The OS must give commands to the I/O devices to perform the desired operations

• At the same time, the OS needs to deal with the interrupts triggered by the I/O devices

...it is through interrupts that those devices communicate with the OS

...e.g., to indicate that an operation terminated or that an error occurred

• Finally, the transfer of data between the device and memory must take place...

(Cont.)

Page 40: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

40

1 By means of memory-mapped I/O

...certain parts of the address space have been assigned to I/O devices (rather than to memory)

...so, if such an address is put in the bus, the corresponding device controller records it and passes it to the device as a command

In other words, commands to the I/O devices are given by reading and writing on those addresses...

How the OS Gives Commands to I/O Devices.Different Approaches

Page 41: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

41

2 Or, by means of specific I/O instructions in the processor

• (see next slide)

(Cont.)

Page 42: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

42

• Example: a basic printer that prints only one character at a time

• The status register of the printer has:

• a ‘done’ bit: set to 1 when the printer has printed a character

• an ‘error’ bit: set to 1 to indicate there is a problem with the printer

• e.g.: no paper...

Communication Between the Processorand the I/O Device

Page 43: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

43

• The data register of the printer contains the character to be printed

• Before passing the next character to be printed the processor must check (poll) the status register...

(Cont.)

Page 44: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

44

• Polling: “periodically checking status bits to see if it is time for the next I/O operation”

• But polling has a problem

• what is it?

...

...the processor wastes time checking the status

• What is the alternative approach to polling?

...

...interrupts...

(Cont.)

Page 45: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

45

Interrupt Mechanism

• Varies with different computers, but the basic functionality is similar

• Events requiring immediate attention from the processor are indicated by means of an interrupt

• Example: an I/O interrupt... ...the device controller informs the CPU that it has

finished its operation by sending a signal through the bus

Page 46: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

46

• The CPU must pay immediate attention to the interrupt

• The processors' fetch-execute cycle checks to see if an "interrupt flag" has been set

• For different interrupts, the CPU must do something different

• This is achieved by the CPU activating the appropriate interrupt service routine

(see next slide)

(Cont.)

Page 47: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

47

• An interrupt vector (a table...) containing the addresses of each of those service routines is used

• it is stored in memory (e.g., in the first 100 locations)

• When an interrupt is sent, an appropriate index into the interrupt vector is given with it

• ...in this way the address of the corresponding service routine is obtained

• and the service routine is activated

How the CPU reacts to the interrupt?

Page 48: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

48

• After servicing the interrupt the CPU should continue doing what it was doing earlier...

• Hence, it must save the address of the instruction the CPU was executing when interrupted

(Cont.)

Page 49: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

49

• ...the printer that prints one character at a time...

• First, the CPU sends the character to be printed to the printer

• Second, the printer prints it

• Third, the printer sends an I/O interrupt to the CPU

• Fourth, the CPU activates the interrupt service routine to handle the interrupt...

Coming back to the example of the simple printer(Now using interrupts)

Page 50: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

50

• Device controllers play a role in transferring data between I/O devices and memory

• The device controller (a piece of h/w) has:

• special-purpose registersand

• buffer storage

• ...and it is in charge of transferring data between the I/O device and its own buffer

• The OS interacts with the device controller by means of a device driver (a piece of software)

A More Detailed Analysis

Page 51: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

51

• The I/O operation starts with the device driver putting appropriate info’ in the device controller’s registers

• Depending on the info’ the controller moves the data from the device (e.g., a hard disk) to its own buffer (or vice versa)

• By means of an interrupt, the device controller informs the device driver that the operation ended

• If the operation was a read, the OS would then proceed to transfer the data from the controller’s buffer to memory

(Cont.)

Page 52: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

52

Issue:

• This approach based on interrupts could produce too much overhead if the amount of data to be transferred is large

• That is, the CPU becomes too directly involved in the I/O transference

Alternative approach:

• ‘direct memory access’...(see next slide)

(Cont.)

Page 53: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

53

• The device controller itself transfers the data between its own buffer and memory!

• the CPU does not intervene

• The data is transferred in blocks (rather than in bytes)

• when the transfer has concluded, the device controller sends an interrupt to the device driver

• In this way, far fewer interrupts are generated and the CPU can do other things

Direct Memory Access

Page 54: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

54

Simplified Interactions

CPU Memory

Device

I/O requestinterrupt direct

memory access

data transfers

Page 55: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

55

• Fast storage is expensive and volatile

• Slow storage is cheap and non-volatile

• CPU registers

• Cache memory (memory buffer within the CPU)

• Main Memory (Memory/Random access mem.)

• Magnetic disk

• Magnetic tapes

Hierarchy of Storage Devices

Page 56: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

56

• Fast storage is expensive and volatile

• Slow storage is cheap and non-volatile

• CPU registers

• Cache memory (memory buffer within the CPU)

• Main Memory (Memory/Random access mem.)

• Magnetic disk

• Magnetic tapes

Hierarchy of Storage Devices

less expensive

S

Page 57: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

57

• Fast storage is expensive and volatile

• Slow storage is cheap and non-volatile

• CPU registers

• Cache memory (memory buffer within the CPU)

• Main Memory (Memory/Random access mem.)

• Magnetic disk

• Magnetic tapes

Hierarchy of Storage Devices

volatile

S

Page 58: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

58

• Fast storage is expensive and volatile

• Slow storage is cheap and non-volatile

• CPU registers

• Cache memory (memory buffer within the CPU)

• Main Memory (Memory/Random access mem.)

• Magnetic disk

• Magnetic tapes

Hierarchy of Storage Devices

volatile

non-volatile

S

Page 59: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

59

• The instruction-execution cycle...

• etc

Other Basic Concepts S

Page 60: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

60

• We have been talking about the basic components of a computer and their interactions

• Now we will say a word about how those components can be put together

==> Computer architecture

So far... S

Page 61: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

61

• Single processor

• Multi-processor

• increased throughput

• increased reliability

Computer Architecture S

Page 62: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

62

• Symmetric multi-processing

• all processors are the same, with the same responsibilities

• Asymmetric multi-processing

• there is a master processor

• the rest of the processors perform specific tasks, and follow the orders of the master

(Cont.) S

Page 63: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

63

Summary.Important Concepts

• Operating system goals• Components of a Computer System• What is an OS• Different kinds of Computer Systems• (personal computer, mainframe,

handheld...)• Computer System organization• Interactions of the I/O Devices with

CPU (Processor), Memory, and OS

Page 64: 1 Agustin Araya CS149 Operating Systems. 2... Running programs ==> Process management Managing main memory ==> Memory management Manipulating files (

64

Summary.Important Concepts

• Interrupt Mechanism• Direct Memory Access• Hierarchy of Storage Devices• Computer architecture: single- and multi-

processing