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.

162 Transput Chapter 5page onto backing store. Similarly, a process that wants to write to a printer might passdata by a system call, which some kernel task might then pass on to the printer driver.The upper part of the device driver transforms these requests into entries in a list of pendingwork for the lower part. It may even sort the entries in the pending-work list so thatsome transput operations precede others.The lower part only wakes up when there is an interrupt or when new work isplaced on its pending-work list. It usually sets the processor status in such a way thatother interrupts from the same device are prevented until it is finished with its currentwork. If the interrupt that awakens the lower part indicates completion of some transput,the appropriate data structure is so marked, and the kernel task that was waiting isunblocked. The upper driver need not be informed. The lower driver then checks to seeif there is any more work queued up for it, and if so, it initiates the next operation.To give some feeling for the sources of complexities in device drivers, we willconsider three devices: the clock, terminals and disks.3.2 Clock device driverClocks come in several styles. The simplest, a line clock, generates an interrupt every‘‘tick,’’ that is, every 60th (or 50th) of a second. It might also have a register that indicateshow many ticks have occurred since the register was reset. The clock may be protectedagainst power failure by a battery, which allows it to continue ticking even whenthe computer is down or without power. Slightly more complex clocks have a registerthat indicates how many interrupts were missed due to the cpu running at a priority toohigh to let the clock interrupt. Programmable clocks also have a count register that maybe set by the software. The clock decrements that register at a standard rate (often everymicrosecond) until it reaches 0, at which time it generates an interrupt. Some computershave both line clocks, which are used for recording the time of day, and programmableclocks, which are used for marking scheduling events. If there is no programmableclock, the line clock alone can be used for scheduling.When a line clock interrupts, the clock driver typically performs the followingfunctions:Increment the software time data structure.If this clock is used for scheduling, decrement the remaining-time field of thecurrently running process, if any. If that value has become zero, invoke thescheduler.Perform simple accounting. For example, the currently running process might becharged for one tick worth of time and for its current main-store use.If there is no programmable clock, decrement the counter for the next alarm, and ifit is now zero, invoke whatever kernel task was waiting for an alarm. Alarms areused for timeouts, which are used in communication protocols and elsewhere. Ifthere is a programmable clock, it will be used to schedule alarms.If the current process wishes to be profiled, use its program counter to determine inwhich region of the program it is executing and increment the associated counter.(For example, each page of the virtual space of the process could have a separate

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

Saved successfully!

Ooh no, something went wrong!