gem5  v19.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) 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_NETWORK_MESSAGEBUFFER_HH__
35 #define __MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
36 
37 #include <algorithm>
38 #include <cassert>
39 #include <functional>
40 #include <iostream>
41 #include <string>
42 #include <vector>
43 
44 #include "base/trace.hh"
45 #include "debug/RubyQueue.hh"
46 #include "mem/packet.hh"
47 #include "mem/port.hh"
52 #include "params/MessageBuffer.hh"
53 #include "sim/sim_object.hh"
54 
55 class MessageBuffer : public SimObject
56 {
57  public:
58  typedef MessageBufferParams Params;
59  MessageBuffer(const Params *p);
60 
61  void reanalyzeMessages(Addr addr, Tick current_time);
62  void reanalyzeAllMessages(Tick current_time);
63  void stallMessage(Addr addr, Tick current_time);
64 
65  // TRUE if head of queue timestamp <= SystemTime
66  bool isReady(Tick current_time) const;
67 
68  void
69  delayHead(Tick current_time, Tick delta)
70  {
71  MsgPtr m = m_prio_heap.front();
72  std::pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
73  std::greater<MsgPtr>());
74  m_prio_heap.pop_back();
75  enqueue(m, current_time, delta);
76  }
77 
78  bool areNSlotsAvailable(unsigned int n, Tick curTime);
79  int getPriority() { return m_priority_rank; }
80  void setPriority(int rank) { m_priority_rank = rank; }
81  void setConsumer(Consumer* consumer)
82  {
83  DPRINTF(RubyQueue, "Setting consumer: %s\n", *consumer);
84  if (m_consumer != NULL) {
85  fatal("Trying to connect %s to MessageBuffer %s. \
86  \n%s already connected. Check the cntrl_id's.\n",
87  *consumer, *this, *m_consumer);
88  }
89  m_consumer = consumer;
90  }
91 
93 
94  bool getOrdered() { return m_strict_fifo; }
95 
98  const Message* peek() const;
99 
100  const MsgPtr &peekMsgPtr() const { return m_prio_heap.front(); }
101 
102  void enqueue(MsgPtr message, Tick curTime, Tick delta);
103 
106  Tick dequeue(Tick current_time, bool decrement_messages = true);
107 
108  void registerDequeueCallback(std::function<void()> callback);
110 
111  void recycle(Tick current_time, Tick recycle_latency);
112  bool isEmpty() const { return m_prio_heap.size() == 0; }
113  bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; }
114  unsigned int getStallMapSize() { return m_stall_msg_map.size(); }
115 
116  unsigned int getSize(Tick curTime);
117 
118  void clear();
119  void print(std::ostream& out) const;
121 
122  void setIncomingLink(int link_id) { m_input_link_id = link_id; }
123  void setVnet(int net) { m_vnet_id = net; }
124 
125  Port &
126  getPort(const std::string &, PortID idx=InvalidPortID) override
127  {
128  return RubyDummyPort::instance();
129  }
130 
131  void regStats() override;
132 
133  // Function for figuring out if any of the messages in the buffer need
134  // to be updated with the data from the packet.
135  // Return value indicates the number of messages that were updated.
136  // This required for debugging the code.
137  uint32_t functionalWrite(Packet *pkt);
138 
139  private:
141 
142  private:
143  // Data Members (m_ prefix)
147 
148  std::function<void()> m_dequeue_callback;
149 
150  // use a std::map for the stalled messages as this container is
151  // sorted and ensures a well-defined iteration order
152  typedef std::map<Addr, std::list<MsgPtr> > StallMsgMapType;
153 
167  StallMsgMapType m_stall_msg_map;
168 
176 
183  const unsigned int m_max_size;
184 
187 
188  // variables used so enqueues appear to happen immediately, while
189  // pop happen the next cycle
193 
194  unsigned int m_size_at_cycle_start;
196  unsigned int m_msgs_this_cycle;
197 
198  Stats::Scalar m_not_avail_count; // count the # of times I didn't have N
199  // slots available
200  uint64_t m_msg_counter;
202  const bool m_strict_fifo;
203  const bool m_randomization;
204 
207 
212 };
213 
214 Tick random_time();
215 
216 inline std::ostream&
217 operator<<(std::ostream& out, const MessageBuffer& obj)
218 {
219  obj.print(out);
220  out << std::flush;
221  return out;
222 }
223 
224 #endif //__MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
bool isReady(Tick current_time) const
#define DPRINTF(x,...)
Definition: trace.hh:229
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:60
Tick m_time_last_time_size_checked
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:175
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:238
A stat that calculates the per tick average of a value.
Definition: statistics.hh:2524
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:335
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:52
uint32_t functionalWrite(Packet *pkt)
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
Stats::Average m_buf_msgs
Bitfield< 31 > n
unsigned int getSize(Tick curTime)
bool areNSlotsAvailable(unsigned int n, Tick curTime)
Tick random_time()
void setPriority(int rank)
uint64_t Tick
Tick count type.
Definition: types.hh:63
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:54
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:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
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:3012
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:237
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:96

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13