From 917499f6257ac51c05e8302af877d56a22f28cb5 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Sat, 17 Oct 2020 00:52:09 -0400 Subject: Cleanup in extra.h for non-paired benchmarks - No parameter or output format changes - Better error messages - Auto-detect core - Fix off-by-one error in job counting - Explicitly invoke the scheduler with sched_yield() between jobs so that there's less work to do when (if) the scheduling timer interrupt comes around. (This has a surprisingly significant impact on timings.) --- baseline/source/adpcm_dec/adpcm_dec.c | 2 +- baseline/source/adpcm_enc/adpcm_enc.c | 2 +- baseline/source/ammunition/ammunition.c | 2 +- baseline/source/anagram/anagram.c | 2 +- baseline/source/audiobeam/audiobeam.c | 2 +- baseline/source/cjpeg_transupp/cjpeg_transupp.c | 2 +- baseline/source/cjpeg_wrbmp/cjpeg_wrbmp.c | 2 +- baseline/source/dijkstra/dijkstra.c | 2 +- baseline/source/epic/epic.c | 2 +- baseline/source/extra.h | 40 +++++++++++++++++-------- baseline/source/fmref/fmref.c | 2 +- baseline/source/g723_enc/g723_enc.c | 2 +- baseline/source/gsm_dec/gsm_dec.c | 2 +- baseline/source/gsm_enc/gsm_enc.c | 2 +- baseline/source/h264_dec/h264_dec.c | 2 +- baseline/source/huff_dec/huff_dec.c | 2 +- baseline/source/huff_enc/huff_enc.c | 2 +- baseline/source/mpeg2/mpeg2.c | 2 +- baseline/source/ndes/ndes.c | 2 +- baseline/source/petrinet/petrinet.c | 2 +- baseline/source/rijndael_dec/rijndael_dec.c | 2 +- baseline/source/rijndael_enc/rijndael_enc.c | 2 +- baseline/source/statemate/statemate.c | 2 +- baseline/source/susan/susan.c | 2 +- 24 files changed, 51 insertions(+), 35 deletions(-) diff --git a/baseline/source/adpcm_dec/adpcm_dec.c b/baseline/source/adpcm_dec/adpcm_dec.c index 6811e69..04a5746 100644 --- a/baseline/source/adpcm_dec/adpcm_dec.c +++ b/baseline/source/adpcm_dec/adpcm_dec.c @@ -708,7 +708,7 @@ void _Pragma( "entrypoint" ) adpcm_dec_main( void ) int main(int argc, char **argv) { SET_UP - for (jobsComplete=-1; jobsComplete #include #include @@ -12,6 +13,12 @@ #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(); // These constants correspond to the imx6q-sabredb platform #define LINE_SIZE 32 @@ -47,15 +54,24 @@ #endif #define LOAD_PARAMS_ITRL \ - if (argc < 6) { \ - printf("Usage: %s \n", argv[0]);\ + if (argc != 6) { \ + fprintf(stderr, "Usage: %s \n", argv[0]);\ + fprintf(stderr, " integer number of iterations. -1 for infitite.\n");\ + fprintf(stderr, " 1 to save results, 0 to discard.\n");\ exit(1);\ }\ char *thisProgram=argv[1];\ - int maxJobs=atoi(argv[2]);\ - char *thisCore=argv[3];\ + int parsedMaxJobs=atoi(argv[2]);\ + unsigned int thisCore=atoi(argv[3]);\ + thisCore = sched_getcpu();\ char *runID=argv[4];\ int output=atoi(argv[5]);\ + if (parsedMaxJobs < 0 && output != 0){\ + fprintf(stderr, "Infinite loops only supported when output is disabled!\n");\ + exit(1);\ + }\ + /* Cheat. -1 is larger than jobsComplete can ever reach. */\ + unsigned int maxJobs = parsedMaxJobs;\ struct timespec _start, _end;\ int jobsComplete;\ int jobs_complete = -1;\ @@ -163,10 +179,10 @@ #if MMDC_PROF #define SAVE_RESULTS \ if(jobs_complete >= maxJobs) {\ - fprintf(stderr, "Max jobs setting too small! Exiting...\n");\ + 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 && output) {\ + if(jobs_complete > -1 && output) {\ progTime[jobs_complete] = _end.tv_sec - _start.tv_sec;\ progTime[jobs_complete] *= 1000000000;\ progTime[jobs_complete] += _end.tv_nsec - _start.tv_nsec;\ @@ -176,10 +192,10 @@ #else #define SAVE_RESULTS \ if(jobs_complete >= maxJobs) {\ - fprintf(stderr, "Max jobs setting too small! Exiting...\n");\ + 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 && output) {\ + if(jobs_complete > -1 && output) {\ progTime[jobs_complete] = _end.tv_sec - _start.tv_sec;\ progTime[jobs_complete] *= 1000000000;\ progTime[jobs_complete] += _end.tv_nsec - _start.tv_nsec;\ @@ -200,8 +216,8 @@ perror("Unable to open output file");\ exit(1);\ }\ - for(int i = 0; i <= jobs_complete; i++){\ - fprintf(fp, "%s none %s none %d %.f %s %d %.f %.f \n",\ + for (int i = 0; i <= jobs_complete; i++){\ + fprintf(fp, "%s none %u none %d %.f %s %d %.f %.f \n",\ thisProgram, thisCore, maxJobs,\ progTime[i], runID, i, mmdc_read[i], mmdc_write[i]);\ }\ @@ -260,7 +276,7 @@ } \ FLUSH_CACHES START_TIMER #else -#define START_LOOP FLUSH_CACHES START_TIMER +#define START_LOOP sched_yield(); FLUSH_CACHES START_TIMER #endif #define STOP_LOOP STOP_TIMER jobs_complete++; SAVE_RESULTS @@ -272,7 +288,7 @@ Intended structure main SET_UP notice that STOP LOOP negates the ++ if outout=0 -for (jobsComplete=-1; jobsComplete