10

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!!

geiserbua
  • 101
  • 1
  • 4
  • +1 as I would like to know the answer. But I fear you're in too deep water – Oskar Kjellin May 26 '10 at 16:09
  • Look at arena allocators for limiting memory to a specific total. – WhirlWind May 26 '10 at 16:12
  • 3
    please note that clockrate is not really a good measure for performance. On one core of my Core2Duo downclocked to 1GHz I get signifficantly better performance than on a 2.5 GHz pentium 4. If you're trying to find out how your software would run on a specific device, you should try to get an emulator of the actual chip. – back2dos May 26 '10 at 16:34

4 Answers4

3

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
  • 31
  • 1
  • 1
    +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 May 26 '10 at 16:29
  • The problem with VMs is that there isn´t a way to change the CPU speed – geiserbua May 27 '10 at 07:57
2

CPU speed limiting? You should check this, perhaps it will useful (to some degree at least). CPU Emulation and locking to a specific clock speed

Community
  • 1
  • 1
Scorchio
  • 2,763
  • 2
  • 20
  • 28
1

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.

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
  • 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 May 27 '10 at 08:03
  • 1
    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. :) – Tim Lloyd May 27 '10 at 08:18
0

A thread to sleep down the software execution of your guest opcodes ?

I think it works but a little weird, like fast-forward, pause, ff, pause, etc...

If you just want to speed down a process, try this: use the cpu single step features, and "debug" the process. You have to wrote a custom handler for the cpu single stepping trap. Your handler job is only a big loop of NOPs.

You have a fine delay between each instruction.

Massimo
  • 3,171
  • 3
  • 28
  • 41