3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "mem/ruby/common/Global.hh"
35 #include "mem/ruby/system/TimerTable.hh"
36 #include "mem/ruby/eventqueue/RubyEventQueue.hh"
38 TimerTable::TimerTable()
40 m_consumer_ptr
= NULL
;
42 m_next_address
= Address(0);
47 bool TimerTable::isReady() const
49 if (m_map
.size() == 0) {
57 return (g_eventQueue_ptr
->getTime() >= m_next_time
);
60 const Address
& TimerTable::readyAddress() const
68 return m_next_address
;
71 void TimerTable::set(const Address
& address
, Time relative_latency
)
73 assert(address
== line_address(address
));
74 assert(relative_latency
> 0);
75 assert(m_map
.exist(address
) == false);
76 Time ready_time
= g_eventQueue_ptr
->getTime() + relative_latency
;
77 m_map
.add(address
, ready_time
);
78 assert(m_consumer_ptr
!= NULL
);
79 g_eventQueue_ptr
->scheduleEventAbsolute(m_consumer_ptr
, ready_time
);
82 // Don't always recalculate the next ready address
83 if (ready_time
<= m_next_time
) {
88 void TimerTable::unset(const Address
& address
)
90 assert(address
== line_address(address
));
91 assert(m_map
.exist(address
) == true);
92 m_map
.remove(address
);
94 // Don't always recalculate the next ready address
95 if (address
== m_next_address
) {
100 void TimerTable::print(ostream
& out
) const
105 void TimerTable::updateNext() const
107 if (m_map
.size() == 0) {
108 assert(m_next_valid
== false);
112 Vector
<Address
> addresses
= m_map
.keys();
113 m_next_address
= addresses
[0];
114 m_next_time
= m_map
.lookup(m_next_address
);
116 // Search for the minimum time
117 int size
= addresses
.size();
118 for (int i
=1; i
<size
; i
++) {
119 Address maybe_next_address
= addresses
[i
];
120 Time maybe_next_time
= m_map
.lookup(maybe_next_address
);
121 if (maybe_next_time
< m_next_time
) {
122 m_next_time
= maybe_next_time
;
123 m_next_address
= maybe_next_address
;