Esempio n. 1
0
File: mttest.c Progetto: dhaley/dcp
/* sema_global: use a global semaphore to process array's data */
void
sema_global(Workblk *array, struct scripttab *k)
{
#ifdef SOLARIS
	sema_wait(&global_sema_lock); 
#endif
#ifdef POSIX
	sem_wait(&global_sema_lock); 
#endif

	array->ready = gethrtime();
	array->vready = gethrvtime();

	array->compute_ready = array->ready;
	array->compute_vready = array->vready;

	/* do some work on the current array */
	(k->called_func)(&array->list[0]);

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();

#ifdef SOLARIS
	sema_post(&global_sema_lock);
#endif
#ifdef POSIX
	sem_post(&global_sema_lock);
#endif

	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
Esempio n. 2
0
File: mttest.c Progetto: dhaley/dcp
/* lock_local: use a local lock to process array's data */
void
lock_local(Workblk *array, struct scripttab *k)
{
	/* acquire the local lock */
#ifdef SOLARIS
	mutex_lock(&(array->lock));
#endif
#ifdef POSIX
	pthread_mutex_lock(&(array->lock));
#endif
	array->ready = gethrtime();
	array->vready = gethrvtime();

	array->compute_ready = array->ready;
	array->compute_vready = array->vready;

	/* do some work on the current array */
	(k->called_func)(&array->list[0]);

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();

	/* free the local lock */
#ifdef SOLARIS
	mutex_unlock(&array->lock);
#endif
#ifdef POSIX
	pthread_mutex_unlock(&array->lock);
#endif
	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
Esempio n. 3
0
File: mttest.c Progetto: dhaley/dcp
/* s5sema: use a global UNIX System V semaphore to process array's data */
void
s5sem(Workblk *array, struct scripttab *k)
{
	static struct sembuf	op_wait[] = { { 0, -1, IPC_NOWAIT } };
	static struct sembuf	op_post[] = { { 0,  1, 0 } };
	int			sema_val;

	/* set ready before starting, since this is a busy wait */
	array->ready = gethrtime();
	array->vready = gethrvtime();

	do {
	    sema_val = semop(s5_sema_id, op_wait, 1);
	} while (sema_val == -1);

	array->compute_ready = gethrtime();
	array->compute_vready = gethrvtime();

	/* do some work on the current array */
	(k->called_func)(&array->list[0]);

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();

	if (semop(s5_sema_id, op_post, 1) == -1)
		perror("semop: post");
	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
Esempio n. 4
0
File: callsx.c Progetto: dhaley/dcp
int
callsx(int k)
{
	int i;
	int (*sx_routine)();
	char	buf[1024];
	hrtime_t	start;
	hrtime_t	vstart;

	start = gethrtime();
	vstart = gethrvtime();
 
	/* Log the event */
	wlog("start of callsx", NULL);

	/* see if already linked */
	if(sx_object != NULL) {
		fprintf(stderr, "callsx: sx_object already linked\n");
		return 0;
	}

	/* open the dynamic shared object */
	sx_object = dlopen(DYNSONAME, RTLD_NOW);
	if(sx_object == NULL) {
		fprintf(stderr, "callsx: dlopen of %s failed--%s\n",
			DYNSONAME, dlerror());
		exit(1);
	}

	/* look up the routine name in it */
	sx_routine = (int (*)())dlsym(sx_object, DYNSOROUTINE);
	if(sx_routine == NULL) {
		fprintf(stderr, "callsx: dlsym %s not found\n",
			DYNSOROUTINE);
		exit(1);
	}

	/* invoke the routine */
	do {
		i = (*sx_routine)();
	} while(start+testtime*1e9 > gethrtime());

	closesx();
	sprintf(buf, "end of callsx, %s returned %d",
		DYNSOROUTINE, i);
	wlog(buf, NULL);

	whrvlog( (gethrtime() - start), (gethrvtime() - vstart),
		"callsx", NULL);

	return 0;
}
void *pthread_main(void *arg)
{
#if 0
   struct vperfctr *ptr = vperfctr_open();
   long long *lcyca;
   int i, iters = atoi(getenv("ITERS"));
   lcyca = (long long *) malloc(sizeof(long long) * iters);

   for (i = 0; i < iters; i++) {
      lcyca[i] = vperfctr_read_tsc(ptr);
   }

   for (i = 1; i < iters; i++)
      if (lcyca[i] - lcyca[i - 1] < 0)
         abort();
#endif
#if 0
   long long *lcyca;
   int i, iters = atoi(getenv("ITERS"));
   lcyca = (long long *) malloc(sizeof(long long) * iters);

   for (i = 0; i < iters; i++) {
      lcyca[i] = gethrvtime();
   }

   for (i = 1; i < iters; i++)
      if (lcyca[i] - lcyca[i - 1] < 0)
         abort();
#endif
   clockcore();
   return (NULL);
}
Esempio n. 6
0
File: mttest.c Progetto: dhaley/dcp
/* read_write: use a global Reader/Writer lock to process array's data */
void
read_write(Workblk *array, struct scripttab *k)
{

#ifdef SOLARIS
	switch (array->tid % NUM_OF_THREADS) {
	case 0:
	case 1:
	default:
	    rw_rdlock(&global_rw_lock);

	    array->ready = gethrtime();
	    array->vready = gethrvtime();

	    array->compute_ready = array->ready;
	    array->compute_vready = array->vready;

	    (k->called_func)(&array->list[0]);
	    array->compute_done = gethrtime();
	    array->compute_vdone = gethrvtime();

	    rw_unlock(&global_rw_lock);
	    break;

	case 2:
	    rw_wrlock(&global_rw_lock);

	    array->ready = gethrtime();
	    array->vready = gethrvtime();

	    array->compute_ready = array->ready;
	    array->compute_vready = array->vready;

	    (k->called_func)(&array->list[0]);

	    array->compute_done = gethrtime();
	    array->compute_vdone = gethrvtime();

	    rw_unlock(&global_rw_lock);
	    break;
	}
#endif

	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
Esempio n. 7
0
/* Current CPU hi-res CPU time used */
jlong
md_get_thread_cpu_timemillis(void)
{
#ifdef LINUX
    return md_timeofday();
#else
    return (jlong)(gethrvtime()/1000); /* Nano seconds to milli seconds */
#endif
}
Esempio n. 8
0
/* Current CPU hi-res CPU time used */
jlong
md_get_thread_cpu_timemillis(void)
{
#if defined(LINUX) || defined(_ALLBSD_SOURCE)
    return md_timeofday();
#else
    return (jlong)(gethrvtime()/1000); /* Nano seconds to milli seconds */
#endif
}
Esempio n. 9
0
File: mttest.c Progetto: dhaley/dcp
/* nothreads: process array's data with no locking; called without threads */
void
nothreads(Workblk *array, struct scripttab *k)
{
/*	array->ready = array->start;
	array->vready = array->vstart;
*/
	array->ready = gethrtime();
	array->vready = gethrvtime();

	array->compute_ready = array->ready;
	array->compute_vready = array->vready;

	/* do some work on the current array */
	(k->called_func)(&array->list[0]);

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();

}
Esempio n. 10
0
File: mttest.c Progetto: dhaley/dcp
/* trylock_global: busy-wait on a global lock to process array's data */
void
trylock_global(Workblk *array, struct scripttab *k)
{
	int ret;

	/* set ready before starting, since this is a busy wait */
	array->ready = gethrtime();
	array->vready = gethrvtime();

	/* busy wait to acquire the global lock */
#ifdef SOLARIS
	do {
	    ret = mutex_trylock(&global_lock);
	} while (ret == EBUSY);
#endif
#ifdef POSIX
	do {
	    ret = pthread_mutex_trylock(&global_lock);
	} while (ret == EBUSY);
#endif
	array->compute_ready = gethrtime();
	array->compute_vready = gethrvtime();

	/* do some work on the current array */
	(k->called_func)(&array->list[0]);

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();

	/* free the global lock */
#ifdef SOLARIS
	mutex_unlock(&global_lock);
#endif
#ifdef POSIX
	pthread_mutex_unlock(&global_lock);
#endif
	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
Esempio n. 11
0
File: mttest.c Progetto: dhaley/dcp
/* lock_local: use a local lock to process array's data */
void
calladd(Workblk *array, struct scripttab *k)
{
	array->ready = array->start;
	array->vready = array->vstart;

	array->compute_ready = array->ready;
	array->compute_vready = array->vready;

	(k->called_func)(&array->list[0]);

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();
}
Esempio n. 12
0
File: mttest.c Progetto: dhaley/dcp
/* cache_trash: multiple threads refer to adjacent words,
 *	causing false sharing of cache lines, and trashing
 */
void
cache_trash(Workblk *array, struct scripttab *k)
{
	array->ready = array->start;
	array->vready = array->vstart;

	array->compute_ready = array->ready;
	array->compute_vready = array->vready;

        /* use a datum that will share a cache line with others */        
        if( (unsigned long)(&element[array->index]) / 32 & 1){
            cache_trash_odd(array,k);
        }else{
            cache_trash_even(array,k);
        }

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();
}
Esempio n. 13
0
long long
_ultra_hwd_get_virt_usec( void )
{
	return ( ( long long ) gethrvtime(  ) / ( long long ) 1000 );
}
Esempio n. 14
0
double RFWTimer::getElapsedTime() {
	return (double)(gethrvtime()-start_time)/(double)10e8;
}
Esempio n. 15
0
long long
_ultra_hwd_get_virt_cycles( hwd_context_t * zero )
{
	return ( ( ( long long ) gethrvtime(  ) / ( long long ) 1000 ) *
			 ( long long ) _papi_hwi_system_info.hw_info.mhz );
}
Esempio n. 16
0
long long
_ultra_hwd_get_virt_usec( hwd_context_t * zero )
{
	return ( ( long long ) gethrvtime(  ) / ( long long ) 1000 );
}
Esempio n. 17
0
long long
_solaris_get_virt_usec( void )
{
	return ( ( long long ) gethrvtime(  ) / ( long long ) 1000 );
}
Esempio n. 18
0
File: mttest.c Progetto: dhaley/dcp
/* cond_timeout_global: use a global condition time wait variable to 
   process array's data */
void
cond_timeout_global(Workblk *array, struct scripttab *k)
{
	int err;
	struct	timeval	current_time;

	/* acquire the global condition lock */
#ifdef SOLARIS
	mutex_lock(&global_cond_lock);
#endif
#ifdef POSIX
	pthread_mutex_lock(&global_cond_lock);
#endif
	gettimeofday(&current_time, NULL);
	time_out.tv_sec = current_time.tv_sec;
	time_out.tv_nsec = current_time.tv_usec * 1000;

	/* check to see if the condition flag is true, If not then wait
	 * for that condition flag to become true
	 */

	while (global_cond_flag != TRUE) {
		/* add MYTIMEOUT to current time for timeout */
		time_out.tv_nsec += MYTIMEOUT;
		while (time_out.tv_nsec > 1000000000) {
			time_out.tv_nsec -= 1000000000;
			time_out.tv_sec ++;
		}
			
#ifdef SOLARIS
		err = cond_timedwait( &global_cond,
			&global_cond_lock, &time_out);
#endif
#ifdef POSIX
		err = pthread_cond_timedwait( &global_cond,
			&global_cond_lock, &time_out);
#endif

		if (err == 0 ) {
			/* with the condition */
			break;
		}

	}
	/* Now, condition is true, and we have the global_cond_lock */

#ifdef SOLARIS
	mutex_unlock(&global_cond_lock);

	mutex_lock(&global_cond_lock2);
	global_cond_flag = FALSE;
	mutex_unlock(&global_cond_lock2);

	/* acquire the global lock */
	mutex_lock(&global_lock);
#endif
#ifdef POSIX
	pthread_mutex_unlock(&global_cond_lock);

	pthread_mutex_lock(&global_cond_lock2);
	global_cond_flag = FALSE;
	pthread_mutex_unlock(&global_cond_lock2);

	/* acquire the global lock */
	pthread_mutex_lock(&global_lock);
#endif

	array->ready = gethrtime();
	array->vready = gethrvtime();

	array->compute_ready = array->ready;
	array->compute_vready = array->vready;

	/* do some work on the current array */
	(k->called_func)(&array->list[0]);
	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();

	/* free the global lock */
#ifdef SOLARIS
	mutex_unlock(&global_lock);

	/* now set the condition, and signal any other threads */
	mutex_lock(&global_cond_lock2);
#endif
#ifdef POSIX
	pthread_mutex_unlock(&global_lock);

	/* now set the condition, and signal any other threads */
	pthread_mutex_lock(&global_cond_lock2);
#endif

	global_cond_flag = TRUE;
#ifdef SOLARIS
	cond_signal(&global_cond);
	mutex_unlock(&global_cond_lock2);
#endif
#ifdef POSIX
	pthread_cond_signal(&global_cond);
	pthread_mutex_unlock(&global_cond_lock2);
#endif

	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
Esempio n. 19
0
File: iosyn.c Progetto: dhaley/dcp
/*	iofile - do some file io operations */
int
iofile()
{
	FILE	*fp;	/* FILE pointer for stdio */
	int	k;	/* temp value for loop */
	int	i;
	char	*buf;
	hrtime_t	start;
	hrtime_t	vstart;
	char *fname = "/usr/tmp/synprogXXXXXX";
	int	ret;

	start = gethrtime();
	vstart = gethrvtime();

	/* Log the event */
	wlog("start of iofile -- stdio", NULL);

	ret = mkstemp(fname);
	if(ret == -1) {
		fprintf(stderr, "Unable to make a temporary name\n");
		exit(1);
	}
	fprintf(stderr, "\tUsing %s as scratch file\n", fname);

	/* allocate a buffer for the reading */
	/* note that this buffer is leaked! */
	buf = (char *) malloc(BUFSIZE);

	/* open the file */
	fp = fdopen(ret, "w");
	if(fp == NULL) {
		fprintf(stderr, "++ERROR opening %s, error %d\n",
			fname, errno );
		exit(1);
	}

	/* loop, writing the buffer to the file... */
	for(i = 0; i < NBLKS; i ++) {
		k = fwrite(buf, sizeof(char), BUFSIZE, fp);
		if (k != BUFSIZE) {
			fprintf(stderr, "++ERROR writing %s, error %d\n",
				fname, errno );
			exit(1);
		}
	}
	fclose (fp);

	sprintf(buf, "fwrite: %d blocks of %d", i, BUFSIZE);
	whrvlog(gethrtime()-start, gethrvtime()-vstart,
		buf, NULL);

	/* now reopen the file, and read it */
	start = gethrtime();
	vstart = gethrvtime();

	fp = fopen(fname, "r");
	if(fp == NULL) {
		fprintf(stderr, "++ERROR opening %s, error %d\n",
			fname, errno );
		exit(1);
	}
	i = 0;
	for(;;) {
		k = fread(buf, sizeof(char), BUFSIZE, fp);
		if (k < 0) {
			fprintf(stderr, "++ERROR reading %s, error %d\n",
				fname, errno );
		}
		if (k == 0) {
			/* close the file */
			fclose(fp);
			break;

		} else if (k != BUFSIZE) {
			/* short read */
			sprintf(buf,
		"\tunexpecter short read %d on %s\n",
				k, fname);
			fprintf(stderr, buf);
			break;
		} else {
			/* bump the block counter */
			i ++;
		}
	}
	sprintf(buf, "fread: %d blocks of %d", i, BUFSIZE);
	whrvlog(gethrtime()-start, gethrvtime()-vstart,
		buf, NULL);

	unlink(fname);

	return 0;
}
Esempio n. 20
0
 double ATL_cputime(void)
 {
    return(gethrvtime()*1.0e-9);
 }
Esempio n. 21
0
File: mttest.c Progetto: dhaley/dcp
/* cond_global: use a global condition variable to process array's data */
void
cond_global(Workblk *array, struct scripttab *k)
{
	/* acquire the global condition lock */

#ifdef SOLARIS
	mutex_lock(&global_cond_lock);
#endif
#ifdef POSIX
	pthread_mutex_lock(&global_cond_lock);
#endif

	/* check to see if the condition flag is true, If not then wait
	for that condition flag to become true. */
	while (global_cond_flag != TRUE) {

#ifdef SOLARIS
		cond_wait(&global_cond, &global_cond_lock);
#endif
#ifdef POSIX
		pthread_cond_wait(&global_cond, &global_cond_lock);
#endif
	}
	/* Now, condition is true, and we have the global_cond_lock */

	/* set the condition flag to be FALSE, so when a new thread
	 * is created, it should wait till this one is done.
	 */
	global_cond_flag = FALSE;

	/* free the global_cond_lock and acquire the global lock */
#ifdef SOLARIS
	mutex_unlock(&global_cond_lock);
	mutex_lock(&global_lock);
#endif
#ifdef POSIX
	pthread_mutex_unlock(&global_cond_lock);
	pthread_mutex_lock(&global_lock);
#endif

	array->ready = gethrtime();
	array->vready = gethrvtime();

	array->compute_ready = array->ready;
	array->compute_vready = array->vready;

	/* do some work on the current array */
	(k->called_func)(&array->list[0]);

	array->compute_done = gethrtime();
	array->compute_vdone = gethrvtime();

	/* free the global lock */

#ifdef SOLARIS
	mutex_unlock(&global_lock);

	/* now set the condition, and signal any other threads */
	mutex_lock(&global_cond_lock);
#endif
#ifdef POSIX
	pthread_mutex_unlock(&global_lock);

	/* now set the condition, and signal any other threads */
	pthread_mutex_lock(&global_cond_lock);
#endif

	global_cond_flag = TRUE;
#ifdef SOLARIS
	cond_signal(&global_cond);
	mutex_unlock(&global_cond_lock);
#endif
#ifdef POSIX
	pthread_cond_signal(&global_cond);
	pthread_mutex_unlock(&global_cond_lock);
#endif
	/* make another call to preclude tail-call optimization on the unlock */
	(void) gethrtime();
}
Esempio n. 22
0
File: mttest.c Progetto: dhaley/dcp
int
locktest()
{
	int	i;
	Workblk *array;
	struct scripttab	*k;
	hrtime_t	start;
	hrtime_t	vstart;
	hrtime_t	end;
	hrtime_t	vend;
	struct timeval	ttime;
	time_t		secs;

	head.size   = narrays;
	head.arrays = (Workblk *) calloc(narrays, sizeof(Workblk));

	for(i = 0, array = head.arrays; i < narrays; i ++, array ++) {
		array->index = i;
	}

	printf( "%s: number of %s = %d, number of blocks = %d, repeat %d times %s\n",
		name, model, nthreads, narrays, repeat_count,
		(uniprocessor == 0 ? "" : "[single CPU]") );

#ifdef SOLARIS
	tid = (thread_t *) calloc(nthreads*repeat_count, sizeof(thread_t));
#endif
#ifdef POSIX
	tid = (pthread_t *) calloc(nthreads*repeat_count, sizeof(pthread_t));
#endif
	for(count = 0; count < repeat_count; count ++) {
	    (void) gettimeofday(&ttime, NULL);
	    secs = (time_t)ttime.tv_sec;
	    printf("Iteration %d, starting %s\n",
		count+1,
		prtime (&secs) );
	    if(job_index == -1) {
	        for (i = 0; ; i++) {
		    k = &scripttab[i];
		    if (k->test_name == NULL) {
			break;
		    }

		    printf("begin thread_work, %s\n", k->test_name);

		    init_arrays(i);

		    start = gethrtime();
		    vstart = gethrvtime();

		    if( strcmp(k->test_name, "nothreads") == 0 ){
			/* the "nothreads" task is special-cased to run in the main thread */
			do_work(NULL);
		    } else if(nthreads == 1) {
			do_work(NULL);
		    } else {
			thread_work();
		    }

		    end = gethrtime();
		    vend = gethrvtime();
#if OS(Solaris)
		    check_sigmask(2);
#endif /* OS(Solaris) */
		    dump_arrays(end-start, vend-vstart, i);
	        }
	    } else {
		    k = &scripttab[job_index];
		    if (k->test_name == NULL) {
			break;
		    }

		    printf("begin thread_work, %s\n", k->test_name);

		    init_arrays(job_index);

		    start = gethrtime();
		    vstart = gethrvtime();

		    if( strcmp(k->test_name, "nothreads") == 0 ){
			/* first one is special-cased to run in 1 thread */
			do_work(NULL);
		    } else if(nthreads == 1) {
			do_work(NULL);
		    } else {
			thread_work();
		    }

		    end = gethrtime();
		    vend = gethrvtime();
#if OS(Solaris)
		    check_sigmask(2);
#endif /* OS(Solaris) */
		    dump_arrays(end-start, vend-vstart, job_index);
	     }
	}

	/* we're done, return */
	return(0);
}
Esempio n. 23
0
void RFWTimer::startTiming() {start_time = (long)gethrvtime();}
Esempio n. 24
0
File: mttest.c Progetto: dhaley/dcp
/* do_work: process array's data with locking, based on array->strategy */
void *
do_work(void *v)
{
	Workblk	*array;
	struct scripttab	*k;
	int i;
	volatile double x;

#ifdef SOLARIS
	thread_t	mytid = thr_self();
#endif
#ifdef POSIX
	pthread_t	mytid = pthread_self();
#endif
#if OS(Solaris)
	/* check for signal masked */
	check_sigmask(0);
#endif /* OS(Solaris) */

	/* delay to ensure that a tick passes, so that the
	 * first profile packet doesn't show the thread startup time
	 * attributed to the accounting functions
	 */
	x = 0;
	for (i = 0; i < 2000000; i++) { x = x + 1.0; }

	for(;;) {
		/* fetch a workblk */
		array = fetch_work();
		if(array == NULL) {
			/* we're done */
			break;
		}
                array->lock = mutex_initializer;
		array->proffail = 0;
		array->tid = mytid;
#if OS(Solaris)		
		array->ilwpid = _lwp_self();
#else
		array->ilwpid = getpid() /* pthread_self()*/ ;
#endif /* OS(Solaris) */

                array->lwpid = -1; /* initialise to inappropriate value */
#if 0
		printf("thread %d, initial lwp %d, block #%d, strategy = %d\n",
		    array->tid, array->ilwpid, array->index, array->strategy);
#endif
		array->start = gethrtime();
		array->vstart = gethrvtime();

		k = &scripttab[array->strategy];
		(k->test_func)(array, k);

		array->done = gethrtime();
		array->vdone = gethrvtime();
#if OS(Solaris)
		array->lwpid = _lwp_self();
#else
		array->lwpid = getpid() /* pthread_self()*/ ;
#endif /* OS(Solaris) */
				

#if defined(BOUND)
                assert(array->lwpid == array->ilwpid);
#endif
#if OS(Solaris)
		if(check_sigmask(1) != 0) {
			/* set flag in the array */
			array->proffail = 1;
		}
#endif /* OS(Solaris) */
	}

	return NULL;
}