gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MessageBuffer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 /*
42  * Unordered buffer of messages that can be inserted such
43  * that they can be dequeued after a given delta time has expired.
44  */
45 
46 #ifndef __MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
47 #define __MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
48 
49 #include <algorithm>
50 #include <cassert>
51 #include <functional>
52 #include <iostream>
53 #include <string>
54 #include <unordered_map>
55 #include <vector>
56 
57 #include "base/trace.hh"
58 #include "debug/RubyQueue.hh"
59 #include "mem/packet.hh"
60 #include "mem/port.hh"
65 #include "params/MessageBuffer.hh"
66 #include "sim/sim_object.hh"
67 
68 class MessageBuffer : public SimObject
69 {
70  public:
71  typedef MessageBufferParams Params;
72  MessageBuffer(const Params &p);
73 
74  void reanalyzeMessages(Addr addr, Tick current_time);
75  void reanalyzeAllMessages(Tick current_time);
76  void stallMessage(Addr addr, Tick current_time);
77  // return true if the stall map has a message of this address
78  bool hasStalledMsg(Addr addr) const;
79 
80  // TRUE if head of queue timestamp <= SystemTime
81  bool isReady(Tick current_time) const;
82 
83  void
84  delayHead(Tick current_time, Tick delta)
85  {
86  MsgPtr m = m_prio_heap.front();
87  std::pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
88  std::greater<MsgPtr>());
89  m_prio_heap.pop_back();
90  enqueue(m, current_time, delta);
91  }
92 
93  bool areNSlotsAvailable(unsigned int n, Tick curTime);
94  int getPriority() { return m_priority_rank; }
95  void setPriority(int rank) { m_priority_rank = rank; }
96  void setConsumer(Consumer* consumer)
97  {
98  DPRINTF(RubyQueue, "Setting consumer: %s\n", *consumer);
99  if (m_consumer != NULL) {
100  fatal("Trying to connect %s to MessageBuffer %s. \
101  \n%s already connected. Check the cntrl_id's.\n",
102  *consumer, *this, *m_consumer);
103  }
104  m_consumer = consumer;
105  }
106 
108 
109  bool getOrdered() { return m_strict_fifo; }
110 
113  const Message* peek() const;
114 
115  const MsgPtr &peekMsgPtr() const { return m_prio_heap.front(); }
116 
117  void enqueue(MsgPtr message, Tick curTime, Tick delta);
118 
119  // Defer enqueueing a message to a later cycle by putting it aside and not
120  // enqueueing it in this cycle
121  // The corresponding controller will need to explicitly enqueue the
122  // deferred message into the message buffer. Otherwise, the message will
123  // be lost.
124  void deferEnqueueingMessage(Addr addr, MsgPtr message);
125 
126  // enqueue all previously deferred messages that are associated with the
127  // input address
128  void enqueueDeferredMessages(Addr addr, Tick curTime, Tick delay);
129  bool isDeferredMsgMapEmpty(Addr addr) const;
130 
133  Tick dequeue(Tick current_time, bool decrement_messages = true);
134 
135  void registerDequeueCallback(std::function<void()> callback);
137 
138  void recycle(Tick current_time, Tick recycle_latency);
139  bool isEmpty() const { return m_prio_heap.size() == 0; }
140  bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; }
141  unsigned int getStallMapSize() { return m_stall_msg_map.size(); }
142 
143  unsigned int getSize(Tick curTime);
144 
145  void clear();
146  void print(std::ostream& out) const;
148 
149  void setIncomingLink(int link_id) { m_input_link_id = link_id; }
150  void setVnet(int net) { m_vnet_id = net; }
151 
152  Port &
153  getPort(const std::string &, PortID idx=InvalidPortID) override
154  {
155  return RubyDummyPort::instance();
156  }
157 
158  // Function for figuring out if any of the messages in the buffer need
159  // to be updated with the data from the packet.
160  // Return value indicates the number of messages that were updated.
161  uint32_t functionalWrite(Packet *pkt)
162  {
163  return functionalAccess(pkt, false, nullptr);
164  }
165 
166  // Function for figuring if message in the buffer has valid data for
167  // the packet.
168  // Returns true only if a message was found with valid data and the
169  // read was performed.
171  {
172  return functionalAccess(pkt, true, nullptr) == 1;
173  }
174 
175  // Functional read with mask
177  {
178  return functionalAccess(pkt, true, &mask) == 1;
179  }
180 
181  private:
183 
184  uint32_t functionalAccess(Packet *pkt, bool is_read, WriteMask *mask);
185 
186  private:
187  // Data Members (m_ prefix)
191 
192  std::function<void()> m_dequeue_callback;
193 
194  // use a std::map for the stalled messages as this container is
195  // sorted and ensures a well-defined iteration order
196  typedef std::map<Addr, std::list<MsgPtr> > StallMsgMapType;
197 
212 
218  typedef std::unordered_map<Addr, std::vector<MsgPtr>> DeferredMsgMapType;
220 
228 
235  const unsigned int m_max_size;
236 
239 
240  // variables used so enqueues appear to happen immediately, while
241  // pop happen the next cycle
245 
246  unsigned int m_size_at_cycle_start;
248  unsigned int m_msgs_this_cycle;
249 
250  uint64_t m_msg_counter;
252  const bool m_strict_fifo;
253  const MessageRandomization m_randomization;
255 
258 
259  Stats::Scalar m_not_avail_count; // count the # of times I didn't have N
260  // slots available
265 };
266 
267 Tick random_time();
268 
269 inline std::ostream&
270 operator<<(std::ostream& out, const MessageBuffer& obj)
271 {
272  obj.print(out);
273  out << std::flush;
274  return out;
275 }
276 
277 #endif //__MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
MessageBuffer::DeferredMsgMapType
std::unordered_map< Addr, std::vector< MsgPtr > > DeferredMsgMapType
A map from line addresses to corresponding vectors of messages that are deferred for enqueueing.
Definition: MessageBuffer.hh:218
MessageBuffer::m_msgs_this_cycle
unsigned int m_msgs_this_cycle
Definition: MessageBuffer.hh:248
MessageBuffer::dequeue
Tick dequeue(Tick current_time, bool decrement_messages=true)
Updates the delay cycles of the message at the head of the queue, removes it from the queue and retur...
Definition: MessageBuffer.cc:273
MessageBuffer::m_stall_time
Stats::Average m_stall_time
Definition: MessageBuffer.hh:262
InvalidPortID
const PortID InvalidPortID
Definition: types.hh:244
MessageBuffer::peek
const Message * peek() const
Function for extracting the message at the head of the message queue.
Definition: MessageBuffer.cc:168
MessageBuffer::m_priority_rank
int m_priority_rank
Definition: MessageBuffer.hh:251
MessageBuffer::delayHead
void delayHead(Tick current_time, Tick delta)
Definition: MessageBuffer.hh:84
MessageBuffer::m_size_at_cycle_start
unsigned int m_size_at_cycle_start
Definition: MessageBuffer.hh:246
MessageBuffer::m_dequeue_callback
std::function< void()> m_dequeue_callback
Definition: MessageBuffer.hh:192
MessageBuffer::StallMsgMapType
std::map< Addr, std::list< MsgPtr > > StallMsgMapType
Definition: MessageBuffer.hh:196
MessageBuffer::m_deferred_msg_map
DeferredMsgMapType m_deferred_msg_map
Definition: MessageBuffer.hh:219
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:243
operator<<
std::ostream & operator<<(std::ostream &out, const MessageBuffer &obj)
Definition: MessageBuffer.hh:270
random_time
Tick random_time()
Definition: MessageBuffer.cc:180
MessageBuffer::getSize
unsigned int getSize(Tick curTime)
Definition: MessageBuffer.cc:110
std::vector< MsgPtr >
MessageBuffer::reanalyzeMessages
void reanalyzeMessages(Addr addr, Tick current_time)
Definition: MessageBuffer.cc:373
MessageBuffer::m_time_last_time_pop
Tick m_time_last_time_pop
Definition: MessageBuffer.hh:243
MessageBuffer::setConsumer
void setConsumer(Consumer *consumer)
Definition: MessageBuffer.hh:96
MessageBuffer::stallMessage
void stallMessage(Addr addr, Tick current_time)
Definition: MessageBuffer.cc:411
MessageBuffer::enqueue
void enqueue(MsgPtr message, Tick curTime, Tick delta)
Definition: MessageBuffer.cc:191
MessageBuffer::m_last_arrival_time
Tick m_last_arrival_time
Definition: MessageBuffer.hh:244
MessageBuffer::getPriority
int getPriority()
Definition: MessageBuffer.hh:94
MessageBuffer::getPort
Port & getPort(const std::string &, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: MessageBuffer.hh:153
packet.hh
MessageBuffer::m_prio_heap
std::vector< MsgPtr > m_prio_heap
Definition: MessageBuffer.hh:190
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1933
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
MessageBuffer::peekMsgPtr
const MsgPtr & peekMsgPtr() const
Definition: MessageBuffer.hh:115
MessageBuffer::m_max_size
const unsigned int m_max_size
The maximum capacity.
Definition: MessageBuffer.hh:235
MessageBuffer::clearStats
void clearStats()
Definition: MessageBuffer.hh:147
MessageBuffer::deferEnqueueingMessage
void deferEnqueueingMessage(Addr addr, MsgPtr message)
Definition: MessageBuffer.cc:439
RubyDummyPort::instance
static RubyDummyPort & instance()
Definition: dummy_port.hh:50
sim_object.hh
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
MessageBuffer::m_time_last_time_enqueue
Tick m_time_last_time_enqueue
Definition: MessageBuffer.hh:242
MessageBuffer::functionalAccess
uint32_t functionalAccess(Packet *pkt, bool is_read, WriteMask *mask)
Definition: MessageBuffer.cc:489
MessageBuffer::m_stalled_at_cycle_start
unsigned int m_stalled_at_cycle_start
Definition: MessageBuffer.hh:247
MessageBuffer::isReady
bool isReady(Tick current_time) const
Definition: MessageBuffer.cc:482
MessageBuffer::isDeferredMsgMapEmpty
bool isDeferredMsgMapEmpty(Addr addr) const
Definition: MessageBuffer.cc:463
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
Consumer
Definition: Consumer.hh:55
MessageBuffer::setPriority
void setPriority(int rank)
Definition: MessageBuffer.hh:95
MessageBuffer::functionalRead
bool functionalRead(Packet *pkt)
Definition: MessageBuffer.hh:170
port.hh
MessageBuffer::reanalyzeAllMessages
void reanalyzeAllMessages(Tick current_time)
Definition: MessageBuffer.cc:391
MessageBuffer::hasStalledMsg
bool hasStalledMsg(Addr addr) const
Definition: MessageBuffer.cc:433
MessageBuffer::m_not_avail_count
Stats::Scalar m_not_avail_count
Definition: MessageBuffer.hh:259
MessageBuffer::m_size_last_time_size_checked
unsigned int m_size_last_time_size_checked
Definition: MessageBuffer.hh:238
MessageBuffer::m_consumer
Consumer * m_consumer
Consumer to signal a wakeup(), can be NULL.
Definition: MessageBuffer.hh:189
MessageBuffer::m_randomization
const MessageRandomization m_randomization
Definition: MessageBuffer.hh:253
MessageBuffer::unregisterDequeueCallback
void unregisterDequeueCallback()
Definition: MessageBuffer.cc:318
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
MessageBuffer::m_allow_zero_latency
const bool m_allow_zero_latency
Definition: MessageBuffer.hh:254
MessageBuffer::getStallMapSize
unsigned int getStallMapSize()
Definition: MessageBuffer.hh:141
MessageBuffer::setIncomingLink
void setIncomingLink(int link_id)
Definition: MessageBuffer.hh:149
MessageBuffer::m_stall_map_size
int m_stall_map_size
Current size of the stall map.
Definition: MessageBuffer.hh:227
MessageBuffer::Params
MessageBufferParams Params
Definition: MessageBuffer.hh:71
MsgPtr
std::shared_ptr< Message > MsgPtr
Definition: Message.hh:53
MessageBuffer::areNSlotsAvailable
bool areNSlotsAvailable(unsigned int n, Tick curTime)
Definition: MessageBuffer.cc:121
MessageBuffer::recycle
void recycle(Tick current_time, Tick recycle_latency)
Definition: MessageBuffer.cc:337
MessageBuffer::registerDequeueCallback
void registerDequeueCallback(std::function< void()> callback)
Definition: MessageBuffer.cc:312
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
Stats::Average
A stat that calculates the per tick average of a value.
Definition: statistics.hh:1960
MessageBuffer::m_input_link_id
int m_input_link_id
Definition: MessageBuffer.hh:256
MessageBuffer::print
void print(std::ostream &out) const
Definition: MessageBuffer.cc:469
dummy_port.hh
Consumer.hh
Address.hh
MessageBuffer::isStallMapEmpty
bool isStallMapEmpty()
Definition: MessageBuffer.hh:140
Stats::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2538
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
MessageBuffer::reanalyzeList
void reanalyzeList(std::list< MsgPtr > &, Tick)
Definition: MessageBuffer.cc:353
MessageBuffer::m_vnet_id
int m_vnet_id
Definition: MessageBuffer.hh:257
MessageBuffer::MessageBuffer
MessageBuffer(const Params &p)
Definition: MessageBuffer.cc:54
MessageBuffer::m_occupancy
Stats::Formula m_occupancy
Definition: MessageBuffer.hh:264
MessageBuffer::enqueueDeferredMessages
void enqueueDeferredMessages(Addr addr, Tick curTime, Tick delay)
Definition: MessageBuffer.cc:447
Message
Definition: Message.hh:56
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MessageBuffer::m_buf_msgs
Stats::Average m_buf_msgs
Definition: MessageBuffer.hh:261
std::list
STL list class.
Definition: stl.hh:51
MessageBuffer::functionalRead
bool functionalRead(Packet *pkt, WriteMask &mask)
Definition: MessageBuffer.hh:176
MessageBuffer
Definition: MessageBuffer.hh:68
MessageBuffer::m_time_last_time_size_checked
Tick m_time_last_time_size_checked
Definition: MessageBuffer.hh:237
MessageBuffer::isEmpty
bool isEmpty() const
Definition: MessageBuffer.hh:139
MessageBuffer::getOrdered
bool getOrdered()
Definition: MessageBuffer.hh:109
Message.hh
MessageBuffer::setVnet
void setVnet(int net)
Definition: MessageBuffer.hh:150
MessageBuffer::m_stall_count
Stats::Scalar m_stall_count
Definition: MessageBuffer.hh:263
WriteMask
Definition: WriteMask.hh:53
MessageBuffer::m_msg_counter
uint64_t m_msg_counter
Definition: MessageBuffer.hh:250
MessageBuffer::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: MessageBuffer.hh:161
MessageBuffer::m_strict_fifo
const bool m_strict_fifo
Definition: MessageBuffer.hh:252
MessageBuffer::m_stall_msg_map
StallMsgMapType m_stall_msg_map
A map from line addresses to lists of stalled messages for that line.
Definition: MessageBuffer.hh:211
MessageBuffer::getConsumer
Consumer * getConsumer()
Definition: MessageBuffer.hh:107
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
ArmISA::m
Bitfield< 0 > m
Definition: miscregs_types.hh:389
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141
MessageBuffer::clear
void clear()
Definition: MessageBuffer.cc:324

Generated on Tue Jun 22 2021 15:28:30 for gem5 by doxygen 1.8.17