Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > pthread > pthread__k_tuple__async
comparison src/Application/main.h @ 0:9cf9b2091eeb
working condition variable version
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Wed, 10 Jul 2013 14:13:46 -0700 |
| parents | |
| children | 88db7b62b961 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:5603505a21cf |
|---|---|
| 1 /* | |
| 2 * | |
| 3 */ | |
| 4 #include <stdio.h> | |
| 5 #include <stdlib.h> | |
| 6 #include <string.h> | |
| 7 #include <math.h> | |
| 8 #include <ctype.h> | |
| 9 #include <errno.h> | |
| 10 #include <pthread.h> | |
| 11 #include <sched.h> | |
| 12 #include <unistd.h> | |
| 13 | |
| 14 #include <linux/perf_event.h> | |
| 15 #include <sys/syscall.h> | |
| 16 | |
| 17 //========================== | |
| 18 //#define TURN_ON_DEBUG | |
| 19 | |
| 20 //========================== | |
| 21 #define NUM_CORES 4 | |
| 22 | |
| 23 //========================== | |
| 24 | |
| 25 //SELECT how the measurement is done | |
| 26 //only one must be enabled | |
| 27 #define MEASURE_TSC | |
| 28 //#define MEASURE_PERF | |
| 29 | |
| 30 | |
| 31 #if !defined(unix) && !defined(__unix__) | |
| 32 #ifdef __MACH__ | |
| 33 #define unix 1 | |
| 34 #define __unix__ 1 | |
| 35 #endif /* __MACH__ */ | |
| 36 #endif /* unix */ | |
| 37 | |
| 38 /* find the appropriate way to define explicitly sized types */ | |
| 39 /* for C99 or GNU libc (also mach's libc) we can use stdint.h */ | |
| 40 #if (__STDC_VERSION__ >= 199900) || defined(__GLIBC__) || defined(__MACH__) | |
| 41 #include <stdint.h> | |
| 42 #elif defined(unix) || defined(__unix__) /* some UNIX systems have them in sys/types.h */ | |
| 43 #include <sys/types.h> | |
| 44 #elif defined(__WIN32__) || defined(WIN32) /* the nameless one */ | |
| 45 typedef unsigned __int8 uint8_t; | |
| 46 typedef unsigned __int32 uint32_t; | |
| 47 #endif /* sized type detection */ | |
| 48 | |
| 49 | |
| 50 //================== | |
| 51 #ifdef TURN_ON_DEBUG | |
| 52 #define DEBUG__printf(msg) printf(msg) | |
| 53 #define DEBUG__printf1(msg, arg1) printf(msg, arg1) | |
| 54 #define DEBUG__printf2(msg, arg1, arg2) printf(msg, arg1, arg2) | |
| 55 #else | |
| 56 #define DEBUG__printf(msg) | |
| 57 #define DEBUG__printf1(msg, arg1) | |
| 58 #define DEBUG__printf2(msg, arg1, arg2) | |
| 59 #endif | |
| 60 //===== RDTSC wrapper ===== //Does work for x86_64 compile | |
| 61 | |
| 62 #define saveTimeStampCountInto(low, high) \ | |
| 63 asm volatile("RDTSC; \ | |
| 64 movl %%eax, %0; \ | |
| 65 movl %%edx, %1;" \ | |
| 66 /* outputs */ : "=m" (low), "=m" (high)\ | |
| 67 /* inputs */ : \ | |
| 68 /* clobber */ : "%eax", "%edx" \ | |
| 69 ); | |
| 70 | |
| 71 #define saveLowTimeStampCountInto(low) \ | |
| 72 asm volatile("RDTSC; \ | |
| 73 movl %%eax, %0;" \ | |
| 74 /* outputs */ : "=m" (low) \ | |
| 75 /* inputs */ : \ | |
| 76 /* clobber */ : "%eax", "%edx" \ | |
| 77 ); | |
| 78 | |
| 79 //==================== | |
| 80 | |
| 81 union timeStamp | |
| 82 { | |
| 83 uint32_t lowHigh[2]; //lowHigh[0] is low, lowHigh[1] is high | |
| 84 uint64_t total; | |
| 85 }; | |
| 86 | |
| 87 struct perfData | |
| 88 { | |
| 89 uint64_t cycles; | |
| 90 uint64_t instructions; | |
| 91 }; | |
| 92 | |
| 93 //MEASURE_TSC should be mutually exclusive with MEASURE_PERF | |
| 94 #ifdef MEASURE_TSC | |
| 95 typedef union timeStamp MeasStruct; | |
| 96 #else | |
| 97 #ifdef MEASURE_PERF | |
| 98 typedef struct perfData MeasStruct; | |
| 99 #endif | |
| 100 #endif | |
| 101 | |
| 102 //fast way to collect time intervals, by putting into hist right away | |
| 103 #define makeAMeasHist( idx, name, numBins, startVal, binWidth ) \ | |
| 104 makeHighestDynArrayIndexBeAtLeast( _VMSMasterEnv->measHistsInfo, idx ); \ | |
| 105 _VMSMasterEnv->measHists[idx] = \ | |
| 106 makeFixedBinHist( numBins, startVal, binWidth, name ); | |
| 107 | |
| 108 //read and save current perf-counter readings for cycles and instrs | |
| 109 #ifdef MEASURE_PERF | |
| 110 #define takeAMeas(core, perfDataStruct) do{ \ | |
| 111 int cycles_fd = cycles_counter_fd[core]; \ | |
| 112 int nread; \ | |
| 113 \ | |
| 114 nread = read(cycles_fd,&(perfDataStruct.cycles),sizeof(perfDataStruct.cycles)); \ | |
| 115 if(nread<0){ \ | |
| 116 perror("Error reading cycles counter"); \ | |
| 117 cycles = 0; \ | |
| 118 } \ | |
| 119 } while (0) //macro magic for scoping | |
| 120 #else | |
| 121 #define takeAMeas(core, timeStampStruct) do{ \ | |
| 122 saveTimeStampCountInto(timeStampStruct.lowHigh[0], timeStampStruct.lowHigh[1]);\ | |
| 123 } while (0) //macro magic for scoping | |
| 124 #endif | |
| 125 | |
| 126 | |
| 127 typedef struct | |
| 128 { | |
| 129 int coreID; | |
| 130 int numTuplesToCreate; | |
| 131 int producerID; | |
| 132 | |
| 133 } | |
| 134 ProducerParams; | |
| 135 | |
| 136 typedef struct | |
| 137 { | |
| 138 int coreID; | |
| 139 int numTuplesToCreate; | |
| 140 int numProducers; | |
| 141 | |
| 142 } | |
| 143 ConsumerParams; | |
| 144 | |
| 145 //=========== Global Vars ============= | |
| 146 pthread_mutex_t tupleIterLock; | |
| 147 pthread_cond_t tupleIterCond; | |
| 148 int tupleIter; | |
| 149 | |
| 150 pthread_mutex_t producerAccessMutex; | |
| 151 pthread_mutex_t productionReadyLock; | |
| 152 pthread_cond_t productionReadyCond; | |
| 153 int currProductionNum; | |
| 154 int producerMessage; | |
| 155 | |
| 156 pthread_mutex_t consumerReceivedAckLock; | |
| 157 pthread_cond_t consumerReceivedAckCond; | |
| 158 int currConsumerReceivedACKNum; | |
| 159 | |
| 160 //======= | |
| 161 void* | |
| 162 producer_birthFn( void* _params ); | |
| 163 void* | |
| 164 consumer_birthFn( void* _params ); | |
| 165 | |
| 166 |
