eventq.hh (5501:b1beee9351a4) | eventq.hh (5502:f0f8a3ee5aad) |
---|---|
1/* 2 * Copyright (c) 2000-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 60 unchanged lines hidden (view full) --- 69 * 70 * Caution, the order of members is chosen to maximize data packing. 71 */ 72class Event : public Serializable, public FastAlloc 73{ 74 friend class EventQueue; 75 76 private: | 1/* 2 * Copyright (c) 2000-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 60 unchanged lines hidden (view full) --- 69 * 70 * Caution, the order of members is chosen to maximize data packing. 71 */ 72class Event : public Serializable, public FastAlloc 73{ 74 friend class EventQueue; 75 76 private: |
77 Event *next; | 77 // The event queue is now a linked list of linked lists. The 78 // 'nextBin' pointer is to find the bin, where a bin is defined as 79 // when+priority. All events in the same bin will be stored in a 80 // second circularly linked list maintained by the 'nextInBin' 81 // pointer. The list will be accessed in FIFO order. The end 82 // result is that the insert/removal in 'nextBin' is 83 // linear/constant, and the lookup/removal in 'nextInBin' is 84 // constant/constant. Hopefully this is a significant improvement 85 // over the current fully linear insertion. 86 Event *nextBin; 87 Event *nextInBin; |
78 | 88 |
89 friend void insertBefore(Event *event, Event *curr); 90 friend Event *removeItem(Event *event, Event *last); 91 |
|
79 /// queue to which this event belongs (though it may or may not be 80 /// scheduled on this queue yet) 81 EventQueue *_queue; 82 83 Tick _when; //!< timestamp when event should be processed 84 short _priority; //!< event priority 85 short _flags; 86 --- 7 unchanged lines hidden (view full) --- 94 /// debugging. 95 Counter instance; 96#endif 97 98#ifdef DEBUG_EVENTQ 99 Tick whenCreated; //!< time created 100 Tick whenScheduled; //!< time scheduled 101#endif | 92 /// queue to which this event belongs (though it may or may not be 93 /// scheduled on this queue yet) 94 EventQueue *_queue; 95 96 Tick _when; //!< timestamp when event should be processed 97 short _priority; //!< event priority 98 short _flags; 99 --- 7 unchanged lines hidden (view full) --- 107 /// debugging. 108 Counter instance; 109#endif 110 111#ifdef DEBUG_EVENTQ 112 Tick whenCreated; //!< time created 113 Tick whenScheduled; //!< time scheduled 114#endif |
115 |
|
102 protected: | 116 protected: |
117 void 118 setWhen(Tick when) 119 { 120 _when = when; 121#ifdef DEBUG_EVENTQ 122 whenScheduled = curTick; 123#endif 124 } 125 126 protected: |
|
103 enum Flags { 104 None = 0x0, 105 Squashed = 0x1, 106 Scheduled = 0x2, 107 AutoDelete = 0x4, 108 AutoSerialize = 0x8, 109 IsExitEvent = 0x10 110 }; --- 65 unchanged lines hidden (view full) --- 176 Maximum_Pri = SHRT_MAX 177 }; 178 179 /* 180 * Event constructor 181 * @param queue that the event gets scheduled on 182 */ 183 Event(EventQueue *q, Priority p = Default_Pri) | 127 enum Flags { 128 None = 0x0, 129 Squashed = 0x1, 130 Scheduled = 0x2, 131 AutoDelete = 0x4, 132 AutoSerialize = 0x8, 133 IsExitEvent = 0x10 134 }; --- 65 unchanged lines hidden (view full) --- 200 Maximum_Pri = SHRT_MAX 201 }; 202 203 /* 204 * Event constructor 205 * @param queue that the event gets scheduled on 206 */ 207 Event(EventQueue *q, Priority p = Default_Pri) |
184 : next(NULL), _queue(q), _priority(p), _flags(None) | 208 : nextBin(NULL), nextInBin(NULL), _queue(q), _priority(p), _flags(None) |
185 { 186#ifndef NDEBUG 187 instance = ++instanceCounter; 188#endif 189#ifdef EVENTQ_DEBUG 190 whenCreated = curTick; 191 whenScheduled = 0; 192#endif --- 145 unchanged lines hidden (view full) --- 338 // constructor 339 EventQueue(const std::string &n) 340 : objName(n), head(NULL) 341 {} 342 343 virtual const std::string name() const { return objName; } 344 345 // schedule the given event on this queue | 209 { 210#ifndef NDEBUG 211 instance = ++instanceCounter; 212#endif 213#ifdef EVENTQ_DEBUG 214 whenCreated = curTick; 215 whenScheduled = 0; 216#endif --- 145 unchanged lines hidden (view full) --- 362 // constructor 363 EventQueue(const std::string &n) 364 : objName(n), head(NULL) 365 {} 366 367 virtual const std::string name() const { return objName; } 368 369 // schedule the given event on this queue |
346 void schedule(Event *ev); | 370 void schedule(Event *ev, Tick when); |
347 void deschedule(Event *ev); | 371 void deschedule(Event *ev); |
348 void reschedule(Event *ev); | 372 void reschedule(Event *ev, Tick when); |
349 350 Tick nextTick() const { return head->when(); } 351 Event *serviceOne(); 352 353 // process all events up to the given timestamp. we inline a 354 // quick test to see if there are any events to process; if so, 355 // call the internal out-of-line version to process them all. 356 void --- 17 unchanged lines hidden (view full) --- 374 375 // return true if no events are queued 376 bool empty() const { return head == NULL; } 377 378 void dump() const; 379 380 Tick nextEventTime() { return empty() ? curTick : head->when(); } 381 | 373 374 Tick nextTick() const { return head->when(); } 375 Event *serviceOne(); 376 377 // process all events up to the given timestamp. we inline a 378 // quick test to see if there are any events to process; if so, 379 // call the internal out-of-line version to process them all. 380 void --- 17 unchanged lines hidden (view full) --- 398 399 // return true if no events are queued 400 bool empty() const { return head == NULL; } 401 402 void dump() const; 403 404 Tick nextEventTime() { return empty() ? curTick : head->when(); } 405 |
406 bool debugVerify() const; 407 |
|
382 virtual void serialize(std::ostream &os); 383 virtual void unserialize(Checkpoint *cp, const std::string §ion); 384}; 385 386 387////////////////////// 388// 389// inline functions 390// 391// can't put these inside declaration due to circular dependence 392// between Event and EventQueue classes. 393// 394////////////////////// 395 396// schedule at specified time (place on event queue specified via 397// constructor) 398inline void | 408 virtual void serialize(std::ostream &os); 409 virtual void unserialize(Checkpoint *cp, const std::string §ion); 410}; 411 412 413////////////////////// 414// 415// inline functions 416// 417// can't put these inside declaration due to circular dependence 418// between Event and EventQueue classes. 419// 420////////////////////// 421 422// schedule at specified time (place on event queue specified via 423// constructor) 424inline void |
399Event::schedule(Tick t) | 425Event::schedule(Tick when) |
400{ | 426{ |
401 assert(!scheduled()); 402 assert(t >= curTick); 403 404 setFlags(Scheduled); 405#ifdef DEBUG_EVENTQ 406 whenScheduled = curTick; 407#endif 408 _when = t; 409 _queue->schedule(this); | 427 _queue->schedule(this, when); |
410} 411 412inline void 413Event::deschedule() 414{ | 428} 429 430inline void 431Event::deschedule() 432{ |
415 assert(scheduled()); 416 417 clearFlags(Squashed); 418 clearFlags(Scheduled); | |
419 _queue->deschedule(this); 420} 421 422inline void | 433 _queue->deschedule(this); 434} 435 436inline void |
423Event::reschedule(Tick t, bool always) | 437Event::reschedule(Tick when, bool always) |
424{ | 438{ |
425 assert(scheduled() || always); 426 assert(t >= curTick); 427 428#ifdef DEBUG_EVENTQ 429 whenScheduled = curTick; 430#endif 431 _when = t; 432 | |
433 if (scheduled()) { | 439 if (scheduled()) { |
434 clearFlags(Squashed); 435 _queue->reschedule(this); | 440 _queue->reschedule(this, when); |
436 } else { | 441 } else { |
437 setFlags(Scheduled); 438 _queue->schedule(this); | 442 assert(always); 443 _queue->schedule(this, when); |
439 } 440} 441 | 444 } 445} 446 |
447inline bool 448operator<(const Event &l, const Event &r) 449{ 450 return l.when() < r.when() || 451 (l.when() == r.when() && l.priority() < r.priority()); 452} 453 454inline bool 455operator>(const Event &l, const Event &r) 456{ 457 return l.when() > r.when() || 458 (l.when() == r.when() && l.priority() > r.priority()); 459} 460 461inline bool 462operator<=(const Event &l, const Event &r) 463{ 464 return l.when() < r.when() || 465 (l.when() == r.when() && l.priority() <= r.priority()); 466} 467inline bool 468operator>=(const Event &l, const Event &r) 469{ 470 return l.when() > r.when() || 471 (l.when() == r.when() && l.priority() >= r.priority()); 472} 473 474inline bool 475operator==(const Event &l, const Event &r) 476{ 477 return l.when() == r.when() && l.priority() == r.priority(); 478} 479 480inline bool 481operator!=(const Event &l, const Event &r) 482{ 483 return l.when() != r.when() || l.priority() != r.priority(); 484} 485 |
|
442inline void | 486inline void |
443EventQueue::schedule(Event *event) | 487EventQueue::schedule(Event *event, Tick when) |
444{ | 488{ |
489 assert(when >= curTick); 490 assert(!event->scheduled()); 491 492 event->setWhen(when); |
|
445 insert(event); | 493 insert(event); |
494 event->setFlags(Event::Scheduled); 495 |
|
446 if (DTRACE(Event)) 447 event->trace("scheduled"); 448} 449 450inline void 451EventQueue::deschedule(Event *event) 452{ | 496 if (DTRACE(Event)) 497 event->trace("scheduled"); 498} 499 500inline void 501EventQueue::deschedule(Event *event) 502{ |
503 assert(event->scheduled()); 504 |
|
453 remove(event); | 505 remove(event); |
454 if (DTRACE(Event)) 455 event->trace("descheduled"); | |
456 | 506 |
507 event->clearFlags(Event::Squashed); 508 event->clearFlags(Event::Scheduled); 509 |
|
457 if (event->getFlags(Event::AutoDelete)) 458 delete event; | 510 if (event->getFlags(Event::AutoDelete)) 511 delete event; |
512 513 if (DTRACE(Event)) 514 event->trace("descheduled"); |
|
459} 460 461inline void | 515} 516 517inline void |
462EventQueue::reschedule(Event *event) | 518EventQueue::reschedule(Event *event, Tick when) |
463{ | 519{ |
520 assert(when >= curTick); 521 assert(event->scheduled()); 522 |
|
464 remove(event); | 523 remove(event); |
524 event->setWhen(when); |
|
465 insert(event); | 525 insert(event); |
526 event->clearFlags(Event::Squashed); 527 |
|
466 if (DTRACE(Event)) 467 event->trace("rescheduled"); 468} 469 470#endif // __SIM_EVENTQ_HH__ | 528 if (DTRACE(Event)) 529 event->trace("rescheduled"); 530} 531 532#endif // __SIM_EVENTQ_HH__ |