VirtualBox

Changeset 44992 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 11, 2013 3:41:01 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84215
Message:

VBOX_WITH_DPC_LATENCY_CHECKER: Some adjustments. Please, don't use #pragma pack() unless you really need and mean it! Misaligning data just makes things slow...

Location:
trunk/src/VBox/Additions/common
Files:
4 edited

Legend:

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

    r44328 r44992  
    3737# include <VBox/HostServices/GuestPropertySvc.h>
    3838#endif
     39#ifdef VBOX_WITH_DPC_LATENCY_CHECKER
     40# include <VBox/VBoxGuest.h>
     41# include "../VBoxGuestLib/VBGLR3Internal.h" /* HACK ALERT! Using vbglR3DoIOCtl directly!! */
     42#endif
     43
    3944
    4045/*******************************************************************************
     
    101106    RTPrintf("\n");
    102107
    103 /* Exclude the Windows bits from the test version.  Anyone who needs to test
    104  * them can fix this. */
     108    /* Exclude the Windows bits from the test version.  Anyone who needs to
     109       test them can fix this. */
    105110#if defined(RT_OS_WINDOWS) && !defined(VBOX_CONTROL_TEST)
    106111    if (eWhich  == GET_VIDEO_ACCEL || eWhich == USAGE_ALL)
     
    14781483#endif
    14791484
     1485#ifdef VBOX_WITH_DPC_LATENCY_CHECKER
     1486/**
     1487 * @callback_method_impl{FNVBOXCTRLCMDHANDLER, Command: help}
     1488 */
     1489static RTEXITCODE handleDpc(int argc, char *argv[])
     1490{
     1491# ifndef VBOX_CONTROL_TEST
     1492    int rc;
     1493    for (int i = 0; i < 30; i++)
     1494    {
     1495        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_DPC_LATENCY_CHECKER, NULL, 0);
     1496        if (RT_FAILURE(rc))
     1497            break;
     1498        RTPrintf("%d\n", i);
     1499    }
     1500# else
     1501    int rc = VERR_NOT_IMPLEMENTED;
     1502# endif
     1503    if (RT_FAILURE(rc))
     1504        return VBoxControlError("Error. rc=%Rrc\n", rc);
     1505    RTPrintf("Samples collection completed.\n");
     1506    return RTEXITCODE_SUCCESS;
     1507}
     1508#endif /* VBOX_WITH_DPC_LATENCY_CHECKER */
     1509
     1510
    14801511/**
    14811512 * @callback_method_impl{FNVBOXCTRLCMDHANDLER, Command: takesnapshot}
     
    15351566}
    15361567
    1537 #ifdef VBOX_WITH_DPC_LATENCY_CHECKER
    1538 #include "..\VBoxGuestLib\VBGLR3Internal.h"
    1539 
    1540 static RTEXITCODE handleDpc(int argc, char *argv[])
    1541 {
    1542 #ifndef VBOX_CONTROL_TEST
    1543     int rc = VINF_SUCCESS;
    1544     int i;
    1545     for (i = 0; i < 30; i++)
    1546     {
    1547         rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_DPC, NULL, 0);
    1548         if (RT_FAILURE(rc))
    1549         {
    1550             break;
    1551         }
    1552         RTPrintf("%d\n", i);
    1553     }
    1554 #else
    1555     int rc = VERR_NOT_IMPLEMENTED;
    1556 #endif
    1557     if (RT_SUCCESS(rc))
    1558     {
    1559         RTPrintf("Samples collection completed.\n");
    1560         return RTEXITCODE_SUCCESS;
    1561     }
    1562     else
    1563     {
    1564         VBoxControlError("Error. rc=%Rrc\n", rc);
    1565         return RTEXITCODE_FAILURE;
    1566     }
    1567 }
    1568 #endif /* VBOX_WITH_DPC_LATENCY_CHECKER */
    15691568
    15701569/** command handler type */
     
    15951594#if !defined(VBOX_CONTROL_TEST)
    15961595    { "writecoredump",          handleWriteCoreDump },
     1596#endif
     1597#ifdef VBOX_WITH_DPC_LATENCY_CHECKER
     1598    { "dpc",                    handleDpc },
    15971599#endif
    15981600    { "takesnapshot",           handleTakeSnapshot },
     
    16041606    { "getversion",             handleVersion },
    16051607    { "version",                handleVersion },
    1606 #ifdef VBOX_WITH_DPC_LATENCY_CHECKER
    1607     { "dpc",                    handleDpc },
    1608 #endif /* VBOX_WITH_DPC_LATENCY_CHECKER */
    16091608    { "help",                   handleHelp }
    16101609};
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp

    r44991 r44992  
    14011401 */
    14021402
    1403 # pragma pack(1) /** @todo r=bird: Not needed for DPCSAMPLE, screwes up member alignment in DPCDATA! */
     1403/**
     1404 * One DPC latency sample.
     1405 */
    14041406typedef struct DPCSAMPLE
    14051407{
     
    14091411    uint64_t        u64TSC;
    14101412} DPCSAMPLE;
    1411 
     1413AssertCompileSize(DPCSAMPLE, 4*8);
     1414
     1415/**
     1416 * The DPC latency measurement workset.
     1417 */
    14121418typedef struct DPCDATA
    14131419{
     
    14181424    ULONG           ulTimerRes;
    14191425
    1420     BOOLEAN         fFinished;
    1421 
     1426    bool volatile   fFinished;
     1427
     1428    /** The timer interval (relative). */
    14221429    LARGE_INTEGER   DueTime;
    14231430
    14241431    LARGE_INTEGER   PerfCounterPrev;
     1432
     1433    /** Align the sample array on a 64 byte boundrary just for the off chance
     1434     * that we'll get cache line aligned memory backing this structure. */
     1435    uint32_t        auPadding[ARCH_BITS == 32 ? 5 : 7];
    14251436
    14261437    int             cSamples;
    14271438    DPCSAMPLE       aSamples[8192];
    14281439} DPCDATA;
    1429 # pragma pack(1)
     1440
     1441AssertCompileMemberAlignment(DPCDATA, aSamples, 64);
    14301442
    14311443# define VBOXGUEST_DPC_TAG 'DPCS'
    14321444
    1433 static VOID DPCDeferredRoutine(struct _KDPC *Dpc,
    1434                                PVOID DeferredContext,
    1435                                PVOID SystemArgument1,
    1436                                PVOID SystemArgument2)
    1437 {
    1438     DPCDATA *pData = (DPCDATA *)DeferredContext;
     1445
     1446/**
     1447 * DPC callback routine for the DPC latency measurement code.
     1448 *
     1449 * @param   pDpc                The DPC, not used.
     1450 * @param   pvDeferredContext   Pointer to the DPCDATA.
     1451 * @param   SystemArgument1     System use, ignored.
     1452 * @param   SystemArgument2     System use, ignored.
     1453 */
     1454static VOID vbgdNtDpcLatencyCallback(PKDPC pDpc, PVOID pvDeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
     1455{
     1456    DPCDATA *pData = (DPCDATA *)pvDeferredContext;
    14391457
    14401458    KeAcquireSpinLockAtDpcLevel(&pData->SpinLock);
    14411459
    14421460    if (pData->cSamples >= RT_ELEMENTS(pData->aSamples))
    1443     {
    1444         pData->fFinished = 1;
    1445         KeReleaseSpinLockFromDpcLevel(&pData->SpinLock);
    1446         return;
    1447     }
    1448 
    1449     DPCSAMPLE *pSample = &pData->aSamples[pData->cSamples++];
    1450 
    1451     pSample->u64TSC = ASMReadTSC();
    1452     pSample->PerfCounter = KeQueryPerformanceCounter(&pSample->PerfFrequency);
    1453     pSample->PerfDelta.QuadPart = pSample->PerfCounter.QuadPart - pData->PerfCounterPrev.QuadPart;
    1454 
    1455     pData->PerfCounterPrev.QuadPart = pSample->PerfCounter.QuadPart;
    1456 
    1457     KeSetTimer(&pData->Timer, pData->DueTime, &pData->Dpc);
     1461        pData->fFinished = true;
     1462    else
     1463    {
     1464        DPCSAMPLE *pSample = &pData->aSamples[pData->cSamples++];
     1465
     1466        pSample->u64TSC = ASMReadTSC();
     1467        pSample->PerfCounter = KeQueryPerformanceCounter(&pSample->PerfFrequency);
     1468        pSample->PerfDelta.QuadPart = pSample->PerfCounter.QuadPart - pData->PerfCounterPrev.QuadPart;
     1469
     1470        pData->PerfCounterPrev.QuadPart = pSample->PerfCounter.QuadPart;
     1471
     1472        KeSetTimer(&pData->Timer, pData->DueTime, &pData->Dpc);
     1473    }
    14581474
    14591475    KeReleaseSpinLockFromDpcLevel(&pData->SpinLock);
    14601476}
    14611477
    1462 int VBoxGuestCommonIOCtl_DPC(PVBOXGUESTDEVEXTWIN pDevExt, PVBOXGUESTSESSION pSession,
    1463                              void *pvData, size_t cbData, size_t *pcbDataReturned)
    1464 {
    1465     /* Allocate a non paged memory for samples and related data. */
     1478
     1479/**
     1480 * Handles the DPC latency checker request.
     1481 *
     1482 * @returns VBox status code.
     1483 */
     1484int VbgdNtIOCtl_DpcLatencyChecker(void)
     1485{
     1486    /*
     1487     * Allocate a block of non paged memory for samples and related data.
     1488     */
    14661489    DPCDATA *pData = (DPCDATA *)ExAllocatePoolWithTag(NonPagedPool, sizeof(DPCDATA), VBOXGUEST_DPC_TAG);
    1467 
    14681490    if (!pData)
    14691491    {
     
    14721494    }
    14731495
    1474     KeInitializeDpc(&pData->Dpc, DPCDeferredRoutine, pData);
     1496    /*
     1497     * Initialize the data.
     1498     */
     1499    KeInitializeDpc(&pData->Dpc, vbgdNtDpcLatencyCallback, pData);
    14751500    KeInitializeTimer(&pData->Timer);
    14761501    KeInitializeSpinLock(&pData->SpinLock);
    14771502
    1478     pData->fFinished = 0;
     1503    pData->fFinished = false;
    14791504    pData->cSamples = 0;
    14801505    pData->PerfCounterPrev.QuadPart = 0;
     
    14831508    pData->DueTime.QuadPart = -(int64_t)pData->ulTimerRes / 10;
    14841509
    1485     /* Start the DPC measurements. */
     1510    /*
     1511     * Start the DPC measurements and wait for a full set.
     1512     */
    14861513    KeSetTimer(&pData->Timer, pData->DueTime, &pData->Dpc);
    14871514
     
    14951522    ExSetTimerResolution(0, 0);
    14961523
    1497     /* Log everything to the host. */
     1524    /*
     1525     * Log everything to the host.
     1526     */
    14981527    RTLogBackdoorPrintf("DPC: ulTimerRes = %d\n", pData->ulTimerRes);
    14991528    for (int i = 0; i < pData->cSamples; i++)
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp

    r44988 r44992  
    24752475        { \
    24762476            LogFunc((mnemonic ": cbData=%#zx (%zu) expected is %#zx (%zu)\n", \
    2477                  cbData, cbData, (size_t)(cb), (size_t)(cb))); \
     2477                     cbData, cbData, (size_t)(cb), (size_t)(cb))); \
    24782478            return VERR_BUFFER_OVERFLOW; \
    24792479        } \
     
    24952495        rc = VBoxGuestCommonIOCtl_VMMRequest(pDevExt, pSession, (VMMDevRequestHeader *)pvData, cbData, pcbDataReturned);
    24962496    }
    2497 #ifdef VBOX_WITH_DPC_LATENCY_CHECKER
    2498     /** @todo r=bird: This request doesn't vary in size?? AFAIK it doesn't have
    2499      *        any data associated with it... grumble. */
    2500     else if (VBOXGUEST_IOCTL_STRIP_SIZE(iFunction) == VBOXGUEST_IOCTL_STRIP_SIZE(VBOXGUEST_IOCTL_DPC))
    2501     {
    2502         rc = VBoxGuestCommonIOCtl_DPC(pDevExt, pSession, pvData, cbData, pcbDataReturned);
    2503     }
    2504 #endif /* VBOX_WITH_DPC_LATENCY_CHECKER */
    25052497#ifdef VBOX_WITH_HGCM
    25062498    /*
     
    26392631                                                         *(uint32_t *)pvData);
    26402632                break;
     2633
     2634#ifdef VBOX_WITH_DPC_LATENCY_CHECKER
     2635            case VBOXGUEST_IOCTL_DPC_LATENCY_CHECKER:
     2636                CHECKRET_SIZE("DPC_LATENCY_CHECKER", 0);
     2637                rc = VbgdNtIOCtl_DpcLatencyChecker();
     2638                break;
     2639#endif
    26412640
    26422641            default:
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h

    r44988 r44992  
    266266
    267267#ifdef VBOX_WITH_DPC_LATENCY_CHECKER
    268 int VBoxGuestCommonIOCtl_DPC(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION pSession,
    269                              void *pvData, size_t cbData, size_t *pcbDataReturned);
     268int VbgdNtIOCtl_DpcLatencyChecker(void);
    270269#endif
    271270
Note: See TracChangeset for help on using the changeset viewer.

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