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)
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.
Kernel
Kernel: “The one program running at all times on the computer”
This is what we care about in this class.
On Course Scope: For this class, we don’t care about:
System programs (file manager, device drivers, task manager, etc.), or
Application programs (web browser, games, etc.)
The OS as an Extended Machine
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.
Four Components of a Computer System
User
System & Application
Compiler, Assembler, Text Editor, Database System, …
Operating System
Hardware
What Operating Systems Do
Depends on POV.
User:
Single-user system wants convenience, ease of use, and good performance.
Doesn’t care about resource utilization.
Optimized for single-user rather than multiple users.
Multi-user system shares the computer and keep all users happy.
e.g., Mainframe, minicomputer, etc.
Even users of dedicated workstations may frequently share resources from servers.
Handheld computers are resource poor, optimized for usability and battery.
Embedded systems have little or no UI
e.g., Raspberry Pi, car consoles, etc.
System:
OS is a resource allocator
Manages all resources
OS is a control program
Controls execution of programs to prevent errors and improper use of the computer.
Resource Management
OS as a Resource Manager:
Multiprogramming: Technique that keeps several programs active in memory and switches execution among the 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.
Like above, CPU can only context switch after we reach an I/O bound instructions.
Sequential: Run through processes sequentially. CPU simply waits through I/O instructions.
Example
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
Startup
Bootstrap Program: Firmware that initializes all aspects of system.
Knows how to load the OS.
Typically stored in ROM or EEPROM.
Organization
Device controllers connect through common bus providing access to shared memory.
The CPU, disk controller, USB controller, graphics adapter all have to compete for memory cycles and bus access.
Operation
Device Controller:
Is in charge of a particular device type.
Has some local buffers and a set of special-purpose register.
Moves data between peripheral devices and its local buffers.
CPU moves data from/to main memory to/from local buffers.
Informs CPU it has finished an operation via interrupt.
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.
Example: Starting an IO 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.
One transfer complete, device controller informs device drivers via interrupt it is finished.
Device driver returns control to OS.
We can use DMA to speed this up.
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.
Smaller than the slower storage.
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.
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 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: TODO
Dual Core: Recent trend in TODO
Clustered Systems: Like multiprocessor, but it’s multiple systems instead.
Usually sharing storage via SAN (storage-area network).
Provides high-availability service which survives failures.
Two Types of Clustered Systems: TODO
Asymmetric: Boss-worker hierarchy.
Symmetric: TODO
Major Functions of the OS
Process Management: Provide process abstraction, and manage processes with CPU scheduling.
Memory Management: Share memory among processes, safely (syncronization).
Storage (disk) Management: Provide file abstraction, manage files.
e.g., mapping files to disk blocks, disk scheduling
I/O Control and Management: Device drivers, buffering, providing uniform access interface.
Protection and Security: Control access to resources, prevent interference with OS and other processes.
Reminder: Definitions
Process: A program (list of instructions and data) that is in memory and being executed.
Things to Think About:
Memory Management:
How can we syncronize access?
How can we defragment memory?
How do we make sure processes only have access to their allocated memory?
What about a swapfile?
Computing Environments
Traditional
We are used to standalone general-purpose machines.
The standalone aspect has been blurred with interconnection via stuff like the internet.
Portals provide web access to internal servers.
Network computers (thin clients) are like Web terminals.
Mobile computers interconnect via wireless networks.
Networking became ubiquitous.
Even home systems use firewalls to protect home computers from internet attacks.
Distributed
Collection of separate, possible heterogeneous, systems networks together.
Network: A communication path.
Network Operating System: An OS made for networking.
Usually does some virtualization/abstraction to create the illusion of a single system.
Common Network Types:
LAN: Local Area Network
WAN: Wide Area Network
MAN: Metropolitan Area Network
PAN: Personal Area Network
Cloud
Deliver computing, storage, and/or apps as a service across a network.
Is a logical extension of virtualization.
e.g., Amazon EC2 has thousands of servers, millions of VM, petabytes of storage, all accessible over the internet.
Major Types:
Public: Available to anyone willing to pay
Private: Run by a company for internal use.
Hybrid: Includes public and private cloud components.
Service Types:
Software as a Service (SaaS): e.g., word processor
Platform as a Service (PaaS): e.g., db server
Infrastructure as a Service (IaaS): e.g., b2 bucket for backups
Real-Time Embedded Systems
Special/limited purpose computers.
The most-prevalent form of computers.
Has well-defined time constraints.
Examples: Embedded systems
Pacemakers, coffee makers, air bags.
Open Source Operating Systems
Make available in source-code rather than just binary closed-source.