From 92df3dcae6747e4410574e7bf1f14dd1c07c3471 Mon Sep 17 00:00:00 2001 From: leochanj105 Date: Fri, 29 Oct 2021 03:40:38 -0400 Subject: tmp 10/29 --- extra.h | 163 ++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 101 insertions(+), 62 deletions(-) (limited to 'extra.h') diff --git a/extra.h b/extra.h index a16c671..a4a3d9c 100644 --- a/extra.h +++ b/extra.h @@ -30,7 +30,7 @@ extern int sched_getcpu(); #endif // This is a proxy for "case study mode" now -#define LITMUS 1 +#define LITMUS 0 #define MMDC_PROF 0 #if LITMUS @@ -44,12 +44,12 @@ extern int sched_getcpu(); // Store state globally so that the job can be outside main() // Arrays use float as a comprimise between overflow and size // Paired arrays use long longs as precision is more important for those times -#ifdef PAIRED +// #ifdef PAIRED long long *_rt_start_time; long long *_rt_end_time; -#else +// #else float *_rt_exec_time; -#endif +// #endif #if MMDC_PERF float *_rt_mmdc_read; float *_rt_mmdc_write; @@ -60,6 +60,8 @@ int _rt_core; int _rt_will_output; struct timespec _rt_start, _rt_end; +int first_job; + char *_rt_run_id; char *_rt_our_prog_name; char *_rt_other_prog_name; @@ -79,15 +81,18 @@ char _rt_shm_name[_ID_SZ] = "/_libextra_barrier-"; #if LITMUS lt_t _rt_period; int _rt_crit; +lt_t _rt_phase; +lt_t _rt_cost; +lt_t _rt_deadline; struct control_page *_rt_cp; #endif static void _rt_load_params_itrl(int argc, char **argv) { #ifdef PAIRED - if (argc != (8 + LITMUS*2) && argc != (9 + LITMUS*2)) { + if (argc != (8 + LITMUS*5) && argc != (9 + LITMUS*5)) { fprintf(stderr, "Usage: %s \n", argv[0]); #else - if (argc != (6 + LITMUS*2)) { + if (argc != (6 + LITMUS*5)) { fprintf(stderr, "Usage: %s \n", argv[0]); #endif /* PAIRED */ fprintf(stderr, " string for logging. Name of this task.\n"); @@ -105,6 +110,9 @@ static void _rt_load_params_itrl(int argc, char **argv) { #if LITMUS fprintf(stderr, " in ms\n"); fprintf(stderr, " 0 for Level-A, 1 for Level-B, 2 for Level-C\n"); + fprintf(stderr, " in ms\n"); + fprintf(stderr, " in ms\n"); + fprintf(stderr, " in ms\n"); #endif /* LITMUS */ exit(1); } @@ -144,18 +152,23 @@ static void _rt_load_params_itrl(int argc, char **argv) { fprintf(stderr, "Run ID is too large! Keep it to less than %d characters.\n", _RT_FILENAME_LEN); exit(1); } -#ifdef PAIRED - // __rt_sem2_name happens to be the longest - if (strlen(pairId) + strlen(_rt_sem2_name) > _ID_SZ) { - fprintf(stderr, "PairID is too long! Maximum length is %ld characters.\n", _ID_SZ - strlen(_rt_sem2_name)); - exit(1); - } _rt_start_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(long long)); _rt_end_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(long long)); if (!_rt_end_time || !_rt_start_time) { perror("Unable to allocate buffers for execution times"); exit(1); } + _rt_exec_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(float)); + if (!_rt_exec_time) { + perror("Unable to allocate buffer for execution times"); + exit(1); + } +#ifdef PAIRED + // __rt_sem2_name happens to be the longest + if (strlen(pairId) + strlen(_rt_sem2_name) > _ID_SZ) { + fprintf(stderr, "PairID is too long! Maximum length is %ld characters.\n", _ID_SZ - strlen(_rt_sem2_name)); + exit(1); + } // Use PairID to create unique semaphore and shared memory paths strcat(_rt_sem1_name, pairId); strcat(_rt_sem2_name, pairId); @@ -194,18 +207,18 @@ static void _rt_load_params_itrl(int argc, char **argv) { exit(1); } *_rt_barrier = 0; -#else - _rt_exec_time = calloc(_rt_max_jobs * _rt_will_output, sizeof(float)); - if (!_rt_exec_time) { - perror("Unable to allocate buffer for execution times"); - exit(1); - } +// #else + #endif /* PAIRED */ _rt_jobs_complete = 0; + first_job = 1; mlockall(MCL_CURRENT || MCL_FUTURE); #if LITMUS _rt_period = ms2ns(strtoul(argv[end], NULL, 10)); _rt_crit = atoi(argv[end+1]); + _rt_phase = ms2ns(strtoul(argv[end+2], NULL, 10)); + _rt_cost = ms2ns(strtoul(argv[end+3], NULL, 10)); + _rt_deadline = ms2ns(strtoul(argv[end+4], NULL, 10)); unsigned int wait = 1; if (be_migrate_to_domain(_rt_core) < 0) { perror("Unable to migrate to specified CPU"); @@ -214,10 +227,10 @@ static void _rt_load_params_itrl(int argc, char **argv) { struct rt_task rt_param; init_rt_task_param(&rt_param); // Fake exec cost - this value ignored by the MC^2 scheduler - rt_param.exec_cost = _rt_period; + rt_param.exec_cost = _rt_cost; rt_param.period = _rt_period; - rt_param.relative_deadline = 0; - rt_param.phase = 0; + rt_param.relative_deadline = _rt_deadline; + rt_param.phase = _rt_phase; rt_param.priority = LITMUS_LOWEST_PRIORITY; rt_param.cls = _rt_crit; rt_param.budget_policy = NO_ENFORCEMENT; @@ -236,10 +249,10 @@ static void _rt_load_params_itrl(int argc, char **argv) { exit(1); } _rt_cp = get_ctrl_page(); - if (wait && wait_for_ts_release() != 0) { - perror("Unable to wait for taskset release"); - exit(1); - } + // if (wait && wait_for_ts_release() != 0) { + // perror("Unable to wait for taskset release"); + // exit(1); + // } #endif /* LITMUS */ #if MMDC_PROF SETUP_MMDC @@ -337,18 +350,18 @@ static void _rt_save_job_result() { fprintf(stderr, "Max jobs setting too small! Trying to record job #%ld when we only have space for %ld jobs. Exiting...\n", _rt_jobs_complete, _rt_max_jobs); exit(1); } -#ifdef PAIRED +// #ifdef PAIRED _rt_start_time[_rt_jobs_complete] = _rt_start.tv_sec; _rt_start_time[_rt_jobs_complete] *= _BILLION; _rt_start_time[_rt_jobs_complete] += _rt_start.tv_nsec; _rt_end_time[_rt_jobs_complete] = _rt_end.tv_sec; _rt_end_time[_rt_jobs_complete] *= _BILLION; _rt_end_time[_rt_jobs_complete] += _rt_end.tv_nsec; -#else +// #else _rt_exec_time[_rt_jobs_complete] = _rt_end.tv_sec - _rt_start.tv_sec; _rt_exec_time[_rt_jobs_complete] *= _BILLION; _rt_exec_time[_rt_jobs_complete] += _rt_end.tv_nsec - _rt_start.tv_nsec; -#endif /* PAIRED */ +// #endif /* PAIRED */ #if MMDC_PROF _rt_mmdc_read[_rt_jobs_complete] = mmdc_res.read_bytes; _rt_mmdc_write[_rt_jobs_complete] = mmdc_res.write_bytes; @@ -373,14 +386,14 @@ static void _rt_write_to_file() { for (int i = 0; i < _rt_jobs_complete; i++){ fprintf(fp, "%s %s %u %s %ld", _rt_our_prog_name, _rt_other_prog_name, _rt_core, _rt_other_core, _rt_max_jobs); -#ifdef PAIRED +// #ifdef PAIRED // For unclear legacy reasons, paired tasks emit sec and ns separately fprintf(fp, " %lld %lld %lld %lld", _rt_start_time[i] / _BILLION, _rt_start_time[i] % _BILLION, _rt_end_time[i] / _BILLION, _rt_end_time[i] % _BILLION); -#else +// #else fprintf(fp, " %.f", _rt_exec_time[i]); -#endif /* PAIRED */ +// #endif /* PAIRED */ fprintf(fp, " %s %d %.f %.f\n", _rt_run_id, i, #if MMDC_PROF _rt_mmdc_read[i], _rt_mmdc_write[i]); @@ -390,12 +403,12 @@ static void _rt_write_to_file() { } fclose(fp); out: -#if LITMUS - if (task_mode(BACKGROUND_TASK) != 0) { - perror("Unable to become a real-time task"); - exit(1); - } -#endif /* LITMUS */ +// #if LITMUS +// if (task_mode(BACKGROUND_TASK) != 0) { +// perror("Unable to become a real-time task"); +// exit(1); +// } +// #endif /* LITMUS */ #ifdef PAIRED munmap(_rt_barrier, 2); sem_unlink(_rt_sem1_name); @@ -414,41 +427,45 @@ out: // Start a job static void _rt_start_loop() { -#if LITMUS - static lt_t last = 0; - lt_t now = litmus_clock(); - if (now > _rt_cp->deadline) { - fprintf(stderr, "(%s/%d:%lu) ", _rt_our_prog_name, gettid(), _rt_cp->job_index); - if (_rt_crit == 0) - fprintf(stderr, "CATASTROPHIC: Level-A"); - else if (_rt_crit == 1) - fprintf(stderr, "HAZARDOUS: Level-B"); - else - fprintf(stderr, "MAJOR: Level-C"); - fprintf(stderr, " tardy %llu ns, " - "relative tardiness %f\n", - now - _rt_cp->deadline, - (now - _rt_cp->deadline) / (double)_rt_period); + // Let the first job run before synchrnous release --- make sure we have no further page faults + if(first_job == 1){ + // FLUSH_CACHES + return; } - if (last == 0) { - last = now; - } else if (now > last + 60ull * _BILLION && _rt_crit >= 2) { - last = now; - fprintf(stderr, "(%s/%d:%lu) Ping\n", _rt_our_prog_name, gettid(), _rt_cp->job_index); +#if LITMUS + // static lt_t last = 0; + if (_rt_jobs_complete == 0) { + if(wait_for_ts_release() != 0){ + perror("Unable to wait for taskset release"); + exit(1); + } } - if (sleep_next_period() != 0) { - perror("Unable to sleep for next period"); + else{ + if (sleep_next_period() != 0) { + perror("Unable to sleep for next period"); + } } + + // if (last == 0) { + // last = now; + // } else if (now > last + 60ull * _BILLION && _rt_crit >= 2) { + // last = now; + // fprintf(stderr, "(%s/%d:%lu) Ping\n", _rt_our_prog_name, gettid(), _rt_cp->job_index); + // } + // if (sleep_next_period() != 0) { + // perror("Unable to sleep for next period"); + // } #else sched_yield(); + // sleep(1); #endif /* LITMUS */ #ifdef PAIRED FIRST_UNLOCK FIRST_LOCK #endif /* PAIRED */ -#if !LITMUS +// #if !LITMUS FLUSH_CACHES -#endif +// #endif #ifdef PAIRED BARRIER_SYNC #endif /* PAIRED */ @@ -462,13 +479,35 @@ static void _rt_start_loop() { // Complete a job static void _rt_stop_loop() { clock_gettime(CLOCK_MONOTONIC, &_rt_end); + // Set first_job == 0 + if(first_job == 1){ + first_job = 0; + return; + } #if MMDC_PROF /* This freezes the profiling and makes results available */ pause_mmdc_profiling(mmdc); get_mmdc_profiling_results(mmdc, &mmdc_res); #endif /* MMDC_PROF */ _rt_save_job_result(); - _rt_jobs_complete++; +#if LITMUS + long long end = _rt_end_time[_rt_jobs_complete]; + if (end > _rt_cp->deadline) { + fprintf(stderr, "(%s/%d:%lu) ", _rt_our_prog_name, gettid(), _rt_cp->job_index); + fprintf(stderr, "tardy %llu ns, relative tardiness %f\n", end - _rt_cp->deadline, (end - _rt_cp->deadline) / (double)_rt_deadline); + } +#endif + _rt_jobs_complete++; +#if LITMUS + if(_rt_jobs_complete == _rt_max_jobs){ + // fprintf(stderr, "complete %s: %d\n" , _rt_our_prog_name, _rt_jobs_complete); + if (task_mode(BACKGROUND_TASK) != 0) { + perror("Unable to become background task"); + exit(1); + } + } +#endif + } /****** New API ****** -- cgit v1.2.2