TimerTable.hh revision 10441
112863Sgabeblack@google.com/*
212863Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
312863Sgabeblack@google.com * All rights reserved.
412863Sgabeblack@google.com *
512863Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612863Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712863Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812863Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912863Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012863Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112863Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212863Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312863Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412863Sgabeblack@google.com * this software without specific prior written permission.
1512863Sgabeblack@google.com *
1612863Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712863Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812863Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912863Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012863Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112863Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212863Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312863Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412863Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512863Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612863Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712863Sgabeblack@google.com */
2812863Sgabeblack@google.com
2912863Sgabeblack@google.com#ifndef __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
3012863Sgabeblack@google.com#define __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
3112863Sgabeblack@google.com
3212863Sgabeblack@google.com#include <cassert>
3312950Sgabeblack@google.com#include <iostream>
3413046Sgabeblack@google.com#include <map>
3513035Sgabeblack@google.com#include <string>
3613035Sgabeblack@google.com
3713035Sgabeblack@google.com#include "mem/ruby/common/Address.hh"
3813053Sgabeblack@google.com#include "mem/ruby/common/Consumer.hh"
3912950Sgabeblack@google.com
4012950Sgabeblack@google.comclass TimerTable
4112950Sgabeblack@google.com{
4212950Sgabeblack@google.com  public:
4313053Sgabeblack@google.com    TimerTable();
4413053Sgabeblack@google.com
4513053Sgabeblack@google.com    void
4613053Sgabeblack@google.com    setConsumer(Consumer* consumer_ptr)
4713053Sgabeblack@google.com    {
4813053Sgabeblack@google.com        assert(m_consumer_ptr == NULL);
4913053Sgabeblack@google.com        m_consumer_ptr = consumer_ptr;
5012950Sgabeblack@google.com    }
5112863Sgabeblack@google.com
5212863Sgabeblack@google.com    void setClockObj(ClockedObject* obj)
5313035Sgabeblack@google.com    {
5413035Sgabeblack@google.com        assert(m_clockobj_ptr == NULL);
5513035Sgabeblack@google.com        m_clockobj_ptr = obj;
5613035Sgabeblack@google.com    }
5713035Sgabeblack@google.com
5813035Sgabeblack@google.com    void
5913035Sgabeblack@google.com    setDescription(const std::string& name)
6013035Sgabeblack@google.com    {
6113035Sgabeblack@google.com        m_name = name;
6213035Sgabeblack@google.com    }
6313035Sgabeblack@google.com
6413035Sgabeblack@google.com    bool isReady() const;
6513035Sgabeblack@google.com    const Address& readyAddress() const;
6613035Sgabeblack@google.com    bool isSet(const Address& address) const { return !!m_map.count(address); }
6713035Sgabeblack@google.com    void set(const Address& address, Cycles relative_latency);
6813035Sgabeblack@google.com    void set(const Address& address, uint64_t relative_latency)
6913035Sgabeblack@google.com    { set(address, Cycles(relative_latency)); }
7012863Sgabeblack@google.com
7112863Sgabeblack@google.com    void unset(const Address& address);
7212863Sgabeblack@google.com    void print(std::ostream& out) const;
7312863Sgabeblack@google.com
7412950Sgabeblack@google.com  private:
7512950Sgabeblack@google.com    void updateNext() const;
7612863Sgabeblack@google.com
7713035Sgabeblack@google.com    // Private copy constructor and assignment operator
7813035Sgabeblack@google.com    TimerTable(const TimerTable& obj);
7912863Sgabeblack@google.com    TimerTable& operator=(const TimerTable& obj);
8012863Sgabeblack@google.com
8112950Sgabeblack@google.com    // Data Members (m_prefix)
8212982Sgabeblack@google.com
8312982Sgabeblack@google.com    // use a std::map for the address map as this container is sorted
8412950Sgabeblack@google.com    // and ensures a well-defined iteration order
8512863Sgabeblack@google.com    typedef std::map<Address, Cycles> AddressMap;
8612950Sgabeblack@google.com    AddressMap m_map;
8712950Sgabeblack@google.com    mutable bool m_next_valid;
8812950Sgabeblack@google.com    mutable Cycles m_next_time; // Only valid if m_next_valid is true
8912950Sgabeblack@google.com    mutable Address m_next_address;  // Only valid if m_next_valid is true
9012950Sgabeblack@google.com
9112950Sgabeblack@google.com    //! Object used for querying time.
9212950Sgabeblack@google.com    ClockedObject* m_clockobj_ptr;
9312950Sgabeblack@google.com    //! Consumer to signal a wakeup()
9412950Sgabeblack@google.com    Consumer* m_consumer_ptr;
9512950Sgabeblack@google.com
9612950Sgabeblack@google.com    std::string m_name;
9712950Sgabeblack@google.com};
9812950Sgabeblack@google.com
9912950Sgabeblack@google.cominline std::ostream&
10012950Sgabeblack@google.comoperator<<(std::ostream& out, const TimerTable& obj)
10112950Sgabeblack@google.com{
10212950Sgabeblack@google.com    obj.print(out);
10312950Sgabeblack@google.com    out << std::flush;
10412950Sgabeblack@google.com    return out;
10512950Sgabeblack@google.com}
10612950Sgabeblack@google.com
10712950Sgabeblack@google.com#endif // __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
10812950Sgabeblack@google.com