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/* 30 * Unordered buffer of messages that can be inserted such 31 * that they can be dequeued after a given delta time has expired. 32 */ 33 34#ifndef __MEM_RUBY_BUFFERS_MESSAGEBUFFER_HH__ 35#define __MEM_RUBY_BUFFERS_MESSAGEBUFFER_HH__ 36 37#include <algorithm> 38#include <cassert> 39#include <functional> 40#include <iostream> 41#include <string> 42#include <vector> 43
| 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/* 30 * Unordered buffer of messages that can be inserted such 31 * that they can be dequeued after a given delta time has expired. 32 */ 33 34#ifndef __MEM_RUBY_BUFFERS_MESSAGEBUFFER_HH__ 35#define __MEM_RUBY_BUFFERS_MESSAGEBUFFER_HH__ 36 37#include <algorithm> 38#include <cassert> 39#include <functional> 40#include <iostream> 41#include <string> 42#include <vector> 43
|
| 44#include "debug/RubyQueue.hh"
|
44#include "mem/ruby/common/Address.hh" 45#include "mem/ruby/common/Consumer.hh" 46#include "mem/ruby/slicc_interface/Message.hh" 47#include "mem/packet.hh"
| 45#include "mem/ruby/common/Address.hh" 46#include "mem/ruby/common/Consumer.hh" 47#include "mem/ruby/slicc_interface/Message.hh" 48#include "mem/packet.hh"
|
| 49#include "params/MessageBuffer.hh" 50#include "sim/sim_object.hh"
|
48
| 51
|
49class MessageBuffer
| 52class MessageBuffer : public SimObject
|
50{ 51 public:
| 53{ 54 public:
|
52 MessageBuffer(const std::string &name = "");
| 55 typedef MessageBufferParams Params; 56 MessageBuffer(const Params *p);
|
53
| 57
|
54 std::string name() const { return m_name; } 55 56 void setRecycleLatency(Cycles recycle_latency) 57 { m_recycle_latency = recycle_latency; } 58
| |
59 void reanalyzeMessages(const Address& addr); 60 void reanalyzeAllMessages(); 61 void stallMessage(const Address& addr); 62 63 // TRUE if head of queue timestamp <= SystemTime 64 bool isReady() const; 65 66 void 67 delayHead() 68 { 69 MsgPtr m = m_prio_heap.front(); 70 std::pop_heap(m_prio_heap.begin(), m_prio_heap.end(), 71 std::greater<MsgPtr>()); 72 m_prio_heap.pop_back(); 73 enqueue(m, Cycles(1)); 74 } 75 76 bool areNSlotsAvailable(unsigned int n); 77 int getPriority() { return m_priority_rank; } 78 void setPriority(int rank) { m_priority_rank = rank; } 79 void setConsumer(Consumer* consumer) 80 {
| 58 void reanalyzeMessages(const Address& addr); 59 void reanalyzeAllMessages(); 60 void stallMessage(const Address& addr); 61 62 // TRUE if head of queue timestamp <= SystemTime 63 bool isReady() const; 64 65 void 66 delayHead() 67 { 68 MsgPtr m = m_prio_heap.front(); 69 std::pop_heap(m_prio_heap.begin(), m_prio_heap.end(), 70 std::greater<MsgPtr>()); 71 m_prio_heap.pop_back(); 72 enqueue(m, Cycles(1)); 73 } 74 75 bool areNSlotsAvailable(unsigned int n); 76 int getPriority() { return m_priority_rank; } 77 void setPriority(int rank) { m_priority_rank = rank; } 78 void setConsumer(Consumer* consumer) 79 {
|
| 80 DPRINTF(RubyQueue, "Setting consumer: %s\n", *consumer);
|
81 if (m_consumer != NULL) { 82 fatal("Trying to connect %s to MessageBuffer %s. \ 83 \n%s already connected. Check the cntrl_id's.\n", 84 *consumer, *this, *m_consumer); 85 } 86 m_consumer = consumer; 87 } 88 89 void setSender(ClockedObject* obj) 90 {
| 81 if (m_consumer != NULL) { 82 fatal("Trying to connect %s to MessageBuffer %s. \ 83 \n%s already connected. Check the cntrl_id's.\n", 84 *consumer, *this, *m_consumer); 85 } 86 m_consumer = consumer; 87 } 88 89 void setSender(ClockedObject* obj) 90 {
|
| 91 DPRINTF(RubyQueue, "Setting sender: %s\n", obj->name());
|
91 assert(m_sender == NULL || m_sender == obj); 92 m_sender = obj; 93 } 94 95 void setReceiver(ClockedObject* obj) 96 {
| 92 assert(m_sender == NULL || m_sender == obj); 93 m_sender = obj; 94 } 95 96 void setReceiver(ClockedObject* obj) 97 {
|
| 98 DPRINTF(RubyQueue, "Setting receiver: %s\n", obj->name());
|
97 assert(m_receiver == NULL || m_receiver == obj); 98 m_receiver = obj; 99 } 100
| 99 assert(m_receiver == NULL || m_receiver == obj); 100 m_receiver = obj; 101 } 102
|
101 void setDescription(const std::string& name) { m_name = name; } 102 std::string getDescription() { return m_name;} 103
| |
104 Consumer* getConsumer() { return m_consumer; } 105
| 103 Consumer* getConsumer() { return m_consumer; } 104
|
| 105 bool getOrdered() { return m_strict_fifo; } 106
|
106 //! Function for extracting the message at the head of the 107 //! message queue. The function assumes that the queue is nonempty. 108 const Message* peek() const; 109 110 const MsgPtr& 111 peekMsgPtr() const 112 { 113 assert(isReady()); 114 return m_prio_heap.front(); 115 } 116 117 void enqueue(MsgPtr message) { enqueue(message, Cycles(1)); } 118 void enqueue(MsgPtr message, Cycles delta); 119 120 //! Updates the delay cycles of the message at the head of the queue, 121 //! removes it from the queue and returns its total delay. 122 Cycles dequeue(); 123 124 void recycle(); 125 bool isEmpty() const { return m_prio_heap.size() == 0; } 126 bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; } 127 unsigned int getStallMapSize() { return m_stall_msg_map.size(); } 128
| 107 //! Function for extracting the message at the head of the 108 //! message queue. The function assumes that the queue is nonempty. 109 const Message* peek() const; 110 111 const MsgPtr& 112 peekMsgPtr() const 113 { 114 assert(isReady()); 115 return m_prio_heap.front(); 116 } 117 118 void enqueue(MsgPtr message) { enqueue(message, Cycles(1)); } 119 void enqueue(MsgPtr message, Cycles delta); 120 121 //! Updates the delay cycles of the message at the head of the queue, 122 //! removes it from the queue and returns its total delay. 123 Cycles dequeue(); 124 125 void recycle(); 126 bool isEmpty() const { return m_prio_heap.size() == 0; } 127 bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; } 128 unsigned int getStallMapSize() { return m_stall_msg_map.size(); } 129
|
129 void 130 setOrdering(bool order) 131 { 132 m_strict_fifo = order; 133 m_ordering_set = true; 134 } 135 136 void resize(unsigned int size) { m_max_size = size; }
| |
137 unsigned int getSize();
| 130 unsigned int getSize();
|
138 void setRandomization(bool random_flag) { m_randomization = random_flag; }
| |
139 140 void clear(); 141 void print(std::ostream& out) const; 142 void clearStats() { m_not_avail_count = 0; m_msg_counter = 0; } 143 144 void setIncomingLink(int link_id) { m_input_link_id = link_id; } 145 void setVnet(int net) { m_vnet_id = net; } 146 147 // Function for figuring out if any of the messages in the buffer can 148 // satisfy the read request for the address in the packet. 149 // Return value, if true, indicates that the request was fulfilled. 150 bool functionalRead(Packet *pkt); 151 152 // Function for figuring out if any of the messages in the buffer need 153 // to be updated with the data from the packet. 154 // Return value indicates the number of messages that were updated. 155 // This required for debugging the code. 156 uint32_t functionalWrite(Packet *pkt); 157 158 private:
| 131 132 void clear(); 133 void print(std::ostream& out) const; 134 void clearStats() { m_not_avail_count = 0; m_msg_counter = 0; } 135 136 void setIncomingLink(int link_id) { m_input_link_id = link_id; } 137 void setVnet(int net) { m_vnet_id = net; } 138 139 // Function for figuring out if any of the messages in the buffer can 140 // satisfy the read request for the address in the packet. 141 // Return value, if true, indicates that the request was fulfilled. 142 bool functionalRead(Packet *pkt); 143 144 // Function for figuring out if any of the messages in the buffer need 145 // to be updated with the data from the packet. 146 // Return value indicates the number of messages that were updated. 147 // This required for debugging the code. 148 uint32_t functionalWrite(Packet *pkt); 149 150 private:
|
| 151 //added by SS 152 const Cycles m_recycle_latency; 153
|
159 void reanalyzeList(std::list<MsgPtr> &, Tick); 160 161 private:
| 154 void reanalyzeList(std::list<MsgPtr> &, Tick); 155 156 private:
|
162 //added by SS 163 Cycles m_recycle_latency; 164
| |
165 // Data Members (m_ prefix) 166 //! The two ends of the buffer. 167 ClockedObject* m_sender; 168 ClockedObject* m_receiver; 169 170 //! Consumer to signal a wakeup(), can be NULL 171 Consumer* m_consumer; 172 std::vector<MsgPtr> m_prio_heap; 173 174 // use a std::map for the stalled messages as this container is 175 // sorted and ensures a well-defined iteration order 176 typedef std::map< Address, std::list<MsgPtr> > StallMsgMapType; 177 178 StallMsgMapType m_stall_msg_map;
| 157 // Data Members (m_ prefix) 158 //! The two ends of the buffer. 159 ClockedObject* m_sender; 160 ClockedObject* m_receiver; 161 162 //! Consumer to signal a wakeup(), can be NULL 163 Consumer* m_consumer; 164 std::vector<MsgPtr> m_prio_heap; 165 166 // use a std::map for the stalled messages as this container is 167 // sorted and ensures a well-defined iteration order 168 typedef std::map< Address, std::list<MsgPtr> > StallMsgMapType; 169 170 StallMsgMapType m_stall_msg_map;
|
179 std::string m_name;
| |
180
| 171
|
181 unsigned int m_max_size;
| 172 const unsigned int m_max_size;
|
182 Cycles m_time_last_time_size_checked; 183 unsigned int m_size_last_time_size_checked; 184 185 // variables used so enqueues appear to happen immediately, while 186 // pop happen the next cycle 187 Cycles m_time_last_time_enqueue; 188 Tick m_time_last_time_pop; 189 Tick m_last_arrival_time; 190 191 unsigned int m_size_at_cycle_start; 192 unsigned int m_msgs_this_cycle; 193 194 int m_not_avail_count; // count the # of times I didn't have N 195 // slots available 196 uint64 m_msg_counter; 197 int m_priority_rank;
| 173 Cycles m_time_last_time_size_checked; 174 unsigned int m_size_last_time_size_checked; 175 176 // variables used so enqueues appear to happen immediately, while 177 // pop happen the next cycle 178 Cycles m_time_last_time_enqueue; 179 Tick m_time_last_time_pop; 180 Tick m_last_arrival_time; 181 182 unsigned int m_size_at_cycle_start; 183 unsigned int m_msgs_this_cycle; 184 185 int m_not_avail_count; // count the # of times I didn't have N 186 // slots available 187 uint64 m_msg_counter; 188 int m_priority_rank;
|
198 bool m_strict_fifo; 199 bool m_ordering_set; 200 bool m_randomization;
| 189 const bool m_strict_fifo; 190 const bool m_randomization;
|
201 202 int m_input_link_id; 203 int m_vnet_id; 204}; 205 206Cycles random_time(); 207 208inline std::ostream& 209operator<<(std::ostream& out, const MessageBuffer& obj) 210{ 211 obj.print(out); 212 out << std::flush; 213 return out; 214} 215 216#endif // __MEM_RUBY_BUFFERS_MESSAGEBUFFER_HH__
| 191 192 int m_input_link_id; 193 int m_vnet_id; 194}; 195 196Cycles random_time(); 197 198inline std::ostream& 199operator<<(std::ostream& out, const MessageBuffer& obj) 200{ 201 obj.print(out); 202 out << std::flush; 203 return out; 204} 205 206#endif // __MEM_RUBY_BUFFERS_MESSAGEBUFFER_HH__
|