TimerTable.hh revision 9507
12139SN/A/*
22139SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
32139SN/A * All rights reserved.
42139SN/A *
52139SN/A * Redistribution and use in source and binary forms, with or without
62139SN/A * modification, are permitted provided that the following conditions are
72139SN/A * met: redistributions of source code must retain the above copyright
82139SN/A * notice, this list of conditions and the following disclaimer;
92139SN/A * redistributions in binary form must reproduce the above copyright
102139SN/A * notice, this list of conditions and the following disclaimer in the
112139SN/A * documentation and/or other materials provided with the distribution;
122139SN/A * neither the name of the copyright holders nor the names of its
132139SN/A * contributors may be used to endorse or promote products derived from
142139SN/A * this software without specific prior written permission.
152139SN/A *
162139SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172139SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182139SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192139SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202139SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212139SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222139SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232139SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242139SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252139SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262139SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272139SN/A */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu#ifndef __MEM_RUBY_SYSTEM_TIMERTABLE_HH__
302139SN/A#define __MEM_RUBY_SYSTEM_TIMERTABLE_HH__
314202Sbinkertn@umich.edu
322139SN/A#include <cassert>
334202Sbinkertn@umich.edu#include <iostream>
342152SN/A#include <map>
352152SN/A#include <string>
362139SN/A
372139SN/A#include "mem/ruby/common/Address.hh"
382139SN/A#include "mem/ruby/common/Consumer.hh"
392139SN/A
402139SN/Aclass TimerTable
412152SN/A{
422152SN/A  public:
432139SN/A    TimerTable();
442139SN/A
452139SN/A    void
462984Sgblack@eecs.umich.edu    setConsumer(Consumer* consumer_ptr)
472439SN/A    {
483520Sgblack@eecs.umich.edu        assert(m_consumer_ptr == NULL);
492139SN/A        m_consumer_ptr = consumer_ptr;
503565Sgblack@eecs.umich.edu    }
513170Sstever@eecs.umich.edu
523806Ssaidi@eecs.umich.edu    void setClockObj(ClockedObject* obj)
532439SN/A    {
542460SN/A        assert(m_clockobj_ptr == NULL);
553536Sgblack@eecs.umich.edu        m_clockobj_ptr = obj;
562439SN/A    }
572972Sgblack@eecs.umich.edu
582171SN/A    void
592439SN/A    setDescription(const std::string& name)
602439SN/A    {
612170SN/A        m_name = name;
622139SN/A    }
632139SN/A
643546Sgblack@eecs.umich.edu    bool isReady() const;
654202Sbinkertn@umich.edu    const Address& readyAddress() const;
662152SN/A    bool isSet(const Address& address) const { return !!m_map.count(address); }
672152SN/A    void set(const Address& address, Cycles relative_latency);
682152SN/A    void set(const Address& address, uint64_t relative_latency)
692152SN/A    { set(address, Cycles(relative_latency)); }
702152SN/A
712152SN/A    void unset(const Address& address);
722152SN/A    void print(std::ostream& out) const;
732152SN/A
742152SN/A  private:
752152SN/A    void updateNext() const;
762152SN/A
772152SN/A    // Private copy constructor and assignment operator
782504SN/A    TimerTable(const TimerTable& obj);
792504SN/A    TimerTable& operator=(const TimerTable& obj);
802504SN/A
812504SN/A    // Data Members (m_prefix)
822152SN/A
832504SN/A    // use a std::map for the address map as this container is sorted
842152SN/A    // and ensures a well-defined iteration order
852152SN/A    typedef std::map<Address, Cycles> AddressMap;
862152SN/A    AddressMap m_map;
872152SN/A    mutable bool m_next_valid;
882152SN/A    mutable Cycles m_next_time; // Only valid if m_next_valid is true
892152SN/A    mutable Address m_next_address;  // Only valid if m_next_valid is true
902152SN/A
912152SN/A    //! Object used for querying time.
922632Sstever@eecs.umich.edu    ClockedObject* m_clockobj_ptr;
932155SN/A    //! Consumer to signal a wakeup()
942155SN/A    Consumer* m_consumer_ptr;
952155SN/A
962155SN/A    std::string m_name;
972155SN/A};
982155SN/A
994202Sbinkertn@umich.eduinline std::ostream&
1002155SN/Aoperator<<(std::ostream& out, const TimerTable& obj)
1012155SN/A{
1022155SN/A    obj.print(out);
1032152SN/A    out << std::flush;
1042766Sktlim@umich.edu    return out;
1052766Sktlim@umich.edu}
1062766Sktlim@umich.edu
1072766Sktlim@umich.edu#endif // __MEM_RUBY_SYSTEM_TIMERTABLE_HH__
1082766Sktlim@umich.edu