13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The process interface 175As we will see, the kernel can use these buffers as a cache to improve performance. Ifthe application is time-critical and does not want to suffer the delay of copying datawithin main store between kernel buffers and the process address space, the appropriatepart of that address space can be tied down and the device can transfer directly into or outof the process space.A popular alternative way to specify where the data reside is by a circular bufferpool in the virtual space of the process. This pool is logically an array of buffersarranged in a circle, as shown in Figure 5.13. Typically, separate buffer pools are usedfor output and input. Buffer pools allow asynchronous transfer without the problem wesaw earlier of two transputs active at the same time. Let us consider output first. Eachbuffer has the following declaration.1 Buffer =2 record3 Busy : Boolean;4 Position : DeviceAddress; { not always required }5 Data : array 1:BlockSize of byte;6 end;The Position field (line 4) is used if every buffer to be output states explicitly where onthe device the data are to be placed. For sequential output, this field can be omitted. TheBusy field (line 3) indicates whether output is in progress from this buffer. Initially, allthe buffers are free — that is, not busy. We have shown free buffers as open squares inFigure 5.13. As the program creates data to be written out, those data are placed in thefirst free buffer. As soon as the buffer is full (shown by crosshatching in the figure), aWrite service call is invoked. The kernel initiates output but allows the process to continueasynchronously. The Busy flag is set true for the duration of the transfer; as soon asthe kernel knows that the transfer is complete, the flag is reset to false. Meanwhile, theprocess may be filling other buffers. The process must pause if it needs another bufferbut the next one is still busy; in this case it may use the Wait service call.process is readingprocess is writinginputoutputkernel is fillingkernel is emptyingFigure 5.13 Circular buffer pools

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

Saved successfully!

Ooh no, something went wrong!