How can I limit the processing power provided by a particular program?

I am developing on a laptop with a dual-core processor with a clock frequency of 1.8 GHz, but people often run my programs on much weaker systems (for example, 300 MHz ARM).

I would like to simulate such weak environments on my laptop so that I can watch how my program works. This is an interactive application.

I looked at qemu and I know how to set up the environment, but it hurts a little, and I did not see the exact switch spell that I need so that qemu mimics a weaker processor.

I have a virtual box, but it seems to me that I can not virtualize less than one full host.

I know about http://cpulimit.sourceforge.net/ , which uses sigstop and sigcont to try to limit the processor given to the process, but I'm worried that this is not really an exact image of a weaker processor.

Any ideas?

+4
source share
3 answers

If your processor is 1800 MHz and your target is 300 MHz, and your code is as follows:

while(1) { /*...*/ } 

you can rewrite it like this:

 long last=gettimestamp(); while(1) { long curr=gettimestamp(); if(curr-last>1000) // out of every second... { long target=curr+833; // ...waste 5/6 of it while(gettimestamp()<target); last=target; } // your original code } 

where gettimestamp() is your high-frequency timer for your OS.

You can work with lower values ​​for smoother playback, for example, 83 ms every 100 ms or 8 ms every 10 ms, etc. The lower you go, the greater the loss of accuracy will destroy your math.


edit: Or how about this? Create a second process that starts the first and joins it as a debugger, and then periodically pauses it and resumes according to the above algorithm.

+1
source

You can look at the emulator that is built for this. For example, from Microsoft you can find this technical note, http://www.nsbasic.com/ce/info/technotes/TN23.htm .

Without knowing more about the languages ​​you use and the platforms, it is difficult to be more specific, but I would trust the emulator programs to do a good job of providing a test environment.

0
source

Somewhere I selected a PIIMMX-266 laptop and installed a miniature Debian on it. It was a great decision until he died a few weeks ago. This is a Panasonic model that has a non-standard IDE connector (not a 40-pin or 44-pin), so I could not replace its CF hard drive (CF-IDE adapter costs about zero) .In addition, the price of such a machine is $ 50 / 40 euros.

(I used it to simulate a slow ARM-based machine for our home aut system, which is expected to run on the smallest and slowest Linux systems. Meanwhile, we chose a small and slow computer for home aut. purposes: GuruPlug. He has a fast processor with a bandwidth of 1.2 GB.)

(I am not familiar with QEMU, but the manual says that you can use KVM (kernel virtualization) to run programs at native speed, I assume that if this is an additional feature, it can be disabled, therefore, it’s strange but true, it can emulate x86 on x86.)

0
source

Source: https://habr.com/ru/post/1335895/


All Articles