Download cs459 - Operating Systems: Introduction

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Asynchronous I/O wikipedia , lookup

Transcript
Operating Systems
• Definition: Software that creates an environment so computer can
perform useful tasks
• What is in an operating system?
– Loose definition: Everything that ships with the computer
– More precise definition: Software that is always resident in
memory (kernel) plus a set of utility programs that help the system
administrator configure and manage the system.
• Possible focus
–
–
–
–
–
–
Provide a good user experience
Responsive to user commands
Minimize idle time and maximize throughput
Respond to real time constraints
Maximize connectivity
Efficient sharing distributed resources
Computer System Components
1. Hardware – One or more CPUs, I/O devices and controllers, bus
or switch connections, memory
2. Operating system modules: kernel, bootstrap (start up
instructions in firmware), device drivers (for I/O), and parts of the
operating system that do not need to be resident in memory all the
time, e.g., functionality that allows the operating system to be
updated while it is running
3. System utilities – Sysgen (System generation) software,
defragmenters, disk editors, etc.
4. Application programs- Word processors, compilers, web
browsers, database systems, video games
5. Entities producing inputs: People devices external to the
current system.
Types of Operating Systems
• Batch: Small resident kernel sequences jobs for one or more batch streams
using a job control interface. Goal: minimize setup time, minimize idle time
• Real time: Often part of special purpose embedded systems with no user
interface. Goal: satisfy well-defined hard or soft time constraints
• Time shared: Responds to multiple users at workstations. Scheduling is
based on real time clock “slices”. Goal: Responsive to users
• Desktop systems: Single users, with multitasked and multi-programming
capabilities. Goal: user friendly and responsive
• Multiprocessor: Tightly coupled processors sharing memory and
peripherals. Goal: maximize throughput and reliability (redundancy)
• Multi-computer: Loosely coupled, often heterogeneous systems working
cooperatively. Goal: efficient and secure client-server or peer-to-peer intercomputer communication
• Grid-based: loosely coupled, heterogeneous, geographically separated.
Communicate through LAN or WAN; peer-to-peer or client-server. Goal:
utilized distributed resources to address grand challenge problems
• Handheld systems: Slow, limited in processor speed, available power and
user interfaces. Goal: support user-friendly portable applications, maximize
wireless connectivity, optimize battery life, optimize execution efficiency
Real Time System Constraints
• Hard (System fails if constraints not satisfied)
– Guarantee that real time constraints complete on-time.
– Not supportable by time-shared operating systems.
– Data is stored in ROM or in short term memory; no secondary
storage, virtual memory, or advanced operating system features.
– Examples: Respond to sensor control inputs, assist scientific
experiments, medical imaging and other devices, e.g.,
pacemakers, weapon systems
• Soft (Best effort made to meet constraints)
– Priority-based, delays are bounded.
– Not reliable enough response for hard constraints, but useful for
systems where some of the signals can be missed without
adversely impacting the user experience.
– Examples: streaming of audio and video, web cams, stock
market activity
Parallel Processing
• Multiprocessors (tightly coupled)
– multiple processors share a common memory:
– Reliability characteristics:
• Service continues upon processor failure (graceful degradation)
• One processor picks up functionality upon failure (fault tolerant)
– Operation can be
• Asymmetric: Each processor performs a separate task
• Symmetric: All processors perform the same tasks simultaneously
• Clustered systems (loosely coupled via local LAN)
– High availability service
– Asymmetric: one machine is in hot-standby mode
– Symmetric: multiple hosts running and monitoring each other
• Grids: loosely connected and geographically separated
• Synchronization is a problem in all parallelism, e.g., processor 1 reads
memory location 59 then processor 2 writes memory location 59,
processor 1’s data is now out of sync.
Computing System Software
Computing System Hardware
Dual-Mode Control
Enables the Operating system to protect itself from rogue programs
• Mode bit: Provided by hardware for dual-mode operation
– User mode: Executing privileged instructions will automatically trap to
the operating system
– kernel mode: Full access to the system is enabled
• Processing
– At boot time: System is automatically in kernel mode
– During System call: Mode automatically changes kernel mode
– After responding to system call: Restore application environment, set
mode to user, and reschedule the application
– Illegal operations: A trap (exception) occurs. Control immediately
transfers to the operating system, which creates a data dump and
terminates the executing program
• Note: Early PC's had no mode bit; applications could (and did) often
crash the entire system – blue screen.
System Timer
Enables the Operating system to maintain ultimate control over the system
• Definition: A device that signals at regular intervals (e.g. every
millisecond)
• Processing: A timer signal occurs
Control transfers to the operating system in kernel mode
Operating System decrements a system counter
IF counter = 0
IF process is compute bound (i.e. allocated time slice expires)
Save application environment and schedule another process to run.
ELSE return control to the application
System Call Processing
System Boot
1. Reset event: The program counter PC is set to the address of the boot
loader in the system BIOS.
2. The instructions in the boot loader:
a. Execute diagnostics
b. Load a boot block from a fixed disk location
3. The boot block then loads the entire operating system into memory
4. The Operating system initializes itself and begins to execute
•
•
•
•
Firmware Notes
Definition: Firmware is a set of instructions programmed persistently on
a Read-only memory (ROM) device.
Early ROM chips had to be physically changed to update the boot loader.
ErasableProgrammableReadOnlyMemory (EPROM) – discovered at Intel
using UV light – patented in 1972.
ElectricallyEPROM – able to erase and rewrite ROM electrically.
System Software Components
• Sysgen:
– Purpose: installs and configures an operating system onto specific
hardware
– Goal: user friendly installation process
• Kernel: The part of the OS that is always in memory
– Provides a basic interface for programs and device drivers
– Includes: scheduler, I/O subsystem, Memory Management module,
and many others
• User Interface: Command line interface, shell, or GUI enabling the
operating system users to issue commands to the OS.
• System Programs: System level applications that normally reside
on disk. Examples include loaders, compilers, editors, disk utilities, batch
systems, communication services, system usage monitors, etc.
The Operating System
• Operating System Functions
–
–
–
–
–
–
–
–
–
–
–
Create a secure and stable user-friendly environment
Efficiently schedule and execute programs (processes )
Read and write from system hardware devices
Connect to local and wide area networks
Manage memory allocation and protect against illegal access
Define and maintain the directory and access to secondary storage
Allocate and share resources efficiently and fairly
Maintain system security
Enforce scheduling priorities
Recovery from system faults
Perform low-level system services for applications
• Implementation
– Higher level language: Portable, fast development, more maintainable
– Assembly language: fast, less portable, difficult to maintain
– Typical operating systems: 95% C, 5% Assembly
Optimizing System Terms
• Multiprogramming: Concurrent process execution
– A set of processes is kept in memory (or partially on disk)
– OS process (job) scheduler chooses next process to run
– A context switch occurs when a process blocks,
e.g., for I/O.
• Time sharing: Multiple users
– OS does a context switch when a process blocks or its time
slice expires.
• Multithreading: Processes may have subprocesses
(threads)
– Threads are spawned by processes. All threads in the same
process share the memory assigned to that process
– Thread synchronization is the responsibility of the process
– Processes can spawn other processes as well as threads. A
new process goes on the OS process list and is separately
scheduled.
Optimizing System Terms, con’t
• Considerations
– Context Switch changes the running process
– Virtual memory allows execution of processes that don't fit in memory
Context Switches are the thief of time – OS only allows a process to run for
specified periods of time
Virtual memory is the thief of space – OS chooses which portions of a
process’s memory image are stored in real memory and which portions are
stored on disk
Process Management
• A process is a program that is executing.
– Programs are passive (blocks of executable instructions/data)
– Processes are active (A running program.)
• Operating System responsibilities
–
–
–
–
–
–
– Give processes the resources they need
Provide an interface (a set of system calls), so a process can
call the OS
Protect processes from one another
Allow processes to communicate with one another
Implement fair share scheduling algorithms
Terminate and reclaim reusable resources
Create and manage execution of threads
• Note: Typically systems have many processes running. These
include applications, system processes, and background services
Kernel Scheduling Algorithms
• Short Term (Non-swapping context switches)
–
–
–
–
–
–
Runs whenever the current process blocks for I/O or its time slice expires
Look at queue of processes that are ready to run
Decide which has the highest priority
Restore its runtime environment
Set the system to user mode
Transfer control to the process
• Medium Term (Swaps processes)
– Writes blocks of memory used by a low priority process to disk (swap
out)
– Reads blocks of data needed by a high priority process into memory
(swap in)
• Long Term (Low priority background process)
– Launch processes (jobs waiting to enter the system)
– Not all OS’s have one of these
Von Neumann model
Predicated on a separation of processing and memory logic. Relatively small
amounts of memory (registers and caches) reside on the processor chip.
Process Control Block
Definition: An block of memory in the kernel that maintains
the state of one process, storing:
• A program counter and registers for all threads in a
process
• Pointers to the resources allocated to a process
– File and device handles
– Mutexes
– Connections to remote resources
• Physical and logical memory allocated to this process
(which can be contiguous or not, in memory or on disk)
• Initialization data
• Runtime statistics and accounting information (used by
the long term scheduling algorithm described above)
• Links to shared memory and connections, e.g., an open
socket, to other processes
Memory Management
• Memory: volatile large array of bytes directly accessible by the
processor. Can be DRAM (dynamic ram – one transistor per bit) or RAM
(volatile transistor based storage)
• Operating System responsibilities
–
–
–
–
–
–
Keep track of which parts of memory are currently in use
Transfer processes (or parts thereof) and data in and out of memory
Allocate and release memory space as needed
Maintain sections of memory for caching disk operations
Assign memory shared by multiple processes
Map logical program addresses into physical memory and maintain
portions that are on disk and not contiguous
“logical program addresses” – the compiler generates jump instructions, e.g., jump
1024, but when the program is actually running, the piece of physical memory holding
the instruction at what the compiler called 1024 may be at, e.g., 32168.
– Prevent processes from overwriting each other's memory
Protect and Manage Memory
Operating System
P1 part 1
P1 part 2
p1 part 3
Disk
Memory Management Examples
Free BSD
MS-DOS
(a) no process (b) process running
Storage Management
The file system
• Provide a uniform logical view of data
– A logical storage view abstracts physical properties
– Each medium is controlled by a storage device
– Examples: disk, flash disks, cd, dvd, tape
• OS responsibilities
– Format media with a particular file system – not usually
done in the kernel.
– Mount and dismount devices
– Maintain secondary storage by effectively mapping files
onto available areas of main memory
– Backup files onto stable storage media
– Establish transparent connections to remote data
– Establish access control mechanisms
– Schedule reads and writes for maximum efficiency
Storage Hierarchy
• Storage systems are organized in hierarchy
– Higher levels are faster, smaller, and are more likely to be volatile
– Lower levels are slower, larger, and are less likely to be volatile
– Higher levels serve as caches for lower levels
• Cache: Temporarily copy data into faster storage (verb)
–
–
–
–
Medium holding a copy of data (noun)
Locality principle: Data accessed in clusters and stored together
Load policy: Retrieve the data needed plus surrounding data
Replacement policy: Choice of cache items to expel when the cache fills
Processing:
• The system looks to a faster cache before accessing the slower hierarchy levels
• On updates, lower levels are either immediately updated (write through) or
updated only when an item is expelled (delayed write) from the higher level
cache
• Cache coherence (consistency of cached data) is an important consideration in
systems that contain multiple caches
• Caching can be explicitly OS controlled or implicitly done in hardware
Fast Expensive
Secondary Storage Hierarchy
Volatile
Non
Volatile
Slow Cheap
The box labeled “cache” means a hardware cache that resides on the processor chip, which is
faster than main memory, but slower than registers, which also reside on the processor chip.
Storage Hierarchy Performance
•
•
•
“Registers managed by the compiler” means the compiler is responsible for generating code
that stores data in specific registers. Note: this ‘management’ does not take place in real
time – the compiler produces the memory image that is eventually run by the operating
system.
“cache managed by the hardware” – think of the cache as intermediate storage for data
moving from registers to main memory and visa versa. Modern hardware handles manages
these data transfers invisibly to the software – including the OS.
“Backed by” means ‘copied to’, so, at run time, the registers are copied to the cache, the
cache to main memory, and so on.
Cache Coherence
• We must always use the most recent value,
no matter where it is in storage hierarchy
• A Multiprocessor environment must provide
cache coherency. All CPUs have the most
recent value in their local cache
• Distributed environments are even more
complex
I/O Management
• Purpose: hide hardware specifics from users
• I/O subsystem responsible for
– Buffering (storing data temporarily while it is being transferred)
– Caching (storing parts of data in faster storage for performance)
– Spooling (writing to disk instead of directly to the device) – print
spoolers are a common example
– Uniform device-driver API to abstract device specifics
– Managing drivers (software modules) for specific hardware devices
• Device Controllers – Hardware devices
–
–
–
–
–
Operate simultaneously and autonomously with CPU
Are limited instruction set processors to solely manage devices
Are responsible for a particular type of device
Contain local memory buffers and hardware registers to control I/O
Example: SCSI (small computer-systems interface) handles seven
or more devices
The Interrupt
Definition: A hardware signal that
forces a program counter (PC) change
• Programmable Interrupt controller (PIC)
– One input line per controlled device, e.g., disk, usb, audio
– Output lines to the CPU to communicate an interrupt’s type and priority
• Interrupt handling mechanism in the CPU
– Able to notice a signal incoming from PIC and transfer control to firmware or
OS code.
• Interrupt request (IRQ)
– When a hardware device completes an operation, it issues an IRQ to
the PIC on its line. The PIC has output lines to the CPU to
communicate an interrupt’s type and priority.
– When software requests a service or attempts an illegal operation
the interrupt handler is activated. (Called a trap, not an interrupt, but
causes the interrupt handler to be activated.)
Interrupt control flow
• Device raises an interrupt signal, and PIC signals
CPU
• Interrupt handler in CPU disables lower priority
interrupts
• The program counter (PC), registers, etc saved
• An interrupt type used to set PC to correct device
driver (part of the kernel)
• Device driver processes the interrupt
• Incoming lower level interrupts are re-enabled
• Control goes back to the OS short term scheduler
Various OS/hardware strategies for
Handling Devices
1. Programmed I/O: Computer starts an operation and then waits in a
tight loop for the operation to complete – a real-time OS strategy
2. Polling: A loop that inquires and responds to each device
3. Interrupts (interrupts raised by completing devices)
a.CPU starts an operation then switches to a different process
b.When an interrupt occurs, CPU transfers available data, so data is
transferred piece by piece, as each interrupt occurs
4. Direct Memory Access (DMA)
a.CPU starts an operation then switches to a different process
b.Device/controller transfers data directly to main memory
independent of the CPU
c. Computer responds to interrupt when device i/o is done
Device Controllers
Non-DMA devices:
Interrupt-driven IO
Direct Memory Access
(DMA) devices
Device-Status Table
Stored in the kernel – a queue of IO requests
Protection and Security
• Protection: OS mechanism to control process access to system
resources
– Distinguish between authorized and unauthorized use
– Detect and recover from hardware faults
– Examples: infinite loops, control to unauthorized memory in user
mode, disk corruption
• Security: OS support for attack defense mechanisms
– Attack Examples: denial-of-service, worms, viruses, identity theft
• Techniques to enforce protection and support security
– Distinguish between groups of users: user ID and group ID
– Privilege escalation: process requests root user privileges (setuid
call)
– File and other resource Access Control, e.g., rwx rights (chmod)
User Interface
Definition: The mode of communication between the operating system and users
• Embedded systems: special purpose buttons and displays
• Unix and batch systems: command line interface (CLI)
– Direct command entry
– Fetch command and execute
– Fast commands execute directly, others launch system programs
• Windows and IOS: Graphics User Interface (GUI)
–
–
–
–
Point and click: mouse, keyboard, and monitor
Touch: finger movements trigger actions
Icon based: files, programs, actions, etc show as icons
Various types of mouse clicks respond accordingly
• Hybrids: Both CLI and GUI components
–
–
–
–
Microsoft Windows is GUI with CLI “command” shell
Apple Mac OS X is GUI interface with various UNIX shells
Solaris is CLI with optional GUIs (Java Desktop, KDE)
Handheld has terminal apps with touch controls
Other OS responsibilities
• Error checking (and actions taken)
–
–
–
–
Faulty disk sectors (maintain spare tracks and sectors)
Physical memory failure (skip use of memory areas)
Network connection problems (retransmission)
Device redundancy (switch devices automatically upon failure)
• Backup and clean up facilities
– Backup utilities and scheduling, Disk defragmenter, disk
verifier (bad block checks), firewall
System Call – OS Application API
• The OS implements a table of available system calls, each with a welldefined interface
• When a user program makes a syscall, a trap happens, which
transfers to the kernel, which then executes and returns.
Parameter Passing via Table
OS Organization Examples
Solaris Kernel Modules
Layered Approach
Unix Kernel
•
•
•
•
•
Each layer built on top of lower layers.
The bottom layer (layer 0), is hardware
The highest (layer N) is user interface.
layers use services of lower-level layers
Easy to debug, and test replacement
layers
OS Policies and Mechanisms
Policy (Design Goal)
Mechanism (Implementation)
Program Independence
Restrict memory access
Fair scheduling of resources
Priority scheduling
Support many devices
Standard device driver interface
Transparent input and output
Privileged instructions
Plug and play
Check for new hardware
Fault recovery
Device redundancy
Authentication/authorization
Access control lists, passwords
Run very large programs
Virtual memory
Handle critical sections
Semaphores
Concurrency
Multithreading, Multiprogramming