gem5  v20.0.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 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 <vector>
55 
56 #include "base/trace.hh"
57 #include "debug/RubyQueue.hh"
58 #include "mem/packet.hh"
59 #include "mem/port.hh"
64 #include "params/MessageBuffer.hh"
65 #include "sim/sim_object.hh"
66 
67 class MessageBuffer : public SimObject
68 {
69  public:
70  typedef MessageBufferParams Params;
71  MessageBuffer(const Params *p);
72 
73  void reanalyzeMessages(Addr addr, Tick current_time);
74  void reanalyzeAllMessages(Tick current_time);
75  void stallMessage(Addr addr, Tick current_time);
76 
77  // TRUE if head of queue timestamp <= SystemTime
78  bool isReady(Tick current_time) const;
79 
80  void
81  delayHead(Tick current_time, Tick delta)
82  {
83  MsgPtr m = m_prio_heap.front();
84  std::pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
85  std::greater<MsgPtr>());
86  m_prio_heap.pop_back();
87  enqueue(m, current_time, delta);
88  }
89 
90  bool areNSlotsAvailable(unsigned int n, Tick curTime);
91  int getPriority() { return m_priority_rank; }
92  void setPriority(int rank) { m_priority_rank = rank; }
93  void setConsumer(Consumer* consumer)
94  {
95  DPRINTF(RubyQueue, "Setting consumer: %s\n", *consumer);
96  if (m_consumer != NULL) {
97  fatal("Trying to connect %s to MessageBuffer %s. \
98  \n%s already connected. Check the cntrl_id's.\n",
99  *consumer, *this, *m_consumer);
100  }
101  m_consumer = consumer;
102  }
103 
105 
106  bool getOrdered() { return m_strict_fifo; }
107 
110  const Message* peek() const;
111 
112  const MsgPtr &peekMsgPtr() const { return m_prio_heap.front(); }
113 
114  void enqueue(MsgPtr message, Tick curTime, Tick delta);
115 
118  Tick dequeue(Tick current_time, bool decrement_messages = true);
119 
120  void registerDequeueCallback(std::function<void()> callback);
122 
123  void recycle(Tick current_time, Tick recycle_latency);
124  bool isEmpty() const { return m_prio_heap.size() == 0; }
125  bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; }
126  unsigned int getStallMapSize() { return m_stall_msg_map.size(); }
127 
128  unsigned int getSize(Tick curTime);
129 
130  void clear();
131  void print(std::ostream& out) const;
133 
134  void setIncomingLink(int link_id) { m_input_link_id = link_id; }
135  void setVnet(int net) { m_vnet_id = net; }
136 
137  Port &
138  getPort(const std::string &, PortID idx=InvalidPortID) override
139  {
140  return RubyDummyPort::instance();
141  }
142 
143  void regStats() override;
144 
145  // Function for figuring out if any of the messages in the buffer need
146  // to be updated with the data from the packet.
147  // Return value indicates the number of messages that were updated.
148  uint32_t functionalWrite(Packet *pkt)
149  {
150  return functionalAccess(pkt, false);
151  }
152 
153  // Function for figuring if message in the buffer has valid data for
154  // the packet.
155  // Returns true only if a message was found with valid data and the
156  // read was performed.
158  {
159  return functionalAccess(pkt, true) == 1;
160  }
161 
162  private:
164 
165  uint32_t functionalAccess(Packet *pkt, bool is_read);
166 
167  private:
168  // Data Members (m_ prefix)
172 
173  std::function<void()> m_dequeue_callback;
174 
175  // use a std::map for the stalled messages as this container is
176  // sorted and ensures a well-defined iteration order
177  typedef std::map<Addr, std::list<MsgPtr> > StallMsgMapType;
178 
192  StallMsgMapType m_stall_msg_map;
193 
201 
208  const unsigned int m_max_size;
209 
212 
213  // variables used so enqueues appear to happen immediately, while
214  // pop happen the next cycle
218 
219  unsigned int m_size_at_cycle_start;
221  unsigned int m_msgs_this_cycle;
222 
223  Stats::Scalar m_not_avail_count; // count the # of times I didn't have N
224  // slots available
225  uint64_t m_msg_counter;
227  const bool m_strict_fifo;
228  const bool m_randomization;
229 
232 
237 };
238 
239 Tick random_time();
240 
241 inline std::ostream&
242 operator<<(std::ostream& out, const MessageBuffer& obj)
243 {
244  obj.print(out);
245  out << std::flush;
246  return out;
247 }
248 
249 #endif //__MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
bool isReady(Tick current_time) const
#define DPRINTF(x,...)
Definition: trace.hh:225
const Message * peek() const
Function for extracting the message at the head of the message queue.
unsigned int m_stalled_at_cycle_start
uint64_t m_msg_counter
Ports are used to interface objects to each other.
Definition: port.hh:56
Tick m_time_last_time_size_checked
bool functionalRead(Packet *pkt)
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:171
std::shared_ptr< Message > MsgPtr
Definition: Message.hh:40
const bool m_randomization
MessageBuffer(const Params *p)
unsigned int getStallMapSize()
const PortID InvalidPortID
Definition: types.hh:236
A stat that calculates the per tick average of a value.
Definition: statistics.hh:2521
Bitfield< 0 > m
bool isStallMapEmpty()
StallMsgMapType m_stall_msg_map
A map from line addresses to lists of stalled messages for that line.
void recycle(Tick current_time, Tick recycle_latency)
void reanalyzeMessages(Addr addr, Tick current_time)
Tick m_last_arrival_time
ip6_addr_t addr
Definition: inet.hh:330
void stallMessage(Addr addr, Tick current_time)
Stats::Average m_stall_time
bool isEmpty() const
Consumer * getConsumer()
unsigned int m_size_last_time_size_checked
static RubyDummyPort & instance()
Definition: dummy_port.hh:50
uint32_t functionalWrite(Packet *pkt)
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2505
Stats::Average m_buf_msgs
Bitfield< 31 > n
unsigned int getSize(Tick curTime)
uint32_t functionalAccess(Packet *pkt, bool is_read)
bool areNSlotsAvailable(unsigned int n, Tick curTime)
Tick random_time()
void setPriority(int rank)
uint64_t Tick
Tick count type.
Definition: types.hh:61
Stats::Scalar m_not_avail_count
int m_stall_map_size
Current size of the stall map.
void setConsumer(Consumer *consumer)
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...
void unregisterDequeueCallback()
Port Object Declaration.
STL list class.
Definition: stl.hh:51
unsigned int m_msgs_this_cycle
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
void setVnet(int net)
unsigned int m_size_at_cycle_start
Stats::Formula m_occupancy
std::map< Addr, std::list< MsgPtr > > StallMsgMapType
void print(std::ostream &out) const
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3009
Port & getPort(const std::string &, PortID idx=InvalidPortID) override
Get a port with a given name and index.
const bool m_strict_fifo
Consumer * m_consumer
Consumer to signal a wakeup(), can be NULL.
void reanalyzeList(std::list< MsgPtr > &, Tick)
Declaration of the Packet class.
void setIncomingLink(int link_id)
void regStats() override
Callback to set stat parameters.
std::ostream & operator<<(std::ostream &out, const MessageBuffer &obj)
Tick m_time_last_time_pop
Stats::Scalar m_stall_count
Tick m_time_last_time_enqueue
void reanalyzeAllMessages(Tick current_time)
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:235
const unsigned int m_max_size
The maximum capacity.
std::function< void()> m_dequeue_callback
void delayHead(Tick current_time, Tick delta)
Bitfield< 0 > p
std::vector< MsgPtr > m_prio_heap
const MsgPtr & peekMsgPtr() const
void enqueue(MsgPtr message, Tick curTime, Tick delta)
void registerDequeueCallback(std::function< void()> callback)
MessageBufferParams Params
Abstract superclass for simulation objects.
Definition: sim_object.hh:93

Generated on Thu May 28 2020 16:21:34 for gem5 by doxygen 1.8.13