gem5 v24.0.0.0
Loading...
Searching...
No Matches
AbstractController.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017,2019-2022 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) 2011-2014 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
42
43#include "debug/RubyQueue.hh"
45#include "mem/ruby/protocol/MemoryMsg.hh"
48#include "sim/system.hh"
49
50namespace gem5
51{
52
53namespace ruby
54{
55
57 : ClockedObject(p), Consumer(this), m_version(p.version),
58 m_clusterID(p.cluster_id),
59 m_id(p.system->getRequestorId(this)), m_is_blocking(false),
60 m_number_of_TBEs(p.number_of_TBEs),
61 m_transitions_per_cycle(p.transitions_per_cycle),
62 m_buffer_size(p.buffer_size), m_recycle_latency(p.recycle_latency),
63 m_mandatory_queue_latency(p.mandatory_queue_latency),
64 m_waiting_mem_retry(false),
65 m_mem_ctrl_waiting_retry(false),
66 memoryPort(csprintf("%s.memory", name()), this),
67 addrRanges(p.addr_ranges.begin(), p.addr_ranges.end()),
68 mRetryRespEvent{*this, false},
69 stats(this)
70{
71 if (m_version == 0) {
72 // Combine the statistics from all controllers
73 // of this particular type.
75 }
76}
77
78void
80{
83 for (uint32_t i = 0; i < size; i++) {
84 stats.delayVCHistogram.push_back(new statistics::Histogram(this));
85 stats.delayVCHistogram[i]->init(10);
86 }
87
88 if (getMemReqQueue()) {
90 }
91
92 // Initialize the addr->downstream machine mappings. Multiple machines
93 // in downstream_destinations can have the same address range if they have
94 // different types. If this is the case, mapAddressToDownstreamMachine
95 // needs to specify the machine type
97 for (auto abs_cntrl : params().downstream_destinations) {
98 MachineID mid = abs_cntrl->getMachineID();
99 const AddrRangeList &ranges = abs_cntrl->getAddrRanges();
100 for (const auto &addr_range : ranges) {
101 auto i = downstreamAddrMap.find(mid.getType());
102 if ((i != downstreamAddrMap.end()) &&
103 (i->second.intersects(addr_range) != i->second.end())) {
104 fatal("%s: %s mapped to multiple machines of the same type\n",
105 name(), addr_range.to_string());
106 }
107 downstreamAddrMap[mid.getType()].insert(addr_range, mid);
108 }
110 }
111 // Initialize the addr->upstream machine list.
112 // We do not need to map address -> upstream machine,
113 // so we don't examine the address ranges
115 for (auto abs_cntrl : params().upstream_destinations) {
116 upstreamDestinations.add(abs_cntrl->getMachineID());
117 }
118}
119
120void
122{
124 uint32_t size = Network::getNumberOfVirtualNetworks();
125 for (uint32_t i = 0; i < size; i++) {
126 stats.delayVCHistogram[i]->reset();
127 }
129}
130
131void
136
137void
138AbstractController::profileMsgDelay(uint32_t virtualNetwork, Cycles delay)
139{
140 assert(virtualNetwork < stats.delayVCHistogram.size());
142 stats.delayVCHistogram[virtualNetwork]->sample(delay);
143}
144
145void
147{
148 if (m_waiting_buffers.count(addr) == 0) {
149 MsgVecType* msgVec = new MsgVecType;
150 msgVec->resize(m_in_ports, NULL);
151 m_waiting_buffers[addr] = msgVec;
152 }
153 DPRINTF(RubyQueue, "stalling %s port %d addr %#x\n", buf, m_cur_in_port,
154 addr);
155 assert(m_in_ports > m_cur_in_port);
157}
158
159void
161{
162 auto iter = m_waiting_buffers.find(addr);
163 if (iter != m_waiting_buffers.end()) {
164 bool has_other_msgs = false;
165 MsgVecType* msgVec = iter->second;
166 for (unsigned int port = 0; port < msgVec->size(); ++port) {
167 if ((*msgVec)[port] == buf) {
169 (*msgVec)[port] = NULL;
170 } else if ((*msgVec)[port] != NULL) {
171 has_other_msgs = true;
172 }
173 }
174 if (!has_other_msgs) {
175 delete msgVec;
176 m_waiting_buffers.erase(iter);
177 }
178 }
179}
180
181void
183{
184 if (m_waiting_buffers.count(addr) > 0) {
185 //
186 // Wake up all possible lower rank (i.e. lower priority) buffers that could
187 // be waiting on this message.
188 //
189 for (int in_port_rank = m_cur_in_port - 1;
190 in_port_rank >= 0;
191 in_port_rank--) {
192 if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) {
193 (*(m_waiting_buffers[addr]))[in_port_rank]->
194 reanalyzeMessages(addr, clockEdge());
195 }
196 }
197 delete m_waiting_buffers[addr];
198 m_waiting_buffers.erase(addr);
199 }
200}
201
202void
204{
205 if (m_waiting_buffers.count(addr) > 0) {
206 //
207 // Wake up all possible buffers that could be waiting on this message.
208 //
209 for (int in_port_rank = m_in_ports - 1;
210 in_port_rank >= 0;
211 in_port_rank--) {
212 if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) {
213 (*(m_waiting_buffers[addr]))[in_port_rank]->
214 reanalyzeMessages(addr, clockEdge());
215 }
216 }
217 delete m_waiting_buffers[addr];
218 m_waiting_buffers.erase(addr);
219 }
220}
221
222void
224{
225 //
226 // Wake up all possible buffers that could be waiting on any message.
227 //
228
229 std::vector<MsgVecType*> wokeUpMsgVecs;
230 MsgBufType wokeUpMsgBufs;
231
232 if (m_waiting_buffers.size() > 0) {
233 for (WaitingBufType::iterator buf_iter = m_waiting_buffers.begin();
234 buf_iter != m_waiting_buffers.end();
235 ++buf_iter) {
236 for (MsgVecType::iterator vec_iter = buf_iter->second->begin();
237 vec_iter != buf_iter->second->end();
238 ++vec_iter) {
239 //
240 // Make sure the MessageBuffer has not already be reanalyzed
241 //
242 if (*vec_iter != NULL &&
243 (wokeUpMsgBufs.count(*vec_iter) == 0)) {
244 (*vec_iter)->reanalyzeAllMessages(clockEdge());
245 wokeUpMsgBufs.insert(*vec_iter);
246 }
247 }
248 wokeUpMsgVecs.push_back(buf_iter->second);
249 }
250
251 for (std::vector<MsgVecType*>::iterator wb_iter = wokeUpMsgVecs.begin();
252 wb_iter != wokeUpMsgVecs.end();
253 ++wb_iter) {
254 delete (*wb_iter);
255 }
256
257 m_waiting_buffers.clear();
258 }
259}
260
261bool
263{
264 auto mem_queue = getMemReqQueue();
265 assert(mem_queue);
266 if (m_waiting_mem_retry || !mem_queue->isReady(clockEdge())) {
267 return false;
268 }
269
270 const MemoryMsg *mem_msg = (const MemoryMsg*)mem_queue->peek();
271 unsigned int req_size = RubySystem::getBlockSizeBytes();
272 if (mem_msg->m_Len > 0) {
273 req_size = mem_msg->m_Len;
274 }
275
276 RequestPtr req
277 = std::make_shared<Request>(mem_msg->m_addr, req_size, 0, m_id);
278 PacketPtr pkt;
279 if (mem_msg->getType() == MemoryRequestType_MEMORY_WB) {
280 pkt = Packet::createWrite(req);
281 pkt->allocate();
282 pkt->setData(mem_msg->m_DataBlk.getData(getOffset(mem_msg->m_addr),
283 req_size));
284 } else if (mem_msg->getType() == MemoryRequestType_MEMORY_READ) {
285 pkt = Packet::createRead(req);
286 uint8_t *newData = new uint8_t[req_size];
287 pkt->dataDynamic(newData);
288 } else {
289 panic("Unknown memory request type (%s) for addr %p",
290 MemoryRequestType_to_string(mem_msg->getType()),
291 mem_msg->m_addr);
292 }
293
294 SenderState *s = new SenderState(mem_msg->m_Sender);
295 pkt->pushSenderState(s);
296
298 // Use functional rather than timing accesses during warmup
299 mem_queue->dequeue(clockEdge());
301 // Since the queue was popped the controller may be able
302 // to make more progress. Make sure it wakes up
304 recvTimingResp(pkt);
305 } else if (memoryPort.sendTimingReq(pkt)) {
306 mem_queue->dequeue(clockEdge());
307 // Since the queue was popped the controller may be able
308 // to make more progress. Make sure it wakes up
310 } else {
312 m_waiting_mem_retry = true;
313 delete pkt;
314 delete s;
315 }
316
317 return true;
318}
319
320void
326
327bool
329{
330 return m_is_blocking && (m_block_map.find(addr) != m_block_map.end());
331}
332
333void
335{
336 m_block_map.erase(addr);
337 if (m_block_map.size() == 0) {
338 m_is_blocking = false;
339 }
340}
341
342bool
344{
345 return (m_block_map.count(addr) > 0);
346}
347
348Port &
349AbstractController::getPort(const std::string &if_name, PortID idx)
350{
351 return memoryPort;
352}
353
354void
356{
357 // read from mem. req. queue if write data is pending there
358 MessageBuffer *req_queue = getMemReqQueue();
359 if (!req_queue || !req_queue->functionalRead(pkt))
361}
362
363int
365{
366 int num_functional_writes = 0;
367
368 // Update memory itself.
370 return num_functional_writes + 1;
371}
372
373bool
375{
376 auto* memRspQueue = getMemRespQueue();
377 gem5_assert(memRspQueue);
378 gem5_assert(pkt->isResponse());
379
380 if (!memRspQueue->areNSlotsAvailable(1, curTick())) {
382 return false;
383 }
384
385 std::shared_ptr<MemoryMsg> msg = std::make_shared<MemoryMsg>(clockEdge());
386 (*msg).m_addr = pkt->getAddr();
387 (*msg).m_Sender = m_machineID;
388
389 SenderState *s = dynamic_cast<SenderState *>(pkt->senderState);
390 (*msg).m_OriginalRequestorMachId = s->id;
391 delete s;
392
393 if (pkt->isRead()) {
394 (*msg).m_Type = MemoryRequestType_MEMORY_READ;
395 (*msg).m_MessageSize = MessageSizeType_Response_Data;
396
397 // Copy data from the packet
398 (*msg).m_DataBlk.setData(pkt->getPtr<uint8_t>(), 0,
400 } else if (pkt->isWrite()) {
401 (*msg).m_Type = MemoryRequestType_MEMORY_WB;
402 (*msg).m_MessageSize = MessageSizeType_Writeback_Control;
403 } else {
404 panic("Incorrect packet type received from memory controller!");
405 }
406
407 memRspQueue->enqueue(msg, clockEdge(), cyclesToTicks(Cycles(1)));
408 delete pkt;
409 return true;
410}
411
412Tick
417
420{
421 NodeID node = m_net_ptr->addressToNodeID(addr, mtype);
422 MachineID mach = {mtype, node};
423 return mach;
424}
425
428const
429{
430 if (mtype == MachineType_NUM) {
431 // map to the first match
432 for (const auto &i : downstreamAddrMap) {
433 const auto mapping = i.second.contains(addr);
434 if (mapping != i.second.end())
435 return mapping->second;
436 }
437 }
438 else {
439 const auto i = downstreamAddrMap.find(mtype);
440 if (i != downstreamAddrMap.end()) {
441 const auto mapping = i->second.contains(addr);
442 if (mapping != i->second.end())
443 return mapping->second;
444 }
445 }
446 fatal("%s: couldn't find mapping for address %x mtype=%s\n",
447 name(), addr, mtype);
448}
449
450
451void
457
458void
465
466void
473
474bool
479
480void
482{
483 controller->m_waiting_mem_retry = false;
484 controller->serviceMemoryQueue();
485}
486
488 AbstractController *_controller,
489 PortID id)
490 : RequestPort(_name, id), controller(_controller)
491{
492}
493
496 : statistics::Group(parent),
497 ADD_STAT(fullyBusyCycles,
498 "cycles for which number of transistions == max transitions"),
499 ADD_STAT(delayHistogram, "delay_histogram")
500{
505}
506
507} // namespace ruby
508} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
ClockedObjectParams Params
Parameters of ClockedObject.
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Tick cyclesToTicks(Cycles c) const
Cycles ticksToCycles(Tick t) const
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
const std::string _name
Definition named.hh:41
virtual std::string name() const
Definition named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
bool isRead() const
Definition packet.hh:593
Addr getAddr() const
Definition packet.hh:807
bool isResponse() const
Definition packet.hh:598
static PacketPtr createWrite(const RequestPtr &req)
Definition packet.hh:1044
SenderState * senderState
This packet's sender state.
Definition packet.hh:545
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
Definition packet.cc:334
T * getPtr()
get a pointer to the data ptr.
Definition packet.hh:1225
void setData(const uint8_t *p)
Copy data into the packet from the provided pointer.
Definition packet.hh:1293
bool isWrite() const
Definition packet.hh:594
static PacketPtr createRead(const RequestPtr &req)
Constructor-like methods that return Packets based on Request objects.
Definition packet.hh:1038
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition packet.hh:1213
void allocate()
Allocate memory for the packet.
Definition packet.hh:1367
Ports are used to interface objects to each other.
Definition port.hh:62
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
virtual void sendRetryResp()
Send a retry to the response port that previously attempted a sendTimingResp to this request port and...
Definition port.hh:637
Tick sendAtomic(PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time,...
Definition port.hh:552
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition port.hh:603
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition port.hh:579
MemoryPort(const std::string &_name, AbstractController *_controller, PortID id=InvalidPortID)
bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
std::vector< MessageBuffer * > MsgVecType
void profileMsgDelay(uint32_t virtualNetwork, Cycles delay)
Profiles the delay associated with messages.
void wakeUpBuffer(MessageBuffer *buf, Addr addr)
virtual void regStats()
Callback to set stat parameters.
std::unordered_map< MachineType, AddrRangeMap< MachineID, 3 > > downstreamAddrMap
virtual MessageBuffer * getMemReqQueue() const =0
std::set< MessageBuffer * > MsgBufType
MachineID mapAddressToDownstreamMachine(Addr addr, MachineType mtype=MachineType_NUM) const
Maps an address to the correct dowstream MachineID (i.e.
virtual void collateStats()
Function for collating statistics from all the controllers of this particular type.
virtual MessageBuffer * getMemRespQueue() const =0
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
MemberEventWrapper<&AbstractController::sendRetryRespToMem > mRetryRespEvent
virtual void resetStats()=0
Callback to reset stats.
void blockOnQueue(Addr, MessageBuffer *)
MachineID mapAddressToMachine(Addr addr, MachineType mtype) const
Map an address to the correct MachineID.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
A function used to return the port associated with this bus object.
gem5::ruby::AbstractController::ControllerStats stats
std::map< Addr, MessageBuffer * > m_block_map
void stallBuffer(MessageBuffer *buf, Addr addr)
void scheduleEvent(Cycles timeDelta)
Definition Consumer.cc:56
void setConsumer(Consumer *consumer)
bool functionalRead(Packet *pkt)
void reanalyzeMessages(Addr addr, Tick current_time)
void add(MachineID newElement)
Definition NetDest.cc:45
static uint32_t getNumberOfVirtualNetworks()
Definition Network.hh:90
NodeID addressToNodeID(Addr addr, MachineType mtype)
Map an address to the correct NodeID.
Definition Network.cc:235
static bool getWarmupEnabled()
Definition RubySystem.hh:75
static uint32_t getBlockSizeBytes()
Definition RubySystem.hh:72
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
void reset()
Reset stat value to default.
Statistics container.
Definition group.hh:93
A simple histogram stat.
Histogram & init(size_type size)
Set the parameters of this histogram.
STL vector class.
Definition stl.hh:37
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition group.hh:75
bool scheduled() const
Determine if the current event is scheduled.
Definition eventq.hh:458
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition logging.hh:317
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
const Params & params() const
static SimObject * find(const char *name)
Find the SimObject with the given name and return a pointer to it.
virtual void regStats()
Callback to set stat parameters.
Definition group.cc:68
virtual void resetStats()
Callback to reset stats.
Definition group.cc:86
Bitfield< 4 > s
Bitfield< 27 > q
Definition misc_types.hh:55
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 33 > id
Bitfield< 0 > p
Bitfield< 15 > system
Definition misc.hh:1032
Bitfield< 3 > addr
Definition types.hh:84
unsigned int NodeID
Addr getOffset(Addr addr)
Definition Address.cc:54
void registerDumpCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are about to be dumped.
const FlagsType nozero
Don't print if this is zero.
Definition info.hh:67
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
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
RubyTester::SenderState SenderState
Definition Check.cc:40
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
statistics::Scalar fullyBusyCycles
Counter for the number of cycles when the transitions carried out were equal to the maximum allowed.
statistics::Histogram delayHistogram
Histogram for profiling delay for the messages this controller cares for.
std::vector< statistics::Histogram * > delayVCHistogram
MachineType getType() const
Definition MachineID.hh:66
const std::string & name()
Definition trace.cc:48

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