From c10cfd98cbaba8d0c602d1f790ce8e3b6c2ff40c Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 17 Jun 2019 08:32:41 -0400 Subject: Commit old version of extra.h --- rtss19/extra.h | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 rtss19/extra.h diff --git a/rtss19/extra.h b/rtss19/extra.h new file mode 100644 index 0000000..f089373 --- /dev/null +++ b/rtss19/extra.h @@ -0,0 +1,208 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Benchmarks use SET_UP, START_LOOP, STOP_LOOP, and WRITE_TO_FILE +#define SET_UP if (argc < 8) {\ + printf("Usage: %s ", argv[0]);\ + exit(1);\ + }\ + char * thisProgram = argv[1];\ + unsigned 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;\ + unsigned int jobsComplete = 0;\ + 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 > 0){\ + 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