Check.cc (8190:8c68155aac00) Check.cc (8232:b28d06a175be)
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
30#include "cpu/testers/rubytest/Check.hh"
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
30#include "cpu/testers/rubytest/Check.hh"
31#include "debug/RubyTest.hh"
31#include "mem/ruby/common/SubBlock.hh"
32#include "mem/ruby/system/Sequencer.hh"
33#include "mem/ruby/system/System.hh"
34
35typedef RubyTester::SenderState SenderState;
36
37Check::Check(const Address& address, const Address& pc,
38 int _num_cpu_sequencers, RubyTester* _tester)
39 : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
40{
41 m_status = TesterStatus_Idle;
42
43 pickValue();
44 pickInitiatingNode();
45 changeAddress(address);
46 m_pc = pc;
47 m_access_mode = RubyAccessMode(random() % RubyAccessMode_NUM);
48 m_store_count = 0;
49}
50
51void
52Check::initiate()
53{
54 DPRINTF(RubyTest, "initiating\n");
55 debugPrint();
56
57 // currently no protocols support prefetches
58 if (false && (random() & 0xf) == 0) {
59 initiatePrefetch(); // Prefetch from random processor
60 }
61
62 if (m_tester_ptr->getCheckFlush() && (random() & 0xff) == 0) {
63 initiateFlush(); // issue a Flush request from random processor
64 }
65
66 if (m_status == TesterStatus_Idle) {
67 initiateAction();
68 } else if (m_status == TesterStatus_Ready) {
69 initiateCheck();
70 } else {
71 // Pending - do nothing
72 DPRINTF(RubyTest,
73 "initiating action/check - failed: action/check is pending\n");
74 }
75}
76
77void
78Check::initiatePrefetch()
79{
80 DPRINTF(RubyTest, "initiating prefetch\n");
81
82 int index = random() % m_num_cpu_sequencers;
83 RubyTester::CpuPort* port =
84 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
85
86 Request::Flags flags;
87 flags.set(Request::PREFETCH);
88
89 Packet::Command cmd;
90
91 // 1 in 8 chance this will be an exclusive prefetch
92 if ((random() & 0x7) != 0) {
93 cmd = MemCmd::ReadReq;
94
95 // 50% chance that the request will be an instruction fetch
96 if ((random() & 0x1) == 0) {
97 flags.set(Request::INST_FETCH);
98 }
99 } else {
100 cmd = MemCmd::WriteReq;
101 flags.set(Request::PF_EXCLUSIVE);
102 }
103
104 // Prefetches are assumed to be 0 sized
105 Request *req = new Request(m_address.getAddress(), 0, flags, curTick(),
106 m_pc.getAddress());
107 req->setThreadContext(index, 0);
108
109 PacketPtr pkt = new Packet(req, cmd, port->idx);
110
111 // push the subblock onto the sender state. The sequencer will
112 // update the subblock on the return
113 pkt->senderState =
114 new SenderState(m_address, req->getSize(), pkt->senderState);
115
116 if (port->sendTiming(pkt)) {
117 DPRINTF(RubyTest, "successfully initiated prefetch.\n");
118 } else {
119 // If the packet did not issue, must delete
120 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState);
121 pkt->senderState = senderState->saved;
122 delete senderState;
123 delete pkt->req;
124 delete pkt;
125
126 DPRINTF(RubyTest,
127 "prefetch initiation failed because Port was busy.\n");
128 }
129}
130
131void
132Check::initiateFlush()
133{
134
135 DPRINTF(RubyTest, "initiating Flush\n");
136
137 int index = random() % m_num_cpu_sequencers;
138 RubyTester::CpuPort* port =
139 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
140
141 Request::Flags flags;
142
143 Request *req = new Request(m_address.getAddress(), CHECK_SIZE, flags, curTick(),
144 m_pc.getAddress());
145
146 Packet::Command cmd;
147
148 cmd = MemCmd::FlushReq;
149
150 PacketPtr pkt = new Packet(req, cmd, port->idx);
151
152 // push the subblock onto the sender state. The sequencer will
153 // update the subblock on the return
154 pkt->senderState =
155 new SenderState(m_address, req->getSize(), pkt->senderState);
156
157 if (port->sendTiming(pkt)) {
158 DPRINTF(RubyTest, "initiating Flush - successful\n");
159 }
160}
161
162void
163Check::initiateAction()
164{
165 DPRINTF(RubyTest, "initiating Action\n");
166 assert(m_status == TesterStatus_Idle);
167
168 int index = random() % m_num_cpu_sequencers;
169 RubyTester::CpuPort* port =
170 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
171
172 Request::Flags flags;
173
174 // Create the particular address for the next byte to be written
175 Address writeAddr(m_address.getAddress() + m_store_count);
176
177 // Stores are assumed to be 1 byte-sized
178 Request *req = new Request(writeAddr.getAddress(), 1, flags, curTick(),
179 m_pc.getAddress());
180
181 req->setThreadContext(index, 0);
182 Packet::Command cmd;
183
184 // 1 out of 8 chance, issue an atomic rather than a write
185 // if ((random() & 0x7) == 0) {
186 // cmd = MemCmd::SwapReq;
187 // } else {
188 cmd = MemCmd::WriteReq;
189 // }
190
191 PacketPtr pkt = new Packet(req, cmd, port->idx);
192 uint8_t* writeData = new uint8_t;
193 *writeData = m_value + m_store_count;
194 pkt->dataDynamic(writeData);
195
196 DPRINTF(RubyTest, "data 0x%x check 0x%x\n",
197 *(pkt->getPtr<uint8_t>()), *writeData);
198
199 // push the subblock onto the sender state. The sequencer will
200 // update the subblock on the return
201 pkt->senderState =
202 new SenderState(writeAddr, req->getSize(), pkt->senderState);
203
204 if (port->sendTiming(pkt)) {
205 DPRINTF(RubyTest, "initiating action - successful\n");
206 DPRINTF(RubyTest, "status before action update: %s\n",
207 (TesterStatus_to_string(m_status)).c_str());
208 m_status = TesterStatus_Action_Pending;
209 } else {
210 // If the packet did not issue, must delete
211 // Note: No need to delete the data, the packet destructor
212 // will delete it
213 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState);
214 pkt->senderState = senderState->saved;
215 delete senderState;
216 delete pkt->req;
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
226void
227Check::initiateCheck()
228{
229 DPRINTF(RubyTest, "Initiating Check\n");
230 assert(m_status == TesterStatus_Ready);
231
232 int index = random() % m_num_cpu_sequencers;
233 RubyTester::CpuPort* port =
234 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
235
236 Request::Flags flags;
237
238 // 50% chance that the request will be an instruction fetch
239 if ((random() & 0x1) == 0) {
240 flags.set(Request::INST_FETCH);
241 }
242
243 // Checks are sized depending on the number of bytes written
244 Request *req = new Request(m_address.getAddress(), CHECK_SIZE, flags,
245 curTick(), m_pc.getAddress());
246
247 req->setThreadContext(index, 0);
248 PacketPtr pkt = new Packet(req, MemCmd::ReadReq, port->idx);
249 uint8_t* dataArray = new uint8_t[CHECK_SIZE];
250 pkt->dataDynamicArray(dataArray);
251
252 // push the subblock onto the sender state. The sequencer will
253 // update the subblock on the return
254 pkt->senderState =
255 new SenderState(m_address, req->getSize(), pkt->senderState);
256
257 if (port->sendTiming(pkt)) {
258 DPRINTF(RubyTest, "initiating check - successful\n");
259 DPRINTF(RubyTest, "status before check update: %s\n",
260 TesterStatus_to_string(m_status).c_str());
261 m_status = TesterStatus_Check_Pending;
262 } else {
263 // If the packet did not issue, must delete
264 // Note: No need to delete the data, the packet destructor
265 // will delete it
266 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState);
267 pkt->senderState = senderState->saved;
268 delete senderState;
269 delete pkt->req;
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
279void
280Check::performCallback(NodeID proc, SubBlock* data)
281{
282 Address address = data->getAddress();
283
284 // This isn't exactly right since we now have multi-byte checks
285 // assert(getAddress() == address);
286
287 assert(getAddress().getLineAddress() == address.getLineAddress());
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 } else {
302 m_status = TesterStatus_Idle;
303 }
304 DPRINTF(RubyTest, "Action callback return data now %d\n",
305 data->getByte(0));
306 } else if (m_status == TesterStatus_Check_Pending) {
307 DPRINTF(RubyTest, "Check callback\n");
308 // Perform load/check
309 for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) {
310 if (uint8(m_value + byte_number) != data->getByte(byte_number)) {
311 panic("Action/check failure: proc: %d address: %s data: %s "
312 "byte_number: %d m_value+byte_number: %d byte: %d %s"
313 "Time: %d\n",
314 proc, address, data, byte_number,
315 (int)m_value + byte_number,
316 (int)data->getByte(byte_number), *this,
317 g_eventQueue_ptr->getTime());
318 }
319 }
320 DPRINTF(RubyTest, "Action/check success\n");
321 debugPrint();
322
323 // successful check complete, increment complete
324 m_tester_ptr->incrementCheckCompletions();
325
326 m_status = TesterStatus_Idle;
327 pickValue();
328
329 } else {
330 panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s "
331 "time: %d\n",
332 *this, proc, data, m_status, g_eventQueue_ptr->getTime());
333 }
334
335 DPRINTF(RubyTest, "proc: %d, Address: 0x%x\n", proc,
336 getAddress().getLineAddress());
337 DPRINTF(RubyTest, "Callback done\n");
338 debugPrint();
339}
340
341void
342Check::changeAddress(const Address& address)
343{
344 assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
345 m_status = TesterStatus_Idle;
346 m_address = address;
347 m_store_count = 0;
348}
349
350void
351Check::pickValue()
352{
353 assert(m_status == TesterStatus_Idle);
354 m_status = TesterStatus_Idle;
355 m_value = random() & 0xff; // One byte
356 m_store_count = 0;
357}
358
359void
360Check::pickInitiatingNode()
361{
362 assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
363 m_status = TesterStatus_Idle;
364 m_initiatingNode = (random() % m_num_cpu_sequencers);
365 DPRINTF(RubyTest, "picked initiating node %d\n", m_initiatingNode);
366 m_store_count = 0;
367}
368
369void
370Check::print(std::ostream& out) const
371{
372 out << "["
373 << m_address << ", value: "
374 << (int)m_value << ", status: "
375 << m_status << ", initiating node: "
376 << m_initiatingNode << ", store_count: "
377 << m_store_count
378 << "]" << std::flush;
379}
380
381void
382Check::debugPrint()
383{
384 DPRINTF(RubyTest,
385 "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n",
386 m_address.getAddress(), (int)m_value,
387 TesterStatus_to_string(m_status).c_str(),
388 m_initiatingNode, m_store_count);
389}
32#include "mem/ruby/common/SubBlock.hh"
33#include "mem/ruby/system/Sequencer.hh"
34#include "mem/ruby/system/System.hh"
35
36typedef RubyTester::SenderState SenderState;
37
38Check::Check(const Address& address, const Address& pc,
39 int _num_cpu_sequencers, RubyTester* _tester)
40 : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester)
41{
42 m_status = TesterStatus_Idle;
43
44 pickValue();
45 pickInitiatingNode();
46 changeAddress(address);
47 m_pc = pc;
48 m_access_mode = RubyAccessMode(random() % RubyAccessMode_NUM);
49 m_store_count = 0;
50}
51
52void
53Check::initiate()
54{
55 DPRINTF(RubyTest, "initiating\n");
56 debugPrint();
57
58 // currently no protocols support prefetches
59 if (false && (random() & 0xf) == 0) {
60 initiatePrefetch(); // Prefetch from random processor
61 }
62
63 if (m_tester_ptr->getCheckFlush() && (random() & 0xff) == 0) {
64 initiateFlush(); // issue a Flush request from random processor
65 }
66
67 if (m_status == TesterStatus_Idle) {
68 initiateAction();
69 } else if (m_status == TesterStatus_Ready) {
70 initiateCheck();
71 } else {
72 // Pending - do nothing
73 DPRINTF(RubyTest,
74 "initiating action/check - failed: action/check is pending\n");
75 }
76}
77
78void
79Check::initiatePrefetch()
80{
81 DPRINTF(RubyTest, "initiating prefetch\n");
82
83 int index = random() % m_num_cpu_sequencers;
84 RubyTester::CpuPort* port =
85 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
86
87 Request::Flags flags;
88 flags.set(Request::PREFETCH);
89
90 Packet::Command cmd;
91
92 // 1 in 8 chance this will be an exclusive prefetch
93 if ((random() & 0x7) != 0) {
94 cmd = MemCmd::ReadReq;
95
96 // 50% chance that the request will be an instruction fetch
97 if ((random() & 0x1) == 0) {
98 flags.set(Request::INST_FETCH);
99 }
100 } else {
101 cmd = MemCmd::WriteReq;
102 flags.set(Request::PF_EXCLUSIVE);
103 }
104
105 // Prefetches are assumed to be 0 sized
106 Request *req = new Request(m_address.getAddress(), 0, flags, curTick(),
107 m_pc.getAddress());
108 req->setThreadContext(index, 0);
109
110 PacketPtr pkt = new Packet(req, cmd, port->idx);
111
112 // push the subblock onto the sender state. The sequencer will
113 // update the subblock on the return
114 pkt->senderState =
115 new SenderState(m_address, req->getSize(), pkt->senderState);
116
117 if (port->sendTiming(pkt)) {
118 DPRINTF(RubyTest, "successfully initiated prefetch.\n");
119 } else {
120 // If the packet did not issue, must delete
121 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState);
122 pkt->senderState = senderState->saved;
123 delete senderState;
124 delete pkt->req;
125 delete pkt;
126
127 DPRINTF(RubyTest,
128 "prefetch initiation failed because Port was busy.\n");
129 }
130}
131
132void
133Check::initiateFlush()
134{
135
136 DPRINTF(RubyTest, "initiating Flush\n");
137
138 int index = random() % m_num_cpu_sequencers;
139 RubyTester::CpuPort* port =
140 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
141
142 Request::Flags flags;
143
144 Request *req = new Request(m_address.getAddress(), CHECK_SIZE, flags, curTick(),
145 m_pc.getAddress());
146
147 Packet::Command cmd;
148
149 cmd = MemCmd::FlushReq;
150
151 PacketPtr pkt = new Packet(req, cmd, port->idx);
152
153 // push the subblock onto the sender state. The sequencer will
154 // update the subblock on the return
155 pkt->senderState =
156 new SenderState(m_address, req->getSize(), pkt->senderState);
157
158 if (port->sendTiming(pkt)) {
159 DPRINTF(RubyTest, "initiating Flush - successful\n");
160 }
161}
162
163void
164Check::initiateAction()
165{
166 DPRINTF(RubyTest, "initiating Action\n");
167 assert(m_status == TesterStatus_Idle);
168
169 int index = random() % m_num_cpu_sequencers;
170 RubyTester::CpuPort* port =
171 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
172
173 Request::Flags flags;
174
175 // Create the particular address for the next byte to be written
176 Address writeAddr(m_address.getAddress() + m_store_count);
177
178 // Stores are assumed to be 1 byte-sized
179 Request *req = new Request(writeAddr.getAddress(), 1, flags, curTick(),
180 m_pc.getAddress());
181
182 req->setThreadContext(index, 0);
183 Packet::Command cmd;
184
185 // 1 out of 8 chance, issue an atomic rather than a write
186 // if ((random() & 0x7) == 0) {
187 // cmd = MemCmd::SwapReq;
188 // } else {
189 cmd = MemCmd::WriteReq;
190 // }
191
192 PacketPtr pkt = new Packet(req, cmd, port->idx);
193 uint8_t* writeData = new uint8_t;
194 *writeData = m_value + m_store_count;
195 pkt->dataDynamic(writeData);
196
197 DPRINTF(RubyTest, "data 0x%x check 0x%x\n",
198 *(pkt->getPtr<uint8_t>()), *writeData);
199
200 // push the subblock onto the sender state. The sequencer will
201 // update the subblock on the return
202 pkt->senderState =
203 new SenderState(writeAddr, req->getSize(), pkt->senderState);
204
205 if (port->sendTiming(pkt)) {
206 DPRINTF(RubyTest, "initiating action - successful\n");
207 DPRINTF(RubyTest, "status before action update: %s\n",
208 (TesterStatus_to_string(m_status)).c_str());
209 m_status = TesterStatus_Action_Pending;
210 } else {
211 // If the packet did not issue, must delete
212 // Note: No need to delete the data, the packet destructor
213 // will delete it
214 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState);
215 pkt->senderState = senderState->saved;
216 delete senderState;
217 delete pkt->req;
218 delete pkt;
219
220 DPRINTF(RubyTest, "failed to initiate action - sequencer not ready\n");
221 }
222
223 DPRINTF(RubyTest, "status after action update: %s\n",
224 (TesterStatus_to_string(m_status)).c_str());
225}
226
227void
228Check::initiateCheck()
229{
230 DPRINTF(RubyTest, "Initiating Check\n");
231 assert(m_status == TesterStatus_Ready);
232
233 int index = random() % m_num_cpu_sequencers;
234 RubyTester::CpuPort* port =
235 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index));
236
237 Request::Flags flags;
238
239 // 50% chance that the request will be an instruction fetch
240 if ((random() & 0x1) == 0) {
241 flags.set(Request::INST_FETCH);
242 }
243
244 // Checks are sized depending on the number of bytes written
245 Request *req = new Request(m_address.getAddress(), CHECK_SIZE, flags,
246 curTick(), m_pc.getAddress());
247
248 req->setThreadContext(index, 0);
249 PacketPtr pkt = new Packet(req, MemCmd::ReadReq, port->idx);
250 uint8_t* dataArray = new uint8_t[CHECK_SIZE];
251 pkt->dataDynamicArray(dataArray);
252
253 // push the subblock onto the sender state. The sequencer will
254 // update the subblock on the return
255 pkt->senderState =
256 new SenderState(m_address, req->getSize(), pkt->senderState);
257
258 if (port->sendTiming(pkt)) {
259 DPRINTF(RubyTest, "initiating check - successful\n");
260 DPRINTF(RubyTest, "status before check update: %s\n",
261 TesterStatus_to_string(m_status).c_str());
262 m_status = TesterStatus_Check_Pending;
263 } else {
264 // If the packet did not issue, must delete
265 // Note: No need to delete the data, the packet destructor
266 // will delete it
267 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState);
268 pkt->senderState = senderState->saved;
269 delete senderState;
270 delete pkt->req;
271 delete pkt;
272
273 DPRINTF(RubyTest, "failed to initiate check - cpu port not ready\n");
274 }
275
276 DPRINTF(RubyTest, "status after check update: %s\n",
277 TesterStatus_to_string(m_status).c_str());
278}
279
280void
281Check::performCallback(NodeID proc, SubBlock* data)
282{
283 Address address = data->getAddress();
284
285 // This isn't exactly right since we now have multi-byte checks
286 // assert(getAddress() == address);
287
288 assert(getAddress().getLineAddress() == address.getLineAddress());
289 assert(data != NULL);
290
291 DPRINTF(RubyTest, "RubyTester Callback\n");
292 debugPrint();
293
294 if (m_status == TesterStatus_Action_Pending) {
295 DPRINTF(RubyTest, "Action callback write value: %d, currently %d\n",
296 (m_value + m_store_count), data->getByte(0));
297 // Perform store one byte at a time
298 data->setByte(0, (m_value + m_store_count));
299 m_store_count++;
300 if (m_store_count == CHECK_SIZE) {
301 m_status = TesterStatus_Ready;
302 } else {
303 m_status = TesterStatus_Idle;
304 }
305 DPRINTF(RubyTest, "Action callback return data now %d\n",
306 data->getByte(0));
307 } else if (m_status == TesterStatus_Check_Pending) {
308 DPRINTF(RubyTest, "Check callback\n");
309 // Perform load/check
310 for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) {
311 if (uint8(m_value + byte_number) != data->getByte(byte_number)) {
312 panic("Action/check failure: proc: %d address: %s data: %s "
313 "byte_number: %d m_value+byte_number: %d byte: %d %s"
314 "Time: %d\n",
315 proc, address, data, byte_number,
316 (int)m_value + byte_number,
317 (int)data->getByte(byte_number), *this,
318 g_eventQueue_ptr->getTime());
319 }
320 }
321 DPRINTF(RubyTest, "Action/check success\n");
322 debugPrint();
323
324 // successful check complete, increment complete
325 m_tester_ptr->incrementCheckCompletions();
326
327 m_status = TesterStatus_Idle;
328 pickValue();
329
330 } else {
331 panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s "
332 "time: %d\n",
333 *this, proc, data, m_status, g_eventQueue_ptr->getTime());
334 }
335
336 DPRINTF(RubyTest, "proc: %d, Address: 0x%x\n", proc,
337 getAddress().getLineAddress());
338 DPRINTF(RubyTest, "Callback done\n");
339 debugPrint();
340}
341
342void
343Check::changeAddress(const Address& address)
344{
345 assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
346 m_status = TesterStatus_Idle;
347 m_address = address;
348 m_store_count = 0;
349}
350
351void
352Check::pickValue()
353{
354 assert(m_status == TesterStatus_Idle);
355 m_status = TesterStatus_Idle;
356 m_value = random() & 0xff; // One byte
357 m_store_count = 0;
358}
359
360void
361Check::pickInitiatingNode()
362{
363 assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready);
364 m_status = TesterStatus_Idle;
365 m_initiatingNode = (random() % m_num_cpu_sequencers);
366 DPRINTF(RubyTest, "picked initiating node %d\n", m_initiatingNode);
367 m_store_count = 0;
368}
369
370void
371Check::print(std::ostream& out) const
372{
373 out << "["
374 << m_address << ", value: "
375 << (int)m_value << ", status: "
376 << m_status << ", initiating node: "
377 << m_initiatingNode << ", store_count: "
378 << m_store_count
379 << "]" << std::flush;
380}
381
382void
383Check::debugPrint()
384{
385 DPRINTF(RubyTest,
386 "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n",
387 m_address.getAddress(), (int)m_value,
388 TesterStatus_to_string(m_status).c_str(),
389 m_initiatingNode, m_store_count);
390}