Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VReo > Reo__Matrix_Mult
view Reo__Matrix_Mult/MeasurementStuff.c @ 3:a6b3cab179b1
Added no-measurments option for platforms without support. Added static X86, ARM
and basic Kalray build support. This branch requires the longjmp versions of
libprt and libvreo
| author | Philipe Louchtch - de Raadt |
|---|---|
| date | Sat, 12 Jul 2014 20:21:47 +0200 |
| parents | 1b61e0c00512 |
| children |
line source
1 /*
2 * Copyright 2014 OpenSourceResearchInstitute.org
3 * Licensed under GNU General Public License version 2
4 *
5 * Author: seanhalle@yahoo.com
6 *
7 */
9 #ifndef H_MEASUREMENTSTUFF_
10 #define H_MEASUREMENTSTUFF_
12 // =============================================================================
14 //SELECT how the measurement is done
15 //only one must be enabled
16 //#define MEASURE_TSC
17 //#define MEASURE_PERF
18 #define MEASURE_SKIP
20 #ifdef MEASURE_SKIP
21 #define saveTimeStampCountInto(low, high)
22 #define saveLowTimeStampCountInto(low)
23 #else
24 #define saveTimeStampCountInto(low, high) \
25 asm volatile("RDTSC; \
26 movl %%eax, %0; \
27 movl %%edx, %1;" \
28 /* outputs */ : "=m" (low), "=m" (high)\
29 /* inputs */ : \
30 /* clobber */ : "%eax", "%edx" \
31 );
33 #define saveLowTimeStampCountInto(low) \
34 asm volatile("RDTSC; \
35 movl %%eax, %0;" \
36 /* outputs */ : "=m" (low) \
37 /* inputs */ : \
38 /* clobber */ : "%eax", "%edx" \
39 );
41 union timeStamp {
42 uint32_t lowHigh[2]; //lowHigh[0] is low, lowHigh[1] is high
43 uint64_t total;
44 };
46 struct perfData {
47 uint64_t cycles;
48 uint64_t instructions;
49 };
50 #endif
52 //MEASURE_TSC should be mutually exclusive with MEASURE_PERF
53 #ifdef MEASURE_TSC
54 typedef union timeStamp MeasStruct;
55 #elif defined MEASURE_PERF
56 typedef struct perfData MeasStruct;
57 #elif defined MEASURE_SKIP
58 typedef void* MeasStruct;
59 #endif
62 //read and save current perf-counter readings for cycles and instrs
63 #ifdef MEASURE_PERF
64 #define takeAMeas(core, perfDataStruct) do{ \
65 int cycles_fd = cycles_counter_fd[core]; \
66 int nread; \
67 \
68 nread = read(cycles_fd,&(perfDataStruct.cycles),sizeof(perfDataStruct.cycles)); \
69 if(nread<0){ \
70 perror("Error reading cycles counter"); \
71 cycles = 0; \
72 } \
73 } while (0) //macro magic for scoping
74 #elif defined MEASURE_TSC
75 #define takeAMeas(core, timeStampStruct) do{ \
76 saveTimeStampCountInto(timeStampStruct.lowHigh[0], timeStampStruct.lowHigh[1]); \
77 } while (0) //macro magic for scoping
78 #elif defined MEASURE_SKIP
79 #define takeAMeas(core, timeStampStruct)
80 #endif
82 #ifdef MEASURE_PERF
83 int cycles_counter_fd[NUM_CORES];
84 int instrs_counter_fd[NUM_CORES];
85 int cycles_counter_main_fd;
86 #endif
88 //===================================
89 /* provide a millisecond-resolution timer for each system */
90 #if defined(unix) || defined(__unix__)
91 #include <time.h>
92 #include <sys/time.h>
93 unsigned long get_msec(void) {
94 static struct timeval timeval, first_timeval;
96 gettimeofday(&timeval, 0);
97 if(first_timeval.tv_sec == 0) {
98 first_timeval = timeval;
99 return 0;
100 }
101 return (timeval.tv_sec - first_timeval.tv_sec) * 1000 + (timeval.tv_usec - first_timeval.tv_usec) / 1000;
102 }
103 #elif defined(__WIN32__) || defined(WIN32)
104 #include <windows.h>
105 unsigned long get_msec(void) {
106 return GetTickCount();
107 }
108 #else
109 #ifndef MEASURE_SKIP
110 #error "I don't know how to measure time on your platform"
111 #endif
112 #endif
114 #endif //H_MEASUREMENTSTUFF_
