gem5  v21.1.0.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 namespace gem5
69 {
70 
71 namespace ruby
72 {
73 
74 class MessageBuffer : public SimObject
75 {
76  public:
77  typedef MessageBufferParams Params;
78  MessageBuffer(const Params &p);
79 
80  void reanalyzeMessages(Addr addr, Tick current_time);
81  void reanalyzeAllMessages(Tick current_time);
82  void stallMessage(Addr addr, Tick current_time);
83  // return true if the stall map has a message of this address
84  bool hasStalledMsg(Addr addr) const;
85 
86  // TRUE if head of queue timestamp <= SystemTime
87  bool isReady(Tick current_time) const;
88 
89  void
90  delayHead(Tick current_time, Tick delta)
91  {
92  MsgPtr m = m_prio_heap.front();
93  std::pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
94  std::greater<MsgPtr>());
95  m_prio_heap.pop_back();
96  enqueue(m, current_time, delta);
97  }
98 
99  bool areNSlotsAvailable(unsigned int n, Tick curTime);
100  int getPriority() { return m_priority_rank; }
101  void setPriority(int rank) { m_priority_rank = rank; }
102  void setConsumer(Consumer* consumer)
103  {
104  DPRINTF(RubyQueue, "Setting consumer: %s\n", *consumer);
105  if (m_consumer != NULL) {
106  fatal("Trying to connect %s to MessageBuffer %s. \
107  \n%s already connected. Check the cntrl_id's.\n",
108  *consumer, *this, *m_consumer);
109  }
110  m_consumer = consumer;
111  }
112 
114 
115  bool getOrdered() { return m_strict_fifo; }
116 
119  const Message* peek() const;
120 
121  const MsgPtr &peekMsgPtr() const { return m_prio_heap.front(); }
122 
123  void enqueue(MsgPtr message, Tick curTime, Tick delta);
124 
125  // Defer enqueueing a message to a later cycle by putting it aside and not
126  // enqueueing it in this cycle
127  // The corresponding controller will need to explicitly enqueue the
128  // deferred message into the message buffer. Otherwise, the message will
129  // be lost.
130  void deferEnqueueingMessage(Addr addr, MsgPtr message);
131 
132  // enqueue all previously deferred messages that are associated with the
133  // input address
134  void enqueueDeferredMessages(Addr addr, Tick curTime, Tick delay);
135  bool isDeferredMsgMapEmpty(Addr addr) const;
136 
139  Tick dequeue(Tick current_time, bool decrement_messages = true);
140 
141  void registerDequeueCallback(std::function<void()> callback);
143 
144  void recycle(Tick current_time, Tick recycle_latency);
145  bool isEmpty() const { return m_prio_heap.size() == 0; }
146  bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; }
147  unsigned int getStallMapSize() { return m_stall_msg_map.size(); }
148 
149  unsigned int getSize(Tick curTime);
150 
151  void clear();
152  void print(std::ostream& out) const;
154 
155  void setIncomingLink(int link_id) { m_input_link_id = link_id; }
156  void setVnet(int net) { m_vnet_id = net; }
157 
158  Port &
159  getPort(const std::string &, PortID idx=InvalidPortID) override
160  {
161  return RubyDummyPort::instance();
162  }
163 
164  // Function for figuring out if any of the messages in the buffer need
165  // to be updated with the data from the packet.
166  // Return value indicates the number of messages that were updated.
167  uint32_t functionalWrite(Packet *pkt)
168  {
169  return functionalAccess(pkt, false, nullptr);
170  }
171 
172  // Function for figuring if message in the buffer has valid data for
173  // the packet.
174  // Returns true only if a message was found with valid data and the
175  // read was performed.
177  {
178  return functionalAccess(pkt, true, nullptr) == 1;
179  }
180 
181  // Functional read with mask
183  {
184  return functionalAccess(pkt, true, &mask) == 1;
185  }
186 
187  private:
189 
190  uint32_t functionalAccess(Packet *pkt, bool is_read, WriteMask *mask);
191 
192  private:
193  // Data Members (m_ prefix)
197 
198  std::function<void()> m_dequeue_callback;
199 
200  // use a std::map for the stalled messages as this container is
201  // sorted and ensures a well-defined iteration order
202  typedef std::map<Addr, std::list<MsgPtr> > StallMsgMapType;
203 
218 
224  typedef std::unordered_map<Addr, std::vector<MsgPtr>> DeferredMsgMapType;
226 
234 
241  const unsigned int m_max_size;
242 
245 
246  // variables used so enqueues appear to happen immediately, while
247  // pop happen the next cycle
251 
252  unsigned int m_size_at_cycle_start;
254  unsigned int m_msgs_this_cycle;
255 
256  uint64_t m_msg_counter;
258  const bool m_strict_fifo;
259  const MessageRandomization m_randomization;
261 
264 
265  // Count the # of times I didn't have N slots available
271 };
272 
273 Tick random_time();
274 
275 inline std::ostream&
276 operator<<(std::ostream& out, const MessageBuffer& obj)
277 {
278  obj.print(out);
279  out << std::flush;
280  return out;
281 }
282 
283 } // namespace ruby
284 } // namespace gem5
285 
286 #endif //__MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1918
gem5::ruby::MessageBuffer::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: MessageBuffer.hh:167
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:189
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:252
gem5::ruby::MessageBuffer::recycle
void recycle(Tick current_time, Tick recycle_latency)
Definition: MessageBuffer.cc:343
gem5::ruby::MessageBuffer::unregisterDequeueCallback
void unregisterDequeueCallback()
Definition: MessageBuffer.cc:324
gem5::ruby::MsgPtr
std::shared_ptr< Message > MsgPtr
Definition: Message.hh:59
gem5::ruby::MessageBuffer::m_time_last_time_size_checked
Tick m_time_last_time_size_checked
Definition: MessageBuffer.hh:243
gem5::ruby::WriteMask
Definition: WriteMask.hh:59
gem5::ruby::MessageBuffer::getPriority
int getPriority()
Definition: MessageBuffer.hh:100
gem5::ruby::MessageBuffer::enqueueDeferredMessages
void enqueueDeferredMessages(Addr addr, Tick curTime, Tick delay)
Definition: MessageBuffer.cc:453
gem5::ruby::operator<<
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition: BoolVec.cc:49
gem5::ruby::MessageBuffer::setVnet
void setVnet(int net)
Definition: MessageBuffer.hh:156
gem5::ruby::MessageBuffer::m_consumer
Consumer * m_consumer
Consumer to signal a wakeup(), can be NULL.
Definition: MessageBuffer.hh:195
gem5::ruby::MessageBuffer::Params
MessageBufferParams Params
Definition: MessageBuffer.hh:77
gem5::ruby::MessageBuffer::setPriority
void setPriority(int rank)
Definition: MessageBuffer.hh:101
gem5::ruby::MessageBuffer::getConsumer
Consumer * getConsumer()
Definition: MessageBuffer.hh:113
gem5::ruby::MessageBuffer::getOrdered
bool getOrdered()
Definition: MessageBuffer.hh:115
gem5::ruby::MessageBuffer::reanalyzeList
void reanalyzeList(std::list< MsgPtr > &, Tick)
Definition: MessageBuffer.cc:359
gem5::ruby::MessageBuffer::m_deferred_msg_map
DeferredMsgMapType m_deferred_msg_map
Definition: MessageBuffer.hh:225
gem5::statistics::Average
A stat that calculates the per tick average of a value.
Definition: statistics.hh:1946
gem5::ruby::MessageBuffer::enqueue
void enqueue(MsgPtr message, Tick curTime, Tick delta)
Definition: MessageBuffer.cc:197
gem5::ruby::MessageBuffer::MessageBuffer
MessageBuffer(const Params &p)
Definition: MessageBuffer.cc:60
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2527
std::vector< MsgPtr >
gem5::ruby::MessageBuffer::functionalRead
bool functionalRead(Packet *pkt, WriteMask &mask)
Definition: MessageBuffer.hh:182
gem5::ruby::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:279
gem5::ruby::Consumer
Definition: Consumer.hh:61
gem5::ruby::MessageBuffer::stallMessage
void stallMessage(Addr addr, Tick current_time)
Definition: MessageBuffer.cc:417
gem5::ruby::MessageBuffer::m_stall_time
statistics::Average m_stall_time
Definition: MessageBuffer.hh:268
gem5::InvalidPortID
const PortID InvalidPortID
Definition: types.hh:253
gem5::ruby::MessageBuffer::getStallMapSize
unsigned int getStallMapSize()
Definition: MessageBuffer.hh:147
gem5::ruby::RubyDummyPort::instance
static RubyDummyPort & instance()
Definition: dummy_port.hh:56
gem5::ruby::MessageBuffer::delayHead
void delayHead(Tick current_time, Tick delta)
Definition: MessageBuffer.hh:90
gem5::ruby::MessageBuffer::m_occupancy
statistics::Formula m_occupancy
Definition: MessageBuffer.hh:270
gem5::ruby::MessageBuffer::reanalyzeMessages
void reanalyzeMessages(Addr addr, Tick current_time)
Definition: MessageBuffer.cc:379
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
packet.hh
gem5::ruby::MessageBuffer::peekMsgPtr
const MsgPtr & peekMsgPtr() const
Definition: MessageBuffer.hh:121
gem5::ruby::MessageBuffer::peek
const Message * peek() const
Function for extracting the message at the head of the message queue.
Definition: MessageBuffer.cc:174
gem5::ruby::MessageBuffer::m_last_arrival_time
Tick m_last_arrival_time
Definition: MessageBuffer.hh:250
gem5::ruby::MessageBuffer::m_size_last_time_size_checked
unsigned int m_size_last_time_size_checked
Definition: MessageBuffer.hh:244
gem5::ruby::MessageBuffer::m_stalled_at_cycle_start
unsigned int m_stalled_at_cycle_start
Definition: MessageBuffer.hh:253
gem5::ruby::MessageBuffer::m_msgs_this_cycle
unsigned int m_msgs_this_cycle
Definition: MessageBuffer.hh:254
gem5::ruby::MessageBuffer::functionalAccess
uint32_t functionalAccess(Packet *pkt, bool is_read, WriteMask *mask)
Definition: MessageBuffer.cc:495
gem5::ruby::MessageBuffer::m_size_at_cycle_start
unsigned int m_size_at_cycle_start
Definition: MessageBuffer.hh:252
gem5::ruby::MessageBuffer::print
void print(std::ostream &out) const
Definition: MessageBuffer.cc:475
sim_object.hh
gem5::ruby::MessageBuffer::m_not_avail_count
statistics::Scalar m_not_avail_count
Definition: MessageBuffer.hh:266
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::ruby::MessageBuffer::functionalRead
bool functionalRead(Packet *pkt)
Definition: MessageBuffer.hh:176
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::ruby::MessageBuffer::StallMsgMapType
std::map< Addr, std::list< MsgPtr > > StallMsgMapType
Definition: MessageBuffer.hh:202
port.hh
gem5::ruby::MessageBuffer::m_randomization
const MessageRandomization m_randomization
Definition: MessageBuffer.hh:259
gem5::ruby::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:217
gem5::ruby::MessageBuffer::m_strict_fifo
const bool m_strict_fifo
Definition: MessageBuffer.hh:258
gem5::ruby::MessageBuffer::isEmpty
bool isEmpty() const
Definition: MessageBuffer.hh:145
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::ruby::MessageBuffer::m_max_size
const unsigned int m_max_size
The maximum capacity.
Definition: MessageBuffer.hh:241
gem5::ruby::MessageBuffer::m_msg_counter
uint64_t m_msg_counter
Definition: MessageBuffer.hh:256
gem5::ruby::MessageBuffer::m_priority_rank
int m_priority_rank
Definition: MessageBuffer.hh:257
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::ruby::MessageBuffer::isDeferredMsgMapEmpty
bool isDeferredMsgMapEmpty(Addr addr) const
Definition: MessageBuffer.cc:469
gem5::ruby::MessageBuffer::setIncomingLink
void setIncomingLink(int link_id)
Definition: MessageBuffer.hh:155
gem5::ruby::MessageBuffer::setConsumer
void setConsumer(Consumer *consumer)
Definition: MessageBuffer.hh:102
gem5::ruby::MessageBuffer::isReady
bool isReady(Tick current_time) const
Definition: MessageBuffer.cc:488
gem5::ruby::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:224
gem5::ruby::MessageBuffer::clear
void clear()
Definition: MessageBuffer.cc:330
gem5::ruby::MessageBuffer::m_prio_heap
std::vector< MsgPtr > m_prio_heap
Definition: MessageBuffer.hh:196
gem5::ArmISA::m
Bitfield< 0 > m
Definition: misc_types.hh:394
gem5::ruby::random_time
Tick random_time()
Definition: MessageBuffer.cc:186
dummy_port.hh
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::ruby::MessageBuffer::registerDequeueCallback
void registerDequeueCallback(std::function< void()> callback)
Definition: MessageBuffer.cc:318
Consumer.hh
Address.hh
gem5::ArmISA::n
Bitfield< 31 > n
Definition: misc_types.hh:455
gem5::ruby::MessageBuffer::m_input_link_id
int m_input_link_id
Definition: MessageBuffer.hh:262
gem5::ruby::MessageBuffer::m_time_last_time_pop
Tick m_time_last_time_pop
Definition: MessageBuffer.hh:249
gem5::ruby::MessageBuffer::areNSlotsAvailable
bool areNSlotsAvailable(unsigned int n, Tick curTime)
Definition: MessageBuffer.cc:127
gem5::ruby::MessageBuffer::getPort
Port & getPort(const std::string &, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: MessageBuffer.hh:159
gem5::ruby::MessageBuffer::m_stall_map_size
int m_stall_map_size
Current size of the stall map.
Definition: MessageBuffer.hh:233
gem5::ruby::MessageBuffer::m_dequeue_callback
std::function< void()> m_dequeue_callback
Definition: MessageBuffer.hh:198
gem5::ruby::Message
Definition: Message.hh:62
trace.hh
gem5::ruby::MessageBuffer::m_buf_msgs
statistics::Average m_buf_msgs
Definition: MessageBuffer.hh:267
gem5::ruby::MessageBuffer::isStallMapEmpty
bool isStallMapEmpty()
Definition: MessageBuffer.hh:146
gem5::ruby::MessageBuffer::hasStalledMsg
bool hasStalledMsg(Addr addr) const
Definition: MessageBuffer.cc:439
gem5::ruby::MessageBuffer::clearStats
void clearStats()
Definition: MessageBuffer.hh:153
gem5::ruby::MessageBuffer
Definition: MessageBuffer.hh:74
std::list
STL list class.
Definition: stl.hh:51
gem5::ruby::MessageBuffer::m_stall_count
statistics::Scalar m_stall_count
Definition: MessageBuffer.hh:269
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
Message.hh
gem5::ruby::MessageBuffer::m_allow_zero_latency
const bool m_allow_zero_latency
Definition: MessageBuffer.hh:260
gem5::ruby::MessageBuffer::deferEnqueueingMessage
void deferEnqueueingMessage(Addr addr, MsgPtr message)
Definition: MessageBuffer.cc:445
gem5::ruby::MessageBuffer::reanalyzeAllMessages
void reanalyzeAllMessages(Tick current_time)
Definition: MessageBuffer.cc:397
gem5::ruby::MessageBuffer::getSize
unsigned int getSize(Tick curTime)
Definition: MessageBuffer.cc:116
gem5::ruby::MessageBuffer::m_time_last_time_enqueue
Tick m_time_last_time_enqueue
Definition: MessageBuffer.hh:248
gem5::ruby::MessageBuffer::m_vnet_id
int m_vnet_id
Definition: MessageBuffer.hh:263
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Wed Jul 28 2021 12:10:28 for gem5 by doxygen 1.8.17