gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
68namespace gem5
69{
70
71namespace ruby
72{
73
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 // earliest tick the head of queue will be ready, or MaxTick if empty
90 Tick readyTime() const;
91
92 void
93 delayHead(Tick current_time, Tick delta)
94 {
95 MsgPtr m = m_prio_heap.front();
96 std::pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
97 std::greater<MsgPtr>());
98 m_prio_heap.pop_back();
99 enqueue(m, current_time, delta);
100 }
101
102 bool areNSlotsAvailable(unsigned int n, Tick curTime);
103 int getPriority() { return m_priority_rank; }
104 void setPriority(int rank) { m_priority_rank = rank; }
105 void setConsumer(Consumer* consumer)
106 {
107 DPRINTF(RubyQueue, "Setting consumer: %s\n", *consumer);
108 if (m_consumer != NULL) {
109 fatal("Trying to connect %s to MessageBuffer %s. \
110 \n%s already connected. Check the cntrl_id's.\n",
111 *consumer, *this, *m_consumer);
112 }
113 m_consumer = consumer;
114 }
115
117
118 bool getOrdered() { return m_strict_fifo; }
119
122 const Message* peek() const;
123
124 const MsgPtr &peekMsgPtr() const { return m_prio_heap.front(); }
125
126 void enqueue(MsgPtr message, Tick curTime, Tick delta,
127 bool bypassStrictFIFO = false);
128
129 // Defer enqueueing a message to a later cycle by putting it aside and not
130 // enqueueing it in this cycle
131 // The corresponding controller will need to explicitly enqueue the
132 // deferred message into the message buffer. Otherwise, the message will
133 // be lost.
134 void deferEnqueueingMessage(Addr addr, MsgPtr message);
135
136 // enqueue all previously deferred messages that are associated with the
137 // input address
138 void enqueueDeferredMessages(Addr addr, Tick curTime, Tick delay);
139 bool isDeferredMsgMapEmpty(Addr addr) const;
140
143 Tick dequeue(Tick current_time, bool decrement_messages = true);
144
145 void registerDequeueCallback(std::function<void()> callback);
147
148 void recycle(Tick current_time, Tick recycle_latency);
149 bool isEmpty() const { return m_prio_heap.size() == 0; }
150 bool isStallMapEmpty() { return m_stall_msg_map.size() == 0; }
151 unsigned int getStallMapSize() { return m_stall_msg_map.size(); }
152
153 unsigned int getSize(Tick curTime);
154
155 void clear();
156 void print(std::ostream& out) const;
158
159 void setIncomingLink(int link_id) { m_input_link_id = link_id; }
160 void setVnet(int net) { m_vnet_id = net; }
161
162 int getIncomingLink() const { return m_input_link_id; }
163 int getVnet() const { return m_vnet_id; }
164
165 Port &
166 getPort(const std::string &, PortID idx=InvalidPortID) override
167 {
169 }
170
171 // Function for figuring out if any of the messages in the buffer need
172 // to be updated with the data from the packet.
173 // Return value indicates the number of messages that were updated.
174 uint32_t functionalWrite(Packet *pkt)
175 {
176 return functionalAccess(pkt, false, nullptr);
177 }
178
179 // Function for figuring if message in the buffer has valid data for
180 // the packet.
181 // Returns true only if a message was found with valid data and the
182 // read was performed.
184 {
185 return functionalAccess(pkt, true, nullptr) == 1;
186 }
187
188 // Functional read with mask
190 {
191 return functionalAccess(pkt, true, &mask) == 1;
192 }
193
194 int routingPriority() const { return m_routing_priority; }
195
196 private:
198
199 uint32_t functionalAccess(Packet *pkt, bool is_read, WriteMask *mask);
200
201 private:
202 // Data Members (m_ prefix)
206
207 std::function<void()> m_dequeue_callback;
208
209 // use a std::map for the stalled messages as this container is
210 // sorted and ensures a well-defined iteration order
211 typedef std::map<Addr, std::list<MsgPtr> > StallMsgMapType;
212
227
233 typedef std::unordered_map<Addr, std::vector<MsgPtr>> DeferredMsgMapType;
235
243
250 const unsigned int m_max_size;
251
256 const unsigned int m_max_dequeue_rate;
257
258 unsigned int m_dequeues_this_cy;
259
262
263 // variables used so enqueues appear to happen immediately, while
264 // pop happen the next cycle
268
271 unsigned int m_msgs_this_cycle;
272
275
277
278 const bool m_strict_fifo;
279 const MessageRandomization m_randomization;
281
283
286
287 // Count the # of times I didn't have N slots available
295};
296
298
299inline std::ostream&
300operator<<(std::ostream& out, const MessageBuffer& obj)
301{
302 obj.print(out);
303 out << std::flush;
304 return out;
305}
306
307} // namespace ruby
308} // namespace gem5
309
310#endif //__MEM_RUBY_NETWORK_MESSAGEBUFFER_HH__
#define DPRINTF(x,...)
Definition trace.hh:210
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Ports are used to interface objects to each other.
Definition port.hh:62
Abstract superclass for simulation objects.
statistics::Scalar m_stall_count
bool isDeferredMsgMapEmpty(Addr addr) const
void setConsumer(Consumer *consumer)
void recycle(Tick current_time, Tick recycle_latency)
MessageBuffer(const Params &p)
bool areNSlotsAvailable(unsigned int n, Tick curTime)
void setIncomingLink(int link_id)
bool isReady(Tick current_time) const
Port & getPort(const std::string &, PortID idx=InvalidPortID) override
Get a port with a given name and index.
const Message * peek() const
Function for extracting the message at the head of the message queue.
unsigned int m_size_last_time_size_checked
void enqueueDeferredMessages(Addr addr, Tick curTime, Tick delay)
std::unordered_map< Addr, std::vector< MsgPtr > > DeferredMsgMapType
A map from line addresses to corresponding vectors of messages that are deferred for enqueueing.
void enqueue(MsgPtr message, Tick curTime, Tick delta, bool bypassStrictFIFO=false)
const unsigned int m_max_dequeue_rate
When != 0, isReady returns false once m_max_dequeue_rate messages have been dequeued in the same cycl...
MessageBufferParams Params
bool functionalRead(Packet *pkt)
const unsigned int m_max_size
The maximum capacity.
void reanalyzeAllMessages(Tick current_time)
unsigned int m_stalled_at_cycle_start
statistics::Formula m_avg_stall_time
Consumer * m_consumer
Consumer to signal a wakeup(), can be NULL.
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...
statistics::Average m_buf_msgs
statistics::Scalar m_stall_time
bool hasStalledMsg(Addr addr) const
std::map< Addr, std::list< MsgPtr > > StallMsgMapType
std::vector< MsgPtr > m_prio_heap
void delayHead(Tick current_time, Tick delta)
const MsgPtr & peekMsgPtr() const
void deferEnqueueingMessage(Addr addr, MsgPtr message)
void registerDequeueCallback(std::function< void()> callback)
StallMsgMapType m_stall_msg_map
A map from line addresses to lists of stalled messages for that line.
void stallMessage(Addr addr, Tick current_time)
statistics::Scalar m_msg_count
statistics::Formula m_occupancy
void print(std::ostream &out) const
void reanalyzeMessages(Addr addr, Tick current_time)
const MessageRandomization m_randomization
void reanalyzeList(std::list< MsgPtr > &, Tick)
unsigned int getSize(Tick curTime)
int m_stall_map_size
Current size of the stall map.
statistics::Scalar m_not_avail_count
std::function< void()> m_dequeue_callback
uint32_t functionalAccess(Packet *pkt, bool is_read, WriteMask *mask)
uint32_t functionalWrite(Packet *pkt)
DeferredMsgMapType m_deferred_msg_map
bool functionalRead(Packet *pkt, WriteMask &mask)
static RubyDummyPort & instance()
Definition dummy_port.hh:56
A stat that calculates the per tick average of a value.
A formula for statistics that is calculated when printed.
This is a simple scalar statistic, like a counter.
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Port Object Declaration.
Bitfield< 31 > n
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 0 > m
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
std::shared_ptr< Message > MsgPtr
Definition Message.hh:60
Tick random_time()
std::ostream & operator<<(std::ostream &os, const BoolVec &myvector)
Definition BoolVec.cc:49
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
Declaration of the Packet class.

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0