tstMicro.cpp revision 7e30b17dc8c151a3e2e96a93ca1d7d01ba06862e
/* $Id$ */
/** @file
* Micro Testcase, profiling special CPU operations.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/semaphore.h>
#include "tstMicro.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define TESTCASE "tstVMM"
{
switch (enmTest)
{
case TSTMICROTEST_OVERHEAD: return "Overhead";
case TSTMICROTEST_INVLPG_0: return "invlpg [0]";
case TSTMICROTEST_INVLPG_EIP: return "invlpg [EIP]";
case TSTMICROTEST_INVLPG_ESP: return "invlpg [ESP]";
case TSTMICROTEST_CR3_RELOAD: return "cr3 reload";
case TSTMICROTEST_WP_DISABLE: return "CR0.WP <- 0";
case TSTMICROTEST_WP_ENABLE: return "CR0.WP <- 1";
case TSTMICROTEST_PF_R0: return "R0 #PG (NULL)";
case TSTMICROTEST_PF_R1: return "R1 #PG (NULL)";
case TSTMICROTEST_PF_R2: return "R2 #PG (NULL)";
case TSTMICROTEST_PF_R3: return "R3 #PG (NULL)";
default:
{
static char sz[64];
return sz;
}
}
}
static void PrintHeaderInstr(void)
{
"Test name",
"Min",
"Avg",
"Max");
}
static void PrintResultInstr(PTSTMICRO pTst, TSTMICROTEST enmTest, int rc, uint64_t cMinTicks, uint64_t cAvgTicks, uint64_t cMaxTicks)
{
if (VBOX_FAILURE(rc))
rc,
else
}
static void PrintHeaderTraps(void)
{
"Test name",
"Total",
"ToRx",
"Trap",
"ToRxTrap",
"int42-done");
}
{
if (VBOX_FAILURE(rc))
rc,
else
}
/**
*
* 0060 - r0 code
* 0068 - r0 data
*
* 1060 - r1 code
* 1068 - r1 data
*
* 2060 - r2 code
* 2068 - r2 data
*
* 3060 - r3 code
* 3068 - r3 data
*
*/
{
/*
* Find the GDT - This is a HACK :-)
*/
for (unsigned i = 0; i <= 3; i++)
{
/* 32-bit code selector. */
/* 32-bit data selector. */
pGDTE++;
}
}
{
/*
* Loading the module and resolve the entry point.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
if (VBOX_FAILURE(rc))
{
RTPrintf(TESTCASE ": Failed to resolve the 'tstMicroGC' entry point in tstMicroGC.gc, rc=%Vra\n", rc);
return rc;
}
if (VBOX_FAILURE(rc))
{
RTPrintf(TESTCASE ": Failed to resolve the 'tstMicroGCAsmStart' entry point in tstMicroGC.gc, rc=%Vra\n", rc);
return rc;
}
if (VBOX_FAILURE(rc))
{
RTPrintf(TESTCASE ": Failed to resolve the 'tstMicroGCAsmEnd' entry point in tstMicroGC.gc, rc=%Vra\n", rc);
return rc;
}
/*
* Allocate and initialize the instance data.
*/
if (VBOX_FAILURE(rc))
{
RTPrintf(TESTCASE ": Failed to resolve allocate instance memory (%d bytes), rc=%Vra\n", sizeof(*pTst), rc);
return rc;
}
/* the page must be writable from user mode */
rc = PGMMapModifyPage(pVM, pTst->GCPtr, sizeof(*pTst), X86_PTE_US | X86_PTE_RW, ~(uint64_t)(X86_PTE_US | X86_PTE_RW));
if (VBOX_FAILURE(rc))
{
return rc;
}
/* all the code must be executable from R3. */
rc = PGMMapModifyPage(pVM, GCPtrStart, GCPtrEnd - GCPtrStart + PAGE_SIZE, X86_PTE_US, ~(uint64_t)X86_PTE_US);
if (VBOX_FAILURE(rc))
{
return rc;
}
#if 0
/*
* Disassemble the assembly...
*/
{
char sz[256];
if (VBOX_SUCCESS(rc))
else
{
cb = 1;
}
}
#endif
/*
* Do the profiling.
*/
/* execute the instruction profiling tests */
int i;
for (i = TSTMICROTEST_OVERHEAD; i < TSTMICROTEST_TRAP_FIRST; i++)
{
unsigned cSamples = 0;
rc = VINF_SUCCESS;
for (int c = 0; c < 100; c++)
{
if (VBOX_SUCCESS(rc2))
{
cSamples++;
}
else if (VBOX_SUCCESS(rc))
}
/* store the overhead */
if (enmTest == TSTMICROTEST_OVERHEAD)
}
RTPrintf("\n");
for (i = TSTMICROTEST_TRAP_FIRST; i < TSTMICROTEST_MAX; i++)
{
}
return VINF_SUCCESS;
}
{
int rcRet = 0; /* error count. */
RTR3Init();
/*
* Create empty VM.
*/
if (VBOX_SUCCESS(rc))
{
/*
* Do testing.
*/
/*
* Cleanup.
*/
if (!VBOX_SUCCESS(rc))
{
rcRet++;
}
}
else
{
rcRet++;
}
return rcRet;
}