gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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"
49 #include "sim/system.hh"
50 
52  : ClockedObject(p), Consumer(this), m_version(p->version),
53  m_clusterID(p->cluster_id),
54  m_masterId(p->system->getMasterId(this)), m_is_blocking(false),
55  m_number_of_TBEs(p->number_of_TBEs),
56  m_transitions_per_cycle(p->transitions_per_cycle),
57  m_buffer_size(p->buffer_size), m_recycle_latency(p->recycle_latency),
58  m_mandatory_queue_latency(p->mandatory_queue_latency),
59  memoryPort(csprintf("%s.memory", name()), this, ""),
60  addrRanges(p->addr_ranges.begin(), p->addr_ranges.end())
61 {
62  if (m_version == 0) {
63  // Combine the statistics from all controllers
64  // of this particular type.
66  }
67 }
68 
69 void
71 {
72  params()->ruby_system->registerAbstractController(this);
74  uint32_t size = Network::getNumberOfVirtualNetworks();
75  for (uint32_t i = 0; i < size; i++) {
76  m_delayVCHistogram.push_back(new Stats::Histogram());
77  m_delayVCHistogram[i]->init(10);
78  }
79 
80  if (getMemReqQueue()) {
81  getMemReqQueue()->setConsumer(this);
82  }
83 }
84 
85 void
87 {
89  uint32_t size = Network::getNumberOfVirtualNetworks();
90  for (uint32_t i = 0; i < size; i++) {
91  m_delayVCHistogram[i]->reset();
92  }
93 }
94 
95 void
97 {
99 
101  .name(name() + ".fully_busy_cycles")
102  .desc("cycles for which number of transistions == max transitions")
104 }
105 
106 void
107 AbstractController::profileMsgDelay(uint32_t virtualNetwork, Cycles delay)
108 {
109  assert(virtualNetwork < m_delayVCHistogram.size());
110  m_delayHistogram.sample(delay);
111  m_delayVCHistogram[virtualNetwork]->sample(delay);
112 }
113 
114 void
116 {
117  if (m_waiting_buffers.count(addr) == 0) {
118  MsgVecType* msgVec = new MsgVecType;
119  msgVec->resize(m_in_ports, NULL);
120  m_waiting_buffers[addr] = msgVec;
121  }
122  DPRINTF(RubyQueue, "stalling %s port %d addr %#x\n", buf, m_cur_in_port,
123  addr);
124  assert(m_in_ports > m_cur_in_port);
125  (*(m_waiting_buffers[addr]))[m_cur_in_port] = buf;
126 }
127 
128 void
130 {
131  if (m_waiting_buffers.count(addr) > 0) {
132  //
133  // Wake up all possible lower rank (i.e. lower priority) buffers that could
134  // be waiting on this message.
135  //
136  for (int in_port_rank = m_cur_in_port - 1;
137  in_port_rank >= 0;
138  in_port_rank--) {
139  if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) {
140  (*(m_waiting_buffers[addr]))[in_port_rank]->
141  reanalyzeMessages(addr, clockEdge());
142  }
143  }
144  delete m_waiting_buffers[addr];
145  m_waiting_buffers.erase(addr);
146  }
147 }
148 
149 void
151 {
152  if (m_waiting_buffers.count(addr) > 0) {
153  //
154  // Wake up all possible lower rank (i.e. lower priority) buffers that could
155  // be waiting on this message.
156  //
157  for (int in_port_rank = m_in_ports - 1;
158  in_port_rank >= 0;
159  in_port_rank--) {
160  if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) {
161  (*(m_waiting_buffers[addr]))[in_port_rank]->
162  reanalyzeMessages(addr, clockEdge());
163  }
164  }
165  delete m_waiting_buffers[addr];
166  m_waiting_buffers.erase(addr);
167  }
168 }
169 
170 void
172 {
173  //
174  // Wake up all possible buffers that could be waiting on any message.
175  //
176 
177  std::vector<MsgVecType*> wokeUpMsgVecs;
178  MsgBufType wokeUpMsgBufs;
179 
180  if (m_waiting_buffers.size() > 0) {
181  for (WaitingBufType::iterator buf_iter = m_waiting_buffers.begin();
182  buf_iter != m_waiting_buffers.end();
183  ++buf_iter) {
184  for (MsgVecType::iterator vec_iter = buf_iter->second->begin();
185  vec_iter != buf_iter->second->end();
186  ++vec_iter) {
187  //
188  // Make sure the MessageBuffer has not already be reanalyzed
189  //
190  if (*vec_iter != NULL &&
191  (wokeUpMsgBufs.count(*vec_iter) == 0)) {
192  (*vec_iter)->reanalyzeAllMessages(clockEdge());
193  wokeUpMsgBufs.insert(*vec_iter);
194  }
195  }
196  wokeUpMsgVecs.push_back(buf_iter->second);
197  }
198 
199  for (std::vector<MsgVecType*>::iterator wb_iter = wokeUpMsgVecs.begin();
200  wb_iter != wokeUpMsgVecs.end();
201  ++wb_iter) {
202  delete (*wb_iter);
203  }
204 
205  m_waiting_buffers.clear();
206  }
207 }
208 
209 bool
211 {
212  auto mem_queue = getMemReqQueue();
213  assert(mem_queue);
214  if (!mem_queue->isReady(clockEdge())) {
215  return false;
216  }
217 
218  const MemoryMsg *mem_msg = (const MemoryMsg*)mem_queue->peek();
219  unsigned int req_size = RubySystem::getBlockSizeBytes();
220  if (mem_msg->m_Len > 0) {
221  req_size = mem_msg->m_Len;
222  }
223 
224  RequestPtr req
225  = std::make_shared<Request>(mem_msg->m_addr, req_size, 0, m_masterId);
226  PacketPtr pkt;
227  if (mem_msg->getType() == MemoryRequestType_MEMORY_WB) {
228  pkt = Packet::createWrite(req);
229  pkt->allocate();
230  pkt->setData(mem_msg->m_DataBlk.getData(getOffset(mem_msg->m_addr),
231  req_size));
232  } else if (mem_msg->getType() == MemoryRequestType_MEMORY_READ) {
233  pkt = Packet::createRead(req);
234  uint8_t *newData = new uint8_t[req_size];
235  pkt->dataDynamic(newData);
236  } else {
237  panic("Unknown memory request type (%s) for addr %p",
238  MemoryRequestType_to_string(mem_msg->getType()),
239  mem_msg->m_addr);
240  }
241 
242  SenderState *s = new SenderState(mem_msg->m_Sender);
243  pkt->pushSenderState(s);
244 
246  // Use functional rather than timing accesses during warmup
247  mem_queue->dequeue(clockEdge());
249  // Since the queue was popped the controller may be able
250  // to make more progress. Make sure it wakes up
251  scheduleEvent(Cycles(1));
252  recvTimingResp(pkt);
253  } else {
254  mem_queue->dequeue(clockEdge());
256  // Since the queue was popped the controller may be able
257  // to make more progress. Make sure it wakes up
258  scheduleEvent(Cycles(1));
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  // Check the buffer from the controller to the memory.
310  if (memoryPort.trySatisfyFunctional(pkt)) {
311  num_functional_writes++;
312  }
313 
314  // Update memory itself.
316  return num_functional_writes + 1;
317 }
318 
319 void
321 {
322  assert(getMemRespQueue());
323  assert(pkt->isResponse());
324 
325  std::shared_ptr<MemoryMsg> msg = std::make_shared<MemoryMsg>(clockEdge());
326  (*msg).m_addr = pkt->getAddr();
327  (*msg).m_Sender = m_machineID;
328 
329  SenderState *s = dynamic_cast<SenderState *>(pkt->senderState);
330  (*msg).m_OriginalRequestorMachId = s->id;
331  delete s;
332 
333  if (pkt->isRead()) {
334  (*msg).m_Type = MemoryRequestType_MEMORY_READ;
335  (*msg).m_MessageSize = MessageSizeType_Response_Data;
336 
337  // Copy data from the packet
338  (*msg).m_DataBlk.setData(pkt->getPtr<uint8_t>(), 0,
340  } else if (pkt->isWrite()) {
341  (*msg).m_Type = MemoryRequestType_MEMORY_WB;
342  (*msg).m_MessageSize = MessageSizeType_Writeback_Control;
343  } else {
344  panic("Incorrect packet type received from memory controller!");
345  }
346 
348  delete pkt;
349 }
350 
351 Tick
353 {
354  return ticksToCycles(memoryPort.sendAtomic(pkt));
355 }
356 
357 MachineID
359 {
360  NodeID node = m_net_ptr->addressToNodeID(addr, mtype);
361  MachineID mach = {mtype, node};
362  return mach;
363 }
364 
365 bool
367 {
368  controller->recvTimingResp(pkt);
369  return true;
370 }
371 
373  AbstractController *_controller,
374  const std::string &_label)
375  : QueuedMasterPort(_name, _controller, reqQueue, snoopRespQueue),
376  reqQueue(*_controller, *this, _label),
377  snoopRespQueue(*_controller, *this, false, _label),
378  controller(_controller)
379 {
380 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
RubyTester::SenderState SenderState
Definition: Check.cc:37
#define DPRINTF(x,...)
Definition: trace.hh:225
Ports are used to interface objects to each other.
Definition: port.hh:56
bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the peer.
Tick recvAtomic(PacketPtr pkt)
WaitingBufType m_waiting_buffers
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:81
const std::string & name()
Definition: trace.cc:50
Bitfield< 7 > i
void recvTimingResp(PacketPtr pkt)
virtual void regStats()
Callback to set stat parameters.
void scheduleEvent(Cycles timeDelta)
Definition: Consumer.cc:34
AbstractController(const Params *p)
MachineID mapAddressToMachine(Addr addr, MachineType mtype) const
Map an address to the correct MachineID.
std::shared_ptr< Request > RequestPtr
Definition: request.hh:81
static uint32_t getNumberOfVirtualNetworks()
Definition: Network.hh:87
The QueuedMasterPort combines two queues, a request queue and a snoop response queue, that both share the same port.
Definition: qport.hh:106
ip6_addr_t addr
Definition: inet.hh:330
static PacketPtr createWrite(const RequestPtr &req)
Definition: packet.hh:913
std::map< Addr, MessageBuffer * > m_block_map
Histogram & init(size_type size)
Set the parameters of this histogram.
Definition: statistics.hh:2641
std::set< MessageBuffer * > MsgBufType
std::vector< MessageBuffer * > MsgVecType
bool isWrite() const
Definition: packet.hh:523
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:333
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1084
virtual MessageBuffer * getMemRespQueue() const =0
bool isRead() const
Definition: packet.hh:522
RubyControllerParams Params
static bool getWarmupEnabled()
Definition: RubySystem.hh:62
Tick cyclesToTicks(Cycles c) const
unsigned int NodeID
Definition: TypeDefines.hh:34
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
Bitfield< 4 > s
Callback class used for collating statistics from all the controller of this type.
virtual void resetStats()=0
Callback to reset stats.
uint64_t Tick
Tick count type.
Definition: types.hh:61
bool isResponse() const
Definition: packet.hh:526
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
std::vector< Stats::Histogram * > m_delayVCHistogram
void setConsumer(Consumer *consumer)
A simple histogram stat.
Definition: statistics.hh:2626
int functionalMemoryWrite(PacketPtr)
Addr getAddr() const
Definition: packet.hh:720
Addr getOffset(Addr addr)
Definition: Address.cc:48
bool trySatisfyFunctional(PacketPtr pkt)
Check the list of buffered packets against the supplied functional request.
Definition: qport.hh:160
void profileMsgDelay(uint32_t virtualNetwork, Cycles delay)
Profiles the delay associated with messages.
Stats::Scalar m_fully_busy_cycles
Counter for the number of cycles when the transitions carried out were equal to the maximum allowed...
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
static PacketPtr createRead(const RequestPtr &req)
Constructor-like methods that return Packets based on Request objects.
Definition: packet.hh:907
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
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...
void reset()
Reset stat value to default.
Definition: statistics.hh:1920
virtual MessageBuffer * getMemReqQueue() const =0
Bitfield< 15 > system
Definition: misc.hh:997
void registerDumpCallback(Callback *cb)
Register a callback that should be called whenever statistics are about to be dumped.
Definition: statistics.cc:589
void blockOnQueue(Addr, MessageBuffer *)
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:276
virtual const std::string name() const
Definition: sim_object.hh:129
Cycles ticksToCycles(Tick t) const
MemoryPort(const std::string &_name, AbstractController *_controller, const std::string &_label)
void schedTimingReq(PacketPtr pkt, Tick when)
Schedule the sending of a timing request.
Definition: qport.hh:146
void wakeUpBuffers(Addr addr)
SenderState * senderState
This packet&#39;s sender state.
Definition: packet.hh:474
NodeID addressToNodeID(Addr addr, MachineType mtype)
Map an address to the correct NodeID.
Definition: Network.cc:199
const Params * params() const
void stallBuffer(MessageBuffer *buf, Addr addr)
const MasterID m_masterId
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:435
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:309
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:235
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
void functionalMemoryRead(PacketPtr)
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:423
const FlagsType nozero
Don&#39;t print if this is zero.
Definition: info.hh:57
Bitfield< 0 > p
bool isBlocked(Addr) const
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:59
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
A function used to return the port associated with this bus object.
void enqueue(MsgPtr message, Tick curTime, Tick delta)
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:1896
Stats::Histogram m_delayHistogram
Histogram for profiling delay for the messages this controller cares for.

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