CLOCKS

CLOCKS

Clocks (also called timers) are necessary to the operation of any multiprogrammed system for a variety of reasons. They keep the time of day and prevent one process from monopolizing the CPU, among other things. The clock software can take the form of a device driver, even though a clock is neither a block device, like a disk, nor a character device, like a mouse. Our examination of clocks will follow the same pattern as in the previous section: first a look at clock hardware and then a look at the clock software.

Clock Hardware

Two types of clocks are normally used in computers, and both are quite different from the clocks and watches used by people. The simpler clocks are tied to the 110- or 220- volt power line and cause an interrupt on every voltage cycle, at 50 or 60 Hz. These clocks used to dominate, but are uncommon nowadays.

The other kind of clock is built out of three components: a crystal oscillator, a counter, and a holding register, as shown in Figure 1. When a piece of quartz crystal is accurately cut and mounted under tension, it can be made to generate a periodic signal of very great accuracy, normally in the range of several hundred megahertz, depending on the crystal chosen. Using electronics, this base signal can be multiplied by a small integer to get frequencies up to 1000 MHz or even more. At least one such circuit is generally found in any computer, providing a synchronizing signal to the computer's various circuits. This signal is fed into the counter to make it count down to zero. When the counter gets to zero, it causes a CPU interrupt.

A programmable clock

Programmable clocks normally have several modes of operation. In one-shot mode, when the clock is started, it copies the value of the holding register into the counter and then decrements the counter at each pulse from the crystal. When the counter gets to zero, it causes an interrupt and stops until it is explicitly started again by the software. In square-wave mode, after getting to zero and causing the interrupt, the holding register is automatically copied into the counter, and the whole process is repeated again indefinitely. These periodic interrupts are called clock ticks.

The advantage of the programmable clock is that its interrupt frequency can be controlled by software. If a 500-MHz crystal is used, then the counter is pulsed every 2 nsec. With (unsigned) 32-bit registers, interrupts can be programmed to happen at intervals from 2 nsec to 8.6 sec. Programmable clock chips generally contain two or three independently programmable clocks and have many other options as well (e.g., counting up instead of down, interrupts disabled, and more).

To prevent the current time from being lost when the computer's power is turned off, most computers have a battery-powered backup clock, implemented with the kind of low-power circuitry used in digital watches. The battery clock can be read at startup. If the backup clock is not present, the software may ask the user for the current date and time. There is also a standard way for a networked system to get the current time from a remote host. In any case the time is then translated into the number of clock ticks since 12 A.M. UTC (Universal Coordinated Time) (formerly known as Greenwich Mean Time) on Jan.1, 1970, as UNIX does, or since some other benchmark moment. The origin of time for Windows is Jan.1, 1980. At every clock tick, the real time is incremented by one count. Generally utility programs are provided to manually set the system clock and the backup clock and to synchronize the two clocks.

Tags

multiprogrammed system, clock ticks, programmable clocks