Device Manager Flashcards
What is the Device Manger?
Monitors every device within the system, ensuring every process gets fair access to these devices. Some tasks include:
- keeps track of devices
- creates virtual files that map onto physical devices
- deals with multiple requests for same devices
- provides syscalls so software can use devices
Layers of Abstraction
Program Code ->
System Call Interface ->
Device Driver ->
Device Controller (memory and registers) ->
Mechanical/Electronic Hardware
Devices Categories
Character vs. block
Sequential vs. random
Shared vs. dedicated
Speed of Operation
Data Direction (read-write, read-only, write-only)
The device driver hides these differences from the kernel.
Character vs. block
Character devices handle data on a character-by-character basis, where each character is treated as a unit of data. Block devices are devices that handle data in fixed-sized blocks.
Sequential vs. random
Sequential devices write data sequentially, whilst random devices write data in any location/order.
Shared vs. dedicated
Shared devices can be accessed by multiple users or processes concurrently, whilst dedicated devices are exclusively assigned to a specific user/process.
Device Drivers
The connection between the operating system and the hardware devices.
Device Buses
PCIe - Peripheral Component Interconnect Express -> general purpose
USB - Universal Series Bus -> general purpose
NVMe - Non-Volatile Memory Express -> flash disks (SSD)
SATA - Serial AT attachment -> mechanical disks (HDD)
Each of these buses have their own protocol and format for sending and receiving data
Peripherals
External devices
System Bus
Used to connect devices buses and CPU, except for interrupts.
Ways of passing Commands and Data to Devices
Memory Mapped I/O -> virtual addresses in main memory are mapped on to device registers, allowing CPU to use its standard instructions to manipulate device registers which look and behave exactly like normal memory.
Port-Mapped I/O -> this is supported by Intel instruction sets, in which devices have a separate address space assigned to the CPU via dedicated pins. This allows in and out instructions to move data between EAX and devices addresses.
Essentially, devices are either assigned specific I/O port addresses, or mapped to main memory addresses.
Scheduling I/O Activities
The device manager schedules I/O activities to maximise system performance. This allows minimal time wasted by moving the HDD read/write head, and prioritise I/O requests. This also ensures disk access is shared equally between processes.
I/O Wait Queue and Scheduling Algorithms
Each disk has an I/O wait queue, which can be reordered depending on policy:
- first come first served
- shortest seek first
- elevator algorithm
- completely fair queueing
- anticipatory scheduling
Completely Fair Queueing
Requests are serviced via time slices according to priority values of the processes.
Anticipatory Scheduling
Essentially, AS takes a few milliseconds to anticipate the next I/O request a process is going to make based upon it historical I/O behaviour, grouping together I/O requests that are likely to be issued by the same process in the queue. So overall, we have a queue with groups of I/O requests which, by guesswork, should belong to different processes respectively.
Elevator Algorithm
Schedules block I/O in the order of travel of the read/write head, only accessing a block when the head is moving in that direction.
Buffering
First of all, a buffer is a use of a temporary storage area to hold data as it is transferred between devices. We use this when we are reading, or writing, a large amount of data, so we do not have to constantly go between one device to another, or from a file to a device etc (for a read-only example, reading from a file for every single character could be very costly).
An issue with this could be that the data on the disk doesn’t match what the system thinks (aka the buffer stored the wrong memory), so it is important to flush the buffer regularly.
Double Buffering
Use one buffer for reading/writing data whilst the other is being emptied.
Buffering Locations
- software programs
- library subroutines
- OS
- hardware
Flushing the Buffer
Actually writing what is on the buffer to the destination.
Spooling
Some devices are non-shareable, so we use the spooler daemon, in which spooler creates a temporary file for each process, so the process writes data into the temporary file that is managed by the spooler. Therefore we do not need accessibility to the device that cannot be accessed, but we have files available.
Direct Memory Access
Hardware devices can access main memory independently of the CPU. The DMA has its own registers, with the CPU initiating the rea/write operation and the DMA using its registers for data transfer.
Devices in Linux
Linux creates a virtual file within /dev directory for all devices in the system, calling access via syscalls. Some devices include:
lp -> printer
sd -> disk
pp -> parallel port
tty -> terminal
pty -> pseudo-terminal (pipes between processes)