# HG changeset patch # User Me@portablequad # Date 1319336849 25200 # Node ID e512fcf3748e6fd86e7ae454c64f85ee8b12b20c # Parent 80a90f2210479f9b3280611909579242d35097f5 Initial add diff -r 80a90f221047 -r e512fcf3748e src/Application/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Application/main.c Sat Oct 22 19:27:29 2011 -0700 @@ -0,0 +1,256 @@ +/* + * + */ +#include +#include +#include +#include +#include +#include +#include +#include "VPThread_lib/VPThread.h" +#include "VPThread_lib/VMS/Queue_impl/PrivateQueue.h" + +#undef DEBUG +//#define DEBUG + +#if !defined(unix) && !defined(__unix__) +#ifdef __MACH__ +#define unix 1 +#define __unix__ 1 +#endif /* __MACH__ */ +#endif /* unix */ + +/* find the appropriate way to define explicitly sized types */ +/* for C99 or GNU libc (also mach's libc) we can use stdint.h */ +#if (__STDC_VERSION__ >= 199900) || defined(__GLIBC__) || defined(__MACH__) +#include +#elif defined(unix) || defined(__unix__) /* some UNIX systems have them in sys/types.h */ +#include +#elif defined(__WIN32__) || defined(WIN32) /* the nameless one */ +typedef unsigned __int8 uint8_t; +typedef unsigned __int32 uint32_t; +#endif /* sized type detection */ + +/* provide a millisecond-resolution timer for each system */ +#if defined(unix) || defined(__unix__) +#include +#include +unsigned long get_msec(void) { + static struct timeval timeval, first_timeval; + + gettimeofday(&timeval, 0); + if(first_timeval.tv_sec == 0) { + first_timeval = timeval; + return 0; + } + return (timeval.tv_sec - first_timeval.tv_sec) * 1000 + (timeval.tv_usec - first_timeval.tv_usec) / 1000; +} +#elif defined(__WIN32__) || defined(WIN32) +#include +unsigned long get_msec(void) { + return GetTickCount(); +} +#else +//#error "I don't know how to measure time on your platform" +#endif + +//======================== Defines ========================= + +const char *usage = { + "Usage: malloc_test [options]\n" + " Spwans a number of threads and allocates memory.\n\n" + "Options:\n" + " -t how many threads to use (default: 1)\n" + " -m repeat workload and sync operation times\n" + " -n size of workload, repeat times\n" + " -h this help screen\n\n" +}; + +struct barrier_t +{ + int counter; + int nthreads; + int32 mutex; + int32 cond; +}; +typedef struct barrier_t barrier; + +void inline barrier_init(barrier *barr, int nthreads, VirtProcr *animatingPr) + { + barr->counter = 0; + barr->nthreads = nthreads; + barr->mutex = VPThread__make_mutex(animatingPr); + barr->cond = VPThread__make_cond(barr->mutex, animatingPr); + } + +void inline barrier_wait(barrier *barr, VirtProcr *animatingPr) + { int i; + + VPThread__mutex_lock(barr->mutex, animatingPr); + barr->counter++; + if(barr->counter == barr->nthreads) + { barr->counter = 0; + for(i=0; i < barr->nthreads; i++) + VPThread__cond_signal(barr->cond, animatingPr); + } + else + { VPThread__cond_wait(barr->cond, animatingPr); + } + VPThread__mutex_unlock(barr->mutex, animatingPr); + } + + + +union workload{ + uint32 highLow[2]; + uint64 total; +}; + +struct input_t{ + struct barrier_t* barrier; + uint64 workcycles; +}; + + +//======================== Globals ========================= +char __ProgrammName[] = "overhead_test"; +char __DataSet[255]; + +int repetitions, workload_size, num_threads; +size_t chunk_size = 0; + + +//======================== App Code ========================= +/* + * Workload + */ +void work(void* input, VirtProcr* animatingPr) +{ + int n,m; + struct input_t* in = (struct input_t*)input; + unsigned int totalCycles = 0; + unsigned int workspace1; + double workspace2; + int32 privateMutex = VPThread__make_mutex(animatingPr); + + for(m=0; mworkcycles = totalCycles; + barrier_wait(in->barrier,animatingPr); + //Shutdown worker + VPThread__dissipate_thread(animatingPr); + printf("%d", workspace1); + printf("%f", workspace2); +} + +/* this is run after the VMS is set up*/ +void benchmark(void *in, VirtProcr *animatingPr) + { + int i; + struct input_t input[num_threads]; + struct barrier_t barr; + barrier_init(&barr, num_threads+1, animatingPr); + + for(i=0; i