diff options
author | Joshua Bakita <jbakita@cs.unc.edu> | 2019-06-17 08:45:24 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2019-06-17 08:45:24 -0400 |
commit | 54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (patch) | |
tree | 94366e3c914e0591ba9e0fd8d884367e8b498f58 | |
parent | c10cfd98cbaba8d0c602d1f790ce8e3b6c2ff40c (diff) |
Cleanup extra.h for the paired tests
-rw-r--r-- | rtss19/extra.h | 82 |
1 files changed, 34 insertions, 48 deletions
diff --git a/rtss19/extra.h b/rtss19/extra.h index f089373..b96671c 100644 --- a/rtss19/extra.h +++ b/rtss19/extra.h | |||
@@ -1,17 +1,39 @@ | |||
1 | #include <time.h> | 1 | /** |
2 | #include <sys/mman.h> | 2 | * Copyright 2019 Sims Hill Osborne and Joshua Bakita |
3 | #include <sys/stat.h> | 3 | * |
4 | #include <unistd.h> | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | * of this software and associated documentation files (the "Software"), to deal | ||
6 | * in the Software without restriction, including without limitation the rights | ||
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
8 | * copies of the Software, and to permit persons to whom the Software is | ||
9 | * furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
20 | * SOFTWARE. | ||
21 | **/ | ||
5 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <limits.h> | ||
24 | #include <semaphore.h> | ||
25 | #include <signal.h> | ||
6 | #include <stdlib.h> | 26 | #include <stdlib.h> |
7 | #include <stdio.h> | 27 | #include <stdio.h> |
8 | #include <string.h> | 28 | #include <string.h> |
9 | #include <signal.h> | 29 | #include <sys/mman.h> |
10 | #include <limits.h> | 30 | #include <sys/stat.h> |
11 | #include <fcntl.h> | 31 | #include <time.h> |
12 | #include <semaphore.h> | 32 | #include <unistd.h> |
13 | 33 | ||
14 | // Benchmarks use SET_UP, START_LOOP, STOP_LOOP, and WRITE_TO_FILE | 34 | // Benchmarks use SET_UP, START_LOOP, STOP_LOOP, and WRITE_TO_FILE |
35 | // These are macros so that we can declare and maintain additional state inside | ||
36 | // the benchmark. | ||
15 | #define SET_UP if (argc < 8) {\ | 37 | #define SET_UP if (argc < 8) {\ |
16 | printf("Usage: %s <name> <runs> <my core> <other core> <other program> <runID> <lockID>", argv[0]);\ | 38 | printf("Usage: %s <name> <runs> <my core> <other core> <other program> <runID> <lockID>", argv[0]);\ |
17 | exit(1);\ | 39 | exit(1);\ |
@@ -101,29 +123,16 @@ | |||
101 | fread(&dummy, 1, 1, fp);\ | 123 | fread(&dummy, 1, 1, fp);\ |
102 | fclose(fp); | 124 | fclose(fp); |
103 | 125 | ||
104 | //invoke start timer twice, stop timer to make sure timer and vars are in cache | 126 | // These timers should just be aliases to the hardware counters w/ some small adjustments |
105 | #define START_TIMER clock_gettime(CLOCK_MONOTONIC, &start); | 127 | #define START_TIMER clock_gettime(CLOCK_MONOTONIC, &start); |
106 | //clock_gettime(CLOCK_MONOTONIC, &end);\ | ||
107 | //clock_gettime(CLOCK_MONOTONIC, &start);\ | ||
108 | |||
109 | #define STOP_TIMER clock_gettime(CLOCK_MONOTONIC, &end); | 128 | #define STOP_TIMER clock_gettime(CLOCK_MONOTONIC, &end); |
110 | 129 | ||
111 | #define LOCK2_LOCKED //printf("Lock2 locked. \n"); | ||
112 | #define LOCK1_LOCKED //printf("Lock1 locked. \n"); | ||
113 | #define LOCK1_UNLOCKED //printf("Lock1 unlocked. \n"); | ||
114 | #define LOCK2_UNLOCKED //printf("Lock2 unlocked. \n"); | ||
115 | |||
116 | //check value of sem | 130 | //check value of sem |
117 | //if sem=0, unlock | 131 | //if sem=0, unlock |
118 | //if sem=1, spin | 132 | //if sem=1, spin |
119 | 133 | ||
120 | #define SLEEP nanosleep((const struct timespec[]){{0, 1000000}}, NULL); | 134 | #define SLEEP nanosleep((const struct timespec[]){{0, 1000000}}, NULL); |
121 | 135 | ||
122 | //#define SAFE_UNLOCK(whichSem) sem_getvalue(whichSem, &val); while(val==1) { printf("Attpt. to unlock unlocked lock. \n"); sem_getvalue(whichSem, &val); } sem_post(whichSem); | ||
123 | |||
124 | |||
125 | //#define SAFE_UNLOCK(whichSem) sem_post(whichSem); SLEEP ; printf("Used SAFE_UNLOCK. \n"); | ||
126 | |||
127 | #define FIRST_UNLOCK if (lockID == 1) {\ | 136 | #define FIRST_UNLOCK if (lockID == 1) {\ |
128 | if (sem_post(secondSem) != 0) {\ | 137 | if (sem_post(secondSem) != 0) {\ |
129 | perror("Unable to unlock second semaphore");\ | 138 | perror("Unable to unlock second semaphore");\ |
@@ -164,29 +173,8 @@ | |||
164 | __sync_bool_compare_and_swap(barrier, 1, 0);\ | 173 | __sync_bool_compare_and_swap(barrier, 1, 0);\ |
165 | } | 174 | } |
166 | 175 | ||
167 | |||
168 | //#define SECOND_UNLOCK if (lockID==1){sem_post(firstSem) ; LOCK1_UNLOCKED }\ | ||
169 | else {sem_post(secondSem) ; LOCK2_UNLOCKED } | ||
170 | |||
171 | //#define SECOND_LOCK if (lockID==1){sem_wait(secondSem); LOCK2_LOCKED }\ | ||
172 | else {sem_wait(firstSem); LOCK1_LOCKED } | ||
173 | |||
174 | |||
175 | #define START_LOOP FIRST_UNLOCK FIRST_LOCK FLUSH_CACHES BARRIER_SYNC START_TIMER | 176 | #define START_LOOP FIRST_UNLOCK FIRST_LOCK FLUSH_CACHES BARRIER_SYNC START_TIMER |
176 | 177 | #define STOP_LOOP STOP_TIMER SAVE_RESULTS | |
177 | |||
178 | /* | ||
179 | First task to reach TRY_CACHE will fail, but unlock the lock. | ||
180 | Second task will get the lock and kill the cache. | ||
181 | Lock remains in place until this point is reached again in code. | ||
182 | */ | ||
183 | |||
184 | //#define TRY_CACHE if (sem_trywait(cacheSem)==0){KILL_CACHE}\ | ||
185 | else {sem_post(cacheSem);} | ||
186 | |||
187 | //#define STOP_LOOP STOP_TIMER SAVE_RESULTS //TRY_CACHE | ||
188 | |||
189 | #define STOP_LOOP STOP_TIMER SAVE_RESULTS //SECOND_UNLOCK SECOND_LOCK KILL_CACHE | ||
190 | 178 | ||
191 | 179 | ||
192 | /* | 180 | /* |
@@ -196,12 +184,10 @@ main | |||
196 | SET_UP | 184 | SET_UP |
197 | notice that STOP LOOP negates the ++ if outout=0 | 185 | notice that STOP LOOP negates the ++ if outout=0 |
198 | for (jobsComplete=-1; jobsComplete<maxJobs; jobsComplete++){ | 186 | for (jobsComplete=-1; jobsComplete<maxJobs; jobsComplete++){ |
199 | KILL_CACHE | 187 | START_LOOP |
200 | START_TIMER | ||
201 | tacleInit(); | 188 | tacleInit(); |
202 | tacleMain(); | 189 | tacleMain(); |
203 | STOP_TIMER | 190 | STOP_LOOP |
204 | SAVE_RESULTS | ||
205 | } | 191 | } |
206 | WRITE_TO_FILE | 192 | WRITE_TO_FILE |
207 | tacleReturn | 193 | tacleReturn |