views:

259

answers:

3

Hi
I have to build a simulator with C#. This simulator should be able to run a second thread with configureable CPU speed and limited RAM size, e.g. 144MHz and 50 MB.
Of course I know that a simulator can never be as accurate as the real hardware. But I try to get almost similar performance.
At the moment I'm thinking about creating a thread which I will stop/sleep from time to time. Depending on the desired CPU speed the simulator should adjust the sleep time of this thread and therefore simulate different cpu frequency. To measure the achieved speed I though about using PerformanceCounters. But with this approach I have the problem that I don't know how to limit the RAM size the thread could use.
Do you have any ideas how to realize such a simulator?

Thanks in advance!!

+1  A: 

If you are concerned with simulating an operating system environment then one answer would be to use a virtual machines environment where you can control memory and CPU parameters, etc.

The threading pause\stop may help you to simulate CPU frequency, but this is going to be terribly inaccurate as when you pause the thread it will be de-scheduled, then it's up to the operating system to re-schedule it at some "random" point in time i.e. a point which you have no control over.

As for limiting the memory, starting a new process that will host your code is an option, and then limiting the memory of that process, e.g.:

http://www.codeproject.com/KB/threads/Setting_Max_Memory_Limit.aspx

This will not really simulate overall OS memory limitations though.

chibacity
For all VMs I saw so far there is the problem that I can´t configure the CPU speed. Additionally I have the problem that I can limit the memory size for the whole VM only and not for particular one process/thread.The second approach with starting a new process and control it is a good idea.
geiserbua
You can usually specify what percentage of CPU resource is allocated to the VM, so this gives a "rough" way of constraining CPU resource. You can do this on Hyper-V at least. PS If you like people's answers - vote on them. :)
chibacity
+1  A: 

CPU speed limiting? You should check this, perhaps it will useful (to some degree at least). http://stackoverflow.com/questions/112439/cpu-emulation-and-locking-to-a-specific-clock-speed

Scorchio
+2  A: 

Limit memory is easy with the virtual machines like vmware. You can change cpu speed with some overclocking tools. For example http://cpu.rightmark.org/products/rmclock.shtml Good luck!

skateboard
+1. Virtualization is probably the best idea. It makes sense for a VM to also implement a CPU cap (cycles/millisecond maybe?), for example if used to have a virtual server. So I'd look whether there's an option for that.
back2dos
The problem with VMs is that there isn´t a way to change the CPU speed
geiserbua