在Windows上引发受控制的CPU压力

时间:2016-02-11 17:11:49

标签: c++ windows multithreading winapi cpu-usage

我试图引导受控的CPU压力进行一些性能测试。

目前使用以下程序诱导压力。

  //Thread function to create 50% stress on one of the cores
unsigned __stdcall threadFunc(void *param)
{
    while(1)
    {
        //Start timer   
        //------ Operations-----
        //------ Operations-----
        //Get Elapsed time in ms
        Sleep(elapsedTime);     
    }
    _endthread();
}

MainFunc()
{
   //loop looking for input
if(inputDetectedToIncreaseStress)
   _beginthreadex(NULL, 0, &threadFunc, NULL, 0, &threadId); //Creates a thread

}

使用上面的代码,我预计会在特定核心上产生50%的CPU压力。 例如,在四核系统中,我希望上面的代码能够产生12.5%的负载,但它实际上会产生25%的负载,在我的情况下,有8个核心,它会导致12.5%的负载,预期为6.25%,并且它会导致相同的负载。加载没有任何睡眠功能。

总而言之,我可以通过创建没有任何睡眠的线程来获得CPU负载百分比12.5,25,37.5,50,62.5,75,87.5,100,但即使尝试引入睡眠功能也无法产生像95这样的压力百分比在特定核心上引起50%的CPU负载。

有人能告诉我哪里出错了吗?

操作系统:Microsoft Windows Server 2012。 CPU核心:8 编程语言:C ++ 定时器功能:使用查询性能计数器 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx

0 个答案:

没有答案