VirtualBox

Ignore:
Timestamp:
Jun 11, 2015 7:09:17 PM (10 years ago)
Author:
vboxsync
Message:

Additions/VBoxService: fix long-standing todo for Windows host, report guest CPU stats for every CPU

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp

    r56294 r56376  
    218218        &&  cbReturned == cbStruct)
    219219    {
    220         if (gCtx.au64LastCpuLoad_Kernel == 0)
    221         {
    222             /* first time */
    223             gCtx.au64LastCpuLoad_Idle[0]    = pProcInfo->IdleTime.QuadPart;
    224             gCtx.au64LastCpuLoad_Kernel[0]  = pProcInfo->KernelTime.QuadPart;
    225             gCtx.au64LastCpuLoad_User[0]    = pProcInfo->UserTime.QuadPart;
    226 
    227             Sleep(250);
    228 
    229             rc = gCtx.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned);
    230             Assert(!rc);
    231         }
    232 
    233         uint64_t deltaIdle    = (pProcInfo->IdleTime.QuadPart   - gCtx.au64LastCpuLoad_Idle[0]);
    234         uint64_t deltaKernel  = (pProcInfo->KernelTime.QuadPart - gCtx.au64LastCpuLoad_Kernel[0]);
    235         uint64_t deltaUser    = (pProcInfo->UserTime.QuadPart   - gCtx.au64LastCpuLoad_User[0]);
    236         deltaKernel          -= deltaIdle;  /* idle time is added to kernel time */
    237         uint64_t ullTotalTime = deltaIdle + deltaKernel + deltaUser;
    238         if (ullTotalTime == 0) /* Prevent division through zero. */
    239             ullTotalTime = 1;
    240 
    241         req.guestStats.u32CpuLoad_Idle      = (uint32_t)(deltaIdle  * 100 / ullTotalTime);
    242         req.guestStats.u32CpuLoad_Kernel    = (uint32_t)(deltaKernel* 100 / ullTotalTime);
    243         req.guestStats.u32CpuLoad_User      = (uint32_t)(deltaUser  * 100 / ullTotalTime);
    244 
    245         req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL | VBOX_GUEST_STAT_CPU_LOAD_USER;
    246 
    247         gCtx.au64LastCpuLoad_Idle[0]   = pProcInfo->IdleTime.QuadPart;
    248         gCtx.au64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart;
    249         gCtx.au64LastCpuLoad_User[0]   = pProcInfo->UserTime.QuadPart;
    250         /** @todo SMP: report details for each CPU?  */
     220        for (uint32_t i = 0; i < systemInfo.dwNumberOfProcessors; i++)
     221        {
     222            if (gCtx.au64LastCpuLoad_Kernel[i] == 0)
     223            {
     224                /* first time */
     225                gCtx.au64LastCpuLoad_Idle[i]    = pProcInfo[i].IdleTime.QuadPart;
     226                gCtx.au64LastCpuLoad_Kernel[i]  = pProcInfo[i].KernelTime.QuadPart;
     227                gCtx.au64LastCpuLoad_User[i]    = pProcInfo[i].UserTime.QuadPart;
     228
     229                Sleep(250);
     230
     231                rc = gCtx.pfnNtQuerySystemInformation(SystemProcessorPerformanceInformation, pProcInfo, cbStruct, &cbReturned);
     232                Assert(!rc);
     233            }
     234
     235            uint64_t deltaIdle    = (pProcInfo[i].IdleTime.QuadPart   - gCtx.au64LastCpuLoad_Idle[i]);
     236            uint64_t deltaKernel  = (pProcInfo[i].KernelTime.QuadPart - gCtx.au64LastCpuLoad_Kernel[i]);
     237            uint64_t deltaUser    = (pProcInfo[i].UserTime.QuadPart   - gCtx.au64LastCpuLoad_User[i]);
     238            deltaKernel          -= deltaIdle;  /* idle time is added to kernel time */
     239            uint64_t ullTotalTime = deltaIdle + deltaKernel + deltaUser;
     240            if (ullTotalTime == 0) /* Prevent division through zero. */
     241                ullTotalTime = 1;
     242
     243            req.guestStats.u32CpuLoad_Idle      = (uint32_t)(deltaIdle  * 100 / ullTotalTime);
     244            req.guestStats.u32CpuLoad_Kernel    = (uint32_t)(deltaKernel* 100 / ullTotalTime);
     245            req.guestStats.u32CpuLoad_User      = (uint32_t)(deltaUser  * 100 / ullTotalTime);
     246
     247            req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL | VBOX_GUEST_STAT_CPU_LOAD_USER;
     248
     249            gCtx.au64LastCpuLoad_Idle[i]   = pProcInfo[i].IdleTime.QuadPart;
     250            gCtx.au64LastCpuLoad_Kernel[i] = pProcInfo[i].KernelTime.QuadPart;
     251            gCtx.au64LastCpuLoad_User[i]   = pProcInfo[i].UserTime.QuadPart;
     252        }
    251253    }
    252254
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette