Вы находитесь на странице: 1из 58

Introduction

Operating System Concepts 8th Edition,!

Modified by M.Rebaudengo - 2010

Silberschatz, Galvin and Gagne 2009 !

What is an Operating System?


A program that acts as an intermediary between a

user of a computer and the computer hardware!


Operating system goals:"
Execute Make Use

user programs and make solving user problems easier" the computer system convenient to use" the computer hardware in an efcient manner"

Operating System Concepts 8th Edition!

1.2!

Silberschatz, Galvin and Gagne 2009 !

Computer System Structure


Computer system can be divided into four components"

Hardware provides basic computing resources"


CPU,

memory, I/O devices"

Operating system!
Controls

and coordinates use of hardware among various applications and users"

Application programs dene the ways in which the system resources are used to solve the computing problems of the users"
Word

processors, compilers, web browsers, database systems, video games" machines, other computers"

Users!
People,

Operating System Concepts 8th Edition!

1.3!

Silberschatz, Galvin and Gagne 2009 !

Four Components of a Computer System

Operating System Concepts 8th Edition!

1.4!

Silberschatz, Galvin and Gagne 2009 !

Operating System Definition


"
From the computer's point of view, the operating system is the program

most involved with the hardware"


OS is a resource allocator!

Manages all resources (CPU time, memory space, le-storage space, I/O devices, etc.)" resource allocation is important where many users access the same computer" Decides between conicting requests for efcient and fair resource use" Controls execution of programs to prevent errors and improper use of the computer" It is especially concerned with the operation and control of I/O devices."

OS is a control program!

Operating System Concepts 8th Edition!

1.5!

Silberschatz, Galvin and Gagne 2009 !

Operating System Definition (Cont.)


No universally accepted denition of what is part of the operating system" The one program running at all times on the computer"

usually called kernel!

Everything else is either a system program (shipped with the operating

system) or an application program.!

Operating System Concepts 8th Edition!

1.6!

Silberschatz, Galvin and Gagne 2009 !

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"

Operating System Concepts 8th Edition!

1.7!

Silberschatz, Galvin and Gagne 2009 !

Basic anatomy on a CPU (1)


Some key CPU Components"

Program Counter (PC)"


holds

memory address of next instruction" instruction currently being executed"

Instruction Register (IR)"


holds

Registers (Reg. 1..n)"


hold

variables and temporary results" arithmetic functions and logic operations"

Arithmetic and Logic Unit (ALU)"


performs

Operating System Concepts 8th Edition!

1.8!

Silberschatz, Galvin and Gagne 2009 !

Basic anatomy on a CPU (2)


Some key CPU Components"

Memory Address Register (MAR)"


contains

address of memory to be read/written" memory data read or to be written"

Memory Data Register (MDR)"


contains

Stack Pointer (SP)"


holds

memory address of a stack with a frame for each procedure s local variables & parameters" the mode bit and various control bits"

Processor Status Word (PSW)"


contains

Operating System Concepts 8th Edition!

1.9!

Silberschatz, Galvin and Gagne 2009 !

Program execution
Instruction sets"

different for different machines" all have load and store instructions for moving items between memory and registers" many instructions for comparing and combining values in registers and putting result in a register" fetch next instruction pointed to by PC" decode it to nd its type and operands" execute it" repeat"

Fetch/Decode/Execute cycle"

Operating System Concepts 8th Edition!

1.10!

Silberschatz, Galvin and Gagne 2009 !

Fetch/decode/execute cycle

CPU PC IR

Memory

ALU

Reg. 1 Reg. n

MAR MDR

Operating System Concepts 8th Edition!

1.11!

Silberschatz, Galvin and Gagne 2009 !

Fetch/decode/execute cycle

CPU PC IR

Memory

ALU

Reg. 1 Reg. n

MAR MDR

While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.12!

Operating System Concepts 8th Edition!

Silberschatz, Galvin and Gagne 2009 !

Fetch/decode/execute cycle

CPU PC IR

Memory

ALU

Reg. 1 Reg. n

MAR MDR

While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.13!

Operating System Concepts 8th Edition!

Silberschatz, Galvin and Gagne 2009 !

Fetch/decode/execute cycle

CPU PC IR

Memory

ALU

Reg. 1 Reg. n

MAR MDR

While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.14!

Operating System Concepts 8th Edition!

Silberschatz, Galvin and Gagne 2009 !

Fetch/decode/execute cycle

CPU PC IR

Memory

ALU

Reg. 1 Reg. n

MAR MDR

While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.15!

Operating System Concepts 8th Edition!

Silberschatz, Galvin and Gagne 2009 !

Fetch/decode/execute cycle

CPU PC IR

Memory

ALU

Reg. 1 Reg. n

MAR MDR

While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.16!

Operating System Concepts 8th Edition!

Silberschatz, Galvin and Gagne 2009 !

Fetch/decode/execute cycle

CPU PC IR

Memory

ALU

Reg. 1 Reg. n

MAR MDR

While (1) { Fetch instruction from memory Execute instruction (Get other operands if necessary) Store result }
1.17!

Operating System Concepts 8th Edition!

Silberschatz, Galvin and Gagne 2009 !

Computer Startup
Bootstrap program is loaded at power-up or reboot"

Typically stored in ROM or EPROM, generally known as rmware" Initializes all aspects of system (CPU registers, device controllers, memory contents, etc.)" Loads operating system kernel and starts execution"

The operating system then starts executing the rst process (init) and waits

for some event to occur."


The occurrence of an event is signaled by an interrupt from either the

hardware and the software:"


hardware may trigger an interrupt by sending a signal to the CPU" software may trigger an interrupt by executing a special operation called system call (or monitor call)."

Operating System Concepts 8th Edition!

1.18!

Silberschatz, Galvin and Gagne 2009 !

Interrupts
Interrupts is the way by which hardware informs

OS of special conditions that require OS s attention"


Interrupt causes the CPU not to execute the next

instruction"
Instead, the control is passed to OS"

Operating System Concepts 8th Edition!

1.19!

Silberschatz, Galvin and Gagne 2009 !

Computer-System 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 local

buffers"
I/O moves from the device to local buffer of controller" Device controller informs CPU that it has nished its

operation by causing an interrupt"

Operating System Concepts 8th Edition!

1.20!

Silberschatz, Galvin and Gagne 2009 !

Common Functions of Interrupts


Interrupt transfers control to the interrupt service routine

generally, through the interrupt vector, which contains the addresses of all the service routines"
Interrupt architecture must save the address of the

interrupted instruction"
A trap is a software-generated interrupt caused either by

an error or a user request"


An operating system is interrupt driven!

Operating System Concepts 8th Edition!

1.21!

Silberschatz, Galvin and Gagne 2009 !

Handling interrupts
Interrupt handler is a piece of the OS code intended to

do something about the condition which caused the interrupt"


Pointers The

to the interrupt handlers are stored in the interrupt vector! interrupt vector is stored at a pre-dened memory location"

Operating System Concepts 8th Edition!

1.22!

Silberschatz, Galvin and Gagne 2009 !

Handling Interrupts (II)


When an interrupt occurs:"
The

CPU enters kernel mode, and"

passes the

control to the appropriate interrupt handler " handler address is found using the interrupt number as an index into the interrupt vector!

Operating System Concepts 8th Edition!

1.23!

Silberschatz, Galvin and Gagne 2009 !

Interrupt types
Asynchronous interrupts are generated by

external devices at unpredictable times"


Internal (synchronous) interrupts are generated

synchronously by CPU as a result of an exceptional condition"


An A

error condition"

temporary problem"

Operating System Concepts 8th Edition!

1.24!

Silberschatz, Galvin and Gagne 2009 !

I/O architecture

Operating System Concepts 8th Edition!

1.25!

Silberschatz, Galvin and Gagne 2009 !

Servicing an interrupt
When an interrupt occurs (and is accepted), the execution of the current

program is suspended"
Must save PC and Registers" A special routine executes to service the interrupt" In most cases the interrupted program resumes" The service routine is called an interrupt handler or interrupt service routine

(ISR).!

Operating System Concepts 8th Edition!

1.26!

Silberschatz, Galvin and Gagne 2009 !

Servicing an interrupt

Operating System Concepts 8th Edition!

1.27!

Silberschatz, Galvin and Gagne 2009 !

Saving Registers
For the interrupted program to resume, the CPU

status and data registers must be saved (because they will change during the ISR)" They are saved before the ISR executes" They are restored after the ISR executes" They are saved either"
On In

the stack (a special area of memory to temporarily hold information), or" a process control block (PCB)!

Operating System Concepts 8th Edition!

1.28!

Silberschatz, Galvin and Gagne 2009 !

Vectored interrupt

Operating System Concepts 8th Edition!

1.29!

Silberschatz, Galvin and Gagne 2009 !

Direct Memory Access (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."

CPU Interrupt

Bus Arbiter On-Chip-Bus Request Acknowledge


1.30!

Memory

DMA Controller
Operating System Concepts 8th Edition!

Peripheral Device
Silberschatz, Galvin and Gagne 2009 !

Program-Controlled I/O (in DMA)


Data bus Address bus Control bus CPU DMAC Memory Disk The CPU prepares the DMAC

Operating System Concepts 8th Edition!

1.31!

Silberschatz, Galvin and Gagne 2009 !

DMA
Data bus Address bus Control bus CPU DMAC Memory Disk The transfer takes place

Operating System Concepts 8th Edition!

1.32!

Silberschatz, Galvin and Gagne 2009 !

I/O Interrupt (in DMA)


Data bus Address bus Control bus The DMAC interrupts the CPU when the transfer is complete

IRQ

CPU DMAC Memory Disk

Operating System Concepts 8th Edition!

1.33!

Silberschatz, Galvin and Gagne 2009 !

Storage-Device Hierarchy

Operating System Concepts 8th Edition!

1.34!

Silberschatz, Galvin and Gagne 2009 !

Storage Structure
Main memory only large storage media that the CPU can access directly! Secondary storage extension of main memory that provides large

nonvolatile storage capacity"


Magnetic disks rigid metal or glass platters covered with magnetic

recording material "


Disk surface is logically divided into tracks, which are subdivided into sectors! The disk controller determines the logical interaction between the device and the computer "

Operating System Concepts 8th Edition!

1.35!

Silberschatz, Galvin and Gagne 2009 !

Storage Hierarchy
Storage systems organized in hierarchy"

The higher levels are more expensive, but they are faster. As we move down the hierarchy"
Speed: Cost:

the access time increases"

the cost per bit decreases"

Volatility:"
registers,

cache and main memory lose their contents when the power to the device is removed."

Operating System Concepts 8th Edition!

1.36!

Silberschatz, Galvin and Gagne 2009 !

Caching
Important principle, performed at many levels in a computer (in

hardware, operating system, software)"


Information in use copied from slower to faster storage temporarily" Faster storage (cache) checked rst to determine if information is

there"

If it is, information used directly from the cache (fast)" If not, data copied to cache and used there" Cache management important design problem" Cache size and replacement policy"

Cache smaller than storage being cached"


"

Operating System Concepts 8th Edition!

1.37!

Silberschatz, Galvin and Gagne 2009 !

How a Modern Computer Works

Operating System Concepts 8th Edition!

1.38!

Silberschatz, Galvin and Gagne 2009 !

Computer-System Architecture
Most systems use a single general-purpose processor (PDAs through

mainframes)"

Most systems have special-purpose processors as well" Also known as parallel systems, tightly-coupled systems" Advantages include"
1. 2. 3.

Multiprocessors systems growing in use and importance"


Increased throughput (speed-up)" Economy of scale" Increased reliability graceful degradation or fault tolerance" Asymmetric Multiprocessing: each processor is assigned a specic task. A master processor controls the system: it schedules and allocates work to the slave processors" Symmetric Multiprocessing: all processors are peers (no masterslave relationship exists between processors)."
1.39! Silberschatz, Galvin and Gagne 2009 !

Two types"
1.

2.

Operating System Concepts 8th Edition!

"

Symmetric Multiprocessing Architecture

Many processes can run simultaneously."

Operating System Concepts 8th Edition!

1.40!

Silberschatz, Galvin and Gagne 2009 !

A Dual-Core Design

Multicore CPUs appear to the operating system as N standard processors."

Operating System Concepts 8th Edition!

1.41!

Silberschatz, Galvin and Gagne 2009 !

Operating System Structure


"

Multiprogramming needed for efciency"


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"

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 t in memory, swapping moves them in and out to run"

Virtual memory allows execution of processes not completely in


memory"

Operating System Concepts 8th Edition!

1.42!

Silberschatz, Galvin and Gagne 2009 !

Memory Layout for Multiprogrammed System

The operating system keeps several jobs in memory simultaneously."

Operating System Concepts 8th Edition!

1.43!

Silberschatz, Galvin and Gagne 2009 !

Operating-System Operations
Since the operating system and the users share the hardware and the

software resources of the computer system, it is important to make sure that an error in a user program could cause problems only for the one program running" With sharing, many processes could be affected by a bug in one program" Dual-mode operation allows OS to protect itself and other system components"

User mode and kernel mode (or supervisor, system or privileged mode)" Mode bit provided by hardware" Provides ability to distinguish when system is running user code or kernel code"
Some

instructions designated as privileged, only executable in kernel mode" System call changes mode to kernel, return from call resets it to user "

Operating System Concepts 8th Edition!

1.44!

Silberschatz, Galvin and Gagne 2009 !

Transition from User to Kernel Mode

System calls provide the means for a user program to ask the operating

system to perform tasks reserved for the operating system on the user program's behalf."

Operating System Concepts 8th Edition!

1.45!

Silberschatz, Galvin and Gagne 2009 !

Transition from User to Kernel Mode


Timer to prevent innite loop / process hogging resources"

Set interrupt after specic period" Operating system decrements counter" When counter reaches 0, an interrupt occurs" Set up before scheduling process to regain control or terminate program that exceeds allotted time"

Operating System Concepts 8th Edition!

1.46!

Silberschatz, Galvin and Gagne 2009 !

Process Management
A process is a program in execution. It is a unit of work

within the system"


Program is a passive entity (like the contents of a le

stored on a disk), process is an active entity"


Process needs resources to accomplish its task"
CPU,

memory, I/O, les (given when it is created or allocated while it is running)" data"

Initialization

Process termination requires reclaim of any reusable

resources"
"

Operating System Concepts 8th Edition!

1.47!

Silberschatz, Galvin and Gagne 2009 !

Process Management (cont.)


Single-threaded process has one
Process

program counter

specifying location of next instruction to execute" 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

processes (executing user code), some operating system processes (executing system code) running concurrently on one or more CPUs"
Concurrency

by multiplexing the CPUs among the processes / threads"

Operating System Concepts 8th Edition!

1.48!

Silberschatz, Galvin and Gagne 2009 !

Process Management Activities


The operating system is responsible for the following activities in connection with process management:"
Scheduling processes and threads of the CPUs" 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."

Operating System Concepts 8th Edition!

1.49!

Silberschatz, Galvin and Gagne 2009 !

Memory Management
Main memory is a large array of words or bytes, where

each word has its own address"


Main memory is a repository of accessible data shared

by the CPU and I/O devices"


CPU reads instructions from main memory during the

instruction-fetch cycle"
CPU reads/writes data from/to main memory during the

data-fetch cycle"
The main memory is the only large storage device that

the CPU is able to address and access directly"


All data in memory before and after processing: to

process data from disk, those data must rst be transferred to main memory by CPU-generated I/O calls"
All instructions in memory in order to be executed"
Operating System Concepts 8th Edition! 1.50! Silberschatz, Galvin and Gagne 2009 !

Memory Management (cont.)


A program, to be executed, must be mapped to absolute

adresses and loaded into memory"


As the program executes, it accesses program

instructions and data from memory by generating these absolute adresses"


When the program terminates, its memory space is

declared available, and the next program can be loaded and executed"
To improve the utilization of the CPU and the speed of

the computer's response to its users, general-purpose computers must keep several programs in memory, creating a need for memory management"
Many different memory management schemes are used."
Operating System Concepts 8th Edition! 1.51! Silberschatz, Galvin and Gagne 2009 !

Memory Management
Memory management activities"
Keeping

track of which parts of memory are currently being used and by whom" which processes (or parts thereof) and data to move into and out of memory" and deallocating memory space as needed"

Deciding

Allocating

"

Operating System Concepts 8th Edition!

1.52!

Silberschatz, Galvin and Gagne 2009 !

Storage Management
OS provides a uniform, logical view of information

storage"
Abstracts OS

physical properties to logical storage unit - le! maps les onto physical media and accesses these les via the storage devices" medium is controlled by device (i.e., disk drive, tape drive)"
Varying

Each

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

Operating System Concepts 8th Edition!

1.53!

Silberschatz, Galvin and Gagne 2009 !

Storage Management
File-System management"

Files usually organized into directories" Access control on most systems to determine who can access in what way (e.g., read, write, append) " OS activities include"
Creating

and deleting les and directories" primitives to manipulate les and directories" les onto secondary storage"

Supporting Mapping Backup

les onto stable (non-volatile) storage media"

Operating System Concepts 8th Edition!

1.54!

Silberschatz, Galvin and Gagne 2009 !

Mass-Storage Management
Computer system must provide secondary storage to back up main memory:"

Main memory is too small to accomodate all data and programs" Data that memory holds are lost when power is lost"

Most programs are stored on a disk until loaded into memory and then use the

disk as both the source and the destination of their processing"


Entire speed of computer operation hinges on disk subsystem and its algorithms" OS activities"

Free-space management" Storage allocation" Disk scheduling" Tertiary storage includes optical storage, magnetic tape" Varies between WORM (write-once, read-many-times) and RW (read-write)"

Some storage need not be fast"


Operating System Concepts 8th Edition!

1.55!

Silberschatz, Galvin and Gagne 2009 !

Performance of Various Levels of Storage

Operating System Concepts 8th Edition!

1.56!

Silberschatz, Galvin and Gagne 2009 !

Migration of Integer A from Disk to Register

Multitasking environments must be careful to use most recent value, no

matter where it is stored in the storage hierarchy"


Multiprocessor environment must provide cache coherency in hardware

such that all CPUs have the most recent value in their cache"

Operating System Concepts 8th Edition!

1.57!

Silberschatz, Galvin and Gagne 2009 !

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)" General device-driver interface" Drivers for specic hardware devices"

Operating System Concepts 8th Edition!

1.58!

Silberschatz, Galvin and Gagne 2009 !

Вам также может понравиться