13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

174 Transput Chapter 5transfer, in which the process knows only that the operation has started. The process maybe able to discover its completion by explicit waiting, with a ‘‘wait’’ service call; by polling,with repeated inspection of a completion flag; or by virtual interrupt. A virtualinterrupt affects the process much as a device-completion interrupt from a physical deviceaffects the kernel. That is, it saves state information in a safe place (usually the stack)and sets the program counter to the address of the interrupt handler. We can devise thefollowing service calls to help processes when transfer is asynchronous. Wait(device descriptor, timeout). The process is blocked until the actioncurrently under way on the device (if any) has finished. The timeout tells howpatient the process is. It can be set to infinity if the process is very patient, to zeroif the process just wants to poll to see if the device has finished yet, or to someintermediate value. This service call returns information on whether the transputfinished or not. Handle(device descriptor, routine). This call tells the device driver that wheneverasynchronous transput completes on this device, the process should be interruptedand should start executing at the address specified by ‘‘routine.’’ The routinewill be called with arguments indicating which transput has finished.If transput is asynchronous, the operating system designer must decide what a secondWrite means if the previous one has not finished or what a simultaneous Read and Writemight mean. These could be treated as errors, or the second call could block (as if it hadperformed Wait) until the first has finished. We will see an alternative solution in thenext section.Until an asynchronous write operation has completed, the process should notmodify the region in its address space that is to be written out because the transfer maybe in progress. The kernel may ease this restriction by copying data to be written out firstinto a kernel data structure called a buffer before unblocking the process. Likewise, theprocess should not access the region into which an asynchronous read operation is in progressbecause it does not know when the data have arrived.A related problem for the kernel is dealing with a process that terminates while anasynchronous transput is in progress. Those parts of its address space that are tied downmust not be reallocated to other purposes until the transput has finished. It is not alwayspossible for the kernel to halt channel programs while they are running. The kernel maynote in the context block for that process that termination is pending; the main-storeresources tied down for that process are reclaimed only after the transput has completed.5.2 Main-store addressesThe process must somehow specify the location in main store that the data are to be readinto or written from. The simplest alternative from the point of view of the process is tospecify a starting place and a length in virtual space. The kernel should check, of course,that the region specified is entirely within the address space of the process. If the deviceis a block device — that is, if it requires transfers in fixed-size chunks — the kernelmight provide its own buffers of the correct size as an intermediate location for the data.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!