Timing
The clock: why computers tick
Gates are fast, but they are not instant. A clock gives every part of a computer the same rhythm, so that each step finishes before the next one starts. The speed of that rhythm is set by the slowest path through your logic.
Gates take time
When a gate’s input changes, its output follows a moment later. That moment is the propagation delay, and in a modern chip it is a few picoseconds per gate. It is tiny, but signals pass through many gates in a row. If the output of one gate feeds the next, the delays add up along the path.
While the signals are still on their way, the outputs can be briefly wrong. An adder whose inputs just changed may show a few nonsense sums while the carries ripple through, and only then settle on the right answer. Those brief wrong values are called glitches, and they are harmless as long as nobody acts on them before the logic has settled.
The clock says “now”
The clock is a signal that switches between 0 and 1 at a steady rate. Every register in a synchronous design loads its new value at the same moment, the rising edge of the clock (see flip-flops). Between edges the combinational logic has a whole clock period to settle. At the next edge the settled results are captured, and the glitches never matter.
The critical path sets the speed
Between two registers there are usually many paths through the logic. The longest one, in delay rather than in distance, is the critical path. The clock cannot tick faster than that path can settle, plus a little margin for the flip-flops’ own timing:
shortest clock period = register delay + critical path delay + setup time
maximum clock rate = 1 / shortest clock period
If the slowest path takes 500 picoseconds, the clock can tick at most every 500 ps, which is 2 GHz. Make that path shorter and the whole machine can run faster. That is why engineers obsess over critical paths. A faster adder, a shallower decoder or a register placed in the middle of a long path (that is the idea behind pipelining) all let the clock go up.
Where the tick comes from
Most clocks start as a quartz crystal, which vibrates at a very stable frequency when driven electrically, often tens of megahertz. A circuit called a phase-locked loop multiplies that up to the gigahertz rates a processor core uses. The clock then has to reach every one of millions of flip-flops at almost the same instant. Differences in arrival time are called clock skew, and a large part of a chip’s design effort goes into the clock tree that distributes the signal evenly.
A clock can also be made from nothing but logic gates. Working out how is one of the puzzles in the game, so we won’t say more.
Clock speed isn’t everything
A higher clock rate means more steps per second, but how much each step achieves matters just as much. Performance is roughly instructions × cycles per instruction × time per cycle. A processor at 3 GHz that finishes four instructions per cycle beats one at 4 GHz that needs two cycles per instruction. Designers trade these terms against each other all the time, which is why comparing CPUs by gigahertz alone stopped making sense long ago.
A note on asynchronous design
Not every circuit needs a global clock. Asynchronous or self-timed designs let each part signal when it has finished. They can save power and avoid the clock-tree problem, but they are much harder to design and verify, so almost all processors today are synchronous.