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;
377039SN/A    m_next_valid = false;
3811025Snilay@cs.wisc.edu    m_next_address = 0;
396145SN/A}
406145SN/A
417039SN/Abool
4211111Snilay@cs.wisc.eduTimerTable::isReady(Tick curTime) const
437039SN/A{
447455SN/A    if (m_map.empty())
457039SN/A        return false;
466145SN/A
477039SN/A    if (!m_next_valid) {
487039SN/A        updateNext();
497039SN/A    }
507039SN/A    assert(m_next_valid);
5111111Snilay@cs.wisc.edu    return (curTime >= m_next_time);
526145SN/A}
536145SN/A
5411025Snilay@cs.wisc.eduAddr
5511111Snilay@cs.wisc.eduTimerTable::nextAddress() const
566145SN/A{
577039SN/A    if (!m_next_valid) {
587039SN/A        updateNext();
597039SN/A    }
607039SN/A    assert(m_next_valid);
617039SN/A    return m_next_address;
626145SN/A}
636145SN/A
647039SN/Avoid
6511111Snilay@cs.wisc.eduTimerTable::set(Addr address, Tick ready_time)
666145SN/A{
6711025Snilay@cs.wisc.edu    assert(address == makeLineAddress(address));
687455SN/A    assert(!m_map.count(address));
699499SN/A
707455SN/A    m_map[address] = ready_time;
717039SN/A    assert(m_consumer_ptr != NULL);
7211111Snilay@cs.wisc.edu    m_consumer_ptr->scheduleEventAbsolute(ready_time);
737039SN/A    m_next_valid = false;
746145SN/A
757039SN/A    // Don't always recalculate the next ready address
767039SN/A    if (ready_time <= m_next_time) {
777039SN/A        m_next_valid = false;
787039SN/A    }
796145SN/A}
806145SN/A
817039SN/Avoid
8211025Snilay@cs.wisc.eduTimerTable::unset(Addr address)
836145SN/A{
8411025Snilay@cs.wisc.edu    assert(address == makeLineAddress(address));
857455SN/A    assert(m_map.count(address));
867455SN/A    m_map.erase(address);
876145SN/A
887039SN/A    // Don't always recalculate the next ready address
897039SN/A    if (address == m_next_address) {
907039SN/A        m_next_valid = false;
917039SN/A    }
926145SN/A}
936145SN/A
947039SN/Avoid
957055SN/ATimerTable::print(std::ostream& out) const
966145SN/A{
976145SN/A}
986145SN/A
997039SN/Avoid
1007039SN/ATimerTable::updateNext() const
1017039SN/A{
1027455SN/A    if (m_map.empty()) {
1037455SN/A        assert(!m_next_valid);
1047039SN/A        return;
1057039SN/A    }
1066145SN/A
1077455SN/A    AddressMap::const_iterator i = m_map.begin();
1087455SN/A    AddressMap::const_iterator end = m_map.end();
1096145SN/A
1107455SN/A    m_next_address = i->first;
1117455SN/A    m_next_time = i->second;
1127455SN/A    ++i;
1137455SN/A
1147455SN/A    for (; i != end; ++i) {
1157455SN/A        if (i->second < m_next_time) {
1167455SN/A            m_next_address = i->first;
1177455SN/A            m_next_time = i->second;
1187039SN/A        }
1196145SN/A    }
1207455SN/A
1217039SN/A    m_next_valid = true;
1226145SN/A}
123