Date post: | 04-Jan-2016 |
Category: |
Documents |
Upload: | winfred-haynes |
View: | 227 times |
Download: | 1 times |
Chap 0
Input and Output (IO)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
Chap 0
HardwareHardware
CPU
cache
cache
system bus
monitor
graphicscontroller
IDE DiskController
disk 1 disk n...
Chap 0
Communicating with a DeviceCommunicating 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)
Chap 0
Communication (cont)Communication (cont)
Two ways of CPU-device communication: Polling: the device is asked (polled) whether it has data
1- host checks the status register for that device2- host tells the device to “go ahead”3- 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 initiative
1- 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 doesn’t waste time polling, but has no control of
when device will interrupt
Chap 0
Real-Time Systems Device Real-Time Systems Device CommunicationCommunication
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
Chap 0
Handling InterruptsHandling 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 InterruptsMore 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
Chap 0
Interacting with DevicesInteracting 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
Chap 0
Kernel IO SubsystemKernel 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
user
OS
DD
controller
device
ISR
Chap 0
Disk as a case studyDisk 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
Chap 0
Accessing the DiskAccessing 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
Chap 0
Accessing the Disk (cont)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 < cyl, track, sect >
Chap 0
Accessing the Disk (cont)Accessing the Disk (cont)
The translations take place each time a new interface is crossed
The file-relative logical address <filename,offset> The volume-relative logical address <sector,offset> The drive-relative physical address <cyl,track,sect> Some disks have also a zone, and the physical
address becomes < cyl, zone, track, sect > This is because the length of outer tracks /cylinders
compared with inner tracks/cylinders (density)
Chap 0
Accessing the Disk (cont)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
Chap 0
Improve Disk SpeedImprove 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
23
4
Chap 0
InterleavingInterleaving
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
Chap 0
Improve Disk Speed (cont)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
Chap 0
Improve Disk Speed (cont)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 StructuresPossible 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 AttributesFile 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 OperationsFile 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 StructureDirectory Structure A collection of nodes containing information about all files.
F 1 F 2 F 3F 4
F n
Directory
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 DirectoryInformation 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 DirectoryOperations 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 OrganizationLogical 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 DirectorySingle-Level Directory
A single directory for all users.
Naming problem Grouping problem
27
Two-Level DirectoryTwo-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 DirectoriesTree-Structured Directories
Efficient searching Grouping Capability Current directory (working directory)
cd /spell/mail/prog type list
29
Tree-Structured Directories (Cont.)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”.
prog copy prt exp count
30
Acyclic-Graph DirectoriesAcyclic-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
ProtectionProtection
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 & GroupsClassical Unix: Access Lists & Groups Mode of access: read, write, execute Three classes of users R W X
a) owner access 7 1 1 1b) 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
owner group public
chmod 761 game
33
AFS (Andrew) Access Control ListsAFS (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”)