如何模拟不同CPU频率并限制RAM

发布于 2024-09-03 01:33:48 字数 316 浏览 9 评论 0原文

我必须用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鲸落 2024-09-10 01:33:48

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

挽梦忆笙歌 2024-09-10 01:33:48

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

安静 2024-09-10 01:33:48

如果您关心模拟操作系统环境,那么一个答案是使用虚拟机环境,您可以在其中控制内存和 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.

行至春深 2024-09-10 01:33:48

一个线程来休眠您的来宾操作码的软件执行?

我认为它的工作原理有点奇怪,例如快进、暂停、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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文