---
title: Low-power digital design
heading: Clock gating, voltage scaling and power gating
eyebrow: C7 · Lesson 46 · Low-power digital design
xp: 40
---

::: hook
A phone's battery and a server's electricity bill are both set by the same formula, $\alpha CV^2f$, plus leakage. Each term is a lever. Stop clocking registers that have nothing to do, and their activity falls to zero. Lower the supply when the work allows a slower clock, and the energy per operation falls as the square of the voltage. Cut the power to blocks that are asleep, and their leakage disappears. Modern chips pull all three levers constantly.

::: play
- The curves show, against supply voltage, how fast the logic can run, how much power it draws at that speed, and how much energy each operation costs, all relative to 1 V.
- Lower the voltage: the speed falls, the power falls faster, and the energy per operation falls as $V^2$.
- Raise the threshold voltage: the speed collapses sooner as the supply approaches it.
:::
:::

```sim plot
view: graph
x: V = 0.4..1.2 V
y: r = 0..1.6
slider: Vt = 0.2..0.4 step 0.01 = 0.3 V
plot: ((V - Vt)^2/V)/((1 - Vt)^2) | label: speed | samples: 200
plot: V^2*((V - Vt)^2/V)/((1 - Vt)^2) | color: ch2 | label: power at that speed | samples: 200
plot: V^2 | color: ch3 | label: energy per operation | samples: 200
readout: speed at 0.7 V = ((0.7 - Vt)^2/0.7)/((1 - Vt)^2) | digits: 3
```

::: predict
## A processor halves its clock frequency without changing its supply. What happens to the energy it uses for each operation?

- [ ] It halves
- [x] It stays about the same: each operation still switches the same capacitance through the same voltage
- [ ] It quarters
- [ ] It doubles

::: reveal
It stays the same. The power halves, but each operation takes twice as long, so the energy per operation, $\alpha CV^2$, doesn't change. Only lowering the voltage, which the slower clock now allows, cuts the energy, and then it falls as $V^2$. Slowing down without lowering the supply saves nothing for a fixed amount of work.
:::
:::

::: nameit
## Where the power goes

$$P = \alpha CV^2f + I_\text{leak}V.$$

The clock network and the registers it feeds switch every cycle ($\alpha$ = 1 for the clock itself), so they often take a third or more of the dynamic power.

## Clock gating

A register that doesn't need to change can simply not be clocked. A **clock gate** (a latch and an AND gate, so the gated clock never glitches) stops the clock to a group of registers while their enable is off. Their switching, and the clock wiring behind the gate, drops to zero. Synthesis tools insert gates automatically wherever a register has a load enable.

## Dynamic voltage and frequency scaling (DVFS)

Gate delay grows as the supply falls toward the threshold; roughly,

$$f \propto \frac{(V - V_t)^2}{V}.$$

When the workload allows a lower frequency, the supply can drop too. Power then falls roughly as $V^2f$, faster than the frequency, and the energy per operation falls as $V^2$.

## Power gating

Leakage flows whenever a block is powered, even idle. A **sleep transistor** in its supply disconnects it entirely, at the cost of losing its state (unless retention registers save it) and of an energy and time cost to wake. It pays only when the block sleeps longer than the **break-even time**, the wake-up energy divided by the leakage power saved.
:::

::: example
## In a 1 W block, the clock network and registers draw 30% of the power. Clock gating stops them 70% of the time. What does the block draw now?

::: solution
1. **The gated share.** It's 0.3 W, off 70% of the time:
   $$0.3 \times 0.7 = 0.21\ \text{W}$$
   saved.
2. **The new total.**
   $$1 - 0.21 = 0.79\ \text{W}$$
   21% less, for the price of a few gates per register group.
3. **What's left.** The logic between the registers still switches when its inputs change, so gating the clock alone doesn't remove all the dynamic power.

**Answer:** 0.79 W.
:::
:::

::: example
## A processor runs at 1 GHz on 1.0 V, with $V_t$ = 0.3 V. Its workload allows 0.7 V. What frequency, power and energy per operation result?

::: solution
1. **Frequency.** With $f \propto \frac{(V - V_t)^2}{V}$, at 0.7 V:
   $$\frac{0.16/0.7}{0.49/1} = 0.466$$
   of 1 GHz, so 466 MHz.
2. **Power.** Power goes as $V^2f$:
   $$0.49 \times 0.466 = 0.23$$
   23% of before.
3. **Energy per operation.** It goes as $V^2$: 49% of before.
4. **Compare.** Running slower and lower does the same work on half the energy, which is why phones race to finish only when they must.

**Answer:** 466 MHz, 23% of the power and 49% of the energy per operation.
:::
:::

::: example
## An idle block leaks 50 mW. A sleep transistor cuts that to 0.5 mW, but waking it costs 5 µJ. How long must it sleep to save energy?

::: solution
1. **Power saved.**
   $$50 - 0.5 = 49.5\ \text{mW}$$
2. **Break-even time.** The wake-up costs 5 µJ:
   $$\frac{5\ \mu\text{J}}{49.5\ \text{mW}} = 101\ \mu\text{s}$$
3. **Choosing.** Shorter idle periods are better spent with only the clock gated; longer ones, powered off.
4. **Predicting.** A power manager predicts which it's likely to be.

**Answer:** longer than 101 µs.
:::
:::

::: check
kind: parts
given: P = 0.5 | 2 | 10; s = 20 | 40; g = 50 | 90

## A block draws {P} W; {s}% of it goes to the clock and registers, which clock gating stops {g}% of the time.

::: part
answer: P*s/100*g/100
unit: W
tolerance: 0.5%

### How much does gating save?

::: misses
- [P*g/100] Only the clocked share is gated.
- [any] Clocked share × fraction gated.
:::
:::

::: part
answer: P*(1 - s/100*g/100)
unit: W
tolerance: 0.5%

### What does the block draw now?

::: misses
- [any] The rest stays.
:::
:::
:::

::: check
kind: parts
given: V = 0.6 | 0.8 | 0.9; Vt = 0.25 | 0.35

## Logic designed for 1.0 V runs at {V} V, with $V_t$ = {Vt} V.

::: part
answer: ((V - Vt)^2/V)/((1 - Vt)^2)
tolerance: 0.5%

### What fraction of its speed remains?

::: misses
- [V] Speed falls faster than the voltage as it nears the threshold.
- [any] $\frac{(V - V_t)^2/V}{(1 - V_t)^2}$.
:::
:::

::: part
answer: V^2
tolerance: 0.5%

### What fraction of the energy per operation does it use?

::: misses
- [V] Energy goes as the square of the voltage.
- [any] $V^2$ relative to 1 V.
:::
:::
:::

::: check
given: E = 1 | 5 | 20; L = 10 | 40; r = 1 | 2
answer: E/(L - r)*1000
unit: µs
tolerance: 0.5%

## Waking a block costs {E} µJ; asleep it leaks {r} mW instead of {L} mW. What's the break-even sleep time?

::: right
Right. Wake-up energy over the leakage saved: {answer}.
:::

::: misses
- [E/L*1000] Subtract the leakage that remains while asleep.
- [any] $\frac{E_\text{wake}}{P_\text{awake} - P_\text{asleep}}$.
:::
:::

::: check
kind: choice

## A battery-powered sensor does a fixed amount of work every second and then idles. To minimize energy, it should:

- [ ] Run at the highest frequency and voltage, finish fast, and idle with the clock running
- [x] Run at the lowest voltage that still finishes in time, then power-gate if the idle time is long enough
- [ ] Run slowly at full voltage
- [ ] Keep everything on so it never pays a wake-up cost

::: right
Right. Energy per operation falls as $V^2$, and power gating removes leakage during long idles.
:::

::: misses
- [1] Full voltage costs the most energy per operation, and an idle running clock still burns power.
- [3] A slow clock at full voltage costs the same energy per operation and leaks longer.
- [4] Leakage over a long idle can far exceed one wake-up.
:::
:::

::: check
kind: derivation
vars: V = 0.4..1.5, W = 0.6..1.5, T = 0.1..0.39, a = 0.01..1, C = 0.000000000001..0.0000001, F = 1000000..5000000000

## Logic with switched capacitance aC runs at frequency F on supply W, with threshold T. The supply is scaled to V.

::: step
answer: F*((V - T)^2/V)/((W - T)^2/W)

### What frequency does it reach at V?
:::

::: step
answer: a*C*V^2*F*((V - T)^2/V)/((W - T)^2/W)

### What dynamic power does it draw there?
:::

::: step
answer: a*C*V^2

### What energy does each cycle cost?
:::

::: right
Right. Frequency and power depend on the threshold; energy per cycle only on V.
:::
:::

::: check
kind: python

## Write `dvfs(V, V0, f0, Vt)` returning `(f, power_ratio, energy_ratio)` when logic that runs at f0 on V0 is moved to V: the new frequency from $f \propto (V - V_t)^2/V$, and the dynamic power and the energy per operation relative to their values at V0.

```python starter
def dvfs(V, V0, f0, Vt):
    return f0 * V / V0, V / V0, 1.0

print(dvfs(0.7, 1.0, 1e9, 0.3))
```

```python solution
def dvfs(V, V0, f0, Vt):
    s = ((V - Vt) ** 2 / V) / ((V0 - Vt) ** 2 / V0)
    e = (V / V0) ** 2
    return f0 * s, e * s, e

print(dvfs(0.7, 1.0, 1e9, 0.3))
```

```python tests
f, p, e = dvfs(0.7, 1.0, 1e9, 0.3)
assert abs(f - 466.4723e6) < 1e3 and abs(p - 0.228571) < 1e-5 and abs(e - 0.49) < 1e-12, f"Expected 466 MHz, 22.9% and 49%; got {f}, {p}, {e}"
assert dvfs(1.0, 1.0, 2e9, 0.3) == (2e9, 1.0, 1.0), "No change, no change."
```

::: right
Right. The power ratio is the energy ratio times the frequency ratio.
:::
:::

::: explain
## Why does lowering the supply voltage save energy per operation, while lowering only the clock frequency doesn't?

::: model
Each operation switches some capacitance between ground and the supply, and charging a capacitance C to V draws C V squared of energy from the supply, half stored and half lost. That depends on the voltage, not on how fast it happens. Slowing the clock spreads the same operations over more time, which lowers the power, but each operation still costs C V squared, so the total energy for a job is unchanged. Lowering the voltage cuts that cost per operation directly, as its square. The catch is that transistors switch more slowly at lower voltage, so the clock must slow too, but for work that isn't urgent, that trade is a large saving.
:::
:::

::: practice

::: check
given: V = 0.5 | 0.75 | 0.85
answer: V^2
tolerance: 0.5%

## Energy per operation at {V} V, relative to 1 V?

::: misses
- [any] $V^2$.
:::
:::
:::
