02.Os Structure

61
Computer System Architecture (Software) Chapter 2. Operating System structure Spring 2008 Guo Xunhua

description

Operating System

Transcript of 02.Os Structure

Page 1: 02.Os Structure

Computer System Architecture (Software)

Chapter 2. Operating System structure

Spring 2008Guo Xunhua

Page 2: 02.Os Structure

2Guo, Xunhua

Operating System Structure

Computer hardware structure

System calls

System programs

Operating system components

Page 3: 02.Os Structure

Computer hardware structure

Page 4: 02.Os Structure

4Guo, Xunhua

Computer hardware

Page 5: 02.Os Structure

5Guo, Xunhua

Hardware Architecture(Storage Centric)

Page 6: 02.Os Structure

6Guo, Xunhua

Hardware Architecture(Bus-based)

Input Devices

Output Devices

... ...

... ...

... ...

... ...

... ...

... ...

CPU

Arithmetric-Logic UnitControl Unit

Primary Storage

SecondaryStorage

CommunicationDevices

... ...

... ...

... ...

BUS

... ...

... ...

... ...

Page 7: 02.Os Structure

7Guo, Xunhua

Hardware components

Central Processing Unit (CPU)Control UnitArithmetic-Logic Unit

StoragePrimary StorageSecondary Storage

Input/Output Devices (Including Communication Devices)

Page 8: 02.Os Structure

8Guo, Xunhua

Computer hardware operation

I/O devices and the CPU can execute concurrently.Each device controller is in charge of a particular device type.Each device controller has a local buffer.CPU moves data from/to main memory to/from the local buffers.I/O is from the device to local buffer of controller.Device controller informs CPU that it has finished its operation by causing an interrupt.

Moni tor

Bus

Page 9: 02.Os Structure

9Guo, Xunhua

Common Functions of InterruptsInterrupt transfers control to the interrupt service routine

interrupt vector contains the addresses of all the service routines.

Interrupt architecture must save the address of the interrupted instruction.Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.A trap is a software-generated interrupt caused either by an error or a user request.An operating system is interrupt driven.

Page 10: 02.Os Structure

10Guo, Xunhua

Interrupts

(a) Steps in starting an I/O device and getting interrupt

(b) How the CPU is interrupted

(a) (b)

Page 11: 02.Os Structure

11Guo, Xunhua

Interrupt time line

Page 12: 02.Os Structure

12Guo, Xunhua

Synchronous I/O interrupts

After I/O starts, control returns to user program only upon I/O completion.

wait instruction idles the CPU until the next interrupt.wait loop (contention for memory access).at most one I/O request is outstanding at a time; no simultaneous I/O processing.

Page 13: 02.Os Structure

13Guo, Xunhua

Asynchronous I/O interruptsAfter I/O starts, control returns to user program without waiting

System call – request to the operating systemDevice-status table contains entry for each I/O device indicating its type, address, and state (not functioning, idle or busy)Multiple requests for the same device are maintained in a wait queue.Operating system indexes into I/O device table to determine device status and to modify table entry to include interrupt.

Page 14: 02.Os Structure

14Guo, Xunhua

DMA Structure

Used for high-speed I/O devices able to transmit information at close to memory speeds.Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention.Only one interrupt is generated per block, rather than the one interrupt per byte.

Page 15: 02.Os Structure

15Guo, Xunhua

Storage Structure

Main memoryThe only large storage media that the CPU can access directly.

Secondary storageextension of main memory that provides large nonvolatile storage capacity.Magnetic disksOptical disksMagnetic tapes

Page 16: 02.Os Structure

16Guo, Xunhua

Typical memory hierarchy

Storage systems organized in hierarchy:Speed, cost, volatility

Cachingcopying information into faster storage system; main memory can be viewed as a fast cache for secondary storage.

Page 17: 02.Os Structure

17Guo, Xunhua

Structure of a large Pentium system

Page 18: 02.Os Structure

18Guo, Xunhua

Hardware protection

Dual-Mode OperationI/O ProtectionMemory ProtectionCPU Protection

Page 19: 02.Os Structure

19Guo, Xunhua

Dual-mode operation

Sharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly.Provide hardware support to differentiate between at least two modes of operations.

User mode – execution done on behalf of a user.Monitor mode (also supervisor mode, kernel mode, or system mode) – execution done on behalf of operating system.

Page 20: 02.Os Structure

20Guo, Xunhua

Dual-mode operation

Page 21: 02.Os Structure

21Guo, Xunhua

User mode and monitor mode

Mode bit added to computer hardware to indicate the current mode

monitor (0) or user (1).When an interrupt or fault occurs hardware switches to monitor modePrivileged instructions can be issued only in monitor mode.

Page 22: 02.Os Structure

22Guo, Xunhua

I/O protection

All I/O instructions are privileged instructions.Must ensure that a user program could never gain control of the computer in monitor mode

i.e., a user program that, as part of its execution, stores a new address in the interrupt vector

Page 23: 02.Os Structure

23Guo, Xunhua

Memory protection

Must provide memory protection at least for the interrupt vector and the interrupt service routines.In order to have memory protection, add two registers that determine the range of legal addresses a program may access:

base register – holds the smallest legal physical memory address.limit register – contains the size of the range.

Memory outside the defined range is protected.

Page 24: 02.Os Structure

24Guo, Xunhua

Example of memory protection

Page 25: 02.Os Structure

25Guo, Xunhua

Protection hardware

Page 26: 02.Os Structure

26Guo, Xunhua

Question

Given that I/O instructions are privileged, how does the user program perform I/O?

Page 27: 02.Os Structure

System calls

Page 28: 02.Os Structure

28Guo, Xunhua

System calls

The method used by a process to request action by the operating system.Usually takes the form of a trap to a specific location in the interrupt vector.Control passes through the interrupt vector to a service routine in the OS, and the mode bit is set to monitor mode.The monitor verifies that the parameters are correct and legal, executes the request, and returns control to the instruction following the system call.

Page 29: 02.Os Structure

29Guo, Xunhua

System calls

System calls provide the interface between a running program and the operating system.Three general methods are used to pass parameters between a running program and the operating system:

Pass parameters in registers.Store the parameters in a table in memory, and the table address is passed as a parameter in a register.Push (store) the parameters onto the stack by the program, and pop off the stack by the operating system.

Page 30: 02.Os Structure

30Guo, Xunhua

Steps in making a system call

Page 31: 02.Os Structure

31

Some System Calls For Process Management

Page 32: 02.Os Structure

32

Some System Calls For File Management

Page 33: 02.Os Structure

33

Some System Calls For Directory Management

Page 34: 02.Os Structure

34

Some System Calls For Miscellaneous Tasks

Page 35: 02.Os Structure

35

System call interface

The layers of a UNIX system.

UserInterface

Page 36: 02.Os Structure

System programs

Page 37: 02.Os Structure

37Guo, Xunhua

System (utility) programs

Solve common problems or perform common operations

File manipulation: e.g., cp, mv, chmod, lsStatus information: e.g., date, ps, dfFile modification: e.g., viProgramming-language support: e.g., gcc, asmProgram loading and execution: e.g., ld, gdbCommunications: e.g., telnet

System programs are invoked from the shell whereas system calls are invoked from programs.

Page 38: 02.Os Structure

38Guo, Xunhua

UNIX utility programs

Page 39: 02.Os Structure

Operating system components

Page 40: 02.Os Structure

40Guo, Xunhua

Common system components

Process ManagementMain-Memory ManagementFile ManagementI/O System ManagementProtection SystemNetworkingCommand-Interpreter System

Page 41: 02.Os Structure

41Guo, Xunhua

Process managementprogram (passive) vs. process (active)

A process is a program in execution. A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task.

The operating system is responsible for:process creation and deletion.process suspension and resumption.provision of mechanisms for:

process synchronizationprocess communicationDeadlock handling

Page 42: 02.Os Structure

42Guo, Xunhua

Main memory management

Memory is a large array of words or bytes, each with its own address.It is a repository of quickly accessible data shared by the CPU and I/O devices.Main memory is a volatile storage deviceThe operating system is responsible for:

Keep track of which parts of memory are currently being used and by whom.Decide which processes to load when memory space becomes available.Allocate and deallocate memory space as needed.

Page 43: 02.Os Structure

43Guo, Xunhua

File Management

The OS through the file system provides a uniform logical view of information storage. The operating system is responsible for:

File creation and deletion.Directory creation and deletion.Support of primitives for manipulating files and directories.Mapping files onto secondary storage.File backup on stable (nonvolatile) storage media.

Page 44: 02.Os Structure

44Guo, Xunhua

I/O system management

The peculiarities of the various I/O devices are hidden from the bulk of the operating system itself by the I/O subsystemThe I/O system consists of:

A buffer-caching systemA general device-driver interfaceDrivers for specific hardware devices

Page 45: 02.Os Structure

45Guo, Xunhua

Secondary-Storage Management

Most modern computer systems use disks as the principle on-line storage medium, for both programs and data.The operating system is responsible for:

Free-space managementStorage allocationDisk scheduling

Page 46: 02.Os Structure

46Guo, Xunhua

Protection system

Protection refers to a mechanism for controlling access by programs, processes, or users to both system and user resources.The protection mechanism must:

distinguish between authorized and unauthorized usage.specify the controls to be imposed.provide a means of enforcement.

Page 47: 02.Os Structure

47Guo, Xunhua

Networking

A distributed system is a collection of processors that do not share memory or a clock. Each processor has its own local memory.The processors in the system are connected through a communication network.A distributed system provides user access to various system resources.

Computation speed-upIncreased data availabilityEnhanced reliability

Page 48: 02.Os Structure

48Guo, Xunhua

Command-Interpreter System

User interface which deals with:process creation and managementI/O handlingsecondary-storage managementmain-memory managementfile-system accessprotectionNetworking

Command-line and GUI

Page 49: 02.Os Structure

49Guo, Xunhua

Common system components

Process ManagementMain-Memory ManagementFile ManagementI/O System ManagementProtection SystemNetworkingCommand-Interpreter System

Page 50: 02.Os Structure

50Guo, Xunhua

Simple structure: MS DOS

Page 51: 02.Os Structure

51Guo, Xunhua

Monolithic kernel vs. Microkernel

Page 52: 02.Os Structure

52Guo, Xunhua

The client-server model in a distributed system

Page 53: 02.Os Structure

53Guo, Xunhua

Operating-System Services

Program executionI/O operationsFile-system manipulationCommunications Error detectionAdditional functions for ensuring efficient system operation.

Resource allocation, Accounting, Protection

Page 54: 02.Os Structure

54Guo, Xunhua

UNIX Structure

Page 55: 02.Os Structure

55Guo, Xunhua

Basic characteristics of modern operating systems

Concurrency (并发 )Sharing (共享 )Virtualization (虚拟 )Asynchronism (异步 )

55Guo, Xunhua

Page 56: 02.Os Structure

56Guo, Xunhua

Concurrency

ConcurrencySeveral events take places in a same time periodSeveral programs (processes) run in the same time

A modern operating system is a concurrency system

The co-existence of multi events and processes is managed by the OS

Page 57: 02.Os Structure

57Guo, Xunhua

Sharing

Sharing: several processes share the limited computer system resource

An OS shall manage the system resource for proper sharingResources are used alternatively by multi processes

Exclusive sharing: e.g. printersNon-exclusive sharing: e.g. harddisks

Page 58: 02.Os Structure

58Guo, Xunhua

Virtualization

Virtualization:A physical entity is map to several logical entities with time or spaceAn important way to improve the utilization effectiveness of resources

Virtual processorVirtual storageVirtual device

Page 59: 02.Os Structure

59Guo, Xunhua

Virtual Machines

Page 60: 02.Os Structure

60Guo, Xunhua

Asynchronism

ConditionsSeveral processes execute concurrentlyThe execution sequence and time of processes are uncertainThe speed of process execution is not pre-determined

TargetNo matter how the processes are executed, the results must be the sam

Page 61: 02.Os Structure

61Guo, Xunhua

Exercises

Reading: Chapter 2 and 3, Textbook

Questions:Why is the distinction between monitor mode and user mode important?What are different between system calls and library functions?