Hi,
For research purpose, I have to degrade the performance of some computer using a cpuburner. I code a program which do this by getting the maximum priority of SCHED_FIFO and then execute the following algorithm:
CLOCK(c0);
sleep_time_tot = 0;
while (1) {
CLOCK(c1);
usleep (1);
CLOCK(c2);
sleep_time_tot += CLOCK_UDIFF(c2, c1);
while (time_tot*(100-percent)/100 < sleep_time_tot) {
sched_yield();
CLOCK(c3); time_tot = CLOCK_UDIFF(c3, c0);
}
}
My first problem is that in the second part (when the program execute the second loop), all the cpu is used by the program and network communication are stalled. The goal of the program is to decrease only the cpu perf, not the network comm. There is certainly a solution for this, but I don't know how the kernel work for doing. Any ideas ?
Another problem: the program should be the more accurate possible and it depends on the time effectively taken by the usleep call. This time is related to the HZ constant. I tryed to increase this constant to at least 10000 (and possibly 100000) but I was constraint at compilation time to take 1500 (or 4000 if I modified another file). How can I increase this constant to the previous values ?
I also found a patch (High Res POSIX Timers) which improve the precision of the timers, however it is quite old and this is still not in the main line. Any hope ? (I was not able to compile a kernel with this patch).
simple solution?
If you can live with dividing your cpu power by natural numbers (i.e. give your process 100%, 50%, 33%, 25%, ...), you can simply start n-1 trivial load processes like
main(){for(;;);}, i.e. to burn 90% of the cpu, start 9 of these processes for every work process. You can do this from a shell script (don't forget to kill the load processes after a while..), or fork() appropriately in C. This should eat the correct amount of user time, but leave system time alone. Note these infinite loops don't use I/O or memory, just cpu cycles.You can also run your program on a xen, uml, ... virtual machine. If you need finer than HZ granularity, you can use the power saving features of mobile cpus to underclock them, or configure your main board for a slower cpu.
This can be a solution but we
This can be a solution but we will be limited to some values of the percent (100%, 50%, 33%, 25%), this is not really accurate and lastly, this become complicated when we have more than one CPU. But, this is better for the communication.
Is it possible to control the cpu usage with xen or uml ?
We tryed to use Cool'nd quiet or some other power saving features but this is still limited to some values. And we don't have physical access to the machine that we are planing to use (and if we want to propose this program to other people, it must be portable).
I find somewhere that RT program have higher priority than kernel process and that time-shared program have lower. I wonder wether our program can become a kernel program and how. If it has the same priority than the kernel, the communication will continue. (I tryed with nice and it is worse than any other solution).