From 386b7d3366f1359a265da207a9cafa3edf553b64 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 7 Oct 2019 19:13:39 -0400 Subject: Reorganize and commit all the modified TACLeBench code and run scripts --- all_pairs/source/extra.h | 197 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 all_pairs/source/extra.h (limited to 'all_pairs/source/extra.h') diff --git a/all_pairs/source/extra.h b/all_pairs/source/extra.h new file mode 100644 index 0000000..bdbd1f5 --- /dev/null +++ b/all_pairs/source/extra.h @@ -0,0 +1,197 @@ +/** + * Copyright 2019 Sims Hill Osborne and Joshua Bakita + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + **/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Benchmarks use SET_UP, START_LOOP, STOP_LOOP, and WRITE_TO_FILE +// These are macros so that we can declare and maintain additional state inside +// the benchmark. +#define SET_UP if (argc < 8) {\ + printf("Usage: %s ", argv[0]);\ + exit(1);\ + }\ + char * thisProgram = argv[1];\ + int maxJobs = atoi(argv[2]);\ + char * thisCore = argv[3];\ + char * otherCore = argv[4];\ + char * otherProgram = argv[5];\ + char * runID = argv[6];\ + int lockID = atoi(argv[7]);\ + struct timespec start, end;\ + int jobsComplete;\ + long * startS = malloc(sizeof(long) *maxJobs);\ + long * startN = malloc(sizeof(long) *maxJobs);\ + long * endS = malloc(sizeof(long) *maxJobs);\ + long * endN = malloc(sizeof(long) *maxJobs);\ + char * bigArray;\ + char fileName[strlen(runID) + 5];\ + strcpy(fileName, runID);\ + strcat(fileName, ".txt");\ + mlockall(MCL_CURRENT || MCL_FUTURE);\ + sem_t *firstSem=sem_open("/firstTacleSem", O_CREAT, 644, 0);\ + if (firstSem == SEM_FAILED) {\ + perror("Error opening/creating first semaphore");\ + exit(1);\ + }\ + sem_t *secondSem=sem_open("/secondTacleSem", O_CREAT, 644, 0);\ + if (secondSem == SEM_FAILED) {\ + perror("Error opening/creating second semaphore");\ + exit(1);\ + }\ + int barrier_file = shm_open("/TacleBarrier", O_CREAT | O_RDWR, 644);\ + if (barrier_file == -1) {\ + perror("Error creating shared memory");\ + exit(1);\ + }\ + /* This sets our shared file to be one byte of '\0'*/ \ + if (ftruncate(barrier_file, 1) == -1) {\ + perror("Error setting size of shared memory");\ + exit(1);\ + }\ + char * barrier = mmap(NULL, 1, PROT_WRITE, MAP_SHARED, barrier_file, 0);\ + if (barrier == MAP_FAILED) {\ + perror("Error mapping shared memory");\ + exit(1);\ + }\ + int error;\ + int val; + +#define SAVE_RESULTS if (jobsComplete > -1){\ + startS[jobsComplete]=start.tv_sec;\ + startN[jobsComplete]=start.tv_nsec;\ + endS[jobsComplete]=end.tv_sec;\ + endN[jobsComplete]=end.tv_nsec;} + +#define WRITE_TO_FILE {\ + munlockall();\ + FILE *fp = fopen(fileName, "a");\ + if (fp == NULL) {\ + perror("Error opening file. \n");\ + exit(1);\ + }\ + for(jobsComplete=0; jobsComplete