VirtualBox

Changeset 5395 in vbox for trunk/src


Ignore:
Timestamp:
Oct 21, 2007 2:19:37 AM (17 years ago)
Author:
vboxsync
Message:

Optimized RDTSC emulation a little bit.

Location:
trunk/src/VBox/VMM
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/TRPM.cpp

    r5394 r5395  
    519519
    520520    STAM_REG(pVM, &pVM->trpm.s.StatTrap0dDisasm,        STAMTYPE_PROFILE_ADV, "/TRPM/Trap0d/Prof/Disasm",         STAMUNIT_TICKS_PER_CALL, "Profiling trpmGCTrap0dHandler.");
     521    STAM_REG(pVM, &pVM->trpm.s.StatTrap0dRing0RdTsc,    STAMTYPE_COUNTER, "/TRPM/Trap0d/RdTsc-R0",                    STAMUNIT_OCCURENCES, "Number of RDTSC #GPs from guest ring-0.");
     522    STAM_REG(pVM, &pVM->trpm.s.StatTrap0dRing3RdTsc,    STAMTYPE_COUNTER, "/TRPM/Trap0d/RdTsc-R3",                    STAMUNIT_OCCURENCES, "Number of RDTSC #GPs from guest ring-3.");
    521523
    522524    /*
  • trunk/src/VBox/VMM/TRPMInternal.h

    r5394 r5395  
    175175    STAMPROFILEADV  StatForwardProfHC;
    176176    STAMPROFILEADV  StatTrap0dDisasm;
     177    STAMCOUNTER     StatTrap0dRing0RdTsc;   /**< Number of RDTSC #GPs from guest ring-0. */
     178    STAMCOUNTER     StatTrap0dRing3RdTsc;   /**< Number of RDTSC #GPs from guest ring-3. */
    177179
    178180    /* R3: Statistics for interrupt handlers (allocated on the hypervisor heap). */
  • trunk/src/VBox/VMM/TRPMInternal.mac

    r5394 r5395  
    6464    .StatForwardProfHC        resb STAMPROFILEADV_size
    6565    .StatTrap0dDisasm         resb STAMPROFILEADV_size
     66    .StatTrap0dRing0RdTsc     resb STAMCOUNTER_size
     67    .StatTrap0dRing3RdTsc     resb STAMCOUNTER_size
    6668
    6769    .paStatForwardedIRQR3  RTR3PTR_RES 1
  • trunk/src/VBox/VMM/VMMGC/TRPMGCHandlers.cpp

    r4697 r5395  
    525525    switch (pCpu->pCurInstr->opcode)
    526526    {
     527        /*
     528         * Since we're usually trapping RDTSC there may be a high volume
     529         * of these instructions. So, put it first and go straight to
     530         * the emulation function to save time.
     531         */
     532        case OP_RDTSC:
     533            STAM_COUNTER_INC(&pVM->trpm.s.StatTrap0dRing0RdTsc);
     534            rc = EMInterpretRdtsc(pVM, pRegFrame);
     535            if (RT_SUCCESS(rc))
     536                pRegFrame->eip += pCpu->opsize;
     537            else if (rc == VERR_EM_INTERPRETER)
     538                rc = VINF_EM_RAW_EXCEPTION_PRIVILEGED;
     539            return trpmGCExitTrap(pVM, rc, pRegFrame);
     540
    527541        case OP_INT3:
    528542            /*
     
    585599        case OP_LLDT:
    586600        case OP_STI:
    587         case OP_RDTSC:
    588601        case OP_CLTS:
    589602        {
     
    622635    switch (pCpu->pCurInstr->opcode)
    623636    {
    624         /*
    625          * STI and CLI are I/O privileged, i.e. if IOPL
    626          */
    627         case OP_STI:
    628         case OP_CLI:
    629         {
    630             uint32_t efl = CPUMRawGetEFlags(pVM, pRegFrame);
    631             if (X86_EFL_GET_IOPL(efl) >= (unsigned)(pRegFrame->ss & X86_SEL_RPL))
    632             {
    633                 LogFlow(("trpmGCTrap0dHandlerRing3: CLI/STI -> REM\n"));
    634                 return trpmGCExitTrap(pVM, VINF_EM_RESCHEDULE_REM, pRegFrame);
    635             }
    636             LogFlow(("trpmGCTrap0dHandlerRing3: CLI/STI -> #GP(0)\n"));
    637             break;
    638         }
    639 
    640637        /*
    641638         * INT3 and INT xx are ring-switching.
     
    679676        /*
    680677         * Handle virtualized TSC reads.
     678         * Call the emulation function directly to skip unnecessary overhead.
    681679         */
    682680        case OP_RDTSC:
    683         {
    684             uint32_t cbIgnored;
    685             rc = EMInterpretInstructionCPU(pVM, pCpu, pRegFrame, PC, &cbIgnored);
    686             if (VBOX_SUCCESS(rc))
     681            STAM_COUNTER_INC(&pVM->trpm.s.StatTrap0dRing3RdTsc);
     682            rc = EMInterpretRdtsc(pVM, pRegFrame);
     683            if (RT_SUCCESS(rc))
    687684                pRegFrame->eip += pCpu->opsize;
    688685            else if (rc == VERR_EM_INTERPRETER)
    689686                rc = VINF_EM_RAW_EXCEPTION_PRIVILEGED;
    690687            return trpmGCExitTrap(pVM, rc, pRegFrame);
     688
     689        /*
     690         * STI and CLI are I/O privileged, i.e. if IOPL
     691         */
     692        case OP_STI:
     693        case OP_CLI:
     694        {
     695            uint32_t efl = CPUMRawGetEFlags(pVM, pRegFrame);
     696            if (X86_EFL_GET_IOPL(efl) >= (unsigned)(pRegFrame->ss & X86_SEL_RPL))
     697            {
     698                LogFlow(("trpmGCTrap0dHandlerRing3: CLI/STI -> REM\n"));
     699                return trpmGCExitTrap(pVM, VINF_EM_RESCHEDULE_REM, pRegFrame);
     700            }
     701            LogFlow(("trpmGCTrap0dHandlerRing3: CLI/STI -> #GP(0)\n"));
     702            break;
    691703        }
    692704    }
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