TimerTable.cc revision 7055
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#include "mem/ruby/common/Global.hh" 30#include "mem/ruby/eventqueue/RubyEventQueue.hh" 31#include "mem/ruby/system/TimerTable.hh" 32 33TimerTable::TimerTable() 34{ 35 m_consumer_ptr = NULL; 36 m_next_valid = false; 37 m_next_address = Address(0); 38 m_next_time = 0; 39} 40 41bool 42TimerTable::isReady() const 43{ 44 if (m_map.size() == 0) { 45 return false; 46 } 47 48 if (!m_next_valid) { 49 updateNext(); 50 } 51 assert(m_next_valid); 52 return (g_eventQueue_ptr->getTime() >= m_next_time); 53} 54 55const Address& 56TimerTable::readyAddress() const 57{ 58 assert(isReady()); 59 60 if (!m_next_valid) { 61 updateNext(); 62 } 63 assert(m_next_valid); 64 return m_next_address; 65} 66 67void 68TimerTable::set(const Address& address, Time relative_latency) 69{ 70 assert(address == line_address(address)); 71 assert(relative_latency > 0); 72 assert(m_map.exist(address) == false); 73 Time ready_time = g_eventQueue_ptr->getTime() + relative_latency; 74 m_map.add(address, ready_time); 75 assert(m_consumer_ptr != NULL); 76 g_eventQueue_ptr->scheduleEventAbsolute(m_consumer_ptr, ready_time); 77 m_next_valid = false; 78 79 // Don't always recalculate the next ready address 80 if (ready_time <= m_next_time) { 81 m_next_valid = false; 82 } 83} 84 85void 86TimerTable::unset(const Address& address) 87{ 88 assert(address == line_address(address)); 89 assert(m_map.exist(address) == true); 90 m_map.remove(address); 91 92 // Don't always recalculate the next ready address 93 if (address == m_next_address) { 94 m_next_valid = false; 95 } 96} 97 98void 99TimerTable::print(std::ostream& out) const 100{ 101} 102 103void 104TimerTable::updateNext() const 105{ 106 if (m_map.size() == 0) { 107 assert(m_next_valid == false); 108 return; 109 } 110 111 Vector<Address> addresses = m_map.keys(); 112 m_next_address = addresses[0]; 113 m_next_time = m_map.lookup(m_next_address); 114 115 // Search for the minimum time 116 int size = addresses.size(); 117 for (int i=1; i<size; i++) { 118 Address maybe_next_address = addresses[i]; 119 Time maybe_next_time = m_map.lookup(maybe_next_address); 120 if (maybe_next_time < m_next_time) { 121 m_next_time = maybe_next_time; 122 m_next_address= maybe_next_address; 123 } 124 } 125 m_next_valid = true; 126} 127