Input/Output Systems, Storage, and CPU Security Mechanisms
Types of I/O Devices
Block Devices
Store data in fixed-size blocks. Data transfer happens in blocks (e.g., SSD).
Character Devices
Handle a stream of characters with no block structure (e.g., Keyboard, Mouse). They do not support seek operations.
Block vs. Character Devices
Block devices support random access and block-level operations, while character devices operate in a stream and cannot seek.
I/O Communication Methods
Separate I/O and Memory Space
Provides easier separation but is less flexible.
Memory-Mapped I/O (MMIO)
A portion of memory (RAM) is used for device I/O. This method is more flexible but reduces the memory available for programs.
Hybrid Communication
A mix of both methods: essential devices (e.g., keyboard) use separate space, while others use shared space.
Benefits and Drawbacks of Memory-Mapped I/O
- Benefit: Easier programming since devices are accessed like memory locations.
- Drawback: Reduces the amount of usable memory for applications.
Bus and Access Mechanisms
The System Bus
A shared communication path between the CPU, memory, and I/O devices. It is fast and connects all components. (Note: L1/L2 refer to specific caching levels within the CPU.)
Direct I/O
The CPU is directly involved in data movement, which is time-consuming and slow.
Direct Memory Access (DMA)
The CPU sets up the transfer and delegates the task to the DMA controller. The DMA controller handles the data transfer independently and interrupts the CPU only when the operation is complete.
Why DMA Improves Efficiency
DMA allows large data transfers to occur without continuous CPU involvement, significantly improving system efficiency.
Interrupts
Device Interrupts
A device interrupts the CPU when it requires attention. This mechanism saves time compared to continuous polling.
Precise Interrupts
A precise interrupt adheres to the following conditions:
- The Program Counter (PC) is saved in a known location.
- All instructions preceding the instruction pointed to by the PC have been executed.
- No instructions following the instruction pointed to by the PC have been executed.
- The execution state of the instruction pointed to by the PC is known.
Imprecise Interrupts
An imprecise interrupt occurs if one or more of the conditions for a precise interrupt fail.
Importance of Precise Interrupts
Precise interrupts ensure predictable program behavior and allow for safe resumption of execution after the interrupt is handled.
Goals of I/O Software
- Device independence
- Uniform Naming
- Error Handling
- Synchronous vs. Asynchronous I/O support
- Buffering (to match device speeds)
Purpose of Buffering
Buffering is used to accommodate speed mismatches between different devices and to ensure smooth data flow.
I/O Methods
Programmed I/O (PIO)
The CPU actively polls and handles I/O operations, which is generally inefficient (e.g., checking email manually).
Interrupt-Driven I/O
The CPU initiates the I/O operation and then waits for an interrupt signal to indicate completion (e.g., a push notification).
DMA-Based I/O
The CPU instructs the DMA controller to manage the I/O transfer and is only notified via an interrupt once the transfer is complete.
Comparison of I/O Methods
- Programmed I/O: CPU wastes time polling.
- Interrupt-Driven I/O: CPU is freed up between the start and finish of the I/O operation.
- DMA-Based I/O: Most efficient method for handling large data transfers.
I/O Software Layers
- User-Level I/O Software: Applications that request I/O (e.g., Discord).
- Device-Independent I/O: The Operating System (OS) interface that provides a uniform way to interact with various devices (e.g., Discord voice chat using the OS microphone driver).
- Device Drivers: Software components that communicate directly with the hardware (the interface between the microphone and the OS).
- Interrupt Handlers: Routines designed to handle hardware interrupts.
- Hardware: The actual physical device.
Buffering Techniques
Why Buffering is Necessary
Buffering is used to match the speed of the CPU with that of slower I/O devices.
Types of Buffering
- User Space: The buffer is stored in the application’s memory.
- Kernel Space: The buffer is managed by the Operating System, offering faster performance and more control.
- Double Buffering: Uses two buffers simultaneously.
Double Buffering
Double buffering allows one buffer to be filled while the other is being emptied, significantly improving I/O throughput and system responsiveness.
Circular Buffer
A buffer structure where the buffers loop back around, commonly used in streaming and logging applications.
Disk Structure and Access
Disk Components
Disks are composed of Platters, Sectors, and Tracks.
Key Access Delays
- Seek Time:
- The time required to move the read/write head to the correct track.
- Rotational Delay:
- The time spent waiting for the desired sector to rotate into position under the head.
- Transfer Time:
- The time taken to actually read or write the data.
RAID Levels
RAID Configurations
- RAID 0 (Striping): Fast performance but offers no redundancy.
- RAID 1 (Mirroring): Creates a duplicate copy for fault tolerance.
- RAID 2–6: Utilize parity bits and backup disks for fault tolerance.
RAID Redundancy
RAID 1 and RAID 5/6 provide redundancy through mirroring or parity mechanisms.
Disk Formatting and Scheduling
Disk Formatting
The disk is logically divided into sectors, tracks, and cylinders. Interleaving is sometimes used to space out sectors for better performance.
Scheduling Algorithms
- FCFS (First-Come, First-Served): Requests are handled in the order they arrive.
- SSF (Shortest Seek First): Prioritizes the request closest to the current head position.
- Elevator (SCAN): The head moves continuously in one direction, servicing requests, then reverses direction.
Minimizing Arm Movement
The SSF (Shortest Seek First) algorithm generally minimizes arm movement.
Stable Storage
Stable storage ensures data persistence even during system failures.
- Stable Writes: Data is written successfully to both primary and backup storage locations.
- Stable Reads: Data is read from both copies and compared for consistency.
- Crash Recovery: If a crash occurs, data is restored from the known good copy.
Clock Software and Hardware
Clock Driver Duties
- Maintain the time of day.
- Enforce time limits for processes.
- Perform CPU usage accounting.
- Handle alarms and scheduled events.
- Manage watchdog timers.
- System monitoring.
Clock Simulation Techniques
Techniques include using a programmable hardware timer and simulating multiple logical timers using a single physical clock.
Preventing Infinite Loops
Watchdog timers are the clock duty responsible for preventing processes from running in infinite loops by enforcing time limits.
X Window System and Device Drivers
X Window System
The X Window System is a client-server graphics system primarily used in UNIX and Linux environments. Clients request display services from the X server.
GUI Application Role
In the X Window System, the client is the Graphical User Interface (GUI) application that makes display requests to the server.
Device Driver Functions
Device drivers are responsible for:
- Configuring hardware.
- Handling DMA and interrupts.
- Exposing standard interfaces (like
read,write,open,close) to the Operating System.
CPU Security Vulnerabilities
Meltdown
Meltdown exploits speculative execution to allow user space programs to access kernel memory, effectively breaking the process isolation barrier. It primarily affects Intel CPUs and was mitigated using KPTI (Kernel Page Table Isolation).
Spectre
Spectre breaks process-to-process isolation by exploiting branch prediction. Both Meltdown and Spectre utilize cache timing and speculative execution techniques to leak sensitive data.
Branch Prediction
Branch prediction algorithms attempt to determine the next instruction that will be executed, retrieving it ahead of time for faster processing.
