VirtualBox

Changeset 27972 in vbox


Ignore:
Timestamp:
Apr 2, 2010 10:59:54 PM (15 years ago)
Author:
vboxsync
Message:

VBoxService: Use VMM_MAX_CPU_COUNT! VBoxServiceBalloonQueryChunks -> VBoxServiceBalloonQueryPages. Windows: Clear req on since the cpu info query may fail. Windows: Report in 4KB units like specified. Linux: Report the page size used by the guest. Linux: added todos for all members that are unset. Nit: au64LastCpuLoadXXX since they are arrays now. Avoid multiple initialized variables on the same line.

Location:
trunk/src/VBox/Additions/common/VBoxService
Files:
3 edited

Legend:

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

    r27496 r27972  
    281281
    282282/**
    283  * Query the size of the memory balloon, given as a count of chunks.
     283 * Query the size of the memory balloon, given as a page count.
    284284 *
    285  * @returns The number of chunks (VMMDEV_MEMORY_BALLOON_CHUNK_SIZE).
    286  */
    287 uint32_t VBoxServiceBalloonQueryChunks(void)
    288 {
    289     return g_cMemBalloonChunks;
     285 * @returns Number of pages.
     286 * @param   cbPage          The page size.
     287 */
     288uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage)
     289{
     290    return g_cMemBalloonChunks * (VMMDEV_MEMORY_BALLOON_CHUNK_SIZE / cbPage);
    290291}
    291292
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h

    r27926 r27972  
    216216
    217217#ifdef VBOXSERVICE_MANAGEMENT
    218 extern uint32_t VBoxServiceBalloonQueryChunks(void);
     218extern uint32_t VBoxServiceBalloonQueryPages(uint32_t cbPage);
    219219#endif
    220220
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp

    r27944 r27972  
    1919 * additional information or have any questions.
    2020 */
    21 #ifdef TARGET_NT4
    22 #undef _WIN32_WINNT
    23 #define _WIN32_WINNT 0x501
    24 #endif
    25 
     21
     22/*******************************************************************************
     23*   Header Files                                                               *
     24*******************************************************************************/
    2625#if defined(RT_OS_WINDOWS)
     26# ifdef TARGET_NT4
     27#  undef _WIN32_WINNT
     28#  define _WIN32_WINNT 0x501
     29# endif
    2730# include <windows.h>
    2831# include <psapi.h>
    2932# include <winternl.h>
     33
    3034#elif defined(RT_OS_LINUX)
    3135# include <iprt/ctype.h>
    3236# include <iprt/stream.h>
     37# include <unistd.h>
     38
     39#else
     40/** @todo port me. */
     41
    3342#endif
    3443
    3544#include <iprt/assert.h>
    3645#include <iprt/mem.h>
    37 #include <iprt/thread.h>
     46#include <VBox/param.h>
     47#include <iprt/semaphore.h>
    3848#include <iprt/string.h>
    39 #include <iprt/semaphore.h>
    4049#include <iprt/system.h>
    4150#include <iprt/time.h>
     51#include <iprt/thread.h>
    4252#include <VBox/VBoxGuestLib.h>
    4353#include "VBoxServiceInternal.h"
    4454#include "VBoxServiceUtils.h"
    4555
    46 #define NR_CPUS  32
    47 
     56
     57/*******************************************************************************
     58*   Structures and Typedefs                                                    *
     59*******************************************************************************/
    4860typedef struct _VBOXSTATSCONTEXT
    4961{
    5062    RTMSINTERVAL          cMsStatInterval;
    5163
    52     uint64_t              u64LastCpuLoad_Idle[NR_CPUS];
    53     uint64_t              u64LastCpuLoad_Kernel[NR_CPUS];
    54     uint64_t              u64LastCpuLoad_User[NR_CPUS];
    55     uint64_t              u64LastCpuLoad_Nice[NR_CPUS];
     64    uint64_t              au64LastCpuLoad_Idle[VMM_MAX_CPU_COUNT];
     65    uint64_t              au64LastCpuLoad_Kernel[VMM_MAX_CPU_COUNT];
     66    uint64_t              au64LastCpuLoad_User[VMM_MAX_CPU_COUNT];
     67    uint64_t              au64LastCpuLoad_Nice[VMM_MAX_CPU_COUNT];
    5668
    5769#ifdef RT_OS_WINDOWS
     
    6274} VBOXSTATSCONTEXT;
    6375
     76
    6477/*******************************************************************************
    6578*   Global Variables                                                           *
     
    98111
    99112    gCtx.cMsStatInterval        = 0;     /* default; update disabled */
    100     RT_ZERO(gCtx.u64LastCpuLoad_Idle);
    101     RT_ZERO(gCtx.u64LastCpuLoad_Kernel);
    102     RT_ZERO(gCtx.u64LastCpuLoad_User);
    103     RT_ZERO(gCtx.u64LastCpuLoad_Nice);
     113    RT_ZERO(gCtx.au64LastCpuLoad_Idle);
     114    RT_ZERO(gCtx.au64LastCpuLoad_Kernel);
     115    RT_ZERO(gCtx.au64LastCpuLoad_User);
     116    RT_ZERO(gCtx.au64LastCpuLoad_Nice);
    104117
    105118    rc = VbglR3StatQueryInterval(&gCtx.cMsStatInterval);
     
    153166
    154167
    155 static void VBoxServiceVMStatsReport()
     168/**
     169 * Gathers VM statistics and reports them to the host.
     170 *
     171 * @returns
     172 * @param   oid                 .
     173 */
     174static void VBoxServiceVMStatsReport(void)
    156175{
    157176#if defined(RT_OS_WINDOWS)
     
    159178    PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pProcInfo;
    160179    MEMORYSTATUSEX memStatus;
    161     VMMDevReportGuestStats req;
    162180    uint32_t cbStruct;
    163181    DWORD    cbReturned;
     
    168186        return;
    169187
     188    /* Clear the report so we don't report garbage should NtQuerySystemInformation
     189       behave in an unexpected manner. */
     190    VMMDevReportGuestStats req;
     191    RT_ZERO(req);
     192
    170193    /* Query and report guest statistics */
    171194    GetSystemInfo(&systemInfo);
     
    175198
    176199    req.guestStats.u32PageSize          = systemInfo.dwPageSize;
    177     req.guestStats.u32PhysMemTotal      = (uint32_t)(memStatus.ullTotalPhys / systemInfo.dwPageSize);
    178     req.guestStats.u32PhysMemAvail      = (uint32_t)(memStatus.ullAvailPhys / systemInfo.dwPageSize);
    179     /* The current size of the committed memory limit, in bytes. This is physical memory plus the size of the page file, minus a small overhead. */
    180     req.guestStats.u32PageFileSize      = (uint32_t)(memStatus.ullTotalPageFile / systemInfo.dwPageSize) - req.guestStats.u32PhysMemTotal;
     200    req.guestStats.u32PhysMemTotal      = (uint32_t)(memStatus.ullTotalPhys / _4K);
     201    req.guestStats.u32PhysMemAvail      = (uint32_t)(memStatus.ullAvailPhys / _4K);
     202    /* The current size of the committed memory limit, in bytes. This is physical
     203       memory plus the size of the page file, minus a small overhead. */
     204    req.guestStats.u32PageFileSize      = (uint32_t)(memStatus.ullTotalPageFile / _4K) - req.guestStats.u32PhysMemTotal;
    181205    req.guestStats.u32MemoryLoad        = memStatus.dwMemoryLoad;
    182     req.guestStats.u32PhysMemBalloon    = VBoxServiceBalloonQueryChunks() * (_1M/systemInfo.dwPageSize);    /* was in megabytes */
    183     req.guestStats.u32StatCaps          = VBOX_GUEST_STAT_PHYS_MEM_TOTAL | VBOX_GUEST_STAT_PHYS_MEM_AVAIL | VBOX_GUEST_STAT_PAGE_FILE_SIZE | VBOX_GUEST_STAT_MEMORY_LOAD | VBOX_GUEST_STAT_PHYS_MEM_BALLOON;
     206    req.guestStats.u32PhysMemBalloon    = VBoxServiceBalloonQueryPages(_4K);
     207    req.guestStats.u32StatCaps          = VBOX_GUEST_STAT_PHYS_MEM_TOTAL | VBOX_GUEST_STAT_PHYS_MEM_AVAIL | VBOX_GUEST_STAT_PAGE_FILE_SIZE
     208                                        | VBOX_GUEST_STAT_MEMORY_LOAD | VBOX_GUEST_STAT_PHYS_MEM_BALLOON;
    184209
    185210    if (gCtx.pfnGetPerformanceInfo)
     
    197222            req.guestStats.u32MemKernelNonPaged = perfInfo.KernelNonpaged;  /* already in pages */
    198223            req.guestStats.u32MemSystemCache    = perfInfo.SystemCache;     /* already in pages */
    199             req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PROCESSES | VBOX_GUEST_STAT_THREADS | VBOX_GUEST_STAT_HANDLES | VBOX_GUEST_STAT_MEM_COMMIT_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_PAGED | VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED | VBOX_GUEST_STAT_MEM_SYSTEM_CACHE;
     224            req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_PROCESSES | VBOX_GUEST_STAT_THREADS | VBOX_GUEST_STAT_HANDLES
     225                                        | VBOX_GUEST_STAT_MEM_COMMIT_TOTAL | VBOX_GUEST_STAT_MEM_KERNEL_TOTAL
     226                                        | VBOX_GUEST_STAT_MEM_KERNEL_PAGED | VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED
     227                                        | VBOX_GUEST_STAT_MEM_SYSTEM_CACHE;
    200228        }
    201229        else
     
    204232
    205233    /* Query CPU load information */
    206     cbStruct = systemInfo.dwNumberOfProcessors*sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
    207     pProcInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)malloc(cbStruct);
    208     Assert(pProcInfo);
     234    cbStruct = systemInfo.dwNumberOfProcessors * sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
     235    pProcInfo = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)RTMemAlloc(cbStruct);
    209236    if (!pProcInfo)
    210237        return;
     
    215242        &&  cbReturned == cbStruct)
    216243    {
    217         if (gCtx.u64LastCpuLoad_Kernel == 0)
     244        if (gCtx.au64LastCpuLoad_Kernel == 0)
    218245        {
    219246            /* first time */
    220             gCtx.u64LastCpuLoad_Idle[0]    = pProcInfo->IdleTime.QuadPart;
    221             gCtx.u64LastCpuLoad_Kernel[0]  = pProcInfo->KernelTime.QuadPart;
    222             gCtx.u64LastCpuLoad_User[0]    = pProcInfo->UserTime.QuadPart;
     247            gCtx.au64LastCpuLoad_Idle[0]    = pProcInfo->IdleTime.QuadPart;
     248            gCtx.au64LastCpuLoad_Kernel[0]  = pProcInfo->KernelTime.QuadPart;
     249            gCtx.au64LastCpuLoad_User[0]    = pProcInfo->UserTime.QuadPart;
    223250
    224251            Sleep(250);
     
    228255        }
    229256
    230         uint64_t deltaIdle    = (pProcInfo->IdleTime.QuadPart   - gCtx.u64LastCpuLoad_Idle[0]);
    231         uint64_t deltaKernel  = (pProcInfo->KernelTime.QuadPart - gCtx.u64LastCpuLoad_Kernel[0]);
    232         uint64_t deltaUser    = (pProcInfo->UserTime.QuadPart   - gCtx.u64LastCpuLoad_User[0]);
     257        uint64_t deltaIdle    = (pProcInfo->IdleTime.QuadPart   - gCtx.au64LastCpuLoad_Idle[0]);
     258        uint64_t deltaKernel  = (pProcInfo->KernelTime.QuadPart - gCtx.au64LastCpuLoad_Kernel[0]);
     259        uint64_t deltaUser    = (pProcInfo->UserTime.QuadPart   - gCtx.au64LastCpuLoad_User[0]);
    233260        deltaKernel          -= deltaIdle;  /* idle time is added to kernel time */
    234261        uint64_t ullTotalTime = deltaIdle + deltaKernel + deltaUser;
     
    240267        req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE | VBOX_GUEST_STAT_CPU_LOAD_KERNEL | VBOX_GUEST_STAT_CPU_LOAD_USER;
    241268
    242         gCtx.u64LastCpuLoad_Idle[0]   = pProcInfo->IdleTime.QuadPart;
    243         gCtx.u64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart;
    244         gCtx.u64LastCpuLoad_User[0]   = pProcInfo->UserTime.QuadPart;
    245     }
    246 
    247     for (uint32_t i=0; i<systemInfo.dwNumberOfProcessors; i++)
     269        gCtx.au64LastCpuLoad_Idle[0]   = pProcInfo->IdleTime.QuadPart;
     270        gCtx.au64LastCpuLoad_Kernel[0] = pProcInfo->KernelTime.QuadPart;
     271        gCtx.au64LastCpuLoad_User[0]   = pProcInfo->UserTime.QuadPart;
     272        /** @todo SMP: report details for each CPU?  */
     273    }
     274
     275    for (uint32_t i = 0; i < systemInfo.dwNumberOfProcessors; i++)
    248276    {
    249277        req.guestStats.u32CpuId = i;
     
    256284    }
    257285
    258     free(pProcInfo);
     286    RTMemFree(pProcInfo);
    259287
    260288#elif defined(RT_OS_LINUX)
     
    313341    }
    314342
    315     req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryChunks() * (_1M/_4K);
     343    req.guestStats.u32PageSize = getpagesize();
     344    req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryPages(_4K);
    316345    req.guestStats.u32StatCaps = VBOX_GUEST_STAT_PHYS_MEM_TOTAL \
    317346                               | VBOX_GUEST_STAT_PHYS_MEM_AVAIL \
     
    319348                               | VBOX_GUEST_STAT_PAGE_FILE_SIZE;
    320349
     350    /** @todo req.guestStats.u32Threads */
     351    /** @todo req.guestStats.u32Processes */
     352    /* req.guestStats.u32Handles doesn't make sense here. */
     353    /** @todo req.guestStats.u32MemoryLoad */
     354    /** @todo req.guestStats.u32MemCommitTotal */
     355    /** @todo req.guestStats.u32MemKernelTotal */
     356    /** @todo req.guestStats.u32MemKernelPaged, make any sense?  = u32MemKernelTotal? */
     357    /** @todo req.guestStats.u32MemKernelNonPaged, make any sense? = 0? */
     358
    321359    rc = RTStrmOpen("/proc/stat", "r", &pStrm);
    322360    if (RT_SUCCESS(rc))
     
    324362        for (;;)
    325363        {
    326             uint32_t u32CpuId;
    327             uint64_t u64User = 0, u64Nice = 0, u64System = 0, u64Idle = 0;
    328364            rc = RTStrmGetLine(pStrm, szLine, sizeof(szLine));
    329365            if (RT_FAILURE(rc))
     
    333369                && RT_C_IS_DIGIT(szLine[3]))
    334370            {
     371                uint32_t u32CpuId;
    335372                rc = RTStrToUInt32Ex(&szLine[3], &psz, 0, &u32CpuId);
    336                 if (u32CpuId < NR_CPUS)
     373                if (u32CpuId < VMM_MAX_CPU_COUNT)
    337374                {
     375                    uint64_t u64User = 0;
    338376                    if (RT_SUCCESS(rc))
    339377                        rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64User);
     378
     379                    uint64_t u64Nice = 0;
    340380                    if (RT_SUCCESS(rc))
    341381                        rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Nice);
     382
     383                    uint64_t u64System = 0;
    342384                    if (RT_SUCCESS(rc))
    343385                        rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64System);
     386
     387                    uint64_t u64Idle = 0;
    344388                    if (RT_SUCCESS(rc))
    345389                        rc = RTStrToUInt64Ex(RTStrStripL(psz), &psz, 0, &u64Idle);
    346390
    347                     uint64_t u64DeltaIdle   = u64Idle   - gCtx.u64LastCpuLoad_Idle[u32CpuId];
    348                     uint64_t u64DeltaSystem = u64System - gCtx.u64LastCpuLoad_Kernel[u32CpuId];
    349                     uint64_t u64DeltaUser   = u64User   - gCtx.u64LastCpuLoad_User[u32CpuId];
    350                     uint64_t u64DeltaNice   = u64Nice   - gCtx.u64LastCpuLoad_Nice[u32CpuId];
     391                    uint64_t u64DeltaIdle   = u64Idle   - gCtx.au64LastCpuLoad_Idle[u32CpuId];
     392                    uint64_t u64DeltaSystem = u64System - gCtx.au64LastCpuLoad_Kernel[u32CpuId];
     393                    uint64_t u64DeltaUser   = u64User   - gCtx.au64LastCpuLoad_User[u32CpuId];
     394                    uint64_t u64DeltaNice   = u64Nice   - gCtx.au64LastCpuLoad_Nice[u32CpuId];
    351395
    352396                    uint64_t u64DeltaAll    = u64DeltaIdle
     
    355399                                            + u64DeltaNice;
    356400
    357                     gCtx.u64LastCpuLoad_Idle[u32CpuId]   = u64Idle;
    358                     gCtx.u64LastCpuLoad_Kernel[u32CpuId] = u64System;
    359                     gCtx.u64LastCpuLoad_User[u32CpuId]   = u64User;
    360                     gCtx.u64LastCpuLoad_Nice[u32CpuId]   = u64Nice;
     401                    gCtx.au64LastCpuLoad_Idle[u32CpuId]   = u64Idle;
     402                    gCtx.au64LastCpuLoad_Kernel[u32CpuId] = u64System;
     403                    gCtx.au64LastCpuLoad_User[u32CpuId]   = u64User;
     404                    gCtx.au64LastCpuLoad_Nice[u32CpuId]   = u64Nice;
    361405
    362406                    req.guestStats.u32CpuId = u32CpuId;
    363407                    req.guestStats.u32CpuLoad_Idle   = (uint32_t)(u64DeltaIdle   * 100 / u64DeltaAll);
    364408                    req.guestStats.u32CpuLoad_Kernel = (uint32_t)(u64DeltaSystem * 100 / u64DeltaAll);
    365                     req.guestStats.u32CpuLoad_User   = (uint32_t)((u64DeltaUser 
     409                    req.guestStats.u32CpuLoad_User   = (uint32_t)((u64DeltaUser
    366410                                                                 + u64DeltaNice) * 100 / u64DeltaAll);
    367411                    req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE \
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