VirtualBox

Changeset 30581 in vbox for trunk/src/VBox/VMM/VMMAll


Ignore:
Timestamp:
Jul 2, 2010 4:02:57 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63305
Message:

TM: Added simple CPU time accounting. Accessible thru the statistics and TMR3GetCpuLoadTimes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/TMAll.cpp

    r29250 r30581  
    167167    PVM pVM = pVCpu->CTX_SUFF(pVM);
    168168
     169#ifndef VBOX_WITHOUT_NS_ACCOUNTING
     170    pVCpu->tm.s.u64NsTsStartExecuting = RTTimeNanoTS();
     171#endif
    169172    if (pVM->tm.s.fTSCTiedToExecution)
    170173        tmCpuTickResume(pVM, pVCpu);
     
    188191    if (pVM->tm.s.fTSCTiedToExecution)
    189192        tmCpuTickPause(pVM, pVCpu);
     193
     194#ifndef VBOX_WITHOUT_NS_ACCOUNTING
     195    uint32_t uGen    = ASMAtomicIncU32(&pVCpu->tm.s.uTimesGen); Assert(uGen & 1);
     196    uint64_t u64NsTs = RTTimeNanoTS();
     197    pVCpu->tm.s.cNsExecuting += u64NsTs - pVCpu->tm.s.u64NsTsStartExecuting;
     198    pVCpu->tm.s.cNsTotal      = u64NsTs - pVCpu->tm.s.u64NsTsStartTotal;
     199    pVCpu->tm.s.cNsOther      = pVCpu->tm.s.cNsTotal - pVCpu->tm.s.cNsExecuting - pVCpu->tm.s.cNsHalted;
     200    ASMAtomicWriteU32(&pVCpu->tm.s.uTimesGen, (uGen | 1) + 1);
     201#endif
    190202}
    191203
     
    204216{
    205217    PVM pVM = pVCpu->CTX_SUFF(pVM);
     218
     219#ifndef VBOX_WITHOUT_NS_ACCOUNTING
     220    pVCpu->tm.s.u64NsTsStartHalting = RTTimeNanoTS();
     221#endif
    206222
    207223    if (    pVM->tm.s.fTSCTiedToExecution
     
    228244        &&  !pVM->tm.s.fTSCNotTiedToHalt)
    229245        tmCpuTickPause(pVM, pVCpu);
     246
     247#ifndef VBOX_WITHOUT_NS_ACCOUNTING
     248    uint32_t uGen    = ASMAtomicIncU32(&pVCpu->tm.s.uTimesGen); Assert(uGen & 1);
     249    uint64_t u64NsTs = RTTimeNanoTS();
     250    pVCpu->tm.s.cNsHalted += u64NsTs - pVCpu->tm.s.u64NsTsStartHalting;
     251    pVCpu->tm.s.cNsTotal   = u64NsTs - pVCpu->tm.s.u64NsTsStartTotal;
     252    pVCpu->tm.s.cNsOther   = pVCpu->tm.s.cNsTotal - pVCpu->tm.s.cNsExecuting - pVCpu->tm.s.cNsHalted;
     253    ASMAtomicWriteU32(&pVCpu->tm.s.uTimesGen, (uGen | 1) + 1);
     254#endif
    230255}
    231256
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