TimerTable.cc revision 11108
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" 3011108Sdavid.hashe@amd.com 3111108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh" 326145SN/A 336467SN/ATimerTable::TimerTable() 349507SN/A : m_next_time(0) 356145SN/A{ 367039SN/A m_consumer_ptr = NULL; 379465SN/A m_clockobj_ptr = NULL; 389465SN/A 397039SN/A m_next_valid = false; 4011025Snilay@cs.wisc.edu m_next_address = 0; 416145SN/A} 426145SN/A 437039SN/Abool 447039SN/ATimerTable::isReady() const 457039SN/A{ 467455SN/A if (m_map.empty()) 477039SN/A return false; 486145SN/A 497039SN/A if (!m_next_valid) { 507039SN/A updateNext(); 517039SN/A } 527039SN/A assert(m_next_valid); 539465SN/A return (m_clockobj_ptr->curCycle() >= m_next_time); 546145SN/A} 556145SN/A 5611025Snilay@cs.wisc.eduAddr 577039SN/ATimerTable::readyAddress() const 586145SN/A{ 597039SN/A assert(isReady()); 606145SN/A 617039SN/A if (!m_next_valid) { 627039SN/A updateNext(); 637039SN/A } 647039SN/A assert(m_next_valid); 657039SN/A return m_next_address; 666145SN/A} 676145SN/A 687039SN/Avoid 6911025Snilay@cs.wisc.eduTimerTable::set(Addr address, Cycles relative_latency) 706145SN/A{ 7111025Snilay@cs.wisc.edu assert(address == makeLineAddress(address)); 727039SN/A assert(relative_latency > 0); 737455SN/A assert(!m_map.count(address)); 749499SN/A 759499SN/A Cycles ready_time = m_clockobj_ptr->curCycle() + relative_latency; 767455SN/A m_map[address] = ready_time; 777039SN/A assert(m_consumer_ptr != NULL); 789600SN/A m_consumer_ptr-> 799600SN/A scheduleEventAbsolute(m_clockobj_ptr->clockPeriod() * ready_time); 807039SN/A m_next_valid = false; 816145SN/A 827039SN/A // Don't always recalculate the next ready address 837039SN/A if (ready_time <= m_next_time) { 847039SN/A m_next_valid = false; 857039SN/A } 866145SN/A} 876145SN/A 887039SN/Avoid 8911025Snilay@cs.wisc.eduTimerTable::unset(Addr address) 906145SN/A{ 9111025Snilay@cs.wisc.edu assert(address == makeLineAddress(address)); 927455SN/A assert(m_map.count(address)); 937455SN/A m_map.erase(address); 946145SN/A 957039SN/A // Don't always recalculate the next ready address 967039SN/A if (address == m_next_address) { 977039SN/A m_next_valid = false; 987039SN/A } 996145SN/A} 1006145SN/A 1017039SN/Avoid 1027055SN/ATimerTable::print(std::ostream& out) const 1036145SN/A{ 1046145SN/A} 1056145SN/A 1067039SN/Avoid 1077039SN/ATimerTable::updateNext() const 1087039SN/A{ 1097455SN/A if (m_map.empty()) { 1107455SN/A assert(!m_next_valid); 1117039SN/A return; 1127039SN/A } 1136145SN/A 1147455SN/A AddressMap::const_iterator i = m_map.begin(); 1157455SN/A AddressMap::const_iterator end = m_map.end(); 1166145SN/A 1177455SN/A m_next_address = i->first; 1187455SN/A m_next_time = i->second; 1197455SN/A ++i; 1207455SN/A 1217455SN/A for (; i != end; ++i) { 1227455SN/A if (i->second < m_next_time) { 1237455SN/A m_next_address = i->first; 1247455SN/A m_next_time = i->second; 1257039SN/A } 1266145SN/A } 1277455SN/A 1287039SN/A m_next_valid = true; 1296145SN/A} 130