3

I wish to carry out some testing on a range of Linux devices to see their power consumption based on current processor load.

As such I am looking for a program I can use to force the CPU to use X% i.e So I can increment the processor load by 10% checks and make measurements at that point.

I have looked at packages like 'stress' and 'cpuburn' but these seem to only use 100%

Hope you can help

Thanks

4

You can use CPU load generator together with a CPU load limiter.

Below is an example with utilities stress and cpulimit. Both utilities are in Debian and derived distribution (like Ubuntu) repositories.

stress -c 1 & cpulimit -p $( pidof -o $! stress ) -l 20

Explanation

20 is the CPU time percentage to be used. stress spawns a child worker so you cannot control the worker directly from cpulimit. pidof is being used to find the child PID. This simple example will work reliably only if single instance of stress is started. To stop the load press Ctrl+c and type killall stress.

Alternatively for easier procedure you can use a different CPU stressing utility which does not spawn child processes.

cpulimit works best if you adjust RLIMIT_NICE limit or if your run it as root.

  • note that because the focus here is on cpu Time%, not frequency %, stress will still be consuming power while it is on the 'off' part of its cycle, since it is processing thread context switching even though the stress programs threads are in a spin-wait state. – Frank Thomas Nov 1 '13 at 14:13
  • Yes stress will run in endless loop but cpulimit will periodically suspend and resume it as needed to achieve the requested CPU load. So in the case shown in my reply it will consume 20% of a single CPU core. When stress is suspended it does not consume any CPU cycles. I think that this is what Zac Powell asked for. --- When load on multiple cores is needed stress can spawn multiple children and cpulimit can be run in multiple instances but I think there is no easy solution to force distribution of individual children to individual cores. – pabouk Nov 1 '13 at 14:41
  • when threads are sleeping, they are still taking cpu time which is how you can say 'sleep for 100ms'. if they were truly not executing, the OS would not know when to resume them, since the sleep instruction was spawned within the very thread that is sleeping. they just yield execution to other threads, and don't do any work themselves. the OSes thread time-multiplexing is constantly allowing the thread to work, and the thread itself says 'nah, I'm gonna wait', which takes cycles and draws power. – Frank Thomas Nov 1 '13 at 15:16
  • Indeed the above answer while I had hoped would work well seems to give very mixed results and I cant seem to generate a good result from it – Zac Powell Nov 1 '13 at 16:00
  • @FrankThomas: 1. In Linux there is no real difference between process and thread. See for example Threads vs Processes in Linux. There are just some parameters set differently. They are scheduled the same way: Linux - threads and process scheduling priorities. – pabouk Nov 1 '13 at 16:13
0

Instead of trying to throttle the Applications use of the cpu, why don't you try throttling the CPU itself, by reducing its capacity to the percentage you desire? you will not be able to tell a thread that would otherwise run at max capacity to "run slower", unless it was designed to sleep x% of the time, which would pollute the data you are trying to collect with processor activity for threading operations like spin-wait/pulse.

depending on your distro, you can use tools like cpupower, granola, or cpufreq

  • Ok so I could throttle the cpu and then use cpuburn – Zac Powell Nov 1 '13 at 12:38
0

There is stress-ng which allows to define workload percentages in an easy way. You could for example use it like this:

stress-ng --cpu 4 --cpu-load 50

This will stress four CPUs with a workload of 50%. If you're using Ubuntu you can simply install it from the repository:

sudo apt-get install -y stress-ng
0

Someone posted an interesting fiddle that can stress all cpu cores 100%.

It uses one web worker per core (default quadcore) , and can be easily modified for variable stress on each core.

http://jsfiddle.net/MTJ27/81/

  • you can use navigator.hardwareConcurrency to get the number of cores.
  • you cannot implement CPU-Z as a web page, although WebGL allows detailed GPU info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.