OSIT CH 1
OSIT CH 1
Objectives
Understand the relationship between the computer system
and operating system Understand the mechanism of interrupts and how it is used within a computer system Specify the role of an operating system and its core modules - process management, memory management, I/O systems, protection and security. Understand how these modules interact among themselves and how they interact with the computer system
Chapter 1: Introduction
What Operating Systems Do Computer-System Organization Computer-System Architecture Operating-System Structure Operating-System Operations Process Management Memory Management
Storage Management
Protection and Security Distributed Systems Special-Purpose Systems
Computing Environments
Open-Source Operating Systems
between a user of a computer and the computer hardware Operating system goals:(Why)
Execute user programs and make solving user problems
easier Make the computer system convenient to use: It provides a user-friendly environment in which a user may easily develop and execute programs. Otherwise, hardware knowledge would be mandatory for computer programming. An OS hides the complexity of hardware from uninterested users. Use the computer hardware in an efficient manner:
A program that runs on the raw hardware and supports Resource Abstraction (different hardware but same interface) Resource Sharing (for multi-programming case) Abstracts and standardizes the interface to the user
Manages the hardware resources Each program gets time with the resource (CPU) Each program gets space on the resource(MEM) May have potentially conflicting goals: Use hardware efficiently Give maximum performance to each user
various applications and users System and Application programs define 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 Users People, machines, other computers
Operating System Concepts 8th Edition , Silberschatz, Galvin,
6
...
User n
compiler
assembler
Text editor
Database system
space, file storage I/O devices, Decides between conflicting requests for efficient and fair resource use (contradicting goals). OS is a control program (governor) Controls execution of programs to prevent errors and improper use of the computer. Ex: a program may write into other program area or on operating system memory, or accesses desk directly, divide by 0, etc.
Operating System Concepts 8th Edition , Silberschatz, Galvin,
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 used ondemand: e.g. compilers) or an application program.
Application Programs
System Programs
execute programs on computer hardware in a convenient and efficient manner. To allocate the separate resources of the computer as needed to solve the problem given. The allocation process should be as fair and efficient as possible. As a control program it serves two major functions: (1) supervision of the execution of user programs to prevent errors and improper use of the computer, and (2) management of the operation and control of I/O devices.
Operating System Concepts 8th Edition , Silberschatz, Galvin,
10
Computer Startup(when)
bootstrap program is loaded at power-up or
reboot Typically stored in ROM or EPROM, generally known as firmware Initializes all aspects of system (CPU registers, memory, I/O device controllers,etc.) Loads operating system kernel and starts its execution.
11
providing access to shared memory. Concurrent execution of CPUs and devices competing for memory cycles.
12
Components of a simple PC
Outside world
Video controller
USB controller
Network controller
CPU Memory
Operating System Concepts 8th Edition , Silberschatz, Galvin,
Interrupts
Defn: an event external to the currently
executing process that causes a change in the normal flow of instruction execution; usually generated by hardware devices external to the CPU
From Design and Implementation of the FreeBSD Operating System, Glossary
Why Interrupts?
People like connecting devices A computer is much more than the CPU
timescale we want to keep the CPU busy between events Need a way for CPU to find out which devices need attention
Operating System Concepts 8th Edition , Silberschatz, Galvin,
15
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 I/O is from the device to local buffer of controller CPU moves data from/to main memory to/from local buffers Device controller informs CPU that it has finished its operation by causing an interrupt Protocol: To get a byte of data from a device
1. CPU sets registers in controller with command to read e.g.
character from modem. 2. I/O is from the device to local buffer of controller 3. Device controller CPU that it has finished its operation Operating System Concepts 8th Edition informs , Silberschatz, Galvin,
16
Polling vs Interrupts
Mario (CPU) and Princess Peach (I/O Device) VIDEO
needs service takes CPU time even when no requests pending overhead may be reduced at expense of response time can be efficient if events arrive rapidly
Polling is like picking up your phone every few seconds to see if you have a call.
Operating System Concepts 8th Edition , Silberschatz, Galvin,
18
Alternative: Interrupts
Give each device a wire (interrupt line) that it
can use to signal the processor When interrupt signaled, processor executes a routine called an interrupt handler to deal with the interrupt No overhead when no requests pending
19
20
Interrupt Handling
Interrupts are issued by 1. an external event raised by hardware: e.g. I/0 2. an internal event trigger by software: e.g. system calls (means application needs a service from the OS. It calls a service). TRAP Interrupt Handler (service routine) ISR a subroutine in the operating system to process a particular type of interrupt
Interrupt Vector an array of starting addresses of interrupt handlers The index for a particular interrupt to the array is provided by the hardware. ISR
(printer) ISR (Keyboard)
21
Basic program state saved (as for system call) CPU jumps to interrupt handler When interrupt done, program state reloaded and
Operating System Concepts 8th Edition , Silberschatz, Galvin,
program resumes
22
generally, through the interrupt vector, which 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
23
I/O Techniques
Programmed I/O: processor interacts with I/O module directly issues I/O commands to I/O module interrogates status bits repeatedly (Polling) reads or writes: transfers the data between CPU and I/O module Interrupt-Driven I/O: I/O module interrupts when I/O module
is ready
issues I/O commands to I/O module
goes off to run other processes (doing something else) get interrupted when I/O module is ready and reads or writes (in
interrupt handlers)
DMA module takes care of the interrupt from I/O and data transfer
Processor sends request to DMA (starting address, number of bytes,
address of I/0 device, read or write) Operating System Concepts with 8th Edition Silberschatz, Galvin, DMA interacts I/O ,module and completes the bulk transfer
24
through OS system calls. The device driver sets appropriate control registers for the device controller to start transferring data from the device to the device local buffer. After completion of data transfer, the controller sends an interrupt which is recognized by the driver. The device driver transfers data from the device buffer to the computer memory. The driver returns control to the operating system (or user program) with actual data read from the device local buffer or a pointer to the data. Example :Keyboard device (slow device) doesn't cause many interrupts: Operating System Concepts 8th Edition , Silberschatz, Galvin, Interrupt per key press: say 50 interrupts/second
25
Device drivers
Device drivers go between
User space Kernel space
Rest of the OS User program
Keyboard driver
Disk driver
Keyboard controller
Disk controller
26
3
CPU 1 5 Interrupt controller 6
1: Interrupt
Disk controller 4
3: Return
controller Interrupt controller notifies CPU Right: interrupt handling (software point of view)
27
28
for high-speed I/O devices able to transmit information at close to memory speeds (network card or disk drive 1G/sec) . Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention per block, rather than the -Only CPUone interrupt is generated - Device controller one interrupt per byte -Sets up (large) buffers -When device I/O in memory complete, transfer data - Asks device controller directly into memory to transfer into buffer -Send interrupt when Receives single transfer complete interrupt for whole buffer -Avoids CPU data intervention Operatingof System Concepts 8 Edition , Silberschatz, Galvin,
th
29
30
Synchronous I/O
Operating System Concepts 8th Edition , Silberschatz, Galvin,
Asynchronous I/O
Storage Structure
Main memory only large storage media that the
CPU can access directly. It stores data and programs in execution (running) until power is disconnected (Volatile storage) Secondary storage extension of main memory that provides large nonvolatile storage capacity. It stores programs (files) that can be executed when needed. Files remains stored until they are deleted. Magnetic disks rigid metal or glass platters covered with magnetic recording material
Disk surface is logically divided into tracks, which are
Operating System Concepts 8th Edition , Silberschatz, Galvin,
32
head
sector
on all surfaces
heads
Actuator moves heads Heads move in unison
surfaces
spindle
actuator
33
Storage Hierarchy
Storage systems organized in hierarchy Speed
Cost
Volatility Caching copying information into faster storage
system; main memory can be viewed as a last cache for secondary storage
34
Storage-Device Hierarchy
35
36
memory with low latency. Movement between levels of storage hierarchy can be explicit (by instructions) or implicit (by hardware) or vice versa.
Operating System Concepts 8th Edition , Silberschatz, Galvin,
37
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 first to determine if information is there
If it is, information used directly from the cache
Computer-System Architecture
Categorizing according to number of general
to relieve the CPU from some I/O tasks such as disk scheduling
importance
(Also known as parallel systems, tightly-coupled systems)
Have two or more processors In close communication Sharing computer bus Sometimes share clock ,memory and peripheral devices. Advantages include 1. Increased throughput : process/unit time
1.
2. Economy of scale
1. Cost is less than the equivalent multiple single-processor systems.
3. Increased reliability
1. If one processor fails the remaining can carry its job
(multi-processes, multiprocessor Operating System Concepts 8th Edition , Silberschatz, Galvin, environment)
Problems
and
distributed
40
network route becomes unusable, a backup component, procedure or route can immediately take its place with no negative impact whatsoever on individual subscribers (implemented by hardware and software duplication). Graceful degradation is the ability of a computer, machine, electronic system or network to maintain limited functionality even when a large portion of it has been destroyed or rendered inoperative. The purpose of graceful degradation is to prevent catastrophic failure. Multiprocessing model can cause a system to change its memory access model from uniform memory access (UMA) to non-uniform memory access (NUMA). UMA is the situation in which access to any RAM from any CPU takes the same amount of time.
Operating System Concepts 8th Edition , Silberschatz, Galvin,
41
42
Note :The difference between SMP and ASMP may result from either hardware or software (OS).
43
Symmetric Multiprocessing Architecture with each processor having its own cash
SMP is easier to implement in operating systems and is the method used most often in operating systems that support multiple processors. Operating systems that support SMP include: OS/2 Warp Server 4.0 ,OS/2 for SMP 2.11,Windows NT 4.0, Novell NetWare 4.1 SMP ,Novell UnixWare SMP 2.0 SCO Open Server 5.0 with SCO MPX 3.0, Banyan Vines
Operating System Concepts 8th Edition , Silberschatz, Galvin,
44
Clustered Systems
Like multiprocessor systems, but multiple systems working together Usually sharing storage via a storage-area network (SAN). Closely linked via a local-area network. (LAN).
(known as High-availability clusters or failover clusters) Asymmetric clustering has one machine in hot-standby mode (redundant node used to provide service when the other fails) Symmetric clustering has multiple nodes running applications, monitoring each other, each working in a different application. Also, if a node fails ,the other carry its job providing availability and scalability. Some clusters are for high-performance computing (HPC): Single application on multiple nodes. Applications must be written to use parallelization Example is Beowulf clusters: use personal computers connected via simple LAN to solve HPC problems using open source software. 46 th Edition , Silberschatz, Galvin, Operating System Concepts 8 The vast majority of the TOP500 supercomputers are clusters.[28]
computer
interconnect
computer
interconnect
computer
47
Beowulf Cluster
A cluster implemented on multiple identical commercial off-the-shelf computers connected with a TCP/IP Ethernet local area network.[27] Beowulf technology was originally developed by Thomas Sterling and Donald Becker
48
49
simultaneously (how)
When a program performs I/O, instead of polling, execute
50
CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing Programs queued for execution in FIFO order. Like multiprogramming, but timer device interrupts after a quantum (timeslice).
Interrupted program is returned to end of FIFO Next program is taken from head of FIFO 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 (ch5) If processes dont fit in memory, swapping moves them in and out to run Virtual memory (ch9) allows execution of processes not completely in memory
Operating System Concepts 8th Edition , Silberschatz, Galvin,
51
52
Operating-System Operations
OS is Interrupt driven by hardware interrupts (I/O or timer) software interrupts caused by
request for operating system service (SW interrupt or trap) SW error (exception or trap)
(solution use timer). processes modifying each other or the operating system area (solution use dual mode).
Operating System Concepts 8th Edition , Silberschatz, Galvin,
53
process. To accomplish this, OS uses Timer to prevent infinite loop / process hogging resources
Timer is Set to interrupt the system after specific period (its counter is initialized by the number of seconds for example) When time is up (counter = 0), Interrupt occurs and control goes to OS which can decide to treat it as error or it can set it again to give the process more time to run
Example a process needs 7 min (420 sec), every sec generate an interrupt
program that exceeds allotted time. Thus preventing a process to run th Operating System Concepts 8 Edition , Silberschatz, Galvin, long period than it is needed.
54
Dual Mode
Dual-mode operation allows OS to protect itself and
kernel code Some instructions designated as privileged, only executable in kernel mode (I/O control and Interrupt and timer management) System call changes mode to kernel, return from call resets it to user If a user tries to execute a privileged instruction or access memory outside its space, the hardware traps to the OS..
55
delete, and use (access) objects (process, files, memory, etc) 1. a special instruction switches the machine from user mode to kernel mode (OS mode) where the OS is running. Set mode = 0 2. Kernel examines the parameters of the sys. Call to determine which service is called (2). E.g read( fd, buf, 100) 3. Kernel then executes the corresponding service procedure indexed in the dispatch table (3). Each sys call has service procedure to execute 4. Finally, the sys. Call is finished and control is given back to the user program. Set mode = 1
UserProgram 1 1 2 4
Service Procdure
User Mode
Kernel Mode
Dispatch Table
56
Core Tasks of an OS
Processor management Memory management Device management Storage management
Application interface
User interface
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
(ch4) Operating System Concepts 8 Edition , Silberschatz, Galvin, Typically, a system has many processes, some user, some
th
58
(ch5) Creating and deleting processes (ch3) Suspending and resuming processes (ch3) Providing mechanisms for process synchronization (ch6) Providing mechanisms for process communication (ch3) Providing mechanisms for deadlock handling (ch7)
Operating System Concepts 8th Edition , Silberschatz, Galvin,
59
time sharing systems because many programs will reside in the same time in memory, to Optimize CPU utilization and computer response to users. Memory management activities Keeping track of which parts of memory are currently being used and by whom. How much free Deciding which processes and data to move into and out of memory (swapping/paging) Allocating and deallocating memory space as needed
Operating System Concepts 8th Edition , Silberschatz, Galvin,
60
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 (Read-Write-Excecute) 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
61
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 (used/free space) Storage allocation/deallocation Disk scheduling Some storage need not be fast ( for backup and long term archiving) Tertiary storage includes optical storage, magnetic tape Still must be managed Varies between WORM (write-once, read-many-times) and RW Operating System Concepts 8th Edition , Silberschatz, Galvin, (read-write)
62
such that all CPUs have the most recent value in their cache Distributed environment situation even more complex Several copies of a datum can exist Various solutions covered in Chapter 17
63
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 outputs of other jobs) General device-driver interface Drivers for specific hardware devices
64
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, then also associated with each process, file. Privilege escalation allows user to change to effective ID with more rights
65
Computing Environments
Traditional computer Blurring over time, As computer matures.
Office environment
PCs connected to a network, terminals attached
to mainframe or minicomputers providing batch and timesharing Now portals allowing networked and remote systems access to same resources Home networks Used to be single system, then modems Now firewalled, networked
Operating System Concepts 8th Edition , Silberschatz, Galvin,
66
Terminals connected to mainframes are supplanted by smart PCs Many systems now are servers, responding to requests generated by clients, two types:
67
Peer-to-Peer Computing
Another model of distributed system P2P does not distinguish clients and servers Instead all nodes are considered peers Each may act as client, server or both Node must join P2P network
Registers its service with central lookup service on network, or Broadcast request for service and respond to requests for
Web-Based Computing
Web has become ubiquitous PCs most prevalent devices
access New category of devices to manage web traffic among similar servers: load balancers Use of operating systems like Windows 95, clientside, have evolved into Linux and Windows XP, which can be clients and servers
69
Management (DRM) movement Started by Free Software Foundation (FSF), which has copyleft GNU Public License (GPL) Examples include GNU/Linux, BSD UNIX (including core of Mac OS X), and Sun Solaris
Operating System Concepts 8th Edition , Silberschatz, Galvin,
71