TimerTable.cc revision 11025
16145SN/A/* 26145SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145SN/A * All rights reserved. 46145SN/A * 56145SN/A * Redistribution and use in source and binary forms, with or without 66145SN/A * modification, are permitted provided that the following conditions are 76145SN/A * met: redistributions of source code must retain the above copyright 86145SN/A * notice, this list of conditions and the following disclaimer; 96145SN/A * redistributions in binary form must reproduce the above copyright 106145SN/A * notice, this list of conditions and the following disclaimer in the 116145SN/A * documentation and/or other materials provided with the distribution; 126145SN/A * neither the name of the copyright holders nor the names of its 136145SN/A * contributors may be used to endorse or promote products derived from 146145SN/A * this software without specific prior written permission. 156145SN/A * 166145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145SN/A */ 286145SN/A 2910301Snilay@cs.wisc.edu#include "mem/ruby/structures/TimerTable.hh" 309171SN/A#include "mem/ruby/system/System.hh" 316145SN/A 326467SN/ATimerTable::TimerTable() 339507SN/A : m_next_time(0) 346145SN/A{ 357039SN/A m_consumer_ptr = NULL; 369465SN/A m_clockobj_ptr = NULL; 379465SN/A 387039SN/A m_next_valid = false; 3911025Snilay@cs.wisc.edu m_next_address = 0; 406145SN/A} 416145SN/A 427039SN/Abool 437039SN/ATimerTable::isReady() const 447039SN/A{ 457455SN/A if (m_map.empty()) 467039SN/A return false; 476145SN/A 487039SN/A if (!m_next_valid) { 497039SN/A updateNext(); 507039SN/A } 517039SN/A assert(m_next_valid); 529465SN/A return (m_clockobj_ptr->curCycle() >= m_next_time); 536145SN/A} 546145SN/A 5511025Snilay@cs.wisc.eduAddr 567039SN/ATimerTable::readyAddress() const 576145SN/A{ 587039SN/A assert(isReady()); 596145SN/A 607039SN/A if (!m_next_valid) { 617039SN/A updateNext(); 627039SN/A } 637039SN/A assert(m_next_valid); 647039SN/A return m_next_address; 656145SN/A} 666145SN/A 677039SN/Avoid 6811025Snilay@cs.wisc.eduTimerTable::set(Addr address, Cycles relative_latency) 696145SN/A{ 7011025Snilay@cs.wisc.edu assert(address == makeLineAddress(address)); 717039SN/A assert(relative_latency > 0); 727455SN/A assert(!m_map.count(address)); 739499SN/A 749499SN/A Cycles ready_time = m_clockobj_ptr->curCycle() + relative_latency; 757455SN/A m_map[address] = ready_time; 767039SN/A assert(m_consumer_ptr != NULL); 779600SN/A m_consumer_ptr-> 789600SN/A scheduleEventAbsolute(m_clockobj_ptr->clockPeriod() * ready_time); 797039SN/A m_next_valid = false; 806145SN/A 817039SN/A // Don't always recalculate the next ready address 827039SN/A if (ready_time <= m_next_time) { 837039SN/A m_next_valid = false; 847039SN/A } 856145SN/A} 866145SN/A 877039SN/Avoid 8811025Snilay@cs.wisc.eduTimerTable::unset(Addr address) 896145SN/A{ 9011025Snilay@cs.wisc.edu assert(address == makeLineAddress(address)); 917455SN/A assert(m_map.count(address)); 927455SN/A m_map.erase(address); 936145SN/A 947039SN/A // Don't always recalculate the next ready address 957039SN/A if (address == m_next_address) { 967039SN/A m_next_valid = false; 977039SN/A } 986145SN/A} 996145SN/A 1007039SN/Avoid 1017055SN/ATimerTable::print(std::ostream& out) const 1026145SN/A{ 1036145SN/A} 1046145SN/A 1057039SN/Avoid 1067039SN/ATimerTable::updateNext() const 1077039SN/A{ 1087455SN/A if (m_map.empty()) { 1097455SN/A assert(!m_next_valid); 1107039SN/A return; 1117039SN/A } 1126145SN/A 1137455SN/A AddressMap::const_iterator i = m_map.begin(); 1147455SN/A AddressMap::const_iterator end = m_map.end(); 1156145SN/A 1167455SN/A m_next_address = i->first; 1177455SN/A m_next_time = i->second; 1187455SN/A ++i; 1197455SN/A 1207455SN/A for (; i != end; ++i) { 1217455SN/A if (i->second < m_next_time) { 1227455SN/A m_next_address = i->first; 1237455SN/A m_next_time = i->second; 1247039SN/A } 1256145SN/A } 1267455SN/A 1277039SN/A m_next_valid = true; 1286145SN/A} 129