TimerTable.cc revision 10301:44839e8febbd
17032SN/A/* 27032SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 37032SN/A * All rights reserved. 47032SN/A * 57032SN/A * Redistribution and use in source and binary forms, with or without 67032SN/A * modification, are permitted provided that the following conditions are 77032SN/A * met: redistributions of source code must retain the above copyright 87032SN/A * notice, this list of conditions and the following disclaimer; 97032SN/A * redistributions in binary form must reproduce the above copyright 107032SN/A * notice, this list of conditions and the following disclaimer in the 117032SN/A * documentation and/or other materials provided with the distribution; 127032SN/A * neither the name of the copyright holders nor the names of its 137032SN/A * contributors may be used to endorse or promote products derived from 147032SN/A * this software without specific prior written permission. 157032SN/A * 167032SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177032SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187032SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197032SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207032SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217032SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227032SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237032SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247032SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257032SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267032SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277032SN/A */ 287032SN/A 297032SN/A#include "mem/ruby/common/Global.hh" 307032SN/A#include "mem/ruby/structures/TimerTable.hh" 317032SN/A#include "mem/ruby/system/System.hh" 329148Spowerjg@cs.wisc.edu 339100SBrad.Beckmann@amd.comTimerTable::TimerTable() 349148Spowerjg@cs.wisc.edu : m_next_time(0) 357540SN/A{ 367540SN/A m_consumer_ptr = NULL; 379862Snilay@cs.wisc.edu m_clockobj_ptr = NULL; 389862Snilay@cs.wisc.edu 399862Snilay@cs.wisc.edu m_next_valid = false; 409862Snilay@cs.wisc.edu m_next_address = Address(0); 419862Snilay@cs.wisc.edu} 4211663Stushar@ece.gatech.edu 437032SN/Abool 449100SBrad.Beckmann@amd.comTimerTable::isReady() const 459862Snilay@cs.wisc.edu{ 469862Snilay@cs.wisc.edu if (m_map.empty()) 479862Snilay@cs.wisc.edu return false; 489100SBrad.Beckmann@amd.com 499100SBrad.Beckmann@amd.com if (!m_next_valid) { 509862Snilay@cs.wisc.edu updateNext(); 519862Snilay@cs.wisc.edu } 529100SBrad.Beckmann@amd.com assert(m_next_valid); 5311663Stushar@ece.gatech.edu return (m_clockobj_ptr->curCycle() >= m_next_time); 5411663Stushar@ece.gatech.edu} 5511663Stushar@ece.gatech.edu 5611663Stushar@ece.gatech.educonst Address& 5711663Stushar@ece.gatech.eduTimerTable::readyAddress() const 5811663Stushar@ece.gatech.edu{ 5911663Stushar@ece.gatech.edu assert(isReady()); 6011663Stushar@ece.gatech.edu 6111663Stushar@ece.gatech.edu if (!m_next_valid) { 6211663Stushar@ece.gatech.edu updateNext(); 6311663Stushar@ece.gatech.edu } 6411663Stushar@ece.gatech.edu assert(m_next_valid); 6511663Stushar@ece.gatech.edu return m_next_address; 6611663Stushar@ece.gatech.edu} 679862Snilay@cs.wisc.edu 68void 69TimerTable::set(const Address& address, Cycles relative_latency) 70{ 71 assert(address == line_address(address)); 72 assert(relative_latency > 0); 73 assert(!m_map.count(address)); 74 75 Cycles ready_time = m_clockobj_ptr->curCycle() + relative_latency; 76 m_map[address] = ready_time; 77 assert(m_consumer_ptr != NULL); 78 m_consumer_ptr-> 79 scheduleEventAbsolute(m_clockobj_ptr->clockPeriod() * ready_time); 80 m_next_valid = false; 81 82 // Don't always recalculate the next ready address 83 if (ready_time <= m_next_time) { 84 m_next_valid = false; 85 } 86} 87 88void 89TimerTable::unset(const Address& address) 90{ 91 assert(address == line_address(address)); 92 assert(m_map.count(address)); 93 m_map.erase(address); 94 95 // Don't always recalculate the next ready address 96 if (address == m_next_address) { 97 m_next_valid = false; 98 } 99} 100 101void 102TimerTable::print(std::ostream& out) const 103{ 104} 105 106void 107TimerTable::updateNext() const 108{ 109 if (m_map.empty()) { 110 assert(!m_next_valid); 111 return; 112 } 113 114 AddressMap::const_iterator i = m_map.begin(); 115 AddressMap::const_iterator end = m_map.end(); 116 117 m_next_address = i->first; 118 m_next_time = i->second; 119 ++i; 120 121 for (; i != end; ++i) { 122 if (i->second < m_next_time) { 123 m_next_address = i->first; 124 m_next_time = i->second; 125 } 126 } 127 128 m_next_valid = true; 129} 130