From 54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 17 Jun 2019 08:45:24 -0400 Subject: Cleanup extra.h for the paired tests --- rtss19/extra.h | 82 ++++++++++++++++++++++++---------------------------------- 1 file 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 @@ -#include -#include -#include -#include +/** + * 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 +#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);\ @@ -101,29 +123,16 @@ fread(&dummy, 1, 1, fp);\ fclose(fp); -//invoke start timer twice, stop timer to make sure timer and vars are in cache +// These timers should just be aliases to the hardware counters w/ some small adjustments #define START_TIMER clock_gettime(CLOCK_MONOTONIC, &start); - //clock_gettime(CLOCK_MONOTONIC, &end);\ - //clock_gettime(CLOCK_MONOTONIC, &start);\ - #define STOP_TIMER clock_gettime(CLOCK_MONOTONIC, &end); -#define LOCK2_LOCKED //printf("Lock2 locked. \n"); -#define LOCK1_LOCKED //printf("Lock1 locked. \n"); -#define LOCK1_UNLOCKED //printf("Lock1 unlocked. \n"); -#define LOCK2_UNLOCKED //printf("Lock2 unlocked. \n"); - //check value of sem //if sem=0, unlock //if sem=1, spin #define SLEEP nanosleep((const struct timespec[]){{0, 1000000}}, NULL); -//#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); - - -//#define SAFE_UNLOCK(whichSem) sem_post(whichSem); SLEEP ; printf("Used SAFE_UNLOCK. \n"); - #define FIRST_UNLOCK if (lockID == 1) {\ if (sem_post(secondSem) != 0) {\ perror("Unable to unlock second semaphore");\ @@ -164,29 +173,8 @@ __sync_bool_compare_and_swap(barrier, 1, 0);\ } - -//#define SECOND_UNLOCK if (lockID==1){sem_post(firstSem) ; LOCK1_UNLOCKED }\ - else {sem_post(secondSem) ; LOCK2_UNLOCKED } - -//#define SECOND_LOCK if (lockID==1){sem_wait(secondSem); LOCK2_LOCKED }\ - else {sem_wait(firstSem); LOCK1_LOCKED } - - #define START_LOOP FIRST_UNLOCK FIRST_LOCK FLUSH_CACHES BARRIER_SYNC START_TIMER - - -/* -First task to reach TRY_CACHE will fail, but unlock the lock. -Second task will get the lock and kill the cache. -Lock remains in place until this point is reached again in code. -*/ - -//#define TRY_CACHE if (sem_trywait(cacheSem)==0){KILL_CACHE}\ - else {sem_post(cacheSem);} - -//#define STOP_LOOP STOP_TIMER SAVE_RESULTS //TRY_CACHE - -#define STOP_LOOP STOP_TIMER SAVE_RESULTS //SECOND_UNLOCK SECOND_LOCK KILL_CACHE +#define STOP_LOOP STOP_TIMER SAVE_RESULTS /* @@ -196,12 +184,10 @@ main SET_UP notice that STOP LOOP negates the ++ if outout=0 for (jobsComplete=-1; jobsComplete