#include <scheduler.h>
Inheritance diagram for SplayScheduler:


Public Member Functions | |
| SplayScheduler () | |
| void | insert (Event *) |
| Event * | deque () |
| const Event * | head () |
| void | cancel (Event *) |
| Event * | lookup (scheduler_uid_t) |
| void | schedule (Handler *, Event *, double delay) |
| virtual void | run () |
| double | clock () const |
| virtual void | sync () |
| virtual double | start () |
| virtual void | reset () |
Static Public Member Functions | |
| Scheduler & | instance () |
Protected Member Functions | |
| Event * | uid_lookup (Event *) |
| void | dumpq () |
| void | dispatch (Event *) |
| void | dispatch (Event *, double) |
| int | command (int argc, const char *const *argv) |
Protected Attributes | |
| Event * | root_ |
| scheduler_uid_t | lookup_uid_ |
| int | qsize_ |
| double | clock_ |
| int | halted_ |
Static Protected Attributes | |
| Scheduler * | instance_ |
| scheduler_uid_t | uid_ = 1 |
Private Member Functions | |
| int | validate (Event *) |
|
|
Definition at line 185 of file scheduler.h.
|
|
|
Implements Scheduler. Definition at line 255 of file splay-scheduler.cc. References abort(), LEFT, qsize_, RIGHT, root_, Event::time_, and Event::uid_.
00256 {
00257
00258 if (e->uid_ <= 0)
00259 return; // event not in queue
00260
00261 Event **t;
00262 //validate();
00263 if (e == root_) {
00264 t = &root_;
00265 } else {
00266 // searching among same-time events is a real bugger,
00267 // all because we don't have a parent pointer; use
00268 // uid_ to resolve conflicts.
00269 for (t = &root_; *t;) {
00270 t = ((e->time_ > (*t)->time_) ||
00271 ((e->time_ == (*t)->time_) && e->uid_ > (*t)->uid_))
00272 ? &RIGHT(*t) : &LEFT(*t);
00273 if (*t == e)
00274 break;
00275 }
00276 if (*t == 0) {
00277 fprintf(stderr, "did not find it\n");
00278 abort(); // not found
00279 }
00280 }
00281 // t is the pointer to e in the parent or to root_ if e is root_
00282 e->uid_ = -e->uid_;
00283 --qsize_;
00284
00285 if (RIGHT(e) == 0) {
00286 *t = LEFT(e);
00287 LEFT(e) = 0;
00288 //validate();
00289 return;
00290 }
00291 if (LEFT(e) == 0) {
00292 *t = RIGHT(e);
00293 RIGHT(e) = 0;
00294 //validate();
00295 return;
00296 }
00297
00298 // find successor
00299 Event *p = RIGHT(e), *q = LEFT(p);
00300
00301 if (q == 0) {
00302 // p is the sucessor
00303 *t = p;
00304 LEFT(p) = LEFT(e);
00305 //validate();
00306 return;
00307 }
00308 for (; LEFT(q); p = q, q = LEFT(q))
00309 ;
00310 // q is the successor
00311 // p is q's parent
00312 *t = q;
00313 LEFT(p) = RIGHT(q);
00314 LEFT(q) = LEFT(e);
00315 RIGHT(q) = RIGHT(e);
00316 RIGHT(e) = LEFT(e) = 0;
00317 //validate();
00318 }
|
Here is the call graph for this function:

|
|
||||||||||||
|
Definition at line 188 of file scheduler.cc. References at_handler, Scheduler::cancel(), Scheduler::clock(), MemTrace::diff(), Scheduler::dumpq(), Scheduler::halted_, Scheduler::instance_, Scheduler::lookup(), AtEvent::proc_, Scheduler::reset(), Scheduler::run(), Scheduler::schedule(), STRTOUID, Event::uid_, and UID_PRINTF_FORMAT.
00189 {
00190 Tcl& tcl = Tcl::instance();
00191 if (instance_ == 0)
00192 instance_ = this;
00193 if (argc == 2) {
00194 if (strcmp(argv[1], "run") == 0) {
00195 /* set global to 0 before calling object reset methods */
00196 reset(); // sets clock to zero
00197 run();
00198 return (TCL_OK);
00199 } else if (strcmp(argv[1], "now") == 0) {
00200 sprintf(tcl.buffer(), "%.17g", clock());
00201 tcl.result(tcl.buffer());
00202 return (TCL_OK);
00203 } else if (strcmp(argv[1], "resume") == 0) {
00204 halted_ = 0;
00205 run();
00206 return (TCL_OK);
00207 } else if (strcmp(argv[1], "halt") == 0) {
00208 halted_ = 1;
00209 return (TCL_OK);
00210
00211 } else if (strcmp(argv[1], "clearMemTrace") == 0) {
00212 #ifdef MEMDEBUG_SIMULATIONS
00213 extern MemTrace *globalMemTrace;
00214 if (globalMemTrace)
00215 globalMemTrace->diff("Sim.");
00216 #endif
00217 return (TCL_OK);
00218 } else if (strcmp(argv[1], "is-running") == 0) {
00219 sprintf(tcl.buffer(), "%d", !halted_);
00220 return (TCL_OK);
00221 } else if (strcmp(argv[1], "dumpq") == 0) {
00222 if (!halted_) {
00223 fprintf(stderr, "Scheduler: dumpq only allowed while halted\n");
00224 tcl.result("0");
00225 return (TCL_ERROR);
00226 }
00227 dumpq();
00228 return (TCL_OK);
00229 }
00230 } else if (argc == 3) {
00231 if (strcmp(argv[1], "at") == 0 ||
00232 strcmp(argv[1], "cancel") == 0) {
00233 Event* p = lookup(STRTOUID(argv[2]));
00234 if (p != 0) {
00235 /*XXX make sure it really is an atevent*/
00236 cancel(p);
00237 AtEvent* ae = (AtEvent*)p;
00238 delete ae;
00239 }
00240 } else if (strcmp(argv[1], "at-now") == 0) {
00241 const char* proc = argv[2];
00242
00243 // "at [$ns now]" may not work because of tcl's
00244 // string number resolution
00245 AtEvent* e = new AtEvent;
00246 int n = strlen(proc);
00247 e->proc_ = new char[n + 1];
00248 strcpy(e->proc_, proc);
00249 schedule(&at_handler, e, 0);
00250 sprintf(tcl.buffer(), UID_PRINTF_FORMAT, e->uid_);
00251 tcl.result(tcl.buffer());
00252 }
00253 return (TCL_OK);
00254 } else if (argc == 4) {
00255 if (strcmp(argv[1], "at") == 0) {
00256 /* t < 0 means relative time: delay = -t */
00257 double delay, t = atof(argv[2]);
00258 const char* proc = argv[3];
00259
00260 AtEvent* e = new AtEvent;
00261 int n = strlen(proc);
00262 e->proc_ = new char[n + 1];
00263 strcpy(e->proc_, proc);
00264 delay = (t < 0) ? -t : t - clock();
00265 if (delay < 0) {
00266 tcl.result("can't schedule command in past");
00267 return (TCL_ERROR);
00268 }
00269 schedule(&at_handler, e, delay);
00270 sprintf(tcl.buffer(), UID_PRINTF_FORMAT, e->uid_);
00271 tcl.result(tcl.buffer());
00272 return (TCL_OK);
00273 }
00274 }
00275 return (TclObject::command(argc, argv));
00276 }
|
Here is the call graph for this function:

|
|
Implements Scheduler. Definition at line 209 of file splay-scheduler.cc. References LEFT, ll, qsize_, RIGHT, and root_.
00210 {
00211 Event *t;
00212 Event *l;
00213 Event *ll;
00214 Event *lll;
00215
00216 if (root_ == 0)
00217 return 0;
00218
00219 --qsize_;
00220
00221 t = root_;
00222 l = LEFT(t);
00223
00224 if (l == 0) { // root is the element to dequeue
00225 root_ = RIGHT(t); // right branch becomes the root
00226 //validate();
00227 return t;
00228 }
00229 for (;;) {
00230 ll = LEFT(l);
00231 if (ll == 0) {
00232 LEFT(t) = RIGHT(l);
00233 //validate();
00234 return l;
00235 }
00236
00237 lll = LEFT(ll);
00238 if (lll == 0) {
00239 LEFT(l) = RIGHT(ll);
00240 //validate();
00241 return ll;
00242 }
00243
00244 // zig-zig: rotate l with ll
00245 LEFT(t) = ll;
00246 LEFT(l) = RIGHT(ll);
00247 RIGHT(ll) = l;
00248
00249 t = ll;
00250 l = lll;
00251 }
00252 }
|
|
||||||||||||
|
Definition at line 140 of file scheduler.cc. References abort(), Scheduler::clock_, Handler::handle(), Event::handler_, and Event::uid_.
|
Here is the call graph for this function:

|
|
Definition at line 153 of file scheduler.cc. References Event::time_. Referenced by RealTimeScheduler::run(), and Scheduler::run().
|
|
|
Definition at line 279 of file scheduler.cc. References Scheduler::clock(), Scheduler::deque(), Event::handler_, Event::time_, Event::uid_, and UID_PRINTF_FORMAT. Referenced by Scheduler::command().
|
Here is the call graph for this function:

|
|
Implements Scheduler. Definition at line 162 of file splay-scheduler.cc. References LEFT, ll, RIGHT, and root_.
00163 {
00164 Event *t;
00165 Event *l;
00166 #if 1
00167 if (root_ == 0)
00168 return 0;
00169 for (t = root_; (l = LEFT(t)); t = l)
00170 ;
00171
00172 return t;
00173 #else
00174 Event *ll;
00175 Event *lll;
00176
00177 if (root_ == 0)
00178 return 0;
00179
00180 t = root_;
00181 l = LEFT(t);
00182
00183 if (l == 0) {
00184 return t;
00185 }
00186 for (;;) {
00187 ll = LEFT(l);
00188 if (ll == 0) {
00189 return l;
00190 }
00191
00192 lll = LEFT(ll);
00193 if (lll == 0) {
00194 return ll;
00195 }
00196
00197 // zig-zig: rotate l with ll
00198 LEFT(t) = ll;
00199 LEFT(l) = RIGHT(ll);
00200 RIGHT(ll) = l;
00201
00202 t = ll;
00203 l = lll;
00204 }
00205 #endif /* 1/0 */
00206 }
|
|
|
Implements Scheduler. Definition at line 97 of file splay-scheduler.cc. References LEFT, LINK_LEFT, LINK_RIGHT, qsize_, RIGHT, root_, ROTATE_LEFT, ROTATE_RIGHT, and Event::time_.
00098 {
00099 Event *l; // bottom right in the left tree
00100 Event *r; // bottom left in the right tree
00101 Event *t; // root of the remaining tree
00102 Event *x; // current node
00103
00104 ++qsize_;
00105
00106 double time = n->time_;
00107
00108 if (root_ == 0) {
00109 LEFT(n) = RIGHT(n) = 0;
00110 root_ = n;
00111 //validate();
00112 return;
00113 }
00114 t = root_;
00115 root_ = n; // n is the new root
00116 l = n;
00117 r = n;
00118 for (;;) {
00119 if (time < t->time_) {
00120 x = LEFT(t);
00121 if (x == 0) {
00122 LEFT(r) = t;
00123 RIGHT(l) = 0;
00124 break;
00125 }
00126 if (time < x->time_) {
00127 ROTATE_RIGHT(t, x);
00128 }
00129 LINK_RIGHT(r, t);
00130 if (t == 0) {
00131 RIGHT(l) = 0;
00132 break;
00133 }
00134 } else {
00135 x = RIGHT(t);
00136 if (x == 0) {
00137 RIGHT(l) = t;
00138 LEFT(r) = 0;
00139 break;
00140 }
00141 if (time >= x->time_) {
00142 ROTATE_LEFT(t, x);
00143 }
00144 LINK_LEFT(l, t);
00145 if (t == 0) {
00146 LEFT(r) = 0;
00147 break;
00148 }
00149
00150 }
00151 } /* for (;;) */
00152
00153 // assemble:
00154 // swap left and right children
00155 x = LEFT(n);
00156 LEFT(n) = RIGHT(n);
00157 RIGHT(n) = x;
00158 //validate();
00159 }
|
|
|
|
Implements Scheduler. Definition at line 322 of file splay-scheduler.cc. References lookup_uid_, root_, and uid_lookup().
00323 {
00324 lookup_uid_ = uid;
00325 return uid_lookup(root_);
00326 }
|
Here is the call graph for this function:

|
|
Reimplemented in RealTimeScheduler. Definition at line 182 of file scheduler.cc. References Scheduler::clock_, and SCHED_START. Referenced by Scheduler::command().
00183 {
00184 clock_ = SCHED_START;
00185 }
|
|
|
Reimplemented in RealTimeScheduler. Definition at line 118 of file scheduler.cc. References Scheduler::deque(), Scheduler::dispatch(), Scheduler::halted_, and Scheduler::instance_. Referenced by Scheduler::command().
00119 {
00120 instance_ = this;
00121 Event *p;
00122 /*
00123 * The order is significant: if halted_ is checked later,
00124 * event p could be lost when the simulator resumes.
00125 * Patch by Thomas Kaemer <Thomas.Kaemer@eas.iis.fhg.de>.
00126 */
00127 while (!halted_ && (p = deque())) {
00128 dispatch(p, p->time_);
00129 }
00130 }
|
Here is the call graph for this function:

|
||||||||||||||||
Here is the call graph for this function:

|
|
Definition at line 94 of file scheduler.h. References SCHED_START.
00094 { // start time
00095 return SCHED_START;
00096 }
|
|
|
Reimplemented in RealTimeScheduler. Definition at line 93 of file scheduler.h. Referenced by TapAgent::dispatch().
00093 {};
|
|
|
Definition at line 329 of file splay-scheduler.cc. References LEFT, lookup_uid_, RIGHT, and Event::uid_. Referenced by lookup().
00330 {
00331 if (root == 0)
00332 return 0;
00333 if (root->uid_ == lookup_uid_)
00334 return root;
00335
00336 Event *res = uid_lookup(LEFT(root));
00337
00338 if (res)
00339 return res;
00340
00341 return uid_lookup(RIGHT(root));
00342 }
|
|
|
Definition at line 345 of file splay-scheduler.cc. References LEFT, RIGHT, and Event::time_.
00346 {
00347 int size = 0;
00348 if (root) {
00349 ++size;
00350 assert(LEFT(root) == 0 || root->time_ >= LEFT(root)->time_);
00351 assert(RIGHT(root) == 0 || root->time_ <= RIGHT(root)->time_);
00352 size += validate(LEFT(root));
00353 size += validate(RIGHT(root));
00354 return size;
00355 }
00356 return 0;
00357 }
|
|
|
Definition at line 105 of file scheduler.h. Referenced by Scheduler::clock(), Scheduler::dispatch(), RealTimeScheduler::reset(), Scheduler::reset(), RealTimeScheduler::run(), Scheduler::schedule(), and RealTimeScheduler::sync(). |
|
|
Definition at line 106 of file scheduler.h. Referenced by Scheduler::command(), RealTimeScheduler::run(), and Scheduler::run(). |
|
|
Definition at line 55 of file scheduler.cc. Referenced by Scheduler::command(), RealTimeScheduler::run(), Scheduler::run(), and Scheduler::~Scheduler(). |
|
|
Definition at line 203 of file scheduler.h. Referenced by lookup(), and uid_lookup(). |
|
|
Definition at line 204 of file scheduler.h. Referenced by cancel(), deque(), insert(), and SplayScheduler(). |
|
|
Definition at line 202 of file scheduler.h. Referenced by cancel(), deque(), head(), insert(), lookup(), and SplayScheduler(). |
|
|
Definition at line 56 of file scheduler.cc. Referenced by Scheduler::schedule(). |
1.3.3