2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2009 Advanced Micro Devices, Inc.
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.
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.
30 #include "cpu/testers/rubytest/Check.hh"
31 #include "debug/RubyTest.hh"
32 #include "mem/ruby/common/SubBlock.hh"
33 #include "mem/ruby/system/Sequencer.hh"
34 #include "mem/ruby/system/System.hh"
36 typedef RubyTester::SenderState SenderState
;
38 Check::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
)
42 m_status
= TesterStatus_Idle
;
46 changeAddress(address
);
48 m_access_mode
= RubyAccessMode(random() % RubyAccessMode_NUM
);
55 DPRINTF(RubyTest
, "initiating\n");
58 // currently no protocols support prefetches
59 if (false && (random() & 0xf) == 0) {
60 initiatePrefetch(); // Prefetch from random processor
63 if (m_tester_ptr
->getCheckFlush() && (random() & 0xff) == 0) {
64 initiateFlush(); // issue a Flush request from random processor
67 if (m_status
== TesterStatus_Idle
) {
69 } else if (m_status
== TesterStatus_Ready
) {
72 // Pending - do nothing
74 "initiating action/check - failed: action/check is pending\n");
79 Check::initiatePrefetch()
81 DPRINTF(RubyTest
, "initiating prefetch\n");
83 int index
= random() % m_num_cpu_sequencers
;
84 RubyTester::CpuPort
* port
=
85 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getCpuPort(index
));
88 flags
.set(Request::PREFETCH
);
92 // 1 in 8 chance this will be an exclusive prefetch
93 if ((random() & 0x7) != 0) {
94 cmd
= MemCmd::ReadReq
;
96 // 50% chance that the request will be an instruction fetch
97 if ((random() & 0x1) == 0) {
98 flags
.set(Request::INST_FETCH
);
101 cmd
= MemCmd::WriteReq
;
102 flags
.set(Request::PF_EXCLUSIVE
);
105 // Prefetches are assumed to be 0 sized
106 Request
*req
= new Request(m_address
.getAddress(), 0, flags
, curTick(),
108 req
->setThreadContext(index
, 0);
110 PacketPtr pkt
= new Packet(req
, cmd
, port
->idx
);
112 // push the subblock onto the sender state. The sequencer will
113 // update the subblock on the return
115 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
117 if (port
->sendTiming(pkt
)) {
118 DPRINTF(RubyTest
, "successfully initiated prefetch.\n");
120 // If the packet did not issue, must delete
121 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
122 pkt
->senderState
= senderState
->saved
;
128 "prefetch initiation failed because Port was busy.\n");
133 Check::initiateFlush()
136 DPRINTF(RubyTest
, "initiating Flush\n");
138 int index
= random() % m_num_cpu_sequencers
;
139 RubyTester::CpuPort
* port
=
140 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getCpuPort(index
));
142 Request::Flags flags
;
144 Request
*req
= new Request(m_address
.getAddress(), CHECK_SIZE
, flags
, curTick(),
149 cmd
= MemCmd::FlushReq
;
151 PacketPtr pkt
= new Packet(req
, cmd
, port
->idx
);
153 // push the subblock onto the sender state. The sequencer will
154 // update the subblock on the return
156 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
158 if (port
->sendTiming(pkt
)) {
159 DPRINTF(RubyTest
, "initiating Flush - successful\n");
164 Check::initiateAction()
166 DPRINTF(RubyTest
, "initiating Action\n");
167 assert(m_status
== TesterStatus_Idle
);
169 int index
= random() % m_num_cpu_sequencers
;
170 RubyTester::CpuPort
* port
=
171 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getCpuPort(index
));
173 Request::Flags flags
;
175 // Create the particular address for the next byte to be written
176 Address
writeAddr(m_address
.getAddress() + m_store_count
);
178 // Stores are assumed to be 1 byte-sized
179 Request
*req
= new Request(writeAddr
.getAddress(), 1, flags
, curTick(),
182 req
->setThreadContext(index
, 0);
185 // 1 out of 8 chance, issue an atomic rather than a write
186 // if ((random() & 0x7) == 0) {
187 // cmd = MemCmd::SwapReq;
189 cmd
= MemCmd::WriteReq
;
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
);
197 DPRINTF(RubyTest
, "data 0x%x check 0x%x\n",
198 *(pkt
->getPtr
<uint8_t>()), *writeData
);
200 // push the subblock onto the sender state. The sequencer will
201 // update the subblock on the return
203 new SenderState(writeAddr
, req
->getSize(), pkt
->senderState
);
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
;
211 // If the packet did not issue, must delete
212 // Note: No need to delete the data, the packet destructor
214 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
215 pkt
->senderState
= senderState
->saved
;
220 DPRINTF(RubyTest
, "failed to initiate action - sequencer not ready\n");
223 DPRINTF(RubyTest
, "status after action update: %s\n",
224 (TesterStatus_to_string(m_status
)).c_str());
228 Check::initiateCheck()
230 DPRINTF(RubyTest
, "Initiating Check\n");
231 assert(m_status
== TesterStatus_Ready
);
233 int index
= random() % m_num_cpu_sequencers
;
234 RubyTester::CpuPort
* port
=
235 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getCpuPort(index
));
237 Request::Flags flags
;
239 // 50% chance that the request will be an instruction fetch
240 if ((random() & 0x1) == 0) {
241 flags
.set(Request::INST_FETCH
);
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());
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
);
253 // push the subblock onto the sender state. The sequencer will
254 // update the subblock on the return
256 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
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
;
264 // If the packet did not issue, must delete
265 // Note: No need to delete the data, the packet destructor
267 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
268 pkt
->senderState
= senderState
->saved
;
273 DPRINTF(RubyTest
, "failed to initiate check - cpu port not ready\n");
276 DPRINTF(RubyTest
, "status after check update: %s\n",
277 TesterStatus_to_string(m_status
).c_str());
281 Check::performCallback(NodeID proc
, SubBlock
* data
)
283 Address address
= data
->getAddress();
285 // This isn't exactly right since we now have multi-byte checks
286 // assert(getAddress() == address);
288 assert(getAddress().getLineAddress() == address
.getLineAddress());
289 assert(data
!= NULL
);
291 DPRINTF(RubyTest
, "RubyTester Callback\n");
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
));
300 if (m_store_count
== CHECK_SIZE
) {
301 m_status
= TesterStatus_Ready
;
303 m_status
= TesterStatus_Idle
;
305 DPRINTF(RubyTest
, "Action callback return data now %d\n",
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"
315 proc
, address
, data
, byte_number
,
316 (int)m_value
+ byte_number
,
317 (int)data
->getByte(byte_number
), *this,
318 g_eventQueue_ptr
->getTime());
321 DPRINTF(RubyTest
, "Action/check success\n");
324 // successful check complete, increment complete
325 m_tester_ptr
->incrementCheckCompletions();
327 m_status
= TesterStatus_Idle
;
331 panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s "
333 *this, proc
, data
, m_status
, g_eventQueue_ptr
->getTime());
336 DPRINTF(RubyTest
, "proc: %d, Address: 0x%x\n", proc
,
337 getAddress().getLineAddress());
338 DPRINTF(RubyTest
, "Callback done\n");
343 Check::changeAddress(const Address
& address
)
345 assert(m_status
== TesterStatus_Idle
|| m_status
== TesterStatus_Ready
);
346 m_status
= TesterStatus_Idle
;
354 assert(m_status
== TesterStatus_Idle
);
355 m_status
= TesterStatus_Idle
;
356 m_value
= random() & 0xff; // One byte
361 Check::pickInitiatingNode()
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
);
371 Check::print(std::ostream
& out
) const
374 << m_address
<< ", value: "
375 << (int)m_value
<< ", status: "
376 << m_status
<< ", initiating node: "
377 << m_initiatingNode
<< ", store_count: "
379 << "]" << std::flush
;
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
);