TimerTable.hh revision 11025
12086SN/A/*
22086SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
35268Sksewell@umich.edu * All rights reserved.
42086SN/A *
52086SN/A * Redistribution and use in source and binary forms, with or without
62086SN/A * modification, are permitted provided that the following conditions are
72086SN/A * met: redistributions of source code must retain the above copyright
82086SN/A * notice, this list of conditions and the following disclaimer;
92086SN/A * redistributions in binary form must reproduce the above copyright
102086SN/A * notice, this list of conditions and the following disclaimer in the
112086SN/A * documentation and/or other materials provided with the distribution;
122086SN/A * neither the name of the copyright holders nor the names of its
132086SN/A * contributors may be used to endorse or promote products derived from
142086SN/A * this software without specific prior written permission.
152086SN/A *
162086SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172086SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182086SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192086SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202086SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212086SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222086SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232086SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242086SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252086SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262086SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272086SN/A */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu#ifndef __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
302665Ssaidi@eecs.umich.edu#define __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
312686Sksewell@umich.edu
322086SN/A#include <cassert>
334202Sbinkertn@umich.edu#include <iostream>
342086SN/A#include <map>
354202Sbinkertn@umich.edu#include <string>
368775Sgblack@eecs.umich.edu
379022Sgblack@eecs.umich.edu#include "mem/ruby/common/Address.hh"
388758Sgblack@eecs.umich.edu#include "mem/ruby/common/Consumer.hh"
394202Sbinkertn@umich.edu
408775Sgblack@eecs.umich.educlass TimerTable
418745Sgblack@eecs.umich.edu{
426313Sgblack@eecs.umich.edu  public:
438775Sgblack@eecs.umich.edu    TimerTable();
448775Sgblack@eecs.umich.edu
458775Sgblack@eecs.umich.edu    void
468758Sgblack@eecs.umich.edu    setConsumer(Consumer* consumer_ptr)
478775Sgblack@eecs.umich.edu    {
488758Sgblack@eecs.umich.edu        assert(m_consumer_ptr == NULL);
498775Sgblack@eecs.umich.edu        m_consumer_ptr = consumer_ptr;
508775Sgblack@eecs.umich.edu    }
514997Sgblack@eecs.umich.edu
524202Sbinkertn@umich.edu    void setClockObj(ClockedObject* obj)
538758Sgblack@eecs.umich.edu    {
544997Sgblack@eecs.umich.edu        assert(m_clockobj_ptr == NULL);
558745Sgblack@eecs.umich.edu        m_clockobj_ptr = obj;
568775Sgblack@eecs.umich.edu    }
574997Sgblack@eecs.umich.edu
585192Ssaidi@eecs.umich.edu    void
598775Sgblack@eecs.umich.edu    setDescription(const std::string& name)
602086SN/A    {
614202Sbinkertn@umich.edu        m_name = name;
624202Sbinkertn@umich.edu    }
634202Sbinkertn@umich.edu
644202Sbinkertn@umich.edu    bool isReady() const;
654202Sbinkertn@umich.edu    Addr readyAddress() const;
664202Sbinkertn@umich.edu    bool isSet(Addr address) const { return !!m_map.count(address); }
67    void set(Addr address, Cycles relative_latency);
68    void set(Addr address, uint64_t relative_latency)
69    { set(address, Cycles(relative_latency)); }
70
71    void unset(Addr address);
72    void print(std::ostream& out) const;
73
74  private:
75    void updateNext() const;
76
77    // Private copy constructor and assignment operator
78    TimerTable(const TimerTable& obj);
79    TimerTable& operator=(const TimerTable& obj);
80
81    // Data Members (m_prefix)
82
83    // use a std::map for the address map as this container is sorted
84    // and ensures a well-defined iteration order
85    typedef std::map<Addr, Cycles> AddressMap;
86    AddressMap m_map;
87    mutable bool m_next_valid;
88    mutable Cycles m_next_time; // Only valid if m_next_valid is true
89    mutable Addr m_next_address;  // Only valid if m_next_valid is true
90
91    //! Object used for querying time.
92    ClockedObject* m_clockobj_ptr;
93    //! Consumer to signal a wakeup()
94    Consumer* m_consumer_ptr;
95
96    std::string m_name;
97};
98
99inline std::ostream&
100operator<<(std::ostream& out, const TimerTable& obj)
101{
102    obj.print(out);
103    out << std::flush;
104    return out;
105}
106
107#endif // __MEM_RUBY_STRUCTURES_TIMERTABLE_HH__
108