loadgenerator.cpp revision cf22150eaeeb72431bf1cf65c309a431454fb22b
/* $Id$ */
/** @file
* Load Generator.
*/
/*
* Copyright (C) 2007-2014 Oracle Corporation
*
* 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Whether the threads should quit or not. */
static bool volatile g_fQuit = false;
static const char *g_pszProgramName = NULL;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
{
do
{
i++;
}
{
return VINF_SUCCESS;
}
static int LoadGenIpiInit(void)
{
/*
* Try make sure the support library is initialized...
*/
/*
* Load the module.
*/
char szPath[RTPATH_MAX];
if (RT_SUCCESS(rc))
{
void *pvImageBase;
if (RT_SUCCESS(rc))
{
/* done */
}
else
}
else
return rc;
}
{
do
{
if (RT_FAILURE(rc))
{
break;
}
}
{
return VINF_SUCCESS;
}
{
return 1;
}
static int SyntaxError(const char *pszFormat, ...)
{
return 1;
}
{
static const struct LOADGENTYPE
{
const char *pszName;
int (*pfnInit)(void);
} s_aLoadTypes[] =
{
};
unsigned iLoadType = 0;
int rc;
bool fScaleByCpus = false;
/*
* Set program name.
*/
/*
* Parse arguments.
*/
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
{
switch (ch)
{
case 'n':
return SyntaxError("Requested number of threads, %RU32, is out of range (1..%d).\n",
break;
case 't':
{
char *psz;
if (RT_FAILURE(rc))
return SyntaxError("Failed reading the alleged number '%s' (option '%s', rc=%Rrc).\n",
psz++;
if (*psz)
{
u64Factor = 1;
u64Factor = 1000;
u64Factor = 1000000000;
else
return SyntaxError("Time representation overflowed! (%RU64 * %RU64)\n",
cNanoSeconds = u64;
}
break;
}
case 'p':
{
char *psz;
{
{
}
{
}
{
}
else
return SyntaxError("can't grok thread type '%s'\n",
}
else
{
return SyntaxError("thread type '%d' is out of range (%d..%d)\n",
}
break;
}
case 'c':
fScaleByCpus = true;
break;
case 'l':
{
for (unsigned i = 0; i < RT_ELEMENTS(s_aLoadTypes); i++)
{
iLoadType = i;
break;
}
if (ValueUnion.psz)
break;
}
case 'h':
"Usage: %s [-p|--thread-type <type>] [-t|--timeout <sec|xxx[h|m|s|ms|ns]>] \\\n"
" %*s [-n|--number-of-threads <threads>] [-l|--load <loadtype>]\n"
"\n"
"Load types: spin, ipi.\n"
,
return 1;
case 'V':
RTPrintf("$Revision$\n");
return 0;
case VINF_GETOPT_NOT_OPTION:
default:
}
}
/*
* Scale thread count by host cpu count.
*/
if (fScaleByCpus)
{
const unsigned cCpus = RTMpGetOnlineCount();
return SyntaxError("Requested number of threads, %RU32, is out of range (1..%d) when scaled by %d.\n",
}
/*
* Modify process and thread priority? (ignore failure)
*/
if (enmThreadType != RTTHREADTYPE_DEFAULT)
/*
* Load type specific init.
*/
{
if (RT_FAILURE(rc))
return 1;
}
/*
* Start threads.
*/
for (unsigned i = 1; i < cThreads; i++)
{
s_aThreads[i] = NIL_RTTHREAD;
if (RT_FAILURE(rc))
{
ASMAtomicXchgBool(&g_fQuit, true);
while (i-- > 1)
return 1;
}
}
/* our selves */
/*
* Wait for threads.
*/
ASMAtomicXchgBool(&g_fQuit, true);
for (unsigned i = 1; i < cThreads; i++)
return 0;
}