diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-02-21 04:09:34 -0500 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-04-11 07:53:40 -0400 |
| commit | 3ee2fdea3adc70148e632b333067fd445e8be87e (patch) | |
| tree | 1bb46a7d46f11c0fe8bdae13944c7fee0a6be21c | |
| parent | b12d172d6599d7578bc811a36d939d89d415f636 (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.
| -rw-r--r-- | native/SConstruct | 3 | ||||
| -rw-r--r-- | native/include/cpu_time.h | 7 | ||||
| -rw-r--r-- | native/include/edf/baruah.h | 2 | ||||
| -rw-r--r-- | native/src/cpu_time.cpp | 25 | ||||
| -rw-r--r-- | native/src/edf/baruah.cpp | 26 |
5 files changed, 49 insertions, 14 deletions
diff --git a/native/SConstruct b/native/SConstruct index 797eaba..99cb6b4 100644 --- a/native/SConstruct +++ b/native/SConstruct | |||
| @@ -110,6 +110,7 @@ swig.Append( | |||
| 110 | ) | 110 | ) |
| 111 | 111 | ||
| 112 | EDF_SRC = [ | 112 | EDF_SRC = [ |
| 113 | 'src/cpu_time.cpp', | ||
| 113 | 'src/edf/baker.cpp', | 114 | 'src/edf/baker.cpp', |
| 114 | 'src/edf/baruah.cpp', | 115 | 'src/edf/baruah.cpp', |
| 115 | 'src/edf/gfb.cpp', | 116 | 'src/edf/gfb.cpp', |
| @@ -132,4 +133,4 @@ gmp.Program('testmain', ['src/testmain.cpp', | |||
| 132 | 133 | ||
| 133 | swig.SharedLibrary('_sched.so', ['src/tasks.cpp', 'interface/sched.i'] + EDF_SRC) | 134 | swig.SharedLibrary('_sched.so', ['src/tasks.cpp', 'interface/sched.i'] + EDF_SRC) |
| 134 | swig.SharedLibrary('_locking.so', ['src/sharedres.cpp', 'interface/locking.i']) | 135 | swig.SharedLibrary('_locking.so', ['src/sharedres.cpp', 'interface/locking.i']) |
| 135 | swig.SharedLibrary('_sim.so', ['src/tasks.cpp', 'interface/sim.i'] + SCHED_SRC) \ No newline at end of file | 136 | swig.SharedLibrary('_sim.so', ['src/tasks.cpp', 'interface/sim.i'] + SCHED_SRC) |
diff --git a/native/include/cpu_time.h b/native/include/cpu_time.h new file mode 100644 index 0000000..2484159 --- /dev/null +++ b/native/include/cpu_time.h | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #ifndef CPU_TIME_H | ||
| 2 | #define CPU_TIME_H | ||
| 3 | |||
| 4 | // How much CPU time used (in seconds)? | ||
| 5 | double get_cpu_usage(void); | ||
| 6 | |||
| 7 | #endif | ||
diff --git a/native/include/edf/baruah.h b/native/include/edf/baruah.h index dcd4f14..c79b49d 100644 --- a/native/include/edf/baruah.h +++ b/native/include/edf/baruah.h | |||
| @@ -23,7 +23,7 @@ public: | |||
| 23 | 23 | ||
| 24 | bool is_schedulable(const TaskSet &ts, bool check_preconditions = true); | 24 | bool is_schedulable(const TaskSet &ts, bool check_preconditions = true); |
| 25 | 25 | ||
| 26 | static const float MINIMUM_SLACK; | 26 | static const double MAX_RUNTIME; |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | #endif | 29 | #endif |
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 | |||
| 15 | double 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 | |||
| 13 | using namespace std; | 15 | using namespace std; |
| 14 | 16 | ||
| 15 | const float BaruahGedf::MINIMUM_SLACK = 0.01; | 17 | const double BaruahGedf::MAX_RUNTIME = 5.0; /* seconds */ |
| 18 | |||
| 16 | 19 | ||
| 17 | static void demand_bound_function(const Task &tsk, | 20 | static 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 | { |
