From a71fc97fd262e1b5770f827047ea60bbaf38d9a2 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 19 Oct 2020 01:09:53 -0400 Subject: Unify all the versions of extra.h into a single multipurpose header There was previously a huge amount of shared code that had to be copied back and forth. This should reduce the maintenance burden by containing all future changes to a single file. New unified library is fully backwards-compatible but also introduces and the easy-to-use `for_each_job` macro which replaces the specific `for(...) START_LOOP ... STOP_LOOP` format requirement and is generally much harder to abuse. New unified library also automatically cleans up its shared memory and semaphores, so this commit also removes the separate `cleanupSemaphores` binary. I also found a precursor of `extra.h` written by Sims in `litmusStuff.h`. This code is only interesting for historical purposes, so it is also removed in this commit. This commit also adds debug options to all the Makefiles and silences rm's complaints about non-existent files in make clean. --- all_pairs/source/adpcm_dec/adpcm_dec.c | 2 +- all_pairs/source/adpcm_enc/adpcm_enc.c | 2 +- all_pairs/source/ammunition/ammunition.c | 2 +- all_pairs/source/anagram/anagram.c | 2 +- all_pairs/source/audiobeam/audiobeam.c | 2 +- all_pairs/source/cjpeg_transupp/cjpeg_transupp.c | 2 +- all_pairs/source/cjpeg_wrbmp/cjpeg_wrbmp.c | 2 +- all_pairs/source/cleanupSemaphores.c | 6 - all_pairs/source/dijkstra/dijkstra.c | 2 +- all_pairs/source/empty.c | 2 +- all_pairs/source/epic/epic.c | 2 +- all_pairs/source/extra.h | 211 ----------------------- all_pairs/source/fmref/fmref.c | 2 +- all_pairs/source/g723_enc/g723_enc.c | 2 +- all_pairs/source/gsm_dec/gsm_dec.c | 2 +- all_pairs/source/gsm_enc/gsm_enc.c | 2 +- all_pairs/source/h264_dec/h264_dec.c | 2 +- all_pairs/source/huff_dec/huff_dec.c | 2 +- all_pairs/source/huff_enc/huff_enc.c | 2 +- all_pairs/source/mpeg2/mpeg2.c | 2 +- all_pairs/source/ndes/ndes.c | 2 +- all_pairs/source/petrinet/petrinet.c | 2 +- all_pairs/source/rijndael_dec/rijndael_dec.c | 2 +- all_pairs/source/rijndael_enc/rijndael_enc.c | 2 +- all_pairs/source/statemate/statemate.c | 2 +- all_pairs/source/susan/susan.c | 2 +- 26 files changed, 24 insertions(+), 241 deletions(-) delete mode 100644 all_pairs/source/cleanupSemaphores.c delete mode 100644 all_pairs/source/extra.h (limited to 'all_pairs/source') diff --git a/all_pairs/source/adpcm_dec/adpcm_dec.c b/all_pairs/source/adpcm_dec/adpcm_dec.c index 04a5746..368e98d 100644 --- a/all_pairs/source/adpcm_dec/adpcm_dec.c +++ b/all_pairs/source/adpcm_dec/adpcm_dec.c @@ -35,7 +35,7 @@ Forward declaration of functions */ -#include "../extra.h" +#include "extra.h" void adpcm_dec_decode( int ); int adpcm_dec_filtez( int *bpl, int *dlt ); diff --git a/all_pairs/source/adpcm_enc/adpcm_enc.c b/all_pairs/source/adpcm_enc/adpcm_enc.c index 464768f..777aaf5 100644 --- a/all_pairs/source/adpcm_enc/adpcm_enc.c +++ b/all_pairs/source/adpcm_enc/adpcm_enc.c @@ -29,7 +29,7 @@ /* common sampling rate for sound cards on IBM/PC */ -#include "../extra.h" +#include "extra.h" #define SAMPLE_RATE 11025 #define PI 3141 diff --git a/all_pairs/source/ammunition/ammunition.c b/all_pairs/source/ammunition/ammunition.c index 269f4c0..052520e 100644 --- a/all_pairs/source/ammunition/ammunition.c +++ b/all_pairs/source/ammunition/ammunition.c @@ -24,7 +24,7 @@ */ -#include "../extra.h" +#include "extra.h" #include "bits.h" #include "arithm.h" #include "ammunition_stdlib.h" diff --git a/all_pairs/source/anagram/anagram.c b/all_pairs/source/anagram/anagram.c index b458fd2..5c1f29a 100644 --- a/all_pairs/source/anagram/anagram.c +++ b/all_pairs/source/anagram/anagram.c @@ -157,7 +157,7 @@ steps to FindAnagram. */ -#include "../extra.h" +#include "extra.h" #include "anagram_ctype.h" #include "anagram_stdlib.h" #include "anagram_strings.h" diff --git a/all_pairs/source/audiobeam/audiobeam.c b/all_pairs/source/audiobeam/audiobeam.c index 208de80..50ebfff 100644 --- a/all_pairs/source/audiobeam/audiobeam.c +++ b/all_pairs/source/audiobeam/audiobeam.c @@ -23,7 +23,7 @@ Include section */ -#include "../extra.h" +#include "extra.h" #include "audiobeamlibm.h" #include "audiobeamlibmalloc.h" #include "audiobeam.h" diff --git a/all_pairs/source/cjpeg_transupp/cjpeg_transupp.c b/all_pairs/source/cjpeg_transupp/cjpeg_transupp.c index 3f48539..5ec7e5e 100644 --- a/all_pairs/source/cjpeg_transupp/cjpeg_transupp.c +++ b/all_pairs/source/cjpeg_transupp/cjpeg_transupp.c @@ -29,7 +29,7 @@ Include section */ -#include "../extra.h" +#include "extra.h" #include "jpeglib.h" diff --git a/all_pairs/source/cjpeg_wrbmp/cjpeg_wrbmp.c b/all_pairs/source/cjpeg_wrbmp/cjpeg_wrbmp.c index 278725c..3c8d7ec 100644 --- a/all_pairs/source/cjpeg_wrbmp/cjpeg_wrbmp.c +++ b/all_pairs/source/cjpeg_wrbmp/cjpeg_wrbmp.c @@ -24,7 +24,7 @@ */ -#include "../extra.h" +#include "extra.h" #include "cdjpeg.h" #ifdef CJPEG_WRBMP_BMP_SUPPORTED diff --git a/all_pairs/source/cleanupSemaphores.c b/all_pairs/source/cleanupSemaphores.c deleted file mode 100644 index dde2bb3..0000000 --- a/all_pairs/source/cleanupSemaphores.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(){ - sem_unlink("/firstTacleSem"); - sem_unlink("/secondTacleSem"); -} diff --git a/all_pairs/source/dijkstra/dijkstra.c b/all_pairs/source/dijkstra/dijkstra.c index 1b6a52f..333fd43 100644 --- a/all_pairs/source/dijkstra/dijkstra.c +++ b/all_pairs/source/dijkstra/dijkstra.c @@ -17,7 +17,7 @@ */ -#include "../extra.h" +#include "extra.h" #include "input.h" /* diff --git a/all_pairs/source/empty.c b/all_pairs/source/empty.c index c7c5f5d..6681ba7 100644 --- a/all_pairs/source/empty.c +++ b/all_pairs/source/empty.c @@ -1,4 +1,4 @@ -#include "../extra.h" +#include "extra.h" int main(int argc, char **argv) { diff --git a/all_pairs/source/epic/epic.c b/all_pairs/source/epic/epic.c index e258a4a..a1e344c 100644 --- a/all_pairs/source/epic/epic.c +++ b/all_pairs/source/epic/epic.c @@ -35,7 +35,7 @@ */ -#include "../extra.h" +#include "extra.h" #include "epic.h" #define X_SIZE 64 diff --git a/all_pairs/source/extra.h b/all_pairs/source/extra.h deleted file mode 100644 index 0681250..0000000 --- a/all_pairs/source/extra.h +++ /dev/null @@ -1,211 +0,0 @@ -/** - * 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. - **/ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// This is only visible if _GNU_SOURCE is defined, and that define does not -// come along to places where this file is included. Address this by manually -// forcing it into the global namespace. -extern int sched_getcpu(); - -// 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]);\ - unsigned int thisCore = atoi(argv[3]);\ - unsigned int otherCore = atoi(argv[4]);\ - thisCore = sched_getcpu();\ - char * otherProgram = argv[5];\ - char * runID = argv[6];\ - int lockID = atoi(argv[7]);\ - struct timespec _start, _end;\ - int jobsComplete;\ - int jobs_complete = -1;\ - 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 val; - -#define SAVE_RESULTS \ - if(jobs_complete >= maxJobs) {\ - 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);\ - exit(1);\ - }\ - if (jobs_complete > -1){\ - startS[jobs_complete]=_start.tv_sec;\ - startN[jobs_complete]=_start.tv_nsec;\ - endS[jobs_complete]=_end.tv_sec;\ - endN[jobs_complete]=_end.tv_nsec;\ - } - -#define WRITE_TO_FILE {\ - munlockall();\ - FILE *fp = fopen(fileName, "a");\ - if (fp == NULL) {\ - perror("Error opening file. \n");\ - exit(1);\ - }\ - for(int i = 0; i <= jobs_complete; i++){\ - fprintf(fp, "%s %s %u %u %d %ld %ld %ld %ld %s %d \n",\ - thisProgram, otherProgram, thisCore, otherCore, maxJobs,\ - startS[i], startN[i], endS[i], endN[i],\ - runID, i);\ - }\ - fclose(fp);\ - /* Clean up the barrier synchronization shared memory */\ - munmap(barrier, 1);\ - shm_unlink("/TacleBarrier");\ - free(startS);\ - free(startN);\ - free(endS);\ - free(endN);\ -} - -// Call the wbinvld instruction (it's in a kernel module due to it being ring-0) -#define FLUSH_CACHES FILE *fp = fopen("/proc/wbinvd", "r");\ - if (fp == NULL) {\ - perror("Cache flush module interface cannot be opened");\ - exit(1);\ - }\ - char dummy;\ - if (fread(&dummy, 1, 1, fp) == 0) {\ - perror("Unable to access cache flush module interface");\ - exit(1);\ - }\ - fclose(fp); - -// These timers should just be aliases to the hardware counters w/ some small adjustments -#define START_TIMER clock_gettime(CLOCK_MONOTONIC, &_start); -#define STOP_TIMER clock_gettime(CLOCK_MONOTONIC, &_end); - -//check value of sem -//if sem=0, unlock -//if sem=1, spin - -#define SLEEP nanosleep((const struct timespec[]){{0, 1000000}}, NULL); - -#define FIRST_UNLOCK if (lockID == 1) {\ - if (sem_post(secondSem) != 0) {\ - perror("Unable to unlock second semaphore");\ - exit(1);\ - }\ - } \ - else {\ - if (sem_post(firstSem) != 0) {\ - perror("Unable to unlock first semaphore");\ - exit(1);\ - }\ - } \ - -#define FIRST_LOCK if (lockID == 1) {\ - if (sem_wait(firstSem) != 0) {\ - perror("Unable to wait on first semaphore");\ - exit(1);\ - }\ - }\ - else {\ - if (sem_wait(secondSem) != 0) {\ - perror("Unable to wait on second semaphore");\ - exit(1);\ - }\ - } - - -#define SECOND_UNLOCK if (lockID==1){sem_post(fourthSem) ; }\ - else {sem_post(thirdSem) ; } - -#define SECOND_LOCK if (lockID==1){sem_wait(thirdSem); }\ - else {sem_wait(fourthSem); } - -#define BARRIER_SYNC if (__sync_bool_compare_and_swap(barrier, 0, 1)) {\ - while (!__sync_bool_compare_and_swap(barrier, 0, 0)) {};\ - }\ - else {\ - __sync_bool_compare_and_swap(barrier, 1, 0);\ - } - -#define START_LOOP FIRST_UNLOCK FIRST_LOCK sched_yield(); FLUSH_CACHES BARRIER_SYNC START_TIMER -#define STOP_LOOP STOP_TIMER jobs_complete++; SAVE_RESULTS - - -/* -Intended structure - -main -SET_UP -notice that STOP LOOP negates the ++ if outout=0 -for (jobsComplete=0; jobsComplete diff --git a/all_pairs/source/rijndael_dec/rijndael_dec.c b/all_pairs/source/rijndael_dec/rijndael_dec.c index 93bb424..61db767 100644 --- a/all_pairs/source/rijndael_dec/rijndael_dec.c +++ b/all_pairs/source/rijndael_dec/rijndael_dec.c @@ -38,7 +38,7 @@ ----------------------------------------------------------------------- */ -#include "../extra.h" +#include "extra.h" #include "aes.h" #include "rijndael_dec_libc.h" diff --git a/all_pairs/source/rijndael_enc/rijndael_enc.c b/all_pairs/source/rijndael_enc/rijndael_enc.c index 0c10353..6c85eee 100644 --- a/all_pairs/source/rijndael_enc/rijndael_enc.c +++ b/all_pairs/source/rijndael_enc/rijndael_enc.c @@ -38,7 +38,7 @@ ----------------------------------------------------------------------- */ -#include "../extra.h" +#include "extra.h" #include "aes.h" #include "rijndael_enc_libc.h" diff --git a/all_pairs/source/statemate/statemate.c b/all_pairs/source/statemate/statemate.c index 00491e5..888d0fa 100644 --- a/all_pairs/source/statemate/statemate.c +++ b/all_pairs/source/statemate/statemate.c @@ -27,7 +27,7 @@ Macro definitions */ -#include "../extra.h" +#include "extra.h" #define SYS_bit_get(a,b) (a)[(b)] #define SYS_bit_clr(a,b) (a)[(b)] = 0 diff --git a/all_pairs/source/susan/susan.c b/all_pairs/source/susan/susan.c index 4bc4cb8..dc27fb1 100644 --- a/all_pairs/source/susan/susan.c +++ b/all_pairs/source/susan/susan.c @@ -269,7 +269,7 @@ \**********************************************************************/ -#include "../extra.h" +#include "extra.h" #include "wcclibm.h" #include "wccfile.h" #include "wccmalloc.h" -- cgit v1.2.2