views:

197

answers:

11

I would like to maximize power consumption on a linux laptop (ubuntu with openbox) to discharge the battery as fast as possible. I would like it to be done purely from software without user intervention. Which strategies would be useful to do this? The ones I can think of are:

  1. Switch off power-save functionality (tips on how to do this are welcome).
  2. Switch off screensaver/blanking (no luck with -setterm blank 0, screen still blanks).
  3. Making the CPU and other hardware consume as much power as possible (ideas are welcome).

This is what I can think of. Are there any more obvious ways to to this?

Edit: To clarify a bit. I have to do this from within a program that runs under openbox. So it is a programming question. Especially p 3.

A: 

Just leave the computer compiling GNOME, KDE, OpenOffice.org and the Kernel in a queue. That should get the computer work at 100% for a few hours.

Maybe try installing Gentoo with all the packages you could think of, as that distro installs everything from source (compiles everything).

voyager
A: 

a busy loop is the best way. with so many multi-proc/multi-core cpus out there today, you might want to figure out how many busy loops to start so that each core is running at 100% - look in /proc/cpu and count the number of 'processor: ' lines.

a busy loop is a loop that runs forever doing nothing. for instance, in c you could do this:

#define EVER ;;
int main() {
   for(EVER) {}
}
Igor
I personally prefer `while(1){}`.
voyager
This is actually not the best way. A lot of chips use clock gating and such, so if you have an idle loop, the chip is probably going to turn down or turn off the functional units that aren't getting exercised. What you really want to do is write a little benchmark that issues the max number of instructions every cycle, so that every functional unit is exercised as much as possible. It's not trivial.
tgamblin
...and in multiple threads. Calculate the value of pi for example?
Kimvais
and Level1 caching, so the RAM will never get exercised like this...
Quamis
+1  A: 

Lots of disk activity might help, too...

Paolo Tedesco
+2  A: 

i would say, plugin some USB power sucking devices, eg. USB lamp ...

Dapeng
Or how about chaining a bunch of hubs together and then running the lamps from those? A scene from A Christmas Story comes to mind...
harschware
+1  A: 

Start the wireless connection... with downloads/uploads

lmsasu
+1  A: 

Dear,

For Switch off power-save functionality, I suggest to steal some modification of powertop and reverse it.

Also you could do the reverse of doing reduced power usage like in this page :

https://wiki.ubuntu.com/ReducedPowerUsage

For that the CPU / Hard Drive / Graphic card work at 100% I suggest you to run like a benchmark test in a loop mode. Don't forget the ethernet and wifi.

Best Regards

madshiva
+6  A: 

I'm assuming you're talking mostly about CPU power consumption. It turns out there's actually quite a bit of work involved in doing this from software, because modern processors use a lot of aggressive clock gating, voltage scaling, and frequency scaling to turn off or slow down parts of the chip that aren't being used. Maximizing the power consumption for a particular processor is going to depend on how well you can keep all of these parts active. To do this you need to make sure you're issuing as many instructions as you can so that the chip uses all the functional units available to you.

I don't believe that Intel or AMD make the clock gating granularity of their chips public, so you'll have to guess. The best way you can do this is to grab a microarchitecture manual and see what the pipelines on your particular laptop's processor look like. For example, you want to know how many floating point instructions you can issue per cycle, how many FP units you have, etc. Likewise, figure out how many integer units you have, how many SSE instructions you can execute, etc. Then write a really tight loop that issues instructions for all these things. You could do this in raw assembly, or you could probably make do with C and SSE intrinsics. If you hit all the functional units on the die with those instructions, you should manage to maximize the CPU's power consumption.

For multicore and multi-socket machines, you will also want to make sure you're using all the processors you have, so run an instance of your tight loop on each core.

Finally, keep in mind that other things on your laptop use power. DMA accesses can cost you a pretty hefty amount of power, so if you can design a benchmark that exercises your CPU and issues lots of DMAs, you might be able to use more power. Likewise, if you've got a wireless card, doing any kind of hefty network transfers over that will run your battery down pretty fast.

There's a whole lot of work going on now in the field of power-aware computing, and people in that domain usually try to conserve power. But, if you're interested in more details on power consumption, you can probably find what you're looking through papers at some of the power-aware computing conferences.

Hopefully that helps. Good luck. It would be interesting to see what you come up with if you attempt to write something like this.

tgamblin
Great answer, thanks.
icecream
@icecream: Thanks. This part of your question is *very* programming-related. I think the first two points in the question got it kicked over to superuser, but #3 is much more interesting. I talked to Marc and he's been kind enough to bring it back over here.
tgamblin
Some of the other answers are useful, but this is the most interesting one from a software perspective.
icecream
+1  A: 

Install something like Prime95 or other distributed computing app of choice, they're quite intense on CPU time and execute proper instructions not just constant idle loops.

+1  A: 

Don't forget about the GPU. You can keep it occupied with relatively few instructions from the CPU, but when stressed, it eats a lot of power. Here, tgamblin's answer about the CPU is probably applicable as well: you'll need to figure out what combinations of instructions to send to keep all processors on the GPU busy at all times.

Thomas
+1  A: 

Basically you will have to build a benchmarking suite to do this thing.

Benchmark the cpu to get around 40-80W or power consumed (be careful about multiprocessors) Benchmark the graphic backed(try Opengl + some sort of shaders) Use the wireless card, if available and do some big transfers. Benchmark the HDD, i guess random seeks should be more power-hungry than linear reads, so create lots of files, write to them, read them randomly, delete them, all this with DIRECT_IO set...

You may do this thing modular and test which of the test drain the battery more quicky. In Ubuntu you can see the power drained from the battery almoust instantly, so it should be easy and really interesting to see.

Please pot the results somewhere on the web when youre done:D

PS: some of the powersaving stuff is implemented by Gnome, not by X (if you use Ubuntu/Gnome) so take that into account. Try to fiddle with gconf

Quamis
A: 

In my humble opinion you should write a program that uses your both CPU 100% and your GPU (Graphics Processing Unit) 100%. The GPU can actually cause more damage to battery lifespan then (trust a gamer :) ).

Kamikaze