2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__
30 #define __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__
36 #include "mem/packet.hh"
37 #include "mem/ruby/common/NetDest.hh"
38 #include "mem/ruby/protocol/MessageSizeType.hh"
41 typedef std::shared_ptr<Message> MsgPtr;
48 m_LastEnqueueTime(curTime),
49 m_DelayedTicks(0), m_msg_counter(0)
52 Message(const Message &other)
53 : m_time(other.m_time),
54 m_LastEnqueueTime(other.m_LastEnqueueTime),
55 m_DelayedTicks(other.m_DelayedTicks),
56 m_msg_counter(other.m_msg_counter)
59 virtual ~Message() { }
61 virtual MsgPtr clone() const = 0;
62 virtual void print(std::ostream& out) const = 0;
64 virtual const MessageSizeType& getMessageSize() const
65 { panic("MessageSizeType() called on wrong message!"); }
66 virtual MessageSizeType& getMessageSize()
67 { panic("MessageSizeType() called on wrong message!"); }
70 * The two functions below are used for reading / writing the message
71 * functionally. The methods return true if the address in the packet
72 * matches the address / address range in the message. Each message
73 * class that can be potentially searched for the address needs to
74 * implement these methods.
76 virtual bool functionalRead(Packet *pkt) = 0;
77 virtual bool functionalWrite(Packet *pkt) = 0;
79 //! Update the delay this message has experienced so far.
80 void updateDelayedTicks(Tick curTime)
82 assert(m_LastEnqueueTime <= curTime);
83 Tick delta = curTime - m_LastEnqueueTime;
84 m_DelayedTicks += delta;
86 Tick getDelayedTicks() const {return m_DelayedTicks;}
88 void setLastEnqueueTime(const Tick& time) { m_LastEnqueueTime = time; }
89 Tick getLastEnqueueTime() const {return m_LastEnqueueTime;}
91 Tick getTime() const { return m_time; }
92 void setMsgCounter(uint64_t c) { m_msg_counter = c; }
93 uint64_t getMsgCounter() const { return m_msg_counter; }
95 // Functions related to network traversal
96 virtual const NetDest& getDestination() const
97 { panic("getDestination() called on wrong message!"); }
98 virtual NetDest& getDestination()
99 { panic("getDestination() called on wrong message!"); }
101 int getIncomingLink() const { return incoming_link; }
102 void setIncomingLink(int link) { incoming_link = link; }
103 int getVnet() const { return vnet; }
104 void setVnet(int net) { vnet = net; }
108 Tick m_LastEnqueueTime; // my last enqueue time
109 Tick m_DelayedTicks; // my delayed cycles
110 uint64_t m_msg_counter; // FIXME, should this be a 64-bit value?
112 // Variables for required network traversal
118 operator>(const MsgPtr &lhs, const MsgPtr &rhs)
120 const Message *l = lhs.get();
121 const Message *r = rhs.get();
123 if (l->getLastEnqueueTime() == r->getLastEnqueueTime()) {
124 return l->getMsgCounter() > r->getMsgCounter();
126 return l->getLastEnqueueTime() > r->getLastEnqueueTime();
130 operator<<(std::ostream& out, const Message& obj)
137 #endif // __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__