From 0512b30f240a006e97913dbc4b8bbf6da610e489 Mon Sep 17 00:00:00 2001 From: Tobias Langer Date: Sun, 9 Oct 2016 10:58:57 +0200 Subject: [PATCH] Minor fixes with timing and task termination. --- templates/normal/experiment.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/templates/normal/experiment.cpp b/templates/normal/experiment.cpp index bd81e60..84bac02 100644 --- a/templates/normal/experiment.cpp +++ b/templates/normal/experiment.cpp @@ -127,11 +127,19 @@ static void TaskStarter() auto& node = embb::mtapi::Node::GetInstance(); /* Storage for any task which is started. */ std::vector running; - /* Storage for task parameters. */ - std::vector> running_num; auto hyperperiod = calculate_hyperperiod(); + /* Storage for task parameters. */ + int task_cnt = 0; + for(int i = 0; i < taskset_length; i++) { + node.CreateAction(ACTION_ID + i + 1, IdleTask); + task_cnt += hyperperiod / taskset[i].period; + std::cout << "Task " << i << " wcet: " << taskset[i].wcet << " period: " << taskset[i].period << " deadline: " << taskset[i].deadline << std::endl; + } + std::vector> running_num(task_cnt); + int task_ptr = 0; + using namespace std::chrono; start = base_clock::now(); @@ -169,11 +177,10 @@ static void TaskStarter() * to make sure that all possible running tasks can access their * parameters. */ - running_num.push_back(std::make_pair(i,count)); - node.CreateAction(ACTION_ID + i + 1, IdleTask); + running_num[task_ptr++] = std::make_pair(i,count); auto job = node.GetJob(ACTION_ID + i + 1, DOMAIN_ID); - int tmp; auto t = node.Start(job, &running_num.back(), &tmp); + int tmp; auto t = node.Start(job, &running_num[task_ptr - 1], &tmp); /* Store task to wait for it. */ running.push_back(t); @@ -181,6 +188,17 @@ 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); } -- libgit2 0.26.0