test_dstore.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2001-2002 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <thread.h>
#include <locale.h>
#include <signal.h>
#include <dhcp_svc_confopt.h>
#include <dhcp_svc_private.h>
#include <dhcp_impl.h>
#ifdef DEBUG
#include <mtmalloc.h>
#endif /* DEBUG */
/*
* Global variables.
*/
int verbose = 0;
volatile int tms;
char *fl;
volatile ulong_t ops_outstanding;
static volatile int minind;
long sample_time = 10L;
long nsamples = 2;
volatile int time_to_go;
volatile int spawn_helper;
char b[1024 * 1024];
volatile double slp;
volatile int worktype;
volatile unsigned int douwork = 0;
volatile int dofsync = 0;
volatile int domalloc = 0;
volatile int dofork = 0;
volatile int doopen = 0;
#define MAXTABLE 1024
int ntable;
char *network;
typedef struct work {
int thread;
}work_t;
void
}
/*
* Simulated binary datastore work
*/
/* ARGSUSED */
static void *
{
int i;
int err;
int fd;
long block;
char *ptr;
~(0x200 - 1);
int wtype;
if (domalloc)
else
ptr = b;
if (wptr->isthreaded) {
}
/* prewrite legal records */
wtype = 4;
size = sizeof (b);
ptr = b;
}
if (wtype == 4) {
"uwork_write%debug 'in function work'",
"uwork_write_end%debug 'in function work'",
"uwork_fsync%debug 'in function work'");
"uwork_fsync_end%debug 'in function work'",
} else {
"uwork_read%debug 'in function work'",
"uwork_read_end%debug 'in function work'",
}
if (wptr->isthreaded) {
}
return ((void *) NULL);
}
/*
* Simulated datastore work
*/
static void *
{
int i, j;
int err;
char *ptr;
int wtype;
int firsttime = 0;
int op;
~(0x1000 - 1);
int table;
if (domalloc)
else
ptr = b;
if (irecords == 12) {
}
if (wptr->isthreaded) {
}
cid_len = 7;
if (worktype == 0) {
if (wtype == 4)
wtype--;
} else
/* preload a legal record */
wtype = 3;
firsttime = 1;
(void) mutex_lock(&thread_mtx);
wtype = -1;
(void) mutex_unlock(&thread_mtx);
}
}
crecords = 0;
switch (wtype) {
case -1:
break;
case 1:
switch (random() & 0x7) {
case 1:
for (j = 0; j < cid_len; j++)
break;
case 2:
for (j = 0; j < cid_len; j++)
break;
}
/* LINTED */
"work_cid%debug 'in function work'",
"work_cid_end%debug 'in function work'",
break;
case 2:
switch (random() & 0x7) {
case 1:
break;
case 2:
break;
}
"work_cip%debug 'in function work'",
"work_cip_end%debug 'in function work'",
break;
case 3:
if (firsttime)
op = 2;
switch (op) {
case 1:
break;
case 2:
for (j = 0; j < cid_len; j++)
break;
}
"work_read%debug 'in function work'",
"work_read_end%debug 'in function work'",
if (firsttime) {
}
}
break;
case 4:
switch (op) {
case 0:
/* write record w/ cid */
for (j = 0; j < ndn.dn_cid_len; j++)
/* LINTED */
"work1_modify%debug 'in function work'",
}
"work1_modify_end%debug 'in function work'",
break;
case 1:
/* re-read record w/ cid */
"work_read1%debug 'in function work'",
&crecords);
"work_read1_end%debug 'in function work'",
}
break;
case 2:
/* write free record */
for (j = 0; j < cid_len; j++)
"work_modify2%debug 'in function work'",
"work_modify2_end%debug 'in function work'",
}
break;
}
break;
default:
switch (random() & 0x1) {
case 0:
for (j = 0; j < cid_len; j++)
break;
case 1:
for (j = 0; j < cid_len; j++)
break;
}
/* LINTED */
"work_modify%debug 'in function work'",
if (verbose)
}
"work_modify_end%debug 'in function work'",
break;
}
if (domalloc)
if (wptr->isthreaded) {
}
if (dncp)
return ((void *) NULL);
}
/*
* Worker thread.
*/
static void *
{
int i = (int)argp;
(void) mutex_lock(&mtx);
for (; time_to_go == 0; ) {
"dowork%debug 'in function dowork'",
tnf_long, thread_number, i);
if (slp > 0.0) {
} else if (slp < 0.0) {
1000000000.0;
}
/* give up processor */
if (slp != 0.0) {
(void) mutex_unlock(&mtx);
}
(void) mutex_unlock(&mtx);
if (spawn_helper) {
/* fire up helper thread */
/* wait for completion */
} else {
if (douwork) {
} else {
}
}
(void) mutex_lock(&mtx);
tops++;
}
(void) mutex_unlock(&mtx);
return ((void *) NULL);
}
/*
* Signal handler routine. All signals handled by calling thread.
*/
/* ARGSUSED */
static void *
sig_handle(void *arg)
{
int i;
int sig;
int go;
int oldi;
for (;;) {
(void) mutex_lock(&mtx);
go = time_to_go;
(void) mutex_unlock(&mtx);
if (go)
break;
case -1:
case SIGHUP:
for (i = 0; i < threads; i++) {
unstarted++;
oldi = i;
}
}
if (start == 0) {
/* toss initial sample */
(void) mutex_lock(&mtx);
(void) mutex_unlock(&mtx);
minind = 0;
} else {
minind + 1;
minstime = 0;
minavg = 0;
for (i = 0; i < nsamples; i++) {
if (mintim[i])
if (minstime == 0)
else if (mintim[i] &&
}
"Persec %4.2f (%4.2f) Oldest %d (%d) "\
"Gap %d Unstarted %d\n",
tops,
- start),
- minstime),
oldi,
}
break;
default:
(void) mutex_lock(&mtx);
time_to_go++;
(void) mutex_unlock(&mtx);
break;
}
}
return ((void *) sig); /* NOTREACHED */
}
int fd[0x10000];
/*
* open handler routine.
*/
/* ARGSUSED */
static void *
open_handle(void *arg)
{
int i;
for (;;) {
for (i = 0; i < doopen; i++)
for (i = 0; i < doopen; i++)
if (fd[i] >= 0)
}
return ((void *) NULL); /* NOTREACHED */
}
/*
* test_dstore network[,network] worktype[,worktype] <thr_create flags>
* <spawn_helper> <nlwp> <nthread> <file> <sleeptype>
*
* network - list of network containers, comma-separated
* worktypes:
* 0 - random
* 1 - cid reads
* 2 - cip reads
* 3 - whole db reads
* 4 - write read write (simulate simple test)
* 5 - modify writes
* sleeptypes:
* N == * condwait N sec.nsec period
* -N == condwait a random 1-N sec.nsec period
*/
main(int c, char **v)
{
int i;
int err;
char *np;
#ifdef DEBUG
#endif /* DEBUG */
if (dofork)
if (fork() != 0)
exit(0);
}
/* handle cases where limit is infinity */
}
/* set NOFILE to unlimited */
}
if (c == 1) {
"/*\n"\
" * test_dstore network[,network] worktype[,"\
"worktype] <thr_create flags>\n"\
" * <spawn_helper> <nlwp> <nthread> "\
"<file> <sleeptype>\n"\
" *\n"\
" * network - list of network containers, "\
"comma-separated\n"\
" * worktypes:\n"\
" * 0 - random\n"\
" * 1 - cid reads\n"\
" * 2 - cip reads\n"\
" * 3 - whole db reads\n"\
" * 4 - write read write (simulate simple"\
" test)\n"\
" * 5 - modify writes\n"\
" * sleeptypes:\n"\
" * N == * condwait N sec.nsec period\n"\
" * -N == condwait a random 1-N sec.nsec "\
"period\n"\
" */\n");
return (0);
}
network = v[1];
if (strtoul(v[5], 0L, 0L) > 0)
fl = v[7];
if (c > 8)
if (douwork == 0) {
/* Load current datastore. */
(void) read_dsvc_conf(&dsp);
!= DSVC_SUCCESS) {
dhcpsvc_errmsg(i));
return (EINVAL);
}
DSVC_READ | DSVC_WRITE);
if (err != DSVC_SUCCESS) {
"%s %s\n", np,
return (err);
}
/*
* XXXX: bug: currently can't get the count as
* advertised
*/
&nrecords[i]);
if (dncp)
if (err != DSVC_SUCCESS) {
nrecords[i]);
return (err);
}
}
ntable = i;
}
"main%debug 'in function main'",
(void) sigfillset(&set);
if (spawn_helper)
tms *= 2;
if (spawn_helper)
tms *= 2;
/*
* Create signal handling thread. XXXX: due to threads library
* limitations, this must currently be directly called in the main
* program thread.
*/
THR_DETACHED, &sigthread)) != 0) {
gettext("Cannot start signal handling thread, error: %d\n"),
err);
return (err);
}
for (i = 0; i < threads; i++)
/* fire up monitor thread */
/*
* Create open handling thread.
*/
&opnthread)) != 0) {
gettext("Cannot start open handling thread, error: %d\n"),
err);
return (err);
}
(void) mutex_lock(&mtx);
for (; time_to_go == 0; ) {
(void) mutex_unlock(&mtx);
}
/*
* Attempt to join threads.
*/
for (i = 0; i < threads; i++)
(void) sleep(5);
return (0);
}