diff options
Diffstat (limited to 'all_pairs/source/extra.h')
| -rw-r--r-- | all_pairs/source/extra.h | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/all_pairs/source/extra.h b/all_pairs/source/extra.h index bdbd1f5..0681250 100644 --- a/all_pairs/source/extra.h +++ b/all_pairs/source/extra.h | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | * SOFTWARE. | 20 | * SOFTWARE. |
| 21 | **/ | 21 | **/ |
| 22 | #define _GNU_SOURCE | ||
| 22 | #include <fcntl.h> | 23 | #include <fcntl.h> |
| 23 | #include <limits.h> | 24 | #include <limits.h> |
| 24 | #include <semaphore.h> | 25 | #include <semaphore.h> |
| @@ -30,23 +31,31 @@ | |||
| 30 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
| 31 | #include <time.h> | 32 | #include <time.h> |
| 32 | #include <unistd.h> | 33 | #include <unistd.h> |
| 34 | #include <sched.h> | ||
| 35 | |||
| 36 | // This is only visible if _GNU_SOURCE is defined, and that define does not | ||
| 37 | // come along to places where this file is included. Address this by manually | ||
| 38 | // forcing it into the global namespace. | ||
| 39 | extern int sched_getcpu(); | ||
| 33 | 40 | ||
| 34 | // Benchmarks use SET_UP, START_LOOP, STOP_LOOP, and WRITE_TO_FILE | 41 | // 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 | 42 | // These are macros so that we can declare and maintain additional state inside |
| 36 | // the benchmark. | 43 | // the benchmark. |
| 37 | #define SET_UP if (argc < 8) {\ | 44 | #define SET_UP if (argc != 8) {\ |
| 38 | printf("Usage: %s <name> <runs> <my core> <other core> <other program> <runID> <lockID>", argv[0]);\ | 45 | printf("Usage: %s <name> <runs> <my core> <other core> <other program> <runID> <lockID>", argv[0]);\ |
| 39 | exit(1);\ | 46 | exit(1);\ |
| 40 | }\ | 47 | }\ |
| 41 | char * thisProgram = argv[1];\ | 48 | char * thisProgram = argv[1];\ |
| 42 | int maxJobs = atoi(argv[2]);\ | 49 | int maxJobs = atoi(argv[2]);\ |
| 43 | char * thisCore = argv[3];\ | 50 | unsigned int thisCore = atoi(argv[3]);\ |
| 44 | char * otherCore = argv[4];\ | 51 | unsigned int otherCore = atoi(argv[4]);\ |
| 52 | thisCore = sched_getcpu();\ | ||
| 45 | char * otherProgram = argv[5];\ | 53 | char * otherProgram = argv[5];\ |
| 46 | char * runID = argv[6];\ | 54 | char * runID = argv[6];\ |
| 47 | int lockID = atoi(argv[7]);\ | 55 | int lockID = atoi(argv[7]);\ |
| 48 | struct timespec start, end;\ | 56 | struct timespec _start, _end;\ |
| 49 | int jobsComplete;\ | 57 | int jobsComplete;\ |
| 58 | int jobs_complete = -1;\ | ||
| 50 | long * startS = malloc(sizeof(long) *maxJobs);\ | 59 | long * startS = malloc(sizeof(long) *maxJobs);\ |
| 51 | long * startN = malloc(sizeof(long) *maxJobs);\ | 60 | long * startN = malloc(sizeof(long) *maxJobs);\ |
| 52 | long * endS = malloc(sizeof(long) *maxJobs);\ | 61 | long * endS = malloc(sizeof(long) *maxJobs);\ |
| @@ -81,14 +90,19 @@ | |||
| 81 | perror("Error mapping shared memory");\ | 90 | perror("Error mapping shared memory");\ |
| 82 | exit(1);\ | 91 | exit(1);\ |
| 83 | }\ | 92 | }\ |
| 84 | int error;\ | ||
| 85 | int val; | 93 | int val; |
| 86 | 94 | ||
| 87 | #define SAVE_RESULTS if (jobsComplete > -1){\ | 95 | #define SAVE_RESULTS \ |
| 88 | startS[jobsComplete]=start.tv_sec;\ | 96 | if(jobs_complete >= maxJobs) {\ |
| 89 | startN[jobsComplete]=start.tv_nsec;\ | 97 | fprintf(stderr, "Max jobs setting too small! Trying to record job #%d when we only have space for %d jobs. Exiting...\n", jobs_complete, maxJobs);\ |
| 90 | endS[jobsComplete]=end.tv_sec;\ | 98 | exit(1);\ |
| 91 | endN[jobsComplete]=end.tv_nsec;} | 99 | }\ |
| 100 | if (jobs_complete > -1){\ | ||
| 101 | startS[jobs_complete]=_start.tv_sec;\ | ||
| 102 | startN[jobs_complete]=_start.tv_nsec;\ | ||
| 103 | endS[jobs_complete]=_end.tv_sec;\ | ||
| 104 | endN[jobs_complete]=_end.tv_nsec;\ | ||
| 105 | } | ||
| 92 | 106 | ||
| 93 | #define WRITE_TO_FILE {\ | 107 | #define WRITE_TO_FILE {\ |
| 94 | munlockall();\ | 108 | munlockall();\ |
| @@ -97,11 +111,11 @@ | |||
| 97 | perror("Error opening file. \n");\ | 111 | perror("Error opening file. \n");\ |
| 98 | exit(1);\ | 112 | exit(1);\ |
| 99 | }\ | 113 | }\ |
| 100 | for(jobsComplete=0; jobsComplete<maxJobs; jobsComplete++){\ | 114 | for(int i = 0; i <= jobs_complete; i++){\ |
| 101 | fprintf(fp, "%s %s %s %s %d %ld %ld %ld %ld %s %d \n",\ | 115 | fprintf(fp, "%s %s %u %u %d %ld %ld %ld %ld %s %d \n",\ |
| 102 | thisProgram, otherProgram, thisCore, otherCore, maxJobs,\ | 116 | thisProgram, otherProgram, thisCore, otherCore, maxJobs,\ |
| 103 | startS[jobsComplete], startN[jobsComplete], endS[jobsComplete], endN[jobsComplete],\ | 117 | startS[i], startN[i], endS[i], endN[i],\ |
| 104 | runID, jobsComplete);\ | 118 | runID, i);\ |
| 105 | }\ | 119 | }\ |
| 106 | fclose(fp);\ | 120 | fclose(fp);\ |
| 107 | /* Clean up the barrier synchronization shared memory */\ | 121 | /* Clean up the barrier synchronization shared memory */\ |
| @@ -127,8 +141,8 @@ | |||
| 127 | fclose(fp); | 141 | fclose(fp); |
| 128 | 142 | ||
| 129 | // These timers should just be aliases to the hardware counters w/ some small adjustments | 143 | // These timers should just be aliases to the hardware counters w/ some small adjustments |
| 130 | #define START_TIMER clock_gettime(CLOCK_MONOTONIC, &start); | 144 | #define START_TIMER clock_gettime(CLOCK_MONOTONIC, &_start); |
| 131 | #define STOP_TIMER clock_gettime(CLOCK_MONOTONIC, &end); | 145 | #define STOP_TIMER clock_gettime(CLOCK_MONOTONIC, &_end); |
| 132 | 146 | ||
| 133 | //check value of sem | 147 | //check value of sem |
| 134 | //if sem=0, unlock | 148 | //if sem=0, unlock |
| @@ -176,8 +190,8 @@ | |||
| 176 | __sync_bool_compare_and_swap(barrier, 1, 0);\ | 190 | __sync_bool_compare_and_swap(barrier, 1, 0);\ |
| 177 | } | 191 | } |
| 178 | 192 | ||
| 179 | #define START_LOOP FIRST_UNLOCK FIRST_LOCK FLUSH_CACHES BARRIER_SYNC START_TIMER | 193 | #define START_LOOP FIRST_UNLOCK FIRST_LOCK sched_yield(); FLUSH_CACHES BARRIER_SYNC START_TIMER |
| 180 | #define STOP_LOOP STOP_TIMER SAVE_RESULTS | 194 | #define STOP_LOOP STOP_TIMER jobs_complete++; SAVE_RESULTS |
| 181 | 195 | ||
| 182 | 196 | ||
| 183 | /* | 197 | /* |
| @@ -186,7 +200,7 @@ Intended structure | |||
| 186 | main | 200 | main |
| 187 | SET_UP | 201 | SET_UP |
| 188 | notice that STOP LOOP negates the ++ if outout=0 | 202 | notice that STOP LOOP negates the ++ if outout=0 |
| 189 | for (jobsComplete=-1; jobsComplete<maxJobs; jobsComplete++){ | 203 | for (jobsComplete=0; jobsComplete<maxJobs; jobsComplete++){ |
| 190 | START_LOOP | 204 | START_LOOP |
| 191 | tacleInit(); | 205 | tacleInit(); |
| 192 | tacleMain(); | 206 | tacleMain(); |
