m5: merge inorder/release-notes/make_release changes
[gem5.git] / src / mem / ruby / eventqueue / RubyEventQueue.hh
1 /*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /*
30 * The RubyEventQueue class implements an event queue which
31 * can be trigger events, allowing our simulation to be event driven.
32 *
33 * Currently, the only event we support is a Consumer being signaled
34 * by calling the consumer's wakeup() routine. Adding the event to
35 * the queue does not require a virtual function call, though calling
36 * wakeup() is a virtual function call.
37 *
38 * The method triggerEvents() is called with a global time. All
39 * events which are before or at this time are triggered in timestamp
40 * order. No ordering is enforced for events scheduled to occur at
41 * the same time. Events scheduled to wakeup the same consumer at the
42 * same time are combined into a single event.
43 *
44 * The method scheduleConsumerWakeup() is called with a global time
45 * and a consumer pointer. The event queue will call the wakeup()
46 * method of the consumer at the appropriate time.
47 *
48 * This implementation of RubyEventQueue uses a dynamically sized array
49 * managed as a heap. The algorithms used has O(lg n) for insert and
50 * O(lg n) for extract minimum element. (Based on chapter 7 of Cormen,
51 * Leiserson, and Rivest.) The array is dynamically sized and is
52 * automatically doubled in size when necessary.
53 *
54 */
55
56 #ifndef __MEM_RUBY_EVENTQUEUE_RUBYEVENTQUEUE_HH__
57 #define __MEM_RUBY_EVENTQUEUE_RUBYEVENTQUEUE_HH__
58
59 #include <iostream>
60
61 #include "config/no_vector_bounds_checks.hh"
62 #include "mem/ruby/common/Global.hh"
63 #include "sim/eventq.hh"
64
65 class Consumer;
66 class RubyEventQueueNode;
67
68 class RubyEventQueue : public EventManager
69 {
70 public:
71 RubyEventQueue(EventQueue* eventq, Tick _clock);
72 ~RubyEventQueue();
73
74 Time getTime() const { return curTick()/m_clock; }
75 Tick getClock() const { return m_clock; }
76 void scheduleEvent(Consumer* consumer, Time timeDelta);
77 void scheduleEventAbsolute(Consumer* consumer, Time timeAbs);
78 void print(std::ostream& out) const;
79
80 void triggerEvents(Time t) { assert(0); }
81 void triggerAllEvents() { assert(0); }
82
83 private:
84 // Private copy constructor and assignment operator
85 RubyEventQueue(const RubyEventQueue& obj);
86 RubyEventQueue& operator=(const RubyEventQueue& obj);
87
88 // Data Members (m_ prefix)
89 Tick m_clock;
90 };
91
92 inline std::ostream&
93 operator<<(std::ostream& out, const RubyEventQueue& obj)
94 {
95 obj.print(out);
96 out << std::flush;
97 return out;
98 }
99
100 #endif // __MEM_RUBY_EVENTQUEUE_RUBYEVENTQUEUE_HH__