0% found this document useful (0 votes)
12 views

11

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

11

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

I/O Hardware

I/O devices are hardware components that facilitate communication between a computer system and
peripheral devices or the external environment. They enable input of data into the system for
processing and output of processed results. I/O devices can be broadly classified into the following
categories:

Input Devices Allow users to input data and commands into the computer system. Common
examples include:

• Keyboard and Mouse: Enable users to input data and issue commands to the operating system
or application programs running on it.
• Barcode/QR code readers: Allow input of machine readable codes that contain encoded data.
• Sensors: Allow environmental properties like temperature, pressure, humidity etc. to be
measured and input into the system.
• Audio/Video capture cards: Allow analog signals like audio, video etc. to be digitized and input
into the system.

Output Devices Allow computer systems to produce outputs that can be consumed by the user.
Common examples include:

• Monitors: Display visual text or graphics output from the system to the user.
• Printers: Produce paper printouts of processed results.
• Speakers: Produce audio output.
• Haptics: Tactile feedback devices.

Storage Devices Allow data to be stored for later retrieval and use. Example include:
• Hard disk drives: Provide non-volatile storage of data and programs
• CD/DVD drives: Allow transfer of data to/from optical storage media
• USB Flash drives: Offer removable non-volatile storage
• Tape drives: Used mainly for backup storage

Communication Devices Enable communication with other systems over a computer network or a
point-to-point link. Examples include:

• Network interface cards (NICs): Enable network connectivity


• Modems: Allow connectivity over telephone lines
• Wireless network cards: Enable connectivity over WiFi or cellular networks.

I/O devices connect to the computer system via I/O ports that allow data to be transferred in or out of
the system. I/O ports connect to internal buses like PCI, SCSI etc. that allow data to flow between the
device and the system memory and processor. Common types of computer ports include:

Serial ports: Transmit data sequentially one bit at a time. Used for low speed devices like older mice.
Parallel ports: Transmit an entire byte simultaneously on 8 separate wires allowing faster transfer
rates. Used for printers, scanners etc.

Universal Serial Bus (USB) ports: Allow hot swapping and easy addition of devices with plug and
play support. Used for most modern peripheral devices.
The device controller is a hardware circuit that enables an I/O device to communicate with the system
across the I/O buses. It acts as an interpreter between the device and the computer system. The key
functions of a device controller include:

Registers: The controller provides special registers that can be accessed by the host processor to issue
device commands, input or output data, and determine device status. Types of registers include:

• Data registers: Enable data input or output


• Status registers: Provide status like ready, busy, error etc.
• Control registers: Used to issue commands like initialize, read, write etc.

I/O bus communication: The device controller handles I/O bus protocols enabling data transfer
between the main memory and the device's internal buffers or storage.

• Buffering: Most devices have different data transfer rate capacities compared to main memory
and processor speeds. Controllers have input and output buffers that match these differing
speeds enabling each component to transfer data at its natural rate without slowing the
system down. This buffering enables concurrency.
• Interrupts: Device controllers can interrupt the host processor when I/O completes or an error
occurs. This facilitates multi-tasking - the CPU can handle other tasks while I/O happens in
parallel.

Direct Memory Access (DMA) is a specialized capability supported by many I/O controllers that
allows them to directly access main memory without going through the CPU. This makes I/O even more
efficient. The sequence of steps for DMA is outlined below:

• The CPU issues an I/O request command to a DMA capable controller.


• On receiving the request, the controller sends a DMA request to the DMA controller chip
rather than interrupting the CPU.
• The DMA controller issues a bus access request to the CPU across the control bus.
• The CPU completes the current machine cycle, disables memory access and provides bus
grants to the DMA controller thereby relinquishing control.
• The DMA controller then directly transfers data between the controller hardware and main
memory without CPU involvement, using address and count information supplied by the
device controller.
• Once the transfer finishes, the device sends an interrupt to the CPU indicating operation
completion.
• The CPU responds to the interrupt, regains control of the system bus from the DMA controller
and resumes its operation.

DMA provides direct access to memory concurrent to CPU operation, enhancing overall system
performance. However, DMA requires explicit hardware support from the device controllers,
motherboard chipset and processor functionality, besides OS kernel support.

On the software side, the high level goals of an operating system's I/O subsystem are:

• Provide uniform naming conventions enabling applications to access devices through standard
path name spaces. Example: use of device files/nodes like /dev/sda1 in UNIX to provide a
consistent namespace.
• Ensure location transparency allowing programs to access local and remote devices seamlessly
using common names whether physically attached or network connected.
• Support user-level application access semantics by providing standard interfaces like
open()/close() requests that can initiate or end access across range of different hardware
devices.
• Controlled access and protection via supporting access control policies, permission checks to
prevent misuse.

Device drivers are critical OS software components that control attached devices on behalf of the
operating system and applications. Their key functions include:

• Initialize controller hardware: Resetting device state and programming control registers at
system boot.
• Enforce OS access control policies: Checking application permissions based on policy defined
by OS with regard to device usage.
• Handle data transfers: Initiating DMA or PIO operations, data buffering, error handling etc.
• Process interrupts: Suspending current process, saving its state, invoking Interrupt Service
Routine (ISR) when device interrupts.
• Manage I/O request queues: Prioritizing, optimally ordering incoming requests for efficiency.

Thus device drivers act as interpreter between physical device hardware and the operating system
kernel providing the abstraction necessary for robust system functioning. The OS determines devices
present on a system at boot time and loads their appropriate drivers dynamically.

The device independent I/O software layer is positioned above the device drivers and enables
applications to access disparate hardware devices using consistent system calls such as open/close,
read/write independent of underlying hardware details. It has two major components:

• Uniform logical device namespaces that provide consistent naming like /dev/hda1 in UNIX to
application programs.
• Device-independent APIs implement common system calls like open()/close() that applications
can invoke irrespective of hardware device details hidden underneath.

This upper layer facilitates applications portability across machines.

Secondary-Storage Structure
Computer systems rely on secondary storage or auxiliary memory devices that provide non-volatile
data storage. Common secondary storage devices are hard disk drives that provide bulk data capacity
for storing operating system files, applications and user data. Hard disks have a series of spinning
magnetic platters coated with magnetic recording material as their storage medium. Key aspects of
hard disk design include:

1. Platters and Surfaces:


• Hard disks contain one or more circular platters stacked on a central spindle. Each
platter has two readable/writeable surfaces for data storage.

• Platters rotate at speeds like 7200 RPM and data bits are stored magnetically using
read/write heads.
2. Cylinders and Tracks

• Disk surfaces are formatted into concentric circles called tracks clustered into
cylinders. All tracks evenly spaced from spindle form a cylinder. This grouping
improves sequential access speeds.

3. Sectors:

• Tracks are further divided into sectors that represent minimum unit of storage.
Sector sizes vary from 512 bytes to 4KB.

4. Head-Positioning System
• Comb-like arms have read-write heads that move in unison and access surfaces of
multiple platters.

• Electronic servos and stepper motors facilitate head-positioning enabling seeking to


millions of tracks.

5. Capacity
• Total storage capacity depends on number of surfaces, tracks per surface, sectors per
track and sector size. Capacity calculation is: Capacity = Number of surfaces × Tracks
per surface × Sectors per track × Sector size in bytes

Thus hard disks provide bulk storage capacity combined with mechanisms supporting direct data
access i.e ability to seek directly to any given sector bypassing those in between. This random access
capability distinguishes secondary storage from sequential-access media like tapes. However, disk I/O
performance is governed by mechanical positioning delays like seek time and rotational latency that
limit speed.

Emerging Storage Technologies


Two major alternatives to traditional hard disks exist - Solid State Drives that use only electronic
memory and Network-Attached Storage.

1. Solid State Drives (SSDs) SSDs use flash memory composed of ICs like EEPROMs or DRAM
chips protected by backup battery. Key aspects of SSDs:

• Data persistence through power failure cycles

• No moving parts - purely electronic medium

• Much faster than hard disks - disjoint access times

• Higher cost per gigabyte compared to HDD currently

• Write cycles per memory cell limits longevity

SSDs represent replacement for hard disks providing secondary storage with order of magnitude
faster throughput. Their predictable response times aid application performance.

2. Network-Attached Storage (NAS) NAS refers to storage devices connected to a network


and accessible over the network by authorized users. NAS devices have dedicated hardware
and OS. Key aspects include:

• Shared pools of storage accessible via network


• Support network file sharing protocols

• Ease data mobility across systems

• Don't consume host resources

• Limited processing capability

NAS allows network centric data access independent of hosts located elsewhere and aids data
sharing.

With exponential growth in data NAS and SSDs are driving future of secondary storage.

File Management
File management refers to the methods used by operating systems to name, organize, store and
retrieve files on secondary storage media. Key aspects include:

1. File Naming Operating systems require human readable names to be assigned to files for
later retrieval.

2. File Structure Refers to format used to organize data layout within a file corresponding to
its type. For example, text files have ASCII/Unicode format, executables have predefined
binary formats. Operating systems recognize and parse certain special formats like
executable files but treat most files simply as streams of bytes without needing to interpret
internal data structure used.

3. File Types Many OS classify files based on contents as it aids appropriate interpretation.
Common file types include - plain text, executable binaries, libraries, images, audio, video,
compressed archives, documents etc. Assigning types facilitates mapping appropriate
applications to open files correctly by default when invoked by user. Windows uses file name
extensions like .exe , .docx extensively to signify types while UNIX relies more on path name
conventions and internal magic numbers for formatted binary identification.

4. File Operations There are several basic file operations that constitute the application
programming interface for file interaction:

• Create and delete files

• Open and close file handles

• Read and write data

• Append new data

• Seek/reposition

• Get/set file attributes like size, date, protections

• Rename and truncate files

• Storage allocation retrieval

• Map file memory

• Lock file ranges


• Synchronize file state

5. Access Methods There are three main storage access techniques used for file data:

• Sequential access: Data accessed sequentially in order stored

• Direct or random access: Data accessed directly in any order

• Index based access: Key based search access into records

The simpler sequential method supports streaming data access while direct access supports
arbitrary file seeks. Indexes facilitate keyed access.

6. Directory Structure Provides a namespace to organize files into hierarchical logical storage
units known as directories or folders. Enables classification of data for ease of use. Basic
directory structures include:

• Single-level: Single folder, unique file names

• Two-level: Separate folders for users, system, unique within folder

• Tree-structure: Nested hierarchy of directories for clear classification

• Acyclic graph directories: Enable file sharing between user directories

7. File Allocation File allocation pertains to how file contents are mapped to physical
secondary storage blocks. Main schemes include:

• Contiguous: Stores file data continuously in sequence

• Linked: Uses pointers to link chunks stored anywhere

• Indexed: Has index blocks mapping data blocks spread across device

Contiguous allocation provides best performance but suffers from fragmentation issues.
Indexed method offers balanced access speed combined with reduced fragmentation via
scatter.

Disk Management
Disk management refers to the operating system mechanisms for initializing disks, structuring
formatted storage, managing requests and reliably tracking on-disk data. Key aspects include:

Disk Structure
Low-level formatting
• Involves dividing each track into physical sectors that form minimum storage units

• Sectors contain identifier fields with header and trailer areas for synchronization and
error correction codes like CRC

• Sector sizes typically range from 512 bytes to 4KB

Partitioning
• Logically divides physical storage device into one or more partitions or logical disks
• Partitions appear as separate storage drives allowing independent file systems

• The master boot record contains a partition table describing partitions

Boot Block
• The bootloader resides on master boot record in first sector

• Later boot stages may reside on subsequent reserved disk blocks

Bad Blocks
• Disk manufacturing defects inevitably create bad sectors unfit for reliable storage

• Low level formats remap bad blocks to reserved good spare sectors

• Bad block remapping by controller creates non-linear layout invisible to operating


system

Disk Scheduling Algorithms


As disk accesses incur significant mechanical positioning delays, the disk access scheduling algorithm
used by operating system impacts overall performance. Goals of disk scheduling are to optimize
bandwidth, minimize seek times and latency leading to high throughput. Common disk scheduling
approaches include:

First Come First Served (FCFS)


• Services requests in order they arrive hence simpler to manage

• But allows head movement optimizations so non-optimal

Shortest Seek Time First (SSTF)


• Seeks to minimize head movement by serving closest request next

• May cause indefinite postponement of some requests leading to starvation

SCAN and C-SCAN


• Move head in one direction serving requests till end reached, then reverse

• Eliminate indefinite postponement risk

• Average waiting time still quite high

LOOK
• Extends SCAN by considering pending requests in both directions

• Once requests in one direction exhausted, head shifts to service requests in other
direction

• Reduces average waiting time through better optimization

Modern operating systems implement C-LOOK or CLOOK blending benefits of SCAN and LOOK for
effective request scheduling.

Disk Reliability
Being electromechanical devices, disks do suffer failures and data loss. Key measures used by
operating systems to improve reliability include:
Error detection and correction
• Storing parity and ECC bits to detect and reconstruct damaged data

• Bad sector remapping also supports this

Disk mirroring
• Storing identical copies of data across multiple disks

• If one disk fails, data intact on mirrored disks

• Used in RAID-1

Disk stripping
• Data is striped by spreading across multiple disks

• If one disk crashes, only a portion of data lost

• Used in RAID-5

Consistency checking
• File system verification done using chkdsk regularly

• Scans and fixes filesystem inconsistencies

Other aspects include Disk formatting, Boot block usage for bootstrapping, Bad block detection and
replacement to avoid failures.

Disk Formatting
It refers to process of writing sector headers and trailers combined with analyzing surface defects
handling bad sectors. Two key format types exist:

Low level formatting


• Done at factory involves radical surface analysis marking bad sectors

• Current drives have spare sectors remappedHide Low level formattingmeaning


surface passes feasible

• OS need only ensure sequential numbering of logical blocks

High level formatting


• Creates File allocation table / Inodes tables with free space marking

• Appears like quick formatting done on personal computer systems

• Involves logical structuring rather than radical surface checks

Thus low level is physical and high level if logical formatting done by operating system utilities.

Boot Block
The boot block constitutes first disk sector reserved to bootstrap operating system load using a
minimal boot program. The small boot program stored here is hardware dependent interacting with
firmware to load first OS kernel sectors into memory and transfer execution control achieving
bootstrapping. Boot block facilitation disk booting critical for OS functioning.
Bad Blocks
Presence of bad sectors unfit for reliable storage is a disk manufacturing reality. So disks sector
remapping and Bad blocks replacement schemes exist as preventive measures:

1. Low level formats detect factory bad sectors during surface analysis then remap those
defective sectors to reserved good ones maintaining sequential logical sector numbering.

2. Similarly slipping involves remapping bad sectors by logically slipping up sectors below, then
substituting bad sector by spare further down disk.

3. Alternatively, simply storing a table of bad sector addresses allows avoiding them for storage
through allocation avoidance to other sectors. This bad sector table must be persisted
carefully on disk itself.

Thus bad sectors need to be detected and substituted persistently for data integrity and reliability.

You might also like