aboutsummaryrefslogtreecommitdiffstats
path: root/native/src
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2012-02-21 04:09:34 -0500
committerBjoern Brandenburg <bbb@mpi-sws.org>2012-04-11 07:53:40 -0400
commit3ee2fdea3adc70148e632b333067fd445e8be87e (patch)
tree1bb46a7d46f11c0fe8bdae13944c7fee0a6be21c /native/src
parentb12d172d6599d7578bc811a36d939d89d415f636 (diff)
Implement timeout in BaruahGEDF
Give up after running for 5 seconds. This is almost never triggered, but once in a while this should help to catch a pseudo-polynomial excursion.
Diffstat (limited to 'native/src')
-rw-r--r--native/src/cpu_time.cpp25
-rw-r--r--native/src/edf/baruah.cpp26
2 files changed, 39 insertions, 12 deletions
diff --git a/native/src/cpu_time.cpp b/native/src/cpu_time.cpp
new file mode 100644
index 0000000..a7dfa6d
--- /dev/null
+++ b/native/src/cpu_time.cpp
@@ -0,0 +1,25 @@
1
2#include <sys/time.h>
3#include <sys/resource.h>
4
5#include "cpu_time.h"
6
7#ifdef RUSAGE_THREAD
8// This is a Linuxism...
9#define ACCOUNTING_SCOPE RUSAGE_THREAD
10#else
11// This is POSIX.
12#define ACCOUNTING_SCOPE RUSAGE_SELF
13#endif
14
15double get_cpu_usage(void)
16{
17 struct rusage u;
18 if (getrusage(ACCOUNTING_SCOPE, &u) == 0)
19 {
20 return u.ru_utime.tv_sec + u.ru_utime.tv_usec / 1E6;
21 }
22 else
23 return 0.0;
24}
25
diff --git a/native/src/edf/baruah.cpp b/native/src/edf/baruah.cpp
index a8d78d8..c4b16af 100644
--- a/native/src/edf/baruah.cpp
+++ b/native/src/edf/baruah.cpp
@@ -10,9 +10,12 @@
10#include <iostream> 10#include <iostream>
11#include "task_io.h" 11#include "task_io.h"
12 12
13#include "cpu_time.h"
14
13using namespace std; 15using namespace std;
14 16
15const float BaruahGedf::MINIMUM_SLACK = 0.01; 17const double BaruahGedf::MAX_RUNTIME = 5.0; /* seconds */
18
16 19
17static void demand_bound_function(const Task &tsk, 20static void demand_bound_function(const Task &tsk,
18 const mpz_class &t, 21 const mpz_class &t,
@@ -253,22 +256,13 @@ bool BaruahGedf::is_schedulable(const TaskSet &ts,
253 return true; 256 return true;
254 } 257 }
255 258
256 /* Always check for too-small rest utilizations, as they 259 double start_time = get_cpu_usage();
257 * create unmanagably-large testing intervals. We'll just 260
258 * enforce a minimum slack threshold here. */
259 mpq_class m_minus_u; 261 mpq_class m_minus_u;
260 ts.get_utilization(m_minus_u); 262 ts.get_utilization(m_minus_u);
261 m_minus_u *= -1; 263 m_minus_u *= -1;
262 m_minus_u += m; 264 m_minus_u += m;
263 265
264 /*
265 if (m_minus_u < MINIMUM_SLACK) {
266 cerr << "# BaruahGedf: skipping task test; slack = " << m_minus_u
267 << endl;
268 return false;
269 }
270 */
271
272 mpz_class i1, sum; 266 mpz_class i1, sum;
273 mpz_class *max_test_point, *idiff; 267 mpz_class *max_test_point, *idiff;
274 mpz_class** ptr; // indirect access to idiff 268 mpz_class** ptr; // indirect access to idiff
@@ -292,9 +286,17 @@ bool BaruahGedf::is_schedulable(const TaskSet &ts,
292 all_pts[k].init(ts, k, max_test_point + k); 286 all_pts[k].init(ts, k, max_test_point + k);
293 287
294 // for every task for which point <= max_ak 288 // for every task for which point <= max_ak
289 unsigned long iter_count = 0;
295 while (point_in_range && schedulable) 290 while (point_in_range && schedulable)
296 { 291 {
297 point_in_range = false; 292 point_in_range = false;
293 // check for excessive run time every 10 iterations
294 if (++iter_count % 10 == 0 && get_cpu_usage() > start_time + MAX_RUNTIME)
295 {
296 // This is taking too long. Give up.
297 schedulable = false;
298 break;
299 }
298 for (unsigned int k = 0; k < ts.get_task_count() && schedulable; k++) 300 for (unsigned int k = 0; k < ts.get_task_count() && schedulable; k++)
299 if (all_pts[k].get_next(ilen)) 301 if (all_pts[k].get_next(ilen))
300 { 302 {