gem5  v20.1.0.0
AbstractController.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017,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) 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 
51  : ClockedObject(p), Consumer(this), m_version(p->version),
52  m_clusterID(p->cluster_id),
53  m_id(p->system->getRequestorId(this)), m_is_blocking(false),
54  m_number_of_TBEs(p->number_of_TBEs),
55  m_transitions_per_cycle(p->transitions_per_cycle),
56  m_buffer_size(p->buffer_size), m_recycle_latency(p->recycle_latency),
57  m_mandatory_queue_latency(p->mandatory_queue_latency),
58  memoryPort(csprintf("%s.memory", name()), this),
59  addrRanges(p->addr_ranges.begin(), p->addr_ranges.end())
60 {
61  if (m_version == 0) {
62  // Combine the statistics from all controllers
63  // of this particular type.
65  }
66 }
67 
68 void
70 {
72  uint32_t size = Network::getNumberOfVirtualNetworks();
73  for (uint32_t i = 0; i < size; i++) {
74  m_delayVCHistogram.push_back(new Stats::Histogram());
75  m_delayVCHistogram[i]->init(10);
76  }
77 
78  if (getMemReqQueue()) {
79  getMemReqQueue()->setConsumer(this);
80  }
81 }
82 
83 void
85 {
87  uint32_t size = Network::getNumberOfVirtualNetworks();
88  for (uint32_t i = 0; i < size; i++) {
89  m_delayVCHistogram[i]->reset();
90  }
91 }
92 
93 void
95 {
97 
99  .name(name() + ".fully_busy_cycles")
100  .desc("cycles for which number of transistions == max transitions")
102 }
103 
104 void
105 AbstractController::profileMsgDelay(uint32_t virtualNetwork, Cycles delay)
106 {
107  assert(virtualNetwork < m_delayVCHistogram.size());
108  m_delayHistogram.sample(delay);
109  m_delayVCHistogram[virtualNetwork]->sample(delay);
110 }
111 
112 void
114 {
115  if (m_waiting_buffers.count(addr) == 0) {
116  MsgVecType* msgVec = new MsgVecType;
117  msgVec->resize(m_in_ports, NULL);
118  m_waiting_buffers[addr] = msgVec;
119  }
120  DPRINTF(RubyQueue, "stalling %s port %d addr %#x\n", buf, m_cur_in_port,
121  addr);
122  assert(m_in_ports > m_cur_in_port);
123  (*(m_waiting_buffers[addr]))[m_cur_in_port] = buf;
124 }
125 
126 void
128 {
129  if (m_waiting_buffers.count(addr) > 0) {
130  //
131  // Wake up all possible lower rank (i.e. lower priority) buffers that could
132  // be waiting on this message.
133  //
134  for (int in_port_rank = m_cur_in_port - 1;
135  in_port_rank >= 0;
136  in_port_rank--) {
137  if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) {
138  (*(m_waiting_buffers[addr]))[in_port_rank]->
139  reanalyzeMessages(addr, clockEdge());
140  }
141  }
142  delete m_waiting_buffers[addr];
143  m_waiting_buffers.erase(addr);
144  }
145 }
146 
147 void
149 {
150  if (m_waiting_buffers.count(addr) > 0) {
151  //
152  // Wake up all possible buffers that could be waiting on this message.
153  //
154  for (int in_port_rank = m_in_ports - 1;
155  in_port_rank >= 0;
156  in_port_rank--) {
157  if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) {
158  (*(m_waiting_buffers[addr]))[in_port_rank]->
159  reanalyzeMessages(addr, clockEdge());
160  }
161  }
162  delete m_waiting_buffers[addr];
163  m_waiting_buffers.erase(addr);
164  }
165 }
166 
167 void
169 {
170  //
171  // Wake up all possible buffers that could be waiting on any message.
172  //
173 
174  std::vector<MsgVecType*> wokeUpMsgVecs;
175  MsgBufType wokeUpMsgBufs;
176 
177  if (m_waiting_buffers.size() > 0) {
178  for (WaitingBufType::iterator buf_iter = m_waiting_buffers.begin();
179  buf_iter != m_waiting_buffers.end();
180  ++buf_iter) {
181  for (MsgVecType::iterator vec_iter = buf_iter->second->begin();
182  vec_iter != buf_iter->second->end();
183  ++vec_iter) {
184  //
185  // Make sure the MessageBuffer has not already be reanalyzed
186  //
187  if (*vec_iter != NULL &&
188  (wokeUpMsgBufs.count(*vec_iter) == 0)) {
189  (*vec_iter)->reanalyzeAllMessages(clockEdge());
190  wokeUpMsgBufs.insert(*vec_iter);
191  }
192  }
193  wokeUpMsgVecs.push_back(buf_iter->second);
194  }
195 
196  for (std::vector<MsgVecType*>::iterator wb_iter = wokeUpMsgVecs.begin();
197  wb_iter != wokeUpMsgVecs.end();
198  ++wb_iter) {
199  delete (*wb_iter);
200  }
201 
202  m_waiting_buffers.clear();
203  }
204 }
205 
206 bool
208 {
209  auto mem_queue = getMemReqQueue();
210  assert(mem_queue);
211  if (!mem_queue->isReady(clockEdge())) {
212  return false;
213  }
214 
215  const MemoryMsg *mem_msg = (const MemoryMsg*)mem_queue->peek();
216  unsigned int req_size = RubySystem::getBlockSizeBytes();
217  if (mem_msg->m_Len > 0) {
218  req_size = mem_msg->m_Len;
219  }
220 
221  RequestPtr req
222  = std::make_shared<Request>(mem_msg->m_addr, req_size, 0, m_id);
223  PacketPtr pkt;
224  if (mem_msg->getType() == MemoryRequestType_MEMORY_WB) {
225  pkt = Packet::createWrite(req);
226  pkt->allocate();
227  pkt->setData(mem_msg->m_DataBlk.getData(getOffset(mem_msg->m_addr),
228  req_size));
229  } else if (mem_msg->getType() == MemoryRequestType_MEMORY_READ) {
230  pkt = Packet::createRead(req);
231  uint8_t *newData = new uint8_t[req_size];
232  pkt->dataDynamic(newData);
233  } else {
234  panic("Unknown memory request type (%s) for addr %p",
235  MemoryRequestType_to_string(mem_msg->getType()),
236  mem_msg->m_addr);
237  }
238 
239  SenderState *s = new SenderState(mem_msg->m_Sender);
240  pkt->pushSenderState(s);
241 
243  // Use functional rather than timing accesses during warmup
244  mem_queue->dequeue(clockEdge());
246  // Since the queue was popped the controller may be able
247  // to make more progress. Make sure it wakes up
248  scheduleEvent(Cycles(1));
249  recvTimingResp(pkt);
250  } else if (memoryPort.sendTimingReq(pkt)) {
251  mem_queue->dequeue(clockEdge());
252  // Since the queue was popped the controller may be able
253  // to make more progress. Make sure it wakes up
254  scheduleEvent(Cycles(1));
255  } else {
256  scheduleEvent(Cycles(1));
257  delete pkt;
258  delete s;
259  }
260 
261  return true;
262 }
263 
264 void
266 {
267  m_is_blocking = true;
268  m_block_map[addr] = port;
269 }
270 
271 bool
273 {
274  return m_is_blocking && (m_block_map.find(addr) != m_block_map.end());
275 }
276 
277 void
279 {
280  m_block_map.erase(addr);
281  if (m_block_map.size() == 0) {
282  m_is_blocking = false;
283  }
284 }
285 
286 bool
288 {
289  return (m_block_map.count(addr) > 0);
290 }
291 
292 Port &
293 AbstractController::getPort(const std::string &if_name, PortID idx)
294 {
295  return memoryPort;
296 }
297 
298 void
300 {
302 }
303 
304 int
306 {
307  int num_functional_writes = 0;
308 
309  // Update memory itself.
311  return num_functional_writes + 1;
312 }
313 
314 void
316 {
317  assert(getMemRespQueue());
318  assert(pkt->isResponse());
319 
320  std::shared_ptr<MemoryMsg> msg = std::make_shared<MemoryMsg>(clockEdge());
321  (*msg).m_addr = pkt->getAddr();
322  (*msg).m_Sender = m_machineID;
323 
324  SenderState *s = dynamic_cast<SenderState *>(pkt->senderState);
325  (*msg).m_OriginalRequestorMachId = s->id;
326  delete s;
327 
328  if (pkt->isRead()) {
329  (*msg).m_Type = MemoryRequestType_MEMORY_READ;
330  (*msg).m_MessageSize = MessageSizeType_Response_Data;
331 
332  // Copy data from the packet
333  (*msg).m_DataBlk.setData(pkt->getPtr<uint8_t>(), 0,
335  } else if (pkt->isWrite()) {
336  (*msg).m_Type = MemoryRequestType_MEMORY_WB;
337  (*msg).m_MessageSize = MessageSizeType_Writeback_Control;
338  } else {
339  panic("Incorrect packet type received from memory controller!");
340  }
341 
343  delete pkt;
344 }
345 
346 Tick
348 {
349  return ticksToCycles(memoryPort.sendAtomic(pkt));
350 }
351 
352 MachineID
354 {
355  NodeID node = m_net_ptr->addressToNodeID(addr, mtype);
356  MachineID mach = {mtype, node};
357  return mach;
358 }
359 
360 bool
362 {
364  return true;
365 }
366 
367 void
369 {
370  controller->serviceMemoryQueue();
371 }
372 
374  AbstractController *_controller,
375  PortID id)
376  : RequestPort(_name, _controller, id), controller(_controller)
377 {
378 }
AbstractController::blockOnQueue
void blockOnQueue(Addr, MessageBuffer *)
Definition: AbstractController.cc:265
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
Packet::isResponse
bool isResponse() const
Definition: packet.hh:560
AbstractController::m_waiting_buffers
WaitingBufType m_waiting_buffers
Definition: AbstractController.hh:198
system.hh
AbstractController::SenderState
Definition: AbstractController.hh:244
RubySystem::getBlockSizeBytes
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:62
AbstractController::recvAtomic
Tick recvAtomic(PacketPtr pkt)
Definition: AbstractController.cc:347
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:754
AbstractController::MemoryPort::controller
AbstractController * controller
Definition: AbstractController.hh:225
AbstractController::m_delayVCHistogram
std::vector< Stats::Histogram * > m_delayVCHistogram
Definition: AbstractController.hh:215
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
AbstractController::getMemReqQueue
virtual MessageBuffer * getMemReqQueue() const =0
Network::addressToNodeID
NodeID addressToNodeID(Addr addr, MachineType mtype)
Map an address to the correct NodeID.
Definition: Network.cc:231
Stats::registerDumpCallback
void registerDumpCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are about to be dumped.
Definition: statistics.cc:589
AbstractController::stallBuffer
void stallBuffer(MessageBuffer *buf, Addr addr)
Definition: AbstractController.cc:113
AbstractController::MemoryPort::recvTimingResp
bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
Definition: AbstractController.cc:361
Packet::isRead
bool isRead() const
Definition: packet.hh:556
AbstractController::wakeUpAllBuffers
void wakeUpAllBuffers()
Definition: AbstractController.cc:168
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
AbstractController::mapAddressToMachine
MachineID mapAddressToMachine(Addr addr, MachineType mtype) const
Map an address to the correct MachineID.
Definition: AbstractController.cc:353
AbstractController.hh
AbstractController::MemoryPort::MemoryPort
MemoryPort(const std::string &_name, AbstractController *_controller, PortID id=InvalidPortID)
Definition: AbstractController.cc:373
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
Packet::dataDynamic
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1145
std::vector< MessageBuffer * >
AbstractController
Definition: AbstractController.hh:74
RequestPort::sendFunctional
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:482
MessageBuffer::setConsumer
void setConsumer(Consumer *consumer)
Definition: MessageBuffer.hh:96
AbstractController::m_cur_in_port
unsigned int m_cur_in_port
Definition: AbstractController.hh:201
MessageBuffer::enqueue
void enqueue(MsgPtr message, Tick curTime, Tick delta)
Definition: MessageBuffer.cc:162
AbstractController::serviceMemoryQueue
bool serviceMemoryQueue()
Definition: AbstractController.cc:207
MachineID
Definition: MachineID.hh:38
AbstractController::isBlocked
bool isBlocked(Addr) const
Definition: AbstractController.cc:272
Packet::setData
void setData(const uint8_t *p)
Copy data into the packet from the provided pointer.
Definition: packet.hh:1225
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
Stats::DataWrap::flags
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:331
Stats::Histogram
A simple histogram stat.
Definition: statistics.hh:2654
X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
AbstractController::wakeUpBuffers
void wakeUpBuffers(Addr addr)
Definition: AbstractController.cc:127
AbstractController::unblock
void unblock(Addr)
Definition: AbstractController.cc:278
Clocked::cyclesToTicks
Tick cyclesToTicks(Cycles c) const
Definition: clocked_object.hh:224
AbstractController::memoryPort
MemoryPort memoryPort
Definition: AbstractController.hh:241
AbstractController::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: AbstractController.cc:94
AbstractController::m_in_ports
unsigned int m_in_ports
Definition: AbstractController.hh:200
RequestPort::sendTimingReq
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition: port.hh:492
AbstractController::m_net_ptr
Network * m_net_ptr
Definition: AbstractController.hh:191
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
SenderState
RubyTester::SenderState SenderState
Definition: Check.cc:37
AbstractController::m_is_blocking
bool m_is_blocking
Definition: AbstractController.hh:192
Packet::createRead
static PacketPtr createRead(const RequestPtr &req)
Constructor-like methods that return Packets based on Request objects.
Definition: packet.hh:980
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
Consumer
Definition: Consumer.hh:43
Clocked::clockEdge
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...
Definition: clocked_object.hh:174
AbstractController::functionalMemoryWrite
int functionalMemoryWrite(PacketPtr)
Definition: AbstractController.cc:305
AbstractController::recvTimingResp
void recvTimingResp(PacketPtr pkt)
Definition: AbstractController.cc:315
AbstractController::m_block_map
std::map< Addr, MessageBuffer * > m_block_map
Definition: AbstractController.hh:193
AbstractController::m_machineID
MachineID m_machineID
Definition: AbstractController.hh:185
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
AbstractController::m_delayHistogram
Stats::Histogram m_delayHistogram
Histogram for profiling delay for the messages this controller cares for.
Definition: AbstractController.hh:214
AbstractController::collateStats
virtual void collateStats()
Function for collating statistics from all the controllers of this particular type.
Definition: AbstractController.hh:133
RubySystem.hh
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
AbstractController::m_fully_busy_cycles
Stats::Scalar m_fully_busy_cycles
Counter for the number of cycles when the transitions carried out were equal to the maximum allowed.
Definition: AbstractController.hh:210
Stats::DataWrap::name
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:274
name
const std::string & name()
Definition: trace.cc:50
Network::getNumberOfVirtualNetworks
static uint32_t getNumberOfVirtualNetworks()
Definition: Network.hh:87
Stats::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
AbstractController::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: AbstractController.cc:69
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
AbstractController::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
A function used to return the port associated with this bus object.
Definition: AbstractController.cc:293
Network.hh
Packet::createWrite
static PacketPtr createWrite(const RequestPtr &req)
Definition: packet.hh:986
Packet::pushSenderState
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:332
RubySystem::getWarmupEnabled
static bool getWarmupEnabled()
Definition: RubySystem.hh:65
Clocked::ticksToCycles
Cycles ticksToCycles(Tick t) const
Definition: clocked_object.hh:219
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
AbstractController::m_id
const RequestorID m_id
Definition: AbstractController.hh:189
AbstractController::MemoryPort::recvReqRetry
void recvReqRetry()
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: AbstractController.cc:368
getOffset
Addr getOffset(Addr addr)
Definition: Address.cc:48
Stats::DistBase::reset
void reset()
Reset stat value to default.
Definition: statistics.hh:1948
AbstractController::Params
RubyControllerParams Params
Definition: AbstractController.hh:77
addr
ip6_addr_t addr
Definition: inet.hh:423
Stats::DistBase::sample
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:1924
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Packet::isWrite
bool isWrite() const
Definition: packet.hh:557
Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1157
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
AbstractController::MsgBufType
std::set< MessageBuffer * > MsgBufType
Definition: AbstractController.hh:196
AbstractController::m_version
const NodeID m_version
Definition: AbstractController.hh:184
Stats::Histogram::init
Histogram & init(size_type size)
Set the parameters of this histogram.
Definition: statistics.hh:2669
Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:508
RequestPort::sendAtomic
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:461
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MessageBuffer
Definition: MessageBuffer.hh:68
AbstractController::profileMsgDelay
void profileMsgDelay(uint32_t virtualNetwork, Cycles delay)
Profiles the delay associated with messages.
Definition: AbstractController.cc:105
Packet::allocate
void allocate()
Allocate memory for the packet.
Definition: packet.hh:1299
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
Stats::DataWrap::desc
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:307
AbstractController::getMemRespQueue
virtual MessageBuffer * getMemRespQueue() const =0
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
AbstractController::MsgVecType
std::vector< MessageBuffer * > MsgVecType
Definition: AbstractController.hh:195
ArmISA::id
Bitfield< 33 > id
Definition: miscregs_types.hh:247
Consumer::scheduleEvent
void scheduleEvent(Cycles timeDelta)
Definition: Consumer.cc:34
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
AbstractController::AbstractController
AbstractController(const Params *p)
Definition: AbstractController.cc:50
AbstractController::resetStats
virtual void resetStats()=0
Callback to reset stats.
Definition: AbstractController.cc:84
AbstractController::functionalMemoryRead
void functionalMemoryRead(PacketPtr)
Definition: AbstractController.cc:299
Sequencer.hh

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17