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