diff options
Diffstat (limited to 'baseline/source/extra.h')
-rw-r--r-- | baseline/source/extra.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/baseline/source/extra.h b/baseline/source/extra.h new file mode 100644 index 0000000..ca92812 --- /dev/null +++ b/baseline/source/extra.h | |||
@@ -0,0 +1,116 @@ | |||
1 | #include <time.h> | ||
2 | #include <sys/mman.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | #include <signal.h> | ||
7 | #include <limits.h> | ||
8 | |||
9 | #define L3_CACHE_SIZE (11264*1024) | ||
10 | |||
11 | |||
12 | |||
13 | #define SET_UP char *thisProgram=argv[1];\ | ||
14 | int maxJobs=atoi(argv[2]);\ | ||
15 | char *thisCore=argv[3];\ | ||
16 | char *otherCore=argv[4];\ | ||
17 | char *otherProgram=argv[5];\ | ||
18 | char *runID=argv[6];\ | ||
19 | int output=atoi(argv[7]);\ | ||
20 | pid_t killMe;\ | ||
21 | struct timespec start, end;\ | ||
22 | int jobsComplete;\ | ||
23 | long progTime[maxJobs*output];\ | ||
24 | char fileName[50];\ | ||
25 | char *bigArray;\ | ||
26 | int wasteCount;\ | ||
27 | strcpy(fileName, runID);\ | ||
28 | strcat(fileName, ".txt");\ | ||
29 | mlockall(MCL_CURRENT || MCL_FUTURE); | ||
30 | |||
31 | |||
32 | //if output==0, endless loop | ||
33 | //avoids int overflow error with large numbers for background loops | ||
34 | |||
35 | #define SAVE_RESULTS if(jobsComplete>-1) progTime[jobsComplete]=(end.tv_nsec-start.tv_nsec)+(1000000000*(end.tv_sec-start.tv_sec)); | ||
36 | |||
37 | #define WRITE_TO_FILE if (output){\ | ||
38 | munlockall();\ | ||
39 | FILE *fp=fopen(fileName, "a");\ | ||
40 | if (fp == NULL) {\ | ||
41 | perror("Error opening file. \n");\ | ||
42 | exit(1);\ | ||
43 | }\ | ||
44 | for(jobsComplete=0; jobsComplete<maxJobs; jobsComplete++){\ | ||
45 | fprintf(fp, "%s %s %s %s %d %ld %s %d \n",\ | ||
46 | thisProgram, otherProgram, thisCore, otherCore, maxJobs,\ | ||
47 | progTime[jobsComplete], runID, jobsComplete);\ | ||
48 | }\ | ||
49 | fclose(fp);\ | ||
50 | } | ||
51 | |||
52 | // Call the wbinvld instruction (it's in a kernel module due to it being ring-0) | ||
53 | #define FLUSH_CACHES FILE *fp = fopen("/proc/wbinvd", "r");\ | ||
54 | if (fp == NULL) {\ | ||
55 | perror("Cache flush module interface cannot be opened");\ | ||
56 | exit(1);\ | ||
57 | }\ | ||
58 | char dummy;\ | ||
59 | if (fread(&dummy, 1, 1, fp) == 0) {\ | ||
60 | perror("Unable to access cache flush module interface");\ | ||
61 | exit(1);\ | ||
62 | }\ | ||
63 | fclose(fp); | ||
64 | |||
65 | //invoke start timer twice, stop timer to make sure timer and vars are in cache | ||
66 | //#define START_TIMER clock_gettime(CLOCK_MONOTONIC, &start);\ | ||
67 | clock_gettime(CLOCK_MONOTONIC, &end);\ | ||
68 | clock_gettime(CLOCK_MONOTONIC, &start);\ | ||
69 | |||
70 | #define START_TIMER clock_gettime(CLOCK_MONOTONIC, &start); | ||
71 | |||
72 | #define STOP_TIMER clock_gettime(CLOCK_MONOTONIC, &end); | ||
73 | |||
74 | //waste a millisecond | ||
75 | |||
76 | #define WASTE_TIME clock_gettime(CLOCK_MONOTONIC, &start);\ | ||
77 | do{clock_gettime(CLOCK_MONOTONIC, &end);}\ | ||
78 | while( (end.tv_sec*1000000000+end.tv_nsec)-(start.tv_sec*1000000000+start.tv_nsec) < 1000000); | ||
79 | |||
80 | |||
81 | #define SLEEP nanosleep((const struct timespec[]){{0, 1000000}}, NULL); | ||
82 | |||
83 | //#define LOOP_WASTE for(wasteCount=0; wasteCount<1000000; wasteCount++){} | ||
84 | |||
85 | //at beginning of loop clear cache, waste some time | ||
86 | //wasting time allows interfering process to build up some cache presence | ||
87 | //using sleep instead of waste time loop causes problems | ||
88 | //both sleeping and spinning give advantage to threaded task | ||
89 | //#define START_LOOP if (output) {KILL_CACHE START_TIMER} | ||
90 | |||
91 | //#define START_LOOP if (output){START_TIMER} | ||
92 | |||
93 | //#define STOP_LOOP if (output) {STOP_TIMER SAVE_RESULTS} | ||
94 | //if (!output) {jobsComplete--;} | ||
95 | |||
96 | #define START_LOOP FLUSH_CACHES START_TIMER | ||
97 | #define STOP_LOOP STOP_TIMER SAVE_RESULTS | ||
98 | |||
99 | |||
100 | /* | ||
101 | Intended structure | ||
102 | |||
103 | main | ||
104 | SET_UP | ||
105 | notice that STOP LOOP negates the ++ if outout=0 | ||
106 | for (jobsComplete=-1; jobsComplete<maxJobs; jobsComplete++){ | ||
107 | KILL_CACHE | ||
108 | START_TIMER | ||
109 | tacleInit(); | ||
110 | tacleMain(); | ||
111 | STOP_TIMER | ||
112 | SAVE_RESULTS | ||
113 | } | ||
114 | WRITE_TO_FILE | ||
115 | tacleReturn | ||
116 | */ | ||