views:

317

answers:

9

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

+4  A: 

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
care to justify the -1?
Jeriko
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
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
++ 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
A: 

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.

DeadMG
A: 

Keep IO to a minimum.

fortran
+5  A: 

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
A: 

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

Junior Mayhé
+4  A: 

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.

Iulian Şerbănoiu
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.
Iulian Şerbănoiu
+1  A: 

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
This shouldn't be necessary for newer operating systems.
Axel Gneiting
@Axel: Yes, I mentioned that...
BlueRaja - Danny Pflughoeft
+3  A: 

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
On the whole, I was pretty disappointed in said article, sadly.
Stephen Canon
Now I'll probably never read it.
High Performance Mark
+2  A: 

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.

dwelch