Message.hh revision 10987:a618349a7953
1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 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. 15 * 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. 27 */ 28 29#ifndef __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ 30#define __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ 31 32#include <iostream> 33#include <memory> 34#include <stack> 35 36#include "mem/packet.hh" 37#include "mem/protocol/MessageSizeType.hh" 38#include "mem/ruby/common/NetDest.hh" 39 40class Message; 41typedef std::shared_ptr<Message> MsgPtr; 42 43class Message 44{ 45 public: 46 Message(Tick curTime) 47 : m_time(curTime), 48 m_LastEnqueueTime(curTime), 49 m_DelayedTicks(0), m_msg_counter(0) 50 { } 51 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) 57 { } 58 59 virtual ~Message() { } 60 61 virtual MsgPtr clone() const = 0; 62 virtual void print(std::ostream& out) const = 0; 63 64 virtual const MessageSizeType& getMessageSize() const 65 { panic("MessageSizeType() called on wrong message!"); } 66 virtual MessageSizeType& getMessageSize() 67 { panic("MessageSizeType() called on wrong message!"); } 68 69 /** 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. 75 */ 76 virtual bool functionalRead(Packet *pkt) = 0; 77 virtual bool functionalWrite(Packet *pkt) = 0; 78 79 //! Update the delay this message has experienced so far. 80 void updateDelayedTicks(Tick curTime) 81 { 82 assert(m_LastEnqueueTime <= curTime); 83 Tick delta = curTime - m_LastEnqueueTime; 84 m_DelayedTicks += delta; 85 } 86 const Tick getDelayedTicks() const {return m_DelayedTicks;} 87 88 void setLastEnqueueTime(const Tick& time) { m_LastEnqueueTime = time; } 89 const Tick getLastEnqueueTime() const {return m_LastEnqueueTime;} 90 91 const 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; } 94 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!"); } 100 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; } 105 106 private: 107 const Tick m_time; 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? 111 112 // Variables for required network traversal 113 int incoming_link; 114 int vnet; 115}; 116 117inline bool 118operator>(const MsgPtr &lhs, const MsgPtr &rhs) 119{ 120 const Message *l = lhs.get(); 121 const Message *r = rhs.get(); 122 123 if (l->getLastEnqueueTime() == r->getLastEnqueueTime()) { 124 return l->getMsgCounter() > r->getMsgCounter(); 125 } 126 return l->getLastEnqueueTime() > r->getLastEnqueueTime(); 127} 128 129inline std::ostream& 130operator<<(std::ostream& out, const Message& obj) 131{ 132 obj.print(out); 133 out << std::flush; 134 return out; 135} 136 137#endif // __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ 138