C ++:故意限制CPU使用率 [英] C++: Limiting CPU usage intentionally

查看:464
本文介绍了C ++:故意限制CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我公司,我们经常在CPU压力下测试USB和FireWire设备的性能。

At my company, we often test the performance of our USB and FireWire devices under CPU strain.

我们运行了一个测试代码来加载CPU,并且

There is a test code we run that loads the CPU, and it is often used in really simple informal tests to see what happens to our device's performance.

我查看了此代码,并发现了一个递增的简单循环一个计数器,并根据新值进行计算,并将结果存储在另一个变量中。

I took a look at the code for this, and its a simple loop that increments a counter and does a calculation based on the new value, storing this result in another variable.

运行单个实例将使用CPU的1 / X,其中X为核数。

Running a single instance will use 1/X of the CPU, where X is the number of cores.

例如,如果我们使用的是8核PC,并且想查看我们的设备在50%CPU使用率下如何运行,我们可以一次打开四个实例,依此类推...

So, for instance, if we're on a 8-core PC and we want to see how our device runs under 50% CPU usage, we can open four instances of this at once, and so forth...

我想知道:


  1. 是什么决定多少CPU被耗尽?它是否可以在单个线程应用程序中的单个线程上以最快的速度运行所有内容?

  1. What decides how much of the CPU gets used up? does it just run everything as fast as it can on a single thread in a single threaded application?

是否有一种方法可以自动限制您的最大CPU使用率?程序可以使用吗?我可以想到一些草率的方法(添加睡眠命令或其他方法),但是有没有办法限制某些特定百分比的可用CPU或其他内容?

Is there a way to voluntarily limit the maximum CPU usage your program can use? I can think of some "sloppy" ways (add sleep commands or something), but is there a way to limit to say, some specified percent of available CPU or something?


推荐答案

Windows 7 Linux 。

也在 QNX(即Blackberry Tablet OS)上 LynuxWorks

在链接断开的情况下,文章的名称为:

In case of broken links, the articles are named:


  • Windows – Windows Server 2008 R2和Windows中的CPU速率限制7

  • Linux- Linux的CPU使用限制器

  • QNX-自适应分区

  • LynuxWorks-分区操作系统和 ARINC 653

  • Windows -- "CPU rate limits in Windows Server 2008 R2 and Windows 7"
  • Linux -- "CPU Usage Limiter for Linux"
  • QNX -- "Adaptive Partitioning"
  • LynuxWorks - "Partitioning Operating Systems" and "ARINC 653"

这篇关于C ++:故意限制CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆