gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Check.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3  * Copyright (c) 2009 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
31 
32 #include "base/random.hh"
33 #include "base/trace.hh"
34 #include "debug/RubyTest.hh"
36 
38 
39 Check::Check(Addr address, Addr pc, int _num_writers, int _num_readers,
40  RubyTester* _tester)
41  : m_num_writers(_num_writers), m_num_readers(_num_readers),
42  m_tester_ptr(_tester)
43 {
44  m_status = TesterStatus_Idle;
45 
46  pickValue();
48  changeAddress(address);
49  m_pc = pc;
50  m_access_mode = RubyAccessMode(random_mt.random(0,
51  RubyAccessMode_NUM - 1));
52  m_store_count = 0;
53 }
54 
55 void
57 {
58  DPRINTF(RubyTest, "initiating\n");
59  debugPrint();
60 
61  // currently no protocols support prefetches
62  if (false && (random_mt.random(0, 0xf) == 0)) {
63  initiatePrefetch(); // Prefetch from random processor
64  }
65 
66  if (m_tester_ptr->getCheckFlush() && (random_mt.random(0, 0xff) == 0)) {
67  initiateFlush(); // issue a Flush request from random processor
68  }
69 
70  if (m_status == TesterStatus_Idle) {
72  } else if (m_status == TesterStatus_Ready) {
73  initiateCheck();
74  } else {
75  // Pending - do nothing
76  DPRINTF(RubyTest,
77  "initiating action/check - failed: action/check is pending\n");
78  }
79 }
80 
81 void
83 {
84  DPRINTF(RubyTest, "initiating prefetch\n");
85 
86  int index = random_mt.random(0, m_num_readers - 1);
88 
89  Request::Flags flags;
90  flags.set(Request::PREFETCH);
91 
92  Packet::Command cmd;
93 
94  // 1 in 8 chance this will be an exclusive prefetch
95  if (random_mt.random(0, 0x7) != 0) {
96  cmd = MemCmd::ReadReq;
97 
98  // if necessary, make the request an instruction fetch
99  if (m_tester_ptr->isInstOnlyCpuPort(index) ||
100  (m_tester_ptr->isInstDataCpuPort(index) &&
101  (random_mt.random(0, 0x1)))) {
102  flags.set(Request::INST_FETCH);
103  }
104  } else {
105  cmd = MemCmd::WriteReq;
106  flags.set(Request::PF_EXCLUSIVE);
107  }
108 
109  // Prefetches are assumed to be 0 sized
110  RequestPtr req = std::make_shared<Request>(m_address, 0, flags,
112  req->setContext(index);
113 
114  PacketPtr pkt = new Packet(req, cmd);
115  // despite the oddity of the 0 size (questionable if this should
116  // even be allowed), a prefetch is still a read and as such needs
117  // a place to store the result
118  uint8_t *data = new uint8_t[1];
119  pkt->dataDynamic(data);
120 
121  // push the subblock onto the sender state. The sequencer will
122  // update the subblock on the return
123  pkt->senderState = new SenderState(m_address, req->getSize());
124 
125  if (port->sendTimingReq(pkt)) {
126  DPRINTF(RubyTest, "successfully initiated prefetch.\n");
127  } else {
128  // If the packet did not issue, must delete
129  delete pkt->senderState;
130  delete pkt;
131 
132  DPRINTF(RubyTest,
133  "prefetch initiation failed because Port was busy.\n");
134  }
135 }
136 
137 void
139 {
140 
141  DPRINTF(RubyTest, "initiating Flush\n");
142 
143  int index = random_mt.random(0, m_num_writers - 1);
145 
146  Request::Flags flags;
147 
148  RequestPtr req = std::make_shared<Request>(m_address, CHECK_SIZE, flags,
150 
151  Packet::Command cmd;
152 
153  cmd = MemCmd::FlushReq;
154 
155  PacketPtr pkt = new Packet(req, cmd);
156 
157  // push the subblock onto the sender state. The sequencer will
158  // update the subblock on the return
159  pkt->senderState = new SenderState(m_address, req->getSize());
160 
161  if (port->sendTimingReq(pkt)) {
162  DPRINTF(RubyTest, "initiating Flush - successful\n");
163  }
164 }
165 
166 void
168 {
169  DPRINTF(RubyTest, "initiating Action\n");
170  assert(m_status == TesterStatus_Idle);
171 
172  int index = random_mt.random(0, m_num_writers - 1);
174 
175  Request::Flags flags;
176 
177  // Create the particular address for the next byte to be written
178  Addr writeAddr(m_address + m_store_count);
179 
180  // Stores are assumed to be 1 byte-sized
181  RequestPtr req = std::make_shared<Request>(
182  writeAddr, 1, flags, m_tester_ptr->masterId(), curTick(), m_pc);
183 
184  req->setContext(index);
185  Packet::Command cmd;
186 
187  // 1 out of 8 chance, issue an atomic rather than a write
188  // if ((random() & 0x7) == 0) {
189  // cmd = MemCmd::SwapReq;
190  // } else {
191  cmd = MemCmd::WriteReq;
192  // }
193 
194  PacketPtr pkt = new Packet(req, cmd);
195  uint8_t *writeData = new uint8_t[1];
196  *writeData = m_value + m_store_count;
197  pkt->dataDynamic(writeData);
198 
199  DPRINTF(RubyTest, "Seq write: index %d data 0x%x check 0x%x\n", index,
200  *(pkt->getConstPtr<uint8_t>()), *writeData);
201 
202  // push the subblock onto the sender state. The sequencer will
203  // update the subblock on the return
204  pkt->senderState = new SenderState(writeAddr, req->getSize());
205 
206  if (port->sendTimingReq(pkt)) {
207  DPRINTF(RubyTest, "initiating action - successful\n");
208  DPRINTF(RubyTest, "status before action update: %s\n",
209  (TesterStatus_to_string(m_status)).c_str());
210  m_status = TesterStatus_Action_Pending;
211  DPRINTF(RubyTest, "Check %#x, State=Action_Pending\n", m_address);
212  } else {
213  // If the packet did not issue, must delete
214  // Note: No need to delete the data, the packet destructor
215  // will delete it
216  delete pkt->senderState;
217  delete pkt;
218 
219  DPRINTF(RubyTest, "failed to initiate action - sequencer not ready\n");
220  }
221 
222  DPRINTF(RubyTest, "status after action update: %s\n",
223  (TesterStatus_to_string(m_status)).c_str());
224 }
225 
226 void
228 {
229  DPRINTF(RubyTest, "Initiating Check\n");
230  assert(m_status == TesterStatus_Ready);
231 
232  int index = random_mt.random(0, m_num_readers - 1);
234 
235  Request::Flags flags;
236 
237  // If necessary, make the request an instruction fetch
238  if (m_tester_ptr->isInstOnlyCpuPort(index) ||
239  (m_tester_ptr->isInstDataCpuPort(index) &&
240  (random_mt.random(0, 0x1)))) {
241  flags.set(Request::INST_FETCH);
242  }
243 
244  // Checks are sized depending on the number of bytes written
245  RequestPtr req = std::make_shared<Request>(m_address, CHECK_SIZE, flags,
247 
248  req->setContext(index);
249  PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
250  uint8_t *dataArray = new uint8_t[CHECK_SIZE];
251  pkt->dataDynamic(dataArray);
252 
253  DPRINTF(RubyTest, "Seq read: index %d\n", index);
254 
255  // push the subblock onto the sender state. The sequencer will
256  // update the subblock on the return
257  pkt->senderState = new SenderState(m_address, req->getSize());
258 
259  if (port->sendTimingReq(pkt)) {
260  DPRINTF(RubyTest, "initiating check - successful\n");
261  DPRINTF(RubyTest, "status before check update: %s\n",
262  TesterStatus_to_string(m_status).c_str());
263  m_status = TesterStatus_Check_Pending;
264  DPRINTF(RubyTest, "Check %#x, State=Check_Pending\n", m_address);
265  } else {
266  // If the packet did not issue, must delete
267  // Note: No need to delete the data, the packet destructor
268  // will delete it
269  delete pkt->senderState;
270  delete pkt;
271 
272  DPRINTF(RubyTest, "failed to initiate check - cpu port not ready\n");
273  }
274 
275  DPRINTF(RubyTest, "status after check update: %s\n",
276  TesterStatus_to_string(m_status).c_str());
277 }
278 
279 void
281 {
282  Addr address = data->getAddress();
283 
284  // This isn't exactly right since we now have multi-byte checks
285  // assert(getAddress() == address);
286 
287  assert(makeLineAddress(m_address) == makeLineAddress(address));
288  assert(data != NULL);
289 
290  DPRINTF(RubyTest, "RubyTester Callback\n");
291  debugPrint();
292 
293  if (m_status == TesterStatus_Action_Pending) {
294  DPRINTF(RubyTest, "Action callback write value: %d, currently %d\n",
295  (m_value + m_store_count), data->getByte(0));
296  // Perform store one byte at a time
297  data->setByte(0, (m_value + m_store_count));
298  m_store_count++;
299  if (m_store_count == CHECK_SIZE) {
300  m_status = TesterStatus_Ready;
301  DPRINTF(RubyTest, "Check %#x, State=Ready\n", m_address);
302  } else {
303  m_status = TesterStatus_Idle;
304  DPRINTF(RubyTest, "Check %#x, State=Idle store_count: %d\n",
306  }
307  DPRINTF(RubyTest, "Action callback return data now %d\n",
308  data->getByte(0));
309  } else if (m_status == TesterStatus_Check_Pending) {
310  DPRINTF(RubyTest, "Check callback\n");
311  // Perform load/check
312  for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) {
313  if (uint8_t(m_value + byte_number) != data->getByte(byte_number)) {
314  panic("Action/check failure: proc: %d address: %#x data: %s "
315  "byte_number: %d m_value+byte_number: %d byte: %d %s"
316  "Time: %d\n",
317  proc, address, data, byte_number,
318  (int)m_value + byte_number,
319  (int)data->getByte(byte_number), *this, curTime);
320  }
321  }
322  DPRINTF(RubyTest, "Action/check success\n");
323  debugPrint();
324 
325  // successful check complete, increment complete
327 
328  m_status = TesterStatus_Idle;
329  DPRINTF(RubyTest, "Check %#x, State=Idle\n", m_address);
330  pickValue();
331 
332  } else {
333  panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s "
334  "time: %d\n", *this, proc, data, m_status, curTime);
335  }
336 
337  DPRINTF(RubyTest, "proc: %d, Address: 0x%x\n", proc,
339  DPRINTF(RubyTest, "Callback done\n");
340  debugPrint();
341 }
342 
343 void
345 {
346  assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
347  m_status = TesterStatus_Idle;
348  m_address = address;
349  DPRINTF(RubyTest, "Check %#x, State=Idle\n", m_address);
350  m_store_count = 0;
351 }
352 
353 void
355 {
356  assert(m_status == TesterStatus_Idle);
357  m_value = random_mt.random(0, 0xff); // One byte
358  m_store_count = 0;
359 }
360 
361 void
363 {
364  assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
365  m_status = TesterStatus_Idle;
367  DPRINTF(RubyTest, "Check %#x, State=Idle, picked initiating node %d\n",
369  m_store_count = 0;
370 }
371 
372 void
373 Check::print(std::ostream& out) const
374 {
375  out << "["
376  << m_address << ", value: "
377  << (int)m_value << ", status: "
378  << m_status << ", initiating node: "
379  << m_initiatingNode << ", store_count: "
380  << m_store_count
381  << "]" << std::flush;
382 }
383 
384 void
386 {
387  DPRINTF(RubyTest,
388  "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n",
389  m_address, (int)m_value, TesterStatus_to_string(m_status).c_str(),
391 }
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
RubyTester::SenderState SenderState
Definition: Check.cc:37
#define DPRINTF(x,...)
Definition: trace.hh:229
void initiate()
Definition: Check.cc:56
int m_num_readers
Definition: Check.hh:77
Bitfield< 30, 0 > index
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
void pickInitiatingNode()
Definition: Check.cc:362
const int CHECK_SIZE
Definition: Check.hh:43
MasterPort * getReadableCpuPort(int idx)
Definition: RubyTester.cc:207
uint8_t getByte(int offset) const
Definition: SubBlock.hh:50
bool isInstOnlyCpuPort(int idx)
Definition: RubyTester.cc:194
Addr m_pc
Definition: Check.hh:74
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
void initiateCheck()
Definition: Check.cc:227
void performCallback(NodeID proc, SubBlock *data, Cycles curTime)
Definition: Check.cc:280
int m_store_count
Definition: Check.hh:71
void initiatePrefetch()
Definition: Check.cc:82
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the slave port by calling its corresponding receive function...
Definition: port.hh:445
RubyTester * m_tester_ptr
Definition: Check.hh:78
uint8_t m_value
Definition: Check.hh:70
NodeID m_initiatingNode
Definition: Check.hh:72
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:83
TesterStatus m_status
Definition: Check.hh:69
MasterID masterId()
Definition: RubyTester.hh:120
Addr getAddress() const
Definition: SubBlock.hh:45
unsigned int NodeID
Definition: TypeDefines.hh:34
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Bitfield< 4 > pc
bool isInstDataCpuPort(int idx)
Definition: RubyTester.cc:200
void initiateAction()
Definition: Check.cc:167
void initiateFlush()
Definition: Check.cc:138
void debugPrint()
Definition: Check.cc:385
The request is a prefetch.
Definition: request.hh:154
bool getCheckFlush()
Definition: RubyTester.hh:118
void print(std::ostream &out) const
Definition: Check.cc:373
RubyAccessMode m_access_mode
Definition: Check.hh:75
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
int m_num_writers
Definition: Check.hh:76
Addr m_address
Definition: Check.hh:73
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Addr makeLineAddress(Addr addr)
Definition: Address.cc:54
MasterPort * getWritableCpuPort(int idx)
Definition: RubyTester.cc:215
The request was an instruction fetch.
Definition: request.hh:105
void setByte(int offset, uint8_t data)
Definition: SubBlock.hh:51
SenderState * senderState
This packet&#39;s sender state.
Definition: packet.hh:480
Check(Addr address, Addr pc, int _num_writers, int _num_readers, RubyTester *_tester)
Definition: Check.cc:39
Random random_mt
Definition: random.cc:100
void changeAddress(Addr address)
Definition: Check.cc:344
const T * getConstPtr() const
Definition: packet.hh:1099
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1078
Command
List of all commands associated with a packet.
Definition: packet.hh:84
The request should be prefetched into the exclusive state.
Definition: request.hh:156
const char data[]
void set(Type flags)
Definition: flags.hh:70
void incrementCheckCompletions()
Definition: RubyTester.hh:111
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:104
void pickValue()
Definition: Check.cc:354

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