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_writers
, int _num_readers
, RubyTester
* _tester
)
40 : m_num_writers(_num_writers
), m_num_readers(_num_readers
),
43 m_status
= TesterStatus_Idle
;
47 changeAddress(address
);
49 m_access_mode
= RubyAccessMode(random() % RubyAccessMode_NUM
);
56 DPRINTF(RubyTest
, "initiating\n");
59 // currently no protocols support prefetches
60 if (false && (random() & 0xf) == 0) {
61 initiatePrefetch(); // Prefetch from random processor
64 if (m_tester_ptr
->getCheckFlush() && (random() & 0xff) == 0) {
65 initiateFlush(); // issue a Flush request from random processor
68 if (m_status
== TesterStatus_Idle
) {
70 } else if (m_status
== TesterStatus_Ready
) {
73 // Pending - do nothing
75 "initiating action/check - failed: action/check is pending\n");
80 Check::initiatePrefetch()
82 DPRINTF(RubyTest
, "initiating prefetch\n");
84 int index
= random() % m_num_readers
;
85 RubyTester::CpuPort
* port
=
86 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getReadableCpuPort(index
));
89 flags
.set(Request::PREFETCH
);
93 // 1 in 8 chance this will be an exclusive prefetch
94 if ((random() & 0x7) != 0) {
95 cmd
= MemCmd::ReadReq
;
97 // if necessary, make the request an instruction fetch
98 if (port
->type
== RubyTester::CpuPort::InstOnly
) {
99 flags
.set(Request::INST_FETCH
);
102 cmd
= MemCmd::WriteReq
;
103 flags
.set(Request::PF_EXCLUSIVE
);
106 // Prefetches are assumed to be 0 sized
107 Request
*req
= new Request(m_address
.getAddress(), 0, flags
,
108 m_tester_ptr
->masterId(), curTick(), m_pc
.getAddress());
109 req
->setThreadContext(index
, 0);
111 PacketPtr pkt
= new Packet(req
, cmd
, port
->idx
);
113 // push the subblock onto the sender state. The sequencer will
114 // update the subblock on the return
116 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
118 if (port
->sendTiming(pkt
)) {
119 DPRINTF(RubyTest
, "successfully initiated prefetch.\n");
121 // If the packet did not issue, must delete
122 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
123 pkt
->senderState
= senderState
->saved
;
129 "prefetch initiation failed because Port was busy.\n");
134 Check::initiateFlush()
137 DPRINTF(RubyTest
, "initiating Flush\n");
139 int index
= random() % m_num_writers
;
140 RubyTester::CpuPort
* port
=
141 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getWritableCpuPort(index
));
143 Request::Flags flags
;
145 Request
*req
= new Request(m_address
.getAddress(), CHECK_SIZE
, flags
,
146 m_tester_ptr
->masterId(), curTick(), m_pc
.getAddress());
150 cmd
= MemCmd::FlushReq
;
152 PacketPtr pkt
= new Packet(req
, cmd
, port
->idx
);
154 // push the subblock onto the sender state. The sequencer will
155 // update the subblock on the return
157 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
159 if (port
->sendTiming(pkt
)) {
160 DPRINTF(RubyTest
, "initiating Flush - successful\n");
165 Check::initiateAction()
167 DPRINTF(RubyTest
, "initiating Action\n");
168 assert(m_status
== TesterStatus_Idle
);
170 int index
= random() % m_num_writers
;
171 RubyTester::CpuPort
* port
=
172 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getWritableCpuPort(index
));
174 Request::Flags flags
;
176 // Create the particular address for the next byte to be written
177 Address
writeAddr(m_address
.getAddress() + m_store_count
);
179 // Stores are assumed to be 1 byte-sized
180 Request
*req
= new Request(writeAddr
.getAddress(), 1, flags
,
181 m_tester_ptr
->masterId(), curTick(),
184 req
->setThreadContext(index
, 0);
187 // 1 out of 8 chance, issue an atomic rather than a write
188 // if ((random() & 0x7) == 0) {
189 // cmd = MemCmd::SwapReq;
191 cmd
= MemCmd::WriteReq
;
194 PacketPtr pkt
= new Packet(req
, cmd
, port
->idx
);
195 uint8_t* writeData
= new uint8_t;
196 *writeData
= m_value
+ m_store_count
;
197 pkt
->dataDynamic(writeData
);
199 DPRINTF(RubyTest
, "data 0x%x check 0x%x\n",
200 *(pkt
->getPtr
<uint8_t>()), *writeData
);
202 // push the subblock onto the sender state. The sequencer will
203 // update the subblock on the return
205 new SenderState(writeAddr
, req
->getSize(), pkt
->senderState
);
207 if (port
->sendTiming(pkt
)) {
208 DPRINTF(RubyTest
, "initiating action - successful\n");
209 DPRINTF(RubyTest
, "status before action update: %s\n",
210 (TesterStatus_to_string(m_status
)).c_str());
211 m_status
= TesterStatus_Action_Pending
;
213 // If the packet did not issue, must delete
214 // Note: No need to delete the data, the packet destructor
216 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
217 pkt
->senderState
= senderState
->saved
;
222 DPRINTF(RubyTest
, "failed to initiate action - sequencer not ready\n");
225 DPRINTF(RubyTest
, "status after action update: %s\n",
226 (TesterStatus_to_string(m_status
)).c_str());
230 Check::initiateCheck()
232 DPRINTF(RubyTest
, "Initiating Check\n");
233 assert(m_status
== TesterStatus_Ready
);
235 int index
= random() % m_num_readers
;
236 RubyTester::CpuPort
* port
=
237 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getReadableCpuPort(index
));
239 Request::Flags flags
;
241 // If necessary, make the request an instruction fetch
242 if (port
->type
== RubyTester::CpuPort::InstOnly
) {
243 flags
.set(Request::INST_FETCH
);
246 // Checks are sized depending on the number of bytes written
247 Request
*req
= new Request(m_address
.getAddress(), CHECK_SIZE
, flags
,
248 m_tester_ptr
->masterId(), curTick(), m_pc
.getAddress());
250 req
->setThreadContext(index
, 0);
251 PacketPtr pkt
= new Packet(req
, MemCmd::ReadReq
, port
->idx
);
252 uint8_t* dataArray
= new uint8_t[CHECK_SIZE
];
253 pkt
->dataDynamicArray(dataArray
);
255 // push the subblock onto the sender state. The sequencer will
256 // update the subblock on the return
258 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
260 if (port
->sendTiming(pkt
)) {
261 DPRINTF(RubyTest
, "initiating check - successful\n");
262 DPRINTF(RubyTest
, "status before check update: %s\n",
263 TesterStatus_to_string(m_status
).c_str());
264 m_status
= TesterStatus_Check_Pending
;
266 // If the packet did not issue, must delete
267 // Note: No need to delete the data, the packet destructor
269 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
270 pkt
->senderState
= senderState
->saved
;
275 DPRINTF(RubyTest
, "failed to initiate check - cpu port not ready\n");
278 DPRINTF(RubyTest
, "status after check update: %s\n",
279 TesterStatus_to_string(m_status
).c_str());
283 Check::performCallback(NodeID proc
, SubBlock
* data
)
285 Address address
= data
->getAddress();
287 // This isn't exactly right since we now have multi-byte checks
288 // assert(getAddress() == address);
290 assert(getAddress().getLineAddress() == address
.getLineAddress());
291 assert(data
!= NULL
);
293 DPRINTF(RubyTest
, "RubyTester Callback\n");
296 if (m_status
== TesterStatus_Action_Pending
) {
297 DPRINTF(RubyTest
, "Action callback write value: %d, currently %d\n",
298 (m_value
+ m_store_count
), data
->getByte(0));
299 // Perform store one byte at a time
300 data
->setByte(0, (m_value
+ m_store_count
));
302 if (m_store_count
== CHECK_SIZE
) {
303 m_status
= TesterStatus_Ready
;
305 m_status
= TesterStatus_Idle
;
307 DPRINTF(RubyTest
, "Action callback return data now %d\n",
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(m_value
+ byte_number
) != data
->getByte(byte_number
)) {
314 panic("Action/check failure: proc: %d address: %s data: %s "
315 "byte_number: %d m_value+byte_number: %d byte: %d %s"
317 proc
, address
, data
, byte_number
,
318 (int)m_value
+ byte_number
,
319 (int)data
->getByte(byte_number
), *this,
320 g_eventQueue_ptr
->getTime());
323 DPRINTF(RubyTest
, "Action/check success\n");
326 // successful check complete, increment complete
327 m_tester_ptr
->incrementCheckCompletions();
329 m_status
= TesterStatus_Idle
;
333 panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s "
335 *this, proc
, data
, m_status
, g_eventQueue_ptr
->getTime());
338 DPRINTF(RubyTest
, "proc: %d, Address: 0x%x\n", proc
,
339 getAddress().getLineAddress());
340 DPRINTF(RubyTest
, "Callback done\n");
345 Check::changeAddress(const Address
& address
)
347 assert(m_status
== TesterStatus_Idle
|| m_status
== TesterStatus_Ready
);
348 m_status
= TesterStatus_Idle
;
356 assert(m_status
== TesterStatus_Idle
);
357 m_status
= TesterStatus_Idle
;
358 m_value
= random() & 0xff; // One byte
363 Check::pickInitiatingNode()
365 assert(m_status
== TesterStatus_Idle
|| m_status
== TesterStatus_Ready
);
366 m_status
= TesterStatus_Idle
;
367 m_initiatingNode
= (random() % m_num_writers
);
368 DPRINTF(RubyTest
, "picked initiating node %d\n", m_initiatingNode
);
373 Check::print(std::ostream
& out
) const
376 << m_address
<< ", value: "
377 << (int)m_value
<< ", status: "
378 << m_status
<< ", initiating node: "
379 << m_initiatingNode
<< ", store_count: "
381 << "]" << std::flush
;
388 "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n",
389 m_address
.getAddress(), (int)m_value
,
390 TesterStatus_to_string(m_status
).c_str(),
391 m_initiatingNode
, m_store_count
);