gem5  v20.1.0.0
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
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>(
111  m_address, 0, flags, m_tester_ptr->requestorId());
112  req->setPC(m_pc);
113  req->setContext(index);
114 
115  PacketPtr pkt = new Packet(req, cmd);
116  // despite the oddity of the 0 size (questionable if this should
117  // even be allowed), a prefetch is still a read and as such needs
118  // a place to store the result
119  uint8_t *data = new uint8_t[1];
120  pkt->dataDynamic(data);
121 
122  // push the subblock onto the sender state. The sequencer will
123  // update the subblock on the return
124  pkt->senderState = new SenderState(m_address, req->getSize());
125 
126  if (port->sendTimingReq(pkt)) {
127  DPRINTF(RubyTest, "successfully initiated prefetch.\n");
128  } else {
129  // If the packet did not issue, must delete
130  delete pkt->senderState;
131  delete pkt;
132 
133  DPRINTF(RubyTest,
134  "prefetch initiation failed because Port was busy.\n");
135  }
136 }
137 
138 void
140 {
141 
142  DPRINTF(RubyTest, "initiating Flush\n");
143 
144  int index = random_mt.random(0, m_num_writers - 1);
146 
147  Request::Flags flags;
148 
149  RequestPtr req = std::make_shared<Request>(
151  req->setPC(m_pc);
152 
153  Packet::Command cmd;
154 
155  cmd = MemCmd::FlushReq;
156 
157  PacketPtr pkt = new Packet(req, cmd);
158 
159  // push the subblock onto the sender state. The sequencer will
160  // update the subblock on the return
161  pkt->senderState = new SenderState(m_address, req->getSize());
162 
163  if (port->sendTimingReq(pkt)) {
164  DPRINTF(RubyTest, "initiating Flush - successful\n");
165  }
166 }
167 
168 void
170 {
171  DPRINTF(RubyTest, "initiating Action\n");
172  assert(m_status == TesterStatus_Idle);
173 
174  int index = random_mt.random(0, m_num_writers - 1);
176 
177  Request::Flags flags;
178 
179  // Create the particular address for the next byte to be written
180  Addr writeAddr(m_address + m_store_count);
181 
182  // Stores are assumed to be 1 byte-sized
183  RequestPtr req = std::make_shared<Request>(
184  writeAddr, 1, flags, m_tester_ptr->requestorId());
185  req->setPC(m_pc);
186 
187  req->setContext(index);
188  Packet::Command cmd;
189 
190  // 1 out of 8 chance, issue an atomic rather than a write
191  // if ((random() & 0x7) == 0) {
192  // cmd = MemCmd::SwapReq;
193  // } else {
194  cmd = MemCmd::WriteReq;
195  // }
196 
197  PacketPtr pkt = new Packet(req, cmd);
198  uint8_t *writeData = new uint8_t[1];
199  *writeData = m_value + m_store_count;
200  pkt->dataDynamic(writeData);
201 
202  DPRINTF(RubyTest, "Seq write: index %d data 0x%x check 0x%x\n", index,
203  *(pkt->getConstPtr<uint8_t>()), *writeData);
204 
205  // push the subblock onto the sender state. The sequencer will
206  // update the subblock on the return
207  pkt->senderState = new SenderState(writeAddr, req->getSize());
208 
209  if (port->sendTimingReq(pkt)) {
210  DPRINTF(RubyTest, "initiating action - successful\n");
211  DPRINTF(RubyTest, "status before action update: %s\n",
212  (TesterStatus_to_string(m_status)).c_str());
213  m_status = TesterStatus_Action_Pending;
214  DPRINTF(RubyTest, "Check %#x, State=Action_Pending\n", m_address);
215  } else {
216  // If the packet did not issue, must delete
217  // Note: No need to delete the data, the packet destructor
218  // will delete it
219  delete pkt->senderState;
220  delete pkt;
221 
222  DPRINTF(RubyTest, "failed to initiate action - sequencer not ready\n");
223  }
224 
225  DPRINTF(RubyTest, "status after action update: %s\n",
226  (TesterStatus_to_string(m_status)).c_str());
227 }
228 
229 void
231 {
232  DPRINTF(RubyTest, "Initiating Check\n");
233  assert(m_status == TesterStatus_Ready);
234 
235  int index = random_mt.random(0, m_num_readers - 1);
237 
238  Request::Flags flags;
239 
240  // If necessary, make the request an instruction fetch
243  (random_mt.random(0, 0x1)))) {
244  flags.set(Request::INST_FETCH);
245  }
246 
247  // Checks are sized depending on the number of bytes written
248  RequestPtr req = std::make_shared<Request>(
250  req->setPC(m_pc);
251 
252  req->setContext(index);
253  PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
254  uint8_t *dataArray = new uint8_t[CHECK_SIZE];
255  pkt->dataDynamic(dataArray);
256 
257  DPRINTF(RubyTest, "Seq read: index %d\n", index);
258 
259  // push the subblock onto the sender state. The sequencer will
260  // update the subblock on the return
261  pkt->senderState = new SenderState(m_address, req->getSize());
262 
263  if (port->sendTimingReq(pkt)) {
264  DPRINTF(RubyTest, "initiating check - successful\n");
265  DPRINTF(RubyTest, "status before check update: %s\n",
266  TesterStatus_to_string(m_status).c_str());
267  m_status = TesterStatus_Check_Pending;
268  DPRINTF(RubyTest, "Check %#x, State=Check_Pending\n", m_address);
269  } else {
270  // If the packet did not issue, must delete
271  // Note: No need to delete the data, the packet destructor
272  // will delete it
273  delete pkt->senderState;
274  delete pkt;
275 
276  DPRINTF(RubyTest, "failed to initiate check - cpu port not ready\n");
277  }
278 
279  DPRINTF(RubyTest, "status after check update: %s\n",
280  TesterStatus_to_string(m_status).c_str());
281 }
282 
283 void
285 {
286  Addr address = data->getAddress();
287 
288  // This isn't exactly right since we now have multi-byte checks
289  // assert(getAddress() == address);
290 
291  assert(makeLineAddress(m_address) == makeLineAddress(address));
292  assert(data != NULL);
293 
294  DPRINTF(RubyTest, "RubyTester Callback\n");
295  debugPrint();
296 
297  if (m_status == TesterStatus_Action_Pending) {
298  DPRINTF(RubyTest, "Action callback write value: %d, currently %d\n",
299  (m_value + m_store_count), data->getByte(0));
300  // Perform store one byte at a time
301  data->setByte(0, (m_value + m_store_count));
302  m_store_count++;
303  if (m_store_count == CHECK_SIZE) {
304  m_status = TesterStatus_Ready;
305  DPRINTF(RubyTest, "Check %#x, State=Ready\n", m_address);
306  } else {
307  m_status = TesterStatus_Idle;
308  DPRINTF(RubyTest, "Check %#x, State=Idle store_count: %d\n",
310  }
311  DPRINTF(RubyTest, "Action callback return data now %d\n",
312  data->getByte(0));
313  } else if (m_status == TesterStatus_Check_Pending) {
314  DPRINTF(RubyTest, "Check callback\n");
315  // Perform load/check
316  for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) {
317  if (uint8_t(m_value + byte_number) != data->getByte(byte_number)) {
318  panic("Action/check failure: proc: %d address: %#x data: %s "
319  "byte_number: %d m_value+byte_number: %d byte: %d %s"
320  "Time: %d\n",
321  proc, address, data, byte_number,
322  (int)m_value + byte_number,
323  (int)data->getByte(byte_number), *this, curTime);
324  }
325  }
326  DPRINTF(RubyTest, "Action/check success\n");
327  debugPrint();
328 
329  // successful check complete, increment complete
331 
332  m_status = TesterStatus_Idle;
333  DPRINTF(RubyTest, "Check %#x, State=Idle\n", m_address);
334  pickValue();
335 
336  } else {
337  panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s "
338  "time: %d\n", *this, proc, data, m_status, curTime);
339  }
340 
341  DPRINTF(RubyTest, "proc: %d, Address: 0x%x\n", proc,
343  DPRINTF(RubyTest, "Callback done\n");
344  debugPrint();
345 }
346 
347 void
349 {
350  assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
351  m_status = TesterStatus_Idle;
352  m_address = address;
353  DPRINTF(RubyTest, "Check %#x, State=Idle\n", m_address);
354  m_store_count = 0;
355 }
356 
357 void
359 {
360  assert(m_status == TesterStatus_Idle);
361  m_value = random_mt.random(0, 0xff); // One byte
362  m_store_count = 0;
363 }
364 
365 void
367 {
368  assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
369  m_status = TesterStatus_Idle;
371  DPRINTF(RubyTest, "Check %#x, State=Idle, picked initiating node %d\n",
373  m_store_count = 0;
374 }
375 
376 void
377 Check::print(std::ostream& out) const
378 {
379  out << "["
380  << m_address << ", value: "
381  << (int)m_value << ", status: "
382  << m_status << ", initiating node: "
383  << m_initiatingNode << ", store_count: "
384  << m_store_count
385  << "]" << std::flush;
386 }
387 
388 void
390 {
391  DPRINTF(RubyTest,
392  "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n",
393  m_address, (int)m_value, TesterStatus_to_string(m_status).c_str(),
395 }
Check::initiateCheck
void initiateCheck()
Definition: Check.cc:230
Check::m_store_count
int m_store_count
Definition: Check.hh:71
Check::pickInitiatingNode
void pickInitiatingNode()
Definition: Check.cc:366
Check::initiatePrefetch
void initiatePrefetch()
Definition: Check.cc:82
Check::initiate
void initiate()
Definition: Check.cc:56
Check::m_num_readers
int m_num_readers
Definition: Check.hh:77
data
const char data[]
Definition: circlebuf.test.cc:42
MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:44
makeLineAddress
Addr makeLineAddress(Addr addr)
Definition: Address.cc:54
RubyTester::requestorId
RequestorID requestorId()
Definition: RubyTester.hh:120
Flags< FlagsType >
RubyTester::incrementCheckCompletions
void incrementCheckCompletions()
Definition: RubyTester.hh:111
random.hh
MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:82
MemCmd::FlushReq
@ FlushReq
Definition: packet.hh:132
Check::performCallback
void performCallback(NodeID proc, SubBlock *data, Cycles curTime)
Definition: Check.cc:284
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
Check::m_value
uint8_t m_value
Definition: Check.hh:70
Packet::dataDynamic
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1145
Check::m_status
TesterStatus m_status
Definition: Check.hh:69
Check::m_pc
Addr m_pc
Definition: Check.hh:74
RubyTester::getWritableCpuPort
RequestPort * getWritableCpuPort(int idx)
Definition: RubyTester.cc:215
Request::INST_FETCH
@ INST_FETCH
The request was an instruction fetch.
Definition: request.hh:104
RubyTester::isInstDataCpuPort
bool isInstDataCpuPort(int idx)
Definition: RubyTester.cc:200
MemCmd::Command
Command
List of all commands associated with a packet.
Definition: packet.hh:79
Check.hh
MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:85
random_mt
Random random_mt
Definition: random.cc:96
Check::m_tester_ptr
RubyTester * m_tester_ptr
Definition: Check.hh:78
RubyTester::getReadableCpuPort
RequestPort * getReadableCpuPort(int idx)
Definition: RubyTester.cc:207
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
Check::m_initiatingNode
NodeID m_initiatingNode
Definition: Check.hh:72
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Request::PREFETCH
@ PREFETCH
The request is a prefetch.
Definition: request.hh:151
SenderState
RubyTester::SenderState SenderState
Definition: Check.cc:37
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
RubyTester::SenderState
Definition: RubyTester.hh:86
Check::initiateAction
void initiateAction()
Definition: Check.cc:169
Check::initiateFlush
void initiateFlush()
Definition: Check.cc:139
Flags::set
void set(Type flags)
Definition: flags.hh:87
Check::debugPrint
void debugPrint()
Definition: Check.cc:389
CHECK_SIZE
const int CHECK_SIZE
Definition: Check.hh:43
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
RubyTester::isInstOnlyCpuPort
bool isInstOnlyCpuPort(int idx)
Definition: RubyTester.cc:194
Check::print
void print(std::ostream &out) const
Definition: Check.cc:377
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Check::m_access_mode
RubyAccessMode m_access_mode
Definition: Check.hh:75
Check::Check
Check(Addr address, Addr pc, int _num_writers, int _num_readers, RubyTester *_tester)
Definition: Check.cc:39
Check::m_num_writers
int m_num_writers
Definition: Check.hh:76
SubBlock
Definition: SubBlock.hh:38
Request::PF_EXCLUSIVE
@ PF_EXCLUSIVE
The request should be prefetched into the exclusive state.
Definition: request.hh:153
Check::changeAddress
void changeAddress(Addr address)
Definition: Check.cc:348
Check::m_address
Addr m_address
Definition: Check.hh:73
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
RubyTester::getCheckFlush
bool getCheckFlush()
Definition: RubyTester.hh:118
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Random::random
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:86
Check::pickValue
void pickValue()
Definition: Check.cc:358
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
trace.hh
RubyTester
Definition: RubyTester.hh:57
Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:508
Packet::getConstPtr
const T * getConstPtr() const
Definition: packet.hh:1166
SubBlock.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

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