Patterus to reuuce COnmiCIS.
2.12 PROGRAM -LEVEL ENERGY AND POWER ANALYSIS AND
OPTIMIZATION
Power con sumption is a particularly important design metric for battery-powered
systems because the battery has a very limited lifetime. However, power consumption
is increasingly important in systems that run off the power grid. Fast chips run hot.
and controlling power consumption is an important element of increasing
and reducing system cost. reliability
We must consume the energy required to perform necessary computations and
there are opportunities for saving power.
Examples appear below.
We may be able to replace the algorithms with others that do things in
clever ways that consume less power.
Memory accesses are a major component of power consumption in many
applications, By optimizing memory accesses we may be able to significantly
reduce power.
We may be able to tum off parts of the system--such as
subsystems of
the CPU, chips in the system, and so on-when we do not need them
order to save power.
in
The first step in optimizing a program's energy consumption knows how
energy the program consumes. It is possible to measure power consumption formuch
an
instruction or a small code fragment. The technique, illustrated in Figure 2.52, executes
the code under test over and over in a loop. By measuring the current flowing
into
Ammeter Curent
Power whie (TRUE)
Supply test.ode );
)
CPU
Figure 2.52: Measuring energy consumption for a piece of code
Embedded Computing Platform Design
2.77
the CPU, we are measuring the power consumption of the complete loop. including
both the body and other code. By separately measuring the power
consumption of a
loop with no body. we can calculate the power consumption of he loop body code
as the difference between the full loop and the bare loop energy cost of an
instruction.
Several factors contribute to the energy consumption of the program.
" Energy consumption varies somewhat from instruction to instruction.
The sequence of instructions has some influence.
The opcode and the locations of the operands also matter.
Choosing which instructions to use can make some difference in a program's
energy consumption, but concentrating on the instruction opcodes has imited payoffs
in most CPUs. The program has to do a certain amount of computation to perform
its function. While there may be some clever ways to perform that computation., the
energy cost of the basic computation will change only a faily small amount compared
to the total system energy consumption, and usually only after a great deal of effon.
Memory conflicts
In many pplications, he biggest payoff in energy reduction for a given
amount of designer effort comes from concentrating on the memory system.
Memory transfers are most expensive type of operation perfomed by à
CPU--Memory transfer takes 33 times more energy than does an addition.
As a result, the biggest payoffs in energy optimization come from properly
organizing instructions and data in memory. Accesses to registers are the
most energy efficient; cache accesses are more energy efficient than main
memory accesses.
Caches are an important factor in energy consumption. On the one hand,
a cache hit saves a costly main memory access, and on the other, the cache
itself is relatively power hungry because it is built from SRAM, not DRAM.
If we can control the size of the cache, we want to choose the smallest
cache that provides us with the nece ssary performance.
As the instruction cache size increases, the energy cost of the software on
the CPU declines. but the instruction cache comes to dominate the energy
consumption.
Experiments like this on several benchmarks show that many programs have
sweet spots in energy consumption. If the cache is too small. the program
runs slowly and the system consumes a lot of power due to the high cost
of main memory accesses. If the cache is too large, the power consumption
is high without a corresponding payoff in performance. At intemediate
values, the execution time and power con sumption are both good.
78 Embedded and Real Time Systems
How can we optimize a program for low power consumption?
The best overall advice is that high perfonance = low power. Generally
speaking, making the program un faster also reduces energy consumption.
Clearly, the biggest factor that can be reasonably well controlled by the
programmer is the memory access patterns. If the program can be modified
to reduce instruction or data cache conflicts, for example, the energy required
by the memory system can be significantly reduced. The effectiveness of
changes such as reordering instructions or selecting different instructions
depends on the processor involved. but they are generally less effective than
cache optimizations.
A few optimizations mentioned previously for perfomance are also often
useful for improving energy consumption:
Try to Use registers efficiently. Group accesses to a value together so
that the value can be brought into a register and kept there.
Analyze cache behavior to find major cache conflicts. Restructure the
code to eliminate as many of these as
as you can:
" For instruction conflicts, if the offending code segment is small.
try
to ewrite the segment to make it as small as possible so that it
better fits, into the cache. Writing in assembly language may be
necessary.
" For conflicts across larger spans of code. try moving the instructions
or padding with NOPS.
" For scalar data conflicts, move the data values to different locations
to reduce conflicts..
" For array data conflicts, consider either moving the arays or
changing your aray access patterns, to reduce conflicts.
Make use of page mode accesses in the
menmory system whenever
possible.
Page mode reads and writes eliminate one step in
the memory access, saving
a considerable amount of power.
Some additional observations about energy optimization as follows:
Moderate loop unrolling eliminates some loop control overhead. Howe ver.
when the loop is unrolled too much. power increases due to the lower hit
rates of straight-line code.
Embedded Computing Platform Design 2.79
Software pipelining reduces pipeline stalls, thereby reducing the average
energy per instruction.
Eliminating recursive procedure calls where possible saves power by getting
can often be eliminated: some
rid of function call overhead. Tail recursion
compilers do this automatically.
O PROGRAM SIZE