From 1d4b1533cfaa7b88268294849aaeef54f2a230bc Mon Sep 17 00:00:00 2001 From: Tobias Langer Date: Mon, 14 Nov 2016 10:14:35 +0100 Subject: [PATCH] Added refinement in idle loop and task starting. --- generate.py | 9 +++++++++ templates/normal/experiment.cpp | 35 +++++++++++++++++++++-------------- templates/normal/fun.cpp | 3 +++ templates/normal/fun.h | 1 + templates/normal/timing_header.h | 8 ++++++++ 5 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 templates/normal/fun.cpp create mode 100644 templates/normal/fun.h create mode 100644 templates/normal/timing_header.h diff --git a/generate.py b/generate.py index 7ee6f1a..13cd4da 100755 --- a/generate.py +++ b/generate.py @@ -114,6 +114,9 @@ def main(): header = os.path.join(template_path, 'defines.h') makefile = os.path.join(template_path, 'Makefile') cpp = os.path.join(template_path, 'experiment.cpp') + timewaste_h = os.path.join(template_path, 'fun.h') + timewaste_cpp = os.path.join(template_path, 'fun.cpp') + timetable = os.path.join(template_path, 'timing_header.h') try: output_path = experiment['output'] @@ -145,6 +148,12 @@ def main(): print('Add C++ file(s)…', file=sys.stderr) cpp_file_path = os.path.join(experiment_dir, 'experiment.cpp') shutil.copyfile(cpp, cpp_file_path) + fun_cpp_file_path = os.path.join(experiment_dir, 'fun.cpp') + shutil.copyfile(timewaste_cpp, fun_cpp_file_path) + fun_h_file_path = os.path.join(experiment_dir, 'fun.h') + shutil.copyfile(timewaste_h, fun_h_file_path) + timetable_file_path = os.path.join(experiment_dir, 'timing_header.h') + shutil.copyfile(timetable, timetable_file_path) if __name__ == '__main__': main() diff --git a/templates/normal/experiment.cpp b/templates/normal/experiment.cpp index 5224e6c..0bc763b 100644 --- a/templates/normal/experiment.cpp +++ b/templates/normal/experiment.cpp @@ -8,12 +8,27 @@ #include "defines.h" +#include "timing_header.h" +#include "fun.h" + #define UNUSED(x) ((void)(x)) #define DOMAIN_ID 1 #define NODE_ID 1 #define ACTION_ID 2 +auto loop_count(int duration) -> long long +{ + if(duration < sizeof(timetable) / sizeof(int)) { + return timetable[duration]; + } + + float m = ((float)timetable[94] - (float)timetable[4]) / (90.0f); + float t = ((float)timetable[9] - m * 9); + + return m * (float) duration + t; +} + auto gcd(long long a, long long b) -> long long { return b == 0 ? a : gcd(b, a % b); @@ -109,8 +124,11 @@ static void IdleTask(const void* args, mtapi_size_t, void*, mtapi_size_t, auto start_time = base_clock::now(); /* idle until task completion. */ - auto idle_time = cpp_time_base(taskset[task_id].wcet); - std::this_thread::sleep_for(idle_time); + auto idle_time = taskset[task_id].wcet; + + for(int i = 0; i < loop_count(idle_time); i++) { + donotoptimize(); + } /* Store our benchmarking data. */ auto end_time = base_clock::now(); @@ -185,7 +203,7 @@ static void TaskStarter() /* Detached TaskAttribute so we don't have to wait for task completion. */ embb::mtapi::TaskAttributes detached_attribute; - // detached_attribute.SetDetached(true); + detached_attribute.SetDetached(true); detached_attribute.SetPolicy(deadline_policy[i]); int tmp; auto t = node.Start(job, &task_arguments[i][count - 1], &tmp, detached_attribute); @@ -196,17 +214,6 @@ static void TaskStarter() } } - auto wait_start = base_clock::now(); - while(min.count() > 0 && running.size() > 0) { - auto status = running.front().Wait(min.count()); // TODO factor for anything bigger than milliseconds - if(status == MTAPI_SUCCESS) { - running.erase(running.begin()); - } - auto remain = duration_cast(wait_start - base_clock::now()); - if(remain.count() > 0) { - min -= remain; - } - } std::this_thread::sleep_for(min); cur_time = duration_cast(base_clock::now() - start); } diff --git a/templates/normal/fun.cpp b/templates/normal/fun.cpp new file mode 100644 index 0000000..fff2340 --- /dev/null +++ b/templates/normal/fun.cpp @@ -0,0 +1,3 @@ +#include "fun.h" + +void donotoptimize() {} diff --git a/templates/normal/fun.h b/templates/normal/fun.h new file mode 100644 index 0000000..e5d2313 --- /dev/null +++ b/templates/normal/fun.h @@ -0,0 +1 @@ +void donotoptimize(); diff --git a/templates/normal/timing_header.h b/templates/normal/timing_header.h new file mode 100644 index 0000000..7aa867d --- /dev/null +++ b/templates/normal/timing_header.h @@ -0,0 +1,8 @@ +int timetable[] = { +0, +933, 1564, 2196, 2827, 3459, 4091, 4716, 5353, 5984, 6610, 7230, 7864, 8473, 9110, 9724, 10347, 10968, 11588, 12207, 12816, +13432, 14054, 14710, 15393, 16034, 16664, 17291, 17920, 18545, 19171, 19798, 20425, 21057, 21681, 22308, 22929, 23555, 24182, 24815, 25445, +26073, 26698, 27320, 27952, 28570, 29205, 29828, 30454, 31098, 31713, 32341, 32963, 33589, 34221, 34836, 35461, 36103, 36708, 37340, 37981, +38607, 39241, 39878, 40512, 41136, 41766, 42409, 43041, 43677, 44311, 44943, 45566, 46195, 46833, 47451, 48079, 48707, 49340, 49949, 50590, +51214, 51836, 52454, 53084, 53709, 54346, 54971, 55586, 56233, 56859, 57480, 58106, 58746, 59350, 59980, 60614, 61238, 61862, 62504, 63125, +}; -- libgit2 0.26.0