Operating Systems Concepts
Module Learning Objectives
- What is an Operating System?
- Components of an Operating System
- Computer System Operation
- Operating System Functions and Structure
- Operating System Storage
- Operating System Cache/Memory
- Operating System Management
- Open Source Operating Systems
What is an Operating System?
- An operating system (OS) is a program that acts as an intermediary between a user of a computer and the computer hardware.
- OS goals:
- Execute user programs and make solving user problems easier
- Make the computer system convenient to use
- Use the computer hardware in an efficient manner
- OS tasks:
- Controls and coordinates use of hardware among various applications and users
- OS is a resource allocator that manages conflicting requests of resources
- OS is a control program that controls execution of programs
Bootstrap and Kernel
- When does an OS start running?
- Bootstrap program is loaded at power-up or reboot
- Typically stored in BIOS/UEFI on ROM (Read-Only Memory) or EPROM (erasable programmable read-only memory), generally known as firmware
- The BIOS is a set of computer instructions in firmware which control input/output operations
- Loads operating system kernel and starts execution of computer system operation
- “The one program running at all times on the computer” is the kernel
Computer System
Components of a Computer System:
- Computer Hardware
- Operating System
- System/Application Programs
- Users
Operation of a Computer System:
- One or more CPUs, device controllers connect through a common bus providing access to shared memory
- Concurrent execution of CPUs and devices competing for memory cycles
- 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 is from the device to the local buffer of the controller
- Device controller informs CPU that it has finished its operation by causing an interrupt
I/O Structure and Operation
- After I/O starts, control returns to the user program only upon I/O completion
- Wait instruction idles the CPU until the next interrupt
- Wait loop (contention for memory access)
- At most one I/O request is outstanding at a time, no simultaneous I/O processing
- Alternatively: system call – request to the OS to allow the user to wait for I/O completion
- Device-status table contains entry for each I/O device indicating its type, address, and state
- OS indexes into the I/O device table to determine device status and to modify table entry to include interrupt
Computer Storage
- The basic unit of computer storage is the bit: a bit can contain one of two values, 0 and 1
- All other storage in a computer is based on collections of bits
- Given enough bits, it is possible to represent numbers, letters, images, movies, sounds, documents, processes, programs, etc.
- A byte is 8 bits, and on most computers it is the smallest convenient chunk of storage
- A word is the computer architecture’s native unit of data; example: 64-bit registers and 64-bit memory addressing typically have 64-bit (8-byte) words
- A computer executes many operations in its native word size rather than a byte at a time
Storage Quantities
- A kilobyte, or KB, is 1,024 bytes
- A megabyte, or MB, is 1,024^2 bytes
- A gigabyte, or GB, is 1,024^3 bytes
- A terabyte, or TB, is 1,024^4 bytes
- A petabyte, or PB, is 1,024^5 bytes
Computer Storage Structure
- Main memory – the large storage medium the CPU can access directly
- Random access
- Typically volatile
- Secondary storage – extension of main memory that provides large nonvolatile storage capacity
- Hard disks – rigid metal or glass platters with magnetic recording material
- Disk surface is logically divided into tracks, which are subdivided into sectors
- Disk controller determines the logical interaction between the device and the computer
- Solid-state disks – faster than hard disks, nonvolatile
- Various technologies
- Becoming more popular
Storage Device Hierarchy
- Registers
- Cache
- Main memory
- Solid-state disk
- Hard disk
- Optical disk
- Magnetic tapes
Storage Performance Levels
- Level 1: Registers
- Size: < 1 KB
- Implementation: custom memory with multiple ports
- Access time: 0.25-0.5\ \text{ns}
- Bandwidth: 20{,}000-100{,}000\ \text{MB/sec}
- Managed by: compiler
- Level 2: Cache
- Size: < 16 MB
- Implementation: CMOS on-chip or off-chip
- Access time: 0.5-25\ \text{ns}
- Bandwidth: 5{,}000-10{,}000\ \text{MB/sec}
- Managed by: hardware
- Backed by: main memory
- Level 3: Main memory
- Size: < 64 GB
- Implementation: CMOS SRAM
- Access time: 80-250\ \text{ns}
- Bandwidth: 1{,}000-5{,}000\ \text{MB/sec}
- Managed by: operating system
- Level 4: Solid-state disk
- Size: < 1 TB
- Implementation: flash memory
- Access time: data not explicitly specified in the slide
- Bandwidth: data not explicitly specified in the slide
- Managed by: operating system
- Level 5: Magnetic disk
- Size: < 10 TB
- Implementation: magnetic disk
- Access time: 25{,}000-50{,}000\ \text{ns}
- Bandwidth: \sim 500\ \text{MB/sec}
- Managed by: disk
- Level 6: Magnetic tape (as the next level in the hierarchy beyond disks per the provided sequence)
- Data not explicitly specified in the excerpt; generally used for archival storage
Caching
- Important principle: caching is performed at many levels (hardware, OS, software)
- Idea: information in use is copied from slower storage to faster storage temporarily
- If data is in the cache, use it directly from the cache (fast)
- If not in cache, copy data to cache and then use it there
- Cache is smaller than the storage it caches
- Cache management is a major design problem: cache size and replacement policy
DMA Structure
- DMA stands for Direct Memory Access
- 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 one interrupt per byte
Operating System Structure
- Multiprogramming (Batch system) needed for efficiency:
- A single user cannot keep the 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 is kept in memory
- One job is selected and run via job scheduling
- When a job has to wait (e.g., for I/O), the OS switches to another job
- Timesharing (multitasking) is the logical extension in which the CPU switches jobs so frequently that users can interact with each job while it is running
- Target: response time should be < 1 second
- Process: a program in execution; each user has at least one program executing in memory
- CPU Scheduling: when several jobs are ready to run at the same time
- If processes don’t fit in memory, swapping moves them in and out to run
- Virtual memory allows execution of processes not completely in memory
Operating System Operations
- Interrupt-driven (hardware and software)
- Hardware interrupt by one of the devices
- Software interrupt (exception or trap): software error (e.g., division by zero) or request for OS service
- Other problems include infinite loop, processes modifying each other or the OS
- Dual-mode operation allows the OS to protect itself and other components:
- User mode and kernel mode
- Mode bit provided by hardware
- Ability to distinguish when the system is running user code or kernel code
- Some instructions are privileged, only executable in kernel mode
- System call changes mode to kernel, return from call resets it to user
Process Management
- A process is a program in execution; a unit of work within the system
- Program vs process:
- Program is a passive entity; process is an active entity
- A process needs resources to accomplish its task: CPU, memory, I/O, files; initialization data
- Process termination requires reclaim of any reusable resources
- Single-threaded process has one program counter; executes instructions sequentially until completion
- Multi-threaded process has one program counter per thread
- In a system there are many processes, some user, some OS; running concurrently on one or more CPUs
- Concurrency achieved by multiplexing CPUs among the processes/threads
Storage Management
- OS provides a uniform, logical view of information storage
- Abstracts physical properties to a logical storage unit – the file
- Each medium is controlled by a device (disk drive, tape drive)
- Varying properties include: access speed, capacity, data-transfer rate, access method (sequential or random)
- OS activities include:
- Creating and deleting files and directories
- Primitives to manipulate files and directories
- Mapping files onto secondary storage
- Backing up files onto stable (non-volatile) storage media
Memory Management
- To execute a program, all (or part) of the instructions must be in memory
- All (or part) of the data needed by the program must be in memory
- OS performs memory management to determine what should be in memory and when
- Aims to optimize CPU utilization and user response
- Memory management activities:
- Keeping track of which parts of memory are currently used and by whom
- Deciding which processes (or parts) and data to move into and out of memory
- Allocating and deallocating memory space as needed
Kernel Data Structures
- What is the Kernel in the OS?
- A kernel is a central component of an operating system that manages the operations of computers and hardware
- It is the core part of an OS
- It is the bridge between software applications and the hardware of a computer
Kernel Data Structures – Examples
- Singly Linked List
- A singly linked list is a data structure consisting of nodes where each node contains data and a pointer to the next node
- Doubly Linked List
- A doubly linked list contains three parts: data, a pointer to the previous node, and a pointer to the next node
- Circular Linked List
- A circular linked list links the last node back to the first node; there is no distinct start or end node
Open Source Open Source OS
- Open Source OS basics:
- Operating systems made available in source-code format rather than just binary (closed-source)
- Counter to copy protection and Digital Rights Management (DRM) movement
- Started by Free Software Foundation (FSF), which promotes copyleft GNU Public License (GPL)
- Examples include GNU/Linux and BSD UNIX (including core of Mac OS X), and many more
- Open source can be used with virtual machines (VMs) like Hyper-V, VMware, VirtualBox, etc.
- Open source can be used to run guest operating systems
Practical and Philosophical Implications
- Open Source OS implications:
- Transparency and potential for security improvements due to public scrutiny
- Freedom to modify and customize for specific needs
- Licensing (e.g., GPL) imposes obligations on modifications and redistribution
- OS design choices impact performance, reliability, and security:
- Cache design and replacement policies influence system speed
- Memory management and virtual memory affect program locality and capacity to run large workloads
- I/O strategies (interrupts, DMA) affect throughput and CPU utilization
- Ethical/practical considerations:
- DRM and copyleft debates influence user rights, software freedom, and vendor control
- Open source promotes governance models focused on collaboration and transparency
To Dos for this module
- Quiz: Operating System Basics
- Essay: Operating System Basics
- Assignment: Data and OS Architecture Binary Math
- Discussion: Learning Reflection