Operating System: Program that runs on bare hardware to help bridge the gap between user and computer hardware.
Role & Goals
Role of the Operating System:
Direct resources (e.g., CPU, memory, peripherals)
Enforce working policies (e.g., share resources fairly, limit resource usage)
Make complex tasks easier (e.g., system calls)
Goals of the Operating System:
Execute user programs and make solving user problems easier.
Make computer convenient to use.
Use hardware efficiently.
Example: Hardware v.s. User Needs
Component
Capabilities
User Needs
CPU
Low-level machine instructions.
Arrays, lists, and other high-level data structures and operations.
Main memory
Linear sequence of addressable bytes / words.
A heterogeneous collection of entities of various types and sizes, accessed by different operations.
Secondary storage
Multi-dimensional structures that require complex sequences of low-level operations to store and access data organized in discrete blocks.
Ability to access and manipulate programs and data without knowledge of disk organization.
I/O devices
Operated by reading and writing registers of the device controllers.
Simple, uniform interfaces to access different devices without detailed knowledge of the access and communication protocols.
Core OS Concepts
Abstraction and Virtualization
Abstraction: Act of removing unimportant details or attributes of objects to make more general and less complex objects.
Makes operations easier to use.
Example: Abstraction at the Programmer and User
Level
User Abstraction: “Copy file f1 to file f2”
OS:
Create file f2
Open file f1 for reading
Repeat for all blocks i of f1:
Read block i into memory buffer
Allocate new block j for file f2
Write memory buffer to block j
Programmer Abstraction: “Read block n into memory at location m”
OS:
Compute block location on disk
Move read/write arm into position.
Check for positioning errors.
Transfer data to memory starting at m.
Check for read errors.
Virtualization: Act of creating the illusion of having one or more objects with more desirable properties than the real object.
e.g., virtual CPUs, memory, I/O devices, etc.
Example: Virtual memory
Virtual memory creates the illusion that each program has access to a large, contiguous address space, even though the actual physical memory may be fragmented, shared with other programs, or partially stored on disk.
OS Conceptual Roles
From a system perspective, the OS can be viewed in two key roles:
OS as a resource allocator:
It manages all resources.
OS as a control program:
It controls execution of programs to prevent errors and improper use of the computer.
Computer System Structure
Four Components of a Computer System
User
System & Application
e.g., compiler, assembler, text editor, database system, etc.
Operating System
Hardware
System Startup & Organization
Bootstrap Program: Firmware that initializes all aspects of system.
Knows how to load the OS.
Typically stored in ROM or EEPROM.
System Bus: Device controllers connect through common bus providing access to shared memory.
e.g., the CPU, disk controller, USB controller, graphics adapter, etc. compete for memory cycles and bus access
System Operations
Device Controller:
Is in charge of a particular device type.
Has some local buffers and a set of special-purpose registers.
Moves data between peripheral devices and its local buffers.
CPU moves data between main memory and local buffers (in both directions).
Informs CPU it has finished an operation via interrupt.
Example: Starting an I/O operation
Device driver loads appropriate registers within the device controller
Device controller examines contents of these registers to determine what action to take
e.g., “read from keyboard”
Controller starts transfer of data from device to local buffer.
Once transfer completes, device controller informs device drivers via interrupt it is finished.
Device driver returns control to OS.
Note — We can use DMA to speed this up.
Storage Subsystem
Storage Structure
CPU can load instructions only from memory.
RAM: Only large storage media the CPU can access directly.
Random access
Usually too small to store all programs and data.
Typically volatile (loses contents on shutoff).
Secondary Storage: Extension of main memory that provides large nonvolatile storage for permanent data.
Hard Disks: Logically divided into tracks, subdivided into sectors.
SSDs: Faster than hard disks.
Storage Hierarchy
Ordered fastest to slowest and most expensive to cheapest:
Registers
Cache
Main Memory
SSD
HDD
Optical Disk
Magnetic Tapes
Note: 1—3 are volatile, 4—7 are non-volatile.
Caching
Cache: Information in use copied from slower to faster storage temporarily.
Important principle at many levels (hardware, OS, software).
Checked first to determine if information is there.
If it is, information is used directly from the cache.
If not, data is copied to the cache and used.
Recall — The guiding principle of “smaller is faster”. This is why CPUs have layers of cache. (Related Notes: “CPU”, from CS3650)
Direct Memory Access (DMA)
Used for high speed I/O devices so that can transmit information at close to memory speeds.
Basically, we give devices permission to move entire blocks of information, rather than slowly sending 1 interrupt per byte.
Hardware Architecture
Many years ago, most systems only had one general-purpose processor (one CPU with a single processing core).
Core: Component that executes instructions and has registers for storing data locally.
Systems may come in the form of device-specific processors.
Multiprocessor: Growing in use and importance.
aka: Parallel systems, tightly-coupled systems
Increases throughput
Economy of scale (cheaper than multiple computers)
Increased reliability (graceful degradation and fault tolerance)
Two Types of Multiprocessors
Asymmetric: Boss-worker hierarchy.
Symmetric: Peer relation.
Dual Core: Multiple cores on a single chip ends up more efficient than multiple single-core chips.
Clustered Systems: Like multiprocessor, but it’s multiple systems instead.
Usually sharing storage via SAN (storage-area network).
For high-availability services or high-performance computing.
Two Types of Clustered Systems:
Asymmetric: One machine stays in hot-standby, where it just monitors the active server and takes over if the active server fails.
Symmetric: Multiple nodes run applications and monitor each other.
Major Operating System Functions
Process Management
Process Management: Provide process abstraction, and manage processes with CPU scheduling.
Reminder: Definitions
Process: A program (list of instructions and data) that is in memory and being executed.
Multiprogramming: Technique that keeps several programs active in memory and switches execution among different programs to maximize the use of the CPU and other resources.
When a program enters an I/O-bound phase where little CPU time is needed, other programs can resume and utilize the CPU in the meantime.
Time-Sharing (Multitasking): Extension of multiprogramming where the CPU is switched periodically among all active computations to guarantee acceptable response times.
Employs concept of virtualization.
The time assigned to each process is the quantum. We’ll cover optimal quantum later.
print, in this example, is I/O bound (need to do the slow task of communicating to a peripheral to print).
Multiprogramming: When we hit print, we context switch to a separate process so CPU can stay busy with other CPU-bound instructions. Once the I/O bound portion is done, we signal we are done via interrupt, and the CPU will get back to us.
This behavior means that we only interrupt when we reach an I/O bound instruction.
Once the CPU begins working on a chunk of CPU-bound instructions, it cannot interrupt until the next I/O-bound instruction
Time-Sharing: Imagine a timer on a process. When that timer runs out, the CPU will context switch to a different process and the process will have to wait for its turn.
Sequential: Run through processes sequentially. CPU simply waits through I/O instructions.
Example: Comparing Sequential, Multiprogramming, and
Timesharing
Processes p1 and p2 share a single CPU and 2 independent I/O devices. Each process executes a compute-bound phase of 10 time units followed by an I/O bound phase of 10 units.
Sequential: 40 TU
CPU
A
B
IO 1
A
IO 2
B
Multiprogramming: 30 TU
CPU
A
B
IO 1
A
IO 2
B
Timesharing: 20 TU (if context switching is negligible)
CPU
A
B
…
A
B
IO 1
A
IO 2
B
Memory Management
Share memory among processes, safely.
Storage (Disk) Management
Provide file abstraction, manage files.
e.g., mapping files to disk blocks, disk scheduling