The CPU is designed to drop into low power modes whenever it can to save power and keep cool, I'd like to make a program to prevent that from happening.
I'm working on a few different embedded platforms (Freescale Coldfire 8052, TI Sitara AM3359, probably a few others in the pipeworks) and so I wanted to make an application that will just keep the CPU fully loaded for benchmarking. I want to write my own since it would be easier to cross-compile then to look for a solution per target.
My initial thought was just:
while(1);
Question 1:
But at I over simplifing this? top shows that program taking about 99.4% CPU usage, so I guess it's working, but it doesn't seem like it should be so simple. :) Anyone know if there should be more to it than that?
Question 2:
If I wanted to expand this to do different loads (say, 50%, 75%, or whatever) how could I do that? I managed to get a 18~20% CPU usage via:
while(1){usleep(1);}
Is there a more, scientific way rather than just guessing and checking at sleep values? I would think these would be different per target anyway.
while(1);
will eat up all your CPU cycles but won't exercise most parts of your CPU (let alone the GPU). Most modern CPUs have the ability to selectively switch off individual execution units if they're not used: the only way to prevent it is: