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(Chip
* chip_ptr
)
40 assert(chip_ptr
!= NULL
);
41 m_consumer_ptr
= NULL
;
42 m_chip_ptr
= chip_ptr
;
44 m_next_address
= Address(0);
49 bool TimerTable::isReady() const
51 if (m_map
.size() == 0) {
59 return (g_eventQueue_ptr
->getTime() >= m_next_time
);
62 const Address
& TimerTable::readyAddress() const
70 return m_next_address
;
73 void TimerTable::set(const Address
& address
, Time relative_latency
)
75 assert(address
== line_address(address
));
76 assert(relative_latency
> 0);
77 assert(m_map
.exist(address
) == false);
78 Time ready_time
= g_eventQueue_ptr
->getTime() + relative_latency
;
79 m_map
.add(address
, ready_time
);
80 assert(m_consumer_ptr
!= NULL
);
81 g_eventQueue_ptr
->scheduleEventAbsolute(m_consumer_ptr
, ready_time
);
84 // Don't always recalculate the next ready address
85 if (ready_time
<= m_next_time
) {
90 void TimerTable::unset(const Address
& address
)
92 assert(address
== line_address(address
));
93 assert(m_map
.exist(address
) == true);
94 m_map
.remove(address
);
96 // Don't always recalculate the next ready address
97 if (address
== m_next_address
) {
102 void TimerTable::print(ostream
& out
) const
107 void TimerTable::updateNext() const
109 if (m_map
.size() == 0) {
110 assert(m_next_valid
== false);
114 Vector
<Address
> addresses
= m_map
.keys();
115 m_next_address
= addresses
[0];
116 m_next_time
= m_map
.lookup(m_next_address
);
118 // Search for the minimum time
119 int size
= addresses
.size();
120 for (int i
=1; i
<size
; i
++) {
121 Address maybe_next_address
= addresses
[i
];
122 Time maybe_next_time
= m_map
.lookup(maybe_next_address
);
123 if (maybe_next_time
< m_next_time
) {
124 m_next_time
= maybe_next_time
;
125 m_next_address
= maybe_next_address
;