Smartphone Operating System (779883), страница 43
Текст из файла (страница 43)
Protocols are the language of request and service,providing methods to communicate that provide for accurate and errorcontrolled delivery of data. A protocol can be seen as an agreementbetween two parties: when one side does something, the other sideknows how to respond because both are abiding by a set of rules.The Small Computer Systems Interface (SCSI) bus in a computer systemis a good example here. The SCSI bus is connected to several SCSI devicesat the same time.
Each device has a SCSI controller that knows how touse the SCSI protocol to communicate with the SCSI device driver forthe operating system. This SCSI protocol is very complicated. The SCSIbus has a certain type of design that accommodates this complexity.
Thisdesign differentiates it from the other buses in a computer system.It is interesting to note that, as with the SCSI example, some devicedrivers are tuned to the bus protocol rather than the device they arecontrolling. In the SCSI example, all devices that connect to the SCSI buswork with the SCSI protocol. This means that device drivers can workwith that protocol too, rather than with each individual device. This canbe called a physical-device abstraction to logical device.1Sometimes the operating system provides the driver. This happens when standardsare clear and devices adhere to these standards.
The USB mass storage driver of MicrosoftWindows is an example of this.I/O HARDWARE ISSUES2019.2 I/O Hardware IssuesA computer works with a large number of devices. These generally fit intoseveral categories: storage devices, communication devices, interfacedevices and display devices. Devices that do not fit into these categoriestend to be specialized, such as data-gathering equipment or automobilemonitoring devices. It is typical of a computer to control these devicesusing a standard interface and a set of generalized commands.
Even withall this variety in hardware, just a few hardware concepts are needed tounderstand how hardware interacts with an operating system.General Device CommunicationAs discussed in Section 9.1, operating systems communicate with devicesthrough buses that connect components from device driver to devicecontroller. A general bus structure is shown in Figure 9.2.A device is connected to a computer system through a bus, but canbe connected to that bus in several ways. A device could be connectedUSB busDeviceScreen displayDeviceCPUDeviceCacheGraphicscontrollerBridge/memorycontrollerMemoryUSB controllerPCI BusIDE controllerExpansion businterfaceexpansion busDiskDiskCD-ROMParallel portSerial portFigure 9.2 Generic I/O bus structureKeyboard202INPUT AND OUTPUTdirectly by being plugged into the bus through a slot on the computer’smotherboard.
This is typical of desktop and server systems. Other devicesare connected through a cable, plugged into a port, or open receiver,on the computer. Others are connected wirelessly, for example, throughBluetooth technology. Sometimes devices can even be daisy-chainedtogether, when one device is connected to another, which is connectedto a third and so forth. Eventually one device in the chain must beconnected to a computer.Communication is initiated by a controller and destined for the operating system or by the operating system and destined for a device througha controller.
A simple way that these communications are passed on isthrough registers. Communication bits and bytes are passed through avariety of registers:• the status register contains a set of bits that are read by both thecomputer and the bus controller; the bits indicate states such aswhether a data transfer is completed or whether there has been adevice error• the control register is used to control the data exchange process; whenit contains data, that data is in the form of a command which usuallyamounts to ‘read’ or ‘status’, but bits can also be set to indicate howdata is to be transferred• the data-in register is read by the operating system to get input datafrom devices• the data-out register is written to by the operating system to pass datato a device.Data registers are typically between one and four bytes long.
Somedevice controllers can hold buffers full of data waiting to be sent throughthese registers to the operating system. The registers are situated eitherin dedicated I/O space in the CPU or in the main memory. This lattersituation is called memory-mapped I/O. In this implementation, the CPUwrites or reads data to or from the dedicated address or range of addressesof the main memory space.Device controllers also send data to operating systems throughmemory-mapped I/O. Memory-mapped I/O uses the register idea but,instead of registers, memory on the processor is used.
When the CPUsends an I/O request, it uses standard registers to issue the request but thedata ends up in main memory.I/O HARDWARE ISSUES203These two methods are adequate for small amounts of data but, forlarger amounts of data, they require too much movement of data oncethe data has left the bus. The direct-memory access (DMA) approachallows the bus controller to access memory directly and to signal to theoperating system when the I/O operation is complete. All I/O functionshappen through memory: from initiation of an I/O operation to the arrivalof data and the signaling of operation completion. DMA allows theoperating system to service other needs and only attend to data when itis signaled.DMA works with system resources and shares them with the CPU. Itaccesses main memory just as the processor does.
Occasionally, DMAdata transfer takes over a resource – for data transfer over the bus, forexample, or for depositing data in memory. In these cases, the CPU cannotuse the resource while it is in use for DMA. This artifact of DMA is calledcycle stealing and it can slow down access to computer resources.
In thefirst, conventional DMA cycle, the data transfer uses the bus to transferall data from or to memory without CPU attention. Since the system busis in use, the CPU does no external operations. In the cycle-stealing DMAtransfer, the system can use those CPU cycles where the CPU does nottransfer any data to or from the memory on the system bus. The bus cyclesare stolen from the CPU and used by the DMA controller to transfer data.PollingTo facilitate the transfer of data, the operating system must pay attentionto the transfer system. For systems using registers and memory access, thisattention amounts to a constant monitoring, a checking that continuallywatches components in the system and reacts to changes in system states.This constant monitoring is called polling.Polling happens with the register method of data transfer by monitoringthe bits in the status register.
There is usually a bit, called the busy bit,that indicates that data is in the process of being transferred. When thatbit clears, the data is completely transferred. Note that, because theprocessor operates at a speed faster than the data transfer, it is likely thatthe operating system does a lot of checking before the data transfer iscomplete. Polling happens on both sides with the register method.
Thebus controller polls the status register and reacts to various settings. Forexample, there is typically a command-ready bit that indicates that acommand is waiting in the control register for the bus controller to use.In the memory-mapped I/O method, polling still takes place. Onemight think that the use of memory would mean that registers are not204INPUT AND OUTPUTused.
However, only the data itself is placed in memory, not the commandand status registers. Therefore, the operating system must continually pollthe register set.Polling is usually detrimental to system performance. The constantchecking of the operating system must be woven into cycles that the operating system goes through to switch the context of processes. Checking isdone regardless of the state of the registers and regardless of whether a datatransfer is actually taking place. This constant checking, including uselesschecking of empty registers, drags down the performance of a system.Direct-memory access avoids the polling penalty.
An operating systemusing DMA does not have to poll but instead waits on devices to inform itwhen data is ready. This frees up the operating system to attend to otherthings and operations such as context switching get more attention and,hence, run faster. Data transfer is attended to when the bus controllersignals that data is ready.InterruptsSeveral of the operations mentioned above rely on some sort of signalingbetween devices and the operating system. This interrupt mechanism isan important part of operating system implementation.Interrupts usually work through a dedicated hardware wire calledthe interrupt-request line.