Input and Output IO - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

Input and Output IO

Description:

The device driver (DD) has to communicate with the device to give it commands ... The FS and DD also use buffering for synchronization (support speed/data size ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 34
Provided by: modi5
Category:
Tags: dd | input | output

less

Transcript and Presenter's Notes

Title: Input and Output IO


1
Input and Output (IO)
  • In addition to processing the job (using CPU and
    memory), IO is the main job of a computer system
  • Input and output are typically carried out by
    peripheral devices, managed by the IO subsystem
    of the kernel
  • Every device has a corresponding device driver
    that manages the interface (IF) between device
    and kernel
  • All device drivers are typically implemented with
    a single interface that the kernel understands
    (syscalls?)
  • Operations open, close, initialize, read, write
  • Typically the device manufacturer provides the IF

2
Hardware
CPU
monitor
cache
cache
graphics controller
system bus
IDE Disk Controller
...
disk 1
disk n
3
Communicating with a Device
  • The device driver (DD) has to communicate with
    the device to give it commands and receive
    feedback
  • So-called IO-instructions read/write data to an
    IO-port
  • usually a register communicates directly with the
    device (i.e., whenever a write is done on an IO
    port, the device subsequently receives the data)
  • Another way of doing it is using memory-mapped IO
  • same idea, but the communication is done through
    specific (predefined) memory locations
  • Some systems use both (for example, a monitor has
    IO-ports for control and memory-mapped IO for
    large data transfers)

4
Communication (cont)
  • Two ways of CPU-device communication
  • Polling the device is asked (polled) whether it
    has data1- host checks the status register for
    that device2- host tells the device to go
    ahead3- device writes data/command to the
    IO-port
  • allows CPU to control how/when it interacts with
    device, but large overhead if it has to poll
    repeatedly
  • Interrupts the device takes the initiative1-
    the device interrupts CPU to pass on
    data/commands2- CPU does a context switch to
    process the interrupt3- CPU returns from
    interrupt and resumes process
  • CPU doesnt waste time polling, but has no
    control of when device will interrupt

5
Real-Time Systems Device Communication
  • In real-time systems (RTSs), due to deadlines,
    devices are usually not allowed to interrupt when
    they want
  • a mal-functioning device could bring down the
    system
  • In RTSs, many tasks are periodic (reading
    sensors, sending commands to actuators)
  • If polling is used, need to guarantee that IO
    will be done in a timely fashion
  • If interrupts are used, need to guarantee that
    they will not violate the deadline guarantees
    given to processes

6
Handling Interrupts
  • Interrupt controller hardware provides ability to
  • defer interrupts
  • call the proper interrupt service routine (ISR)
  • distinguish and prioritize between high- and
    low-priority interrupts
  • In addition, processors can (and do!) mask
    interrupts
  • disallow some interrupts to occur to process
    other stuff
  • however, there is the non-maskable interrupt
    (emergency)

7
More on Interrupts
  • Interrupt vectors are very common keep the
    address of the ISR in a fixed location, the
    hardware will read the number of the interrupt
    and jump to the appropriate location
  • The interrupt handler will not have its own
    stack. However, it will execute on top of the
    kernel stack, not in the user stack
  • This is because there is little control over the
    size of the user stack and the ISR may run out of
    memory

8
Interacting with Devices
  • Sometimes a mixture of interrupts and IO using
    direct memory access (DMA) is beneficial.
  • A disk that has to read large data block to
    position X
  • receives the request, reads the data
  • asks the DMA controller to put it in the memory
    location X
  • and then, finally, interrupts the CPU
  • The DMA controller and the disk exchange
    information (a protocol) to be able to do this
    transfer
  • In some architectures this is called cycle
    stealing, since the bus is used to transfer data
    into the memory and thus the CPU cannot use the
    memory in those cycles

9
Kernel IO Subsystem
  • The users want to use the devices. How to
    achieve it?
  • The user uses a library that invokessystem calls
    in the OS.
  • The system calls get translated intodevice
    driver requests
  • The DDs request service from the IOcontrollers,
    who talk to the device
  • When the service is done, the controller sends an
    interrupt, to signal CPU

10
Disk as a case study
  • A disk drive has several physical components
  • spindle
  • surface (one side in the pack)
  • read/write arm and head
  • cylinder (or track)
  • sector

11
Accessing the Disk
  • A disk is accessed through the library, file
    system, DevDriver and disk controller
  • The calls to the controller are called disk drive
    commands, such as drive select, head select,
    direction, read/write, data out, etc
  • The disk controller does the synchronization
    between disk and OS, signaling/timing, some error
    control
  • Several users may request data to/from the disk
    at once
  • The file system is the first entity to recognize
    it and synchronize access to the disk

12
Accessing the Disk (cont)
  • The FS does the scheduling of the requests, that
    is, it determines the order in which the requests
    are serviced
  • The FS and DD also use buffering for
    synchronization (support speed/data size mismatch
    between OS-device)
  • The user, FS, and DD have different ideas
    (abstraction) of how the file looks like.
  • user contiguous space, byte by byte
  • file system blocks of data, with logical
    addresses
  • DD sectors in disk, in specific hardware
    addresses (typically consists of
    sect

13
Accessing the Disk (cont)
  • The translations take place each time a new
    interface is crossed
  • The file-relative logical address
  • The volume-relative logical address
  • The drive-relative physical address
  • Some disks have also a zone, and the physical
    address becomes
  • This is because the length of outer tracks
    /cylinders compared with inner tracks/cylinders
    (density)

14
Accessing the Disk (cont)
  • When we need to access a sector, the disk head
    needs to be positioned over that sector (or more
    accurately, the disk must rotate until the sector
    is under the head)
  • For that, several delays are involved in the disk
    operation, in decreasing time
  • seek delay position HEAD on correct
    track/cylinder
  • rotational delay position correct SECTOR under
    head
  • transfer delay transfer data to/from memory
  • Therefore, it is important to minimize the
    highest delay, namely, the seek delay

15
Improve Disk Speed
  • Increase buffering in the device driver and/or
    disk controller (this is a type of cache)
  • Reduce rotational delay
  • place blocks of the same file in the same
    cylinder
  • read the blocks in the appropriate order
  • allow block interleaving (clearly, the number of
    sectors in the disk should be odd,unlike the
    drawing)

1
4
2
3
16
Interleaving
  • Interleaving is done in the device driver, since
    it will have to tell the controller where to
    place sectors in the disk. Clearly, interleaving
    is tightly coupled with the device itself
  • The device decides the interleaving degree (how
    many sectors to skip over), which is tightly
    coupled with the speeds of the disk
  • Rotational
  • Seek (or arm speed)
  • Transfer

17
Improve Disk Speed (cont)
  • To decrease seek delays one can
  • increase the number of heads
  • park the head in the middle track of the disk to
    decrease the average seek delay
  • place the data in the appropriate locations
    (tracks)
  • The organ pipe distribution does the last trick
  • create a histogram of the disk block usage (count
    the number of times that disk blocks are used)
  • place most used blocks in the middle track

spindle
18
Improve Disk Speed (cont)
  • RAID Redundant Array of Inexpensive Disks
  • Allows for more parallelism when retrieving data
  • store each part of a block in a separate disk,
    and allow all sub-blocks to be retrieved in
    parallel
  • If disks are homogeneous and synchronized, even
    better performance can be achieved
  • If disks are heterogeneous or not synchronized,
    performance is worse since it depends on the
    slowest of the disks, or the one off phase.
  • can use slower, cheaper disks

19
Possible File Structures
  • None - sequence of words or bytes
  • Simple record structure
  • Lines
  • Fixed length
  • Variable length
  • Complex Structures
  • Formatted document
  • Relocatable load file
  • Can simulate last two with first method by
    inserting appropriate control characters.
  • Who decides
  • Operating system
  • Program

20
File Attributes
  • Name only data kept in human-readable form.
  • Type needed for supporting different file
    types.
  • Location pointer to file location on device.
  • Size current file size.
  • Protection controls who can do reading,
    writing, executing, access, etc.
  • Time, date, and user identification data for
    protection, security, and usage monitoring.
  • Information about files are kept in the directory
    structure, which is maintained on the disk.

21
File Operations
  • create
  • write
  • read
  • file seek reposition within file
  • delete
  • truncate
  • open(Fi) search the directory structure on disk
    for entry Fi, and move the content of entry to
    memory.
  • close (Fi) move the content of entry Fi in
    memory to directory structure on disk.

22
Directory Structure
  • A collection of nodes containing information
    about all files.
  • Both the directory structure and the files reside
    on disk.
  • Backups of these two structures are kept on tapes.

23
Information in a Device Directory
  • Name
  • Type
  • Address
  • Current length
  • Maximum length
  • Date last accessed (for archival)
  • Date last updated
  • Owner ID
  • Protection information

24
Operations Performed on a Directory
  • Search for a file
  • Create a file
  • Delete a file
  • List a directory
  • Rename a file
  • Traverse the file system

25
Logical Directory Organization
  • Goals
  • Efficiency locating a file quickly.
  • Naming convenient to users.
  • Two users can have same name for different files.
  • The same file can have several different names.
  • Grouping logical grouping of files by
    properties, (e.g., all Pascal programs, all
    games, )

26
Single-Level Directory
  • A single directory for all users.
  • Naming problem
  • Grouping problem

27
Two-Level Directory
  • Separate (flat) directory for each user.
  • Path name
  • Can have the same file name for different user
  • Efficient searching
  • No grouping capability

28
Tree-Structured Directories
  • Efficient searching
  • Grouping Capability
  • Current directory (working directory)
  • cd /spell/mail/prog
  • type list

29
Tree-Structured Directories (Cont.)
  • Absolute or relative path name
  • Concept of current working directory
  • Creating/deleting a new file/subdirectory is done
    in current directory.
  • Example Deleting mail ? deleting the entire
    subtree rooted by mail.

30
Acyclic-Graph Directories
  • Have shared subdirectories and files.
  • Two different names (aliasing)
  • If dict deletes count ? dangling pointer.
  • Solutions
  • Backpointers, so we can delete all pointers.
  • Entry-hold-count solution.

31
Protection
  • File owner/creator should be able to control
  • what can be done
  • by whom
  • Types of access
  • Read
  • Write
  • Execute
  • Append
  • Delete
  • List

32
Classical Unix Access Lists Groups
  • Mode of access read, write, execute
  • Three classes of users R W X
  • a) owner access 7 ? 1 1 1 b) groups
    access 6 ? 1 1 0
  • c) public access 1 ? 0 0 1
  • SysAdmin creates a group (unique name), say G,
    and add users to the group.
  • Attach a group to a file
  • chgrp G game

33
AFS (Andrew) Access Control Lists
  • More details, more information
  • For each file, maintain a list of users and their
    access capabilities
  • More costly, due to more checking
  • More flexibility, more degrees of sharing (read,
    list dir, admin, write, insert, delete)
  • ACLs are easy to use, and render Unix protection
    bits useless
  • dangers of different user interfaces (the unix
    bits are still listed in ls)
Write a Comment
User Comments (0)
About PowerShow.com