如何模拟不同CPU频率并限制RAM
我必须用 C# 构建一个模拟器。该模拟器应该能够运行第二个线程,具有可配置的 CPU 速度和有限的 RAM 大小,例如 144MHz 和 50 MB。
当然,我知道模拟器永远不可能像真实硬件一样准确。但我尝试获得几乎相似的性能。
目前我正在考虑创建一个线程,我会不时地停止/睡眠。根据所需的 CPU 速度,模拟器应调整该线程的睡眠时间,从而模拟不同的 CPU 频率。为了测量所达到的速度,我考虑使用 PerformanceCounters。但使用这种方法时,我遇到的问题是我不知道如何限制线程可以使用的 RAM 大小。
您对如何实现这样的模拟器有什么想法吗?
提前致谢!
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!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 vmware 等虚拟机限制内存很容易。您可以使用一些超频工具更改 CPU 速度。例如 http://cpu.rightmark.org/products/rmclock.shtml
祝你好运!
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!
CPU 速度限制?你应该检查一下,也许它会有用(至少在某种程度上)。
CPU 模拟并锁定到特定时钟速度
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
如果您关心模拟操作系统环境,那么一个答案是使用虚拟机环境,您可以在其中控制内存和 CPU 参数等。
线程暂停\停止可能会帮助您模拟 CPU 频率,但这会影响您的系统性能。非常不准确,因为当您暂停线程时,它将被取消调度,然后由操作系统在某个“随机”时间点(即您无法控制的点)重新调度它。
至于限制内存,可以选择启动一个托管代码的新进程,然后限制该进程的内存,例如:
http://www.codeproject.com/KB/threads/Setting_Max_Memory_Limit.aspx
但这并不能真正模拟总体操作系统内存限制。
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.
一个线程来休眠您的来宾操作码的软件执行?
我认为它的工作原理有点奇怪,例如快进、暂停、ff、暂停等...
如果您只是想加快进程速度,请尝试以下操作:使用 cpu 单步功能,然后“调试” “这个过程。您必须为 cpu 单步陷阱编写一个自定义处理程序。你的处理程序工作只是一个大循环的 NOP。
每条指令之间有一个很好的延迟。
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.