15

Are there any techniques to optimize code in order to ensure lesser power consumption.Architecture is ARM.language is C

Manik Mahajan
  • 1,566
  • 2
  • 13
  • 19
  • 23
    Use the `//` optimization operator. :) – SLaks May 25 '10 at 15:15
  • Cycles not used by your program will still be used as idle processes. I suppose if your CPU is tuned to give it less power when it needs fewer cycles, then you just need to make your code faster. Otherwise, your only option is `#include "gogreen.h"`. – corsiKa May 25 '10 at 15:18
  • 4
    @Slaks that optimization is only available to C++ (and newer than ANSI C variants), so it's better to use /**/ operator :-p – fortran May 25 '10 at 15:22
  • It's often easier to optimize hardware to use less power than it is to optimize software to use less power. – Brian May 25 '10 at 15:27
  • 3
    @Brian, we are programmers, not chemists to optimize batteries, nor engineers to optimize CPU schema. We solve this problem just in the other way--by fixing our software. – P Shved May 25 '10 at 15:32
  • 3
    @Pavel, buy smaller hardware. And actually, some of us are engineers. – Nathan Ernst May 25 '10 at 15:43
  • The best technique is always good program design. If you have this then you need not worry you're 90% there. The other 10% will come from knowledge of additional CPU features like auto powering down when idle (or you could trigger this yourself but I'm not sure). – Dark Star1 May 25 '10 at 15:49
  • @Pavel: Actually, I meant by buying a different chip, not making a new one. Though I admit this is a non-answer. – Brian May 25 '10 at 16:59

9 Answers9

7

From the ARM technical reference site:

The features of the ARM11 MPCore processor that improve energy efficiency include:

  • accurate branch and sub-routine return prediction, reducing the number of incorrect instruction fetch and decode operations
  • use of physically addressed caches, which reduces the number of cache flushes and refills, saving energy in the system
  • the use of MicroTLBs reduces the power consumed in translation and protection lookups each cycle
  • the caches use sequential access information to reduce the number of accesses to the tag RAMs and to unwanted data RAMs.

In the ARM11 MPCore processor extensive use is also made of gated clocks and gates to disable inputs to unused functional blocks. Only the logic actively in use to perform a calculation consumes any dynamic power.

Based on this information, I'd say that the processor does a lot of work for you to save power. Any power wastage would come from poorly written code that does more processing than necessary, which you wouldn't want anyway. If you're looking to save power, the overall design of your application will have more effect. Network access, screen rendering, and other power-hungry operations will be of more concern for power consumption.

Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
5

Optimizing code to use less power is, effectively, just optimizing code. Regardless of whether your motives are monetary, social, politital or the like, fewer CPU cycles = less energy used. What I'm trying to say is I think you can probably replace "power consumption" with "execution time", as they would, essentially, be directly proportional - and you therefore may have more success when not "scaring" people off with a power-related question. I may, however, stand corrected :)

Jeriko
  • 6,547
  • 4
  • 28
  • 40
  • I didn't -1 you, but my laptop uses less power if the cpu is running slower, so execution time is inversely proportional to power consumption. – Pete Kirkham May 25 '10 at 15:42
  • You can't claim execution time is inversely proportional to power consumption. That implies I could write a 10-year-long script and expect it to consume a single joule of energy. I'll admit to previous ambiguity- How about "power usage is proportional to the number of CPU operations, bearing in mind that the power required per operation is inverse to the successive speed at which said operations are executed (along with a million other factors which remain unmentioned because I was attempting to write a general rule-of-thumb and not a tautology required to stand up in a court of law)"? :P – Jeriko May 25 '10 at 17:01
  • ++ I think you and the other responders are correct. Supposing most code runs on a periodic basis, the goal would be to spend as much time as possible in the idle state. – Mike Dunlavey May 25 '10 at 20:02
5

Yes. Use a profiler and see what routines are using most of the CPU. On ARM you can use some JTAG connectors, if available (I used Lauterbach both for debugging and for profiling). The main problem is generally to put your processor, when in idle, in a low-consumption state (deep sleep). If you cannot reduce the CPU percentage used by much (for example from 80% to 50%) it won't make a big difference. Depending on what operating systems you are running the options may vary.

INS
  • 10,594
  • 7
  • 58
  • 89
  • and I might add: do not keep peripherals in an "open" state unless you are really using them (for example keeping bluetooth/wi-fi open reduces *a lot* of the battery life in case of mobile devices. – INS May 25 '10 at 15:38
3

The July 2010 edition of the Communications of the ACM has an article on energy-efficient algorithms which might interest you. I haven't read it yet so cannot impart any of its wisdom.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
3

Try to stay in on chip memory (cache) for idle loops, keep I/O to a minimum, keep bit flipping to a minimum on busses. NV memory like proms and flash consume more power to store zeros than ones (which is why they erase to ones, it is actually a zero but the transitor(s) invert the bit before you see it, zeros stored as ones, ones stored as zeros, this is also why they degrade to ones when they fail), I dont know about volatile memories, dram uses half as many transistors as sram, but has to be refreshed.

For all of this to matter though you need to start with a lower power system as the above may not be noticeable. dont use anything from intel for example.

old_timer
  • 69,149
  • 8
  • 89
  • 168
1

If you are not running Windows XP+ or a newer version of Linux, you could run a background thread which does nothing but HLT.

This is how programs like CPUIdle reduce power consumption/heat.

BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
0

If the processor is tuned to use less power when it needs less cycles, then simply making your code run more efficiently is the solution. Else, there's not much you can do unless the operating system exposes some sort of power management functionality.

Puppy
  • 144,682
  • 38
  • 256
  • 465
0

Keep IO to a minimum.

fortran
  • 74,053
  • 25
  • 135
  • 175
0

On some ARM processors it's possible to reduce power consumption by putting the voltage regulator in standby mode.

Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161