TimerTable.hh revision 10441
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
2910441Snilay@cs.wisc.edu#ifndef __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
3010441Snilay@cs.wisc.edu#define __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
316145SN/A
327039SN/A#include <cassert>
337055SN/A#include <iostream>
349171SN/A#include <map>
357055SN/A#include <string>
366145SN/A
376154SN/A#include "mem/ruby/common/Address.hh"
389171SN/A#include "mem/ruby/common/Consumer.hh"
396145SN/A
407039SN/Aclass TimerTable
417039SN/A{
427039SN/A  public:
437039SN/A    TimerTable();
446145SN/A
457039SN/A    void
467039SN/A    setConsumer(Consumer* consumer_ptr)
477039SN/A    {
487039SN/A        assert(m_consumer_ptr == NULL);
497039SN/A        m_consumer_ptr = consumer_ptr;
507039SN/A    }
516145SN/A
529465SN/A    void setClockObj(ClockedObject* obj)
539465SN/A    {
549465SN/A        assert(m_clockobj_ptr == NULL);
559465SN/A        m_clockobj_ptr = obj;
569465SN/A    }
579465SN/A
587039SN/A    void
597055SN/A    setDescription(const std::string& name)
607039SN/A    {
617039SN/A        m_name = name;
627039SN/A    }
636145SN/A
647039SN/A    bool isReady() const;
657039SN/A    const Address& readyAddress() const;
667455SN/A    bool isSet(const Address& address) const { return !!m_map.count(address); }
679499SN/A    void set(const Address& address, Cycles relative_latency);
689499SN/A    void set(const Address& address, uint64_t relative_latency)
699499SN/A    { set(address, Cycles(relative_latency)); }
709499SN/A
717039SN/A    void unset(const Address& address);
727055SN/A    void print(std::ostream& out) const;
736145SN/A
747039SN/A  private:
757039SN/A    void updateNext() const;
766145SN/A
777039SN/A    // Private copy constructor and assignment operator
787039SN/A    TimerTable(const TimerTable& obj);
797039SN/A    TimerTable& operator=(const TimerTable& obj);
806145SN/A
817039SN/A    // Data Members (m_prefix)
828943SN/A
838943SN/A    // use a std::map for the address map as this container is sorted
848943SN/A    // and ensures a well-defined iteration order
859499SN/A    typedef std::map<Address, Cycles> AddressMap;
867455SN/A    AddressMap m_map;
877039SN/A    mutable bool m_next_valid;
889507SN/A    mutable Cycles m_next_time; // Only valid if m_next_valid is true
897039SN/A    mutable Address m_next_address;  // Only valid if m_next_valid is true
909465SN/A
919465SN/A    //! Object used for querying time.
929465SN/A    ClockedObject* m_clockobj_ptr;
939465SN/A    //! Consumer to signal a wakeup()
949465SN/A    Consumer* m_consumer_ptr;
959465SN/A
967055SN/A    std::string m_name;
976145SN/A};
986145SN/A
997055SN/Ainline std::ostream&
1007055SN/Aoperator<<(std::ostream& out, const TimerTable& obj)
1016145SN/A{
1027039SN/A    obj.print(out);
1037055SN/A    out << std::flush;
1047039SN/A    return out;
1056145SN/A}
1067039SN/A
10710441Snilay@cs.wisc.edu#endif // __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
108