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 "mem/ruby/common/SubBlock.hh"
32 #include "mem/ruby/system/Sequencer.hh"
33 #include "mem/ruby/system/System.hh"
35 typedef RubyTester::SenderState SenderState
;
37 Check::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
)
41 m_status
= TesterStatus_Idle
;
45 changeAddress(address
);
47 m_access_mode
= AccessModeType(random() % AccessModeType_NUM
);
54 DPRINTF(RubyTest
, "initiating\n");
57 // currently no protocols support prefetches
58 if (false && (random() & 0xf) == 0) {
59 initiatePrefetch(); // Prefetch from random processor
62 if (m_status
== TesterStatus_Idle
) {
64 } else if (m_status
== TesterStatus_Ready
) {
67 // Pending - do nothing
69 "initiating action/check - failed: action/check is pending\n");
74 Check::initiatePrefetch()
76 DPRINTF(RubyTest
, "initiating prefetch\n");
78 int index
= random() % m_num_cpu_sequencers
;
79 RubyTester::CpuPort
* port
=
80 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getCpuPort(index
));
83 flags
.set(Request::PREFETCH
);
87 // 1 in 8 chance this will be an exclusive prefetch
88 if ((random() & 0x7) != 0) {
89 cmd
= MemCmd::ReadReq
;
91 // 50% chance that the request will be an instruction fetch
92 if ((random() & 0x1) == 0) {
93 flags
.set(Request::INST_FETCH
);
96 cmd
= MemCmd::WriteReq
;
97 flags
.set(Request::PF_EXCLUSIVE
);
100 // Prefetches are assumed to be 0 sized
101 Request
*req
= new Request(m_address
.getAddress(), 0, flags
, curTick
,
104 PacketPtr pkt
= new Packet(req
, cmd
, port
->idx
);
106 // push the subblock onto the sender state. The sequencer will
107 // update the subblock on the return
109 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
111 if (port
->sendTiming(pkt
)) {
112 DPRINTF(RubyTest
, "successfully initiated prefetch.\n");
114 // If the packet did not issue, must delete
115 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
116 pkt
->senderState
= senderState
->saved
;
122 "prefetch initiation failed because Port was busy.\n");
127 Check::initiateAction()
129 DPRINTF(RubyTest
, "initiating Action\n");
130 assert(m_status
== TesterStatus_Idle
);
132 int index
= random() % m_num_cpu_sequencers
;
133 RubyTester::CpuPort
* port
=
134 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getCpuPort(index
));
136 Request::Flags flags
;
138 // Create the particular address for the next byte to be written
139 Address
writeAddr(m_address
.getAddress() + m_store_count
);
141 // Stores are assumed to be 1 byte-sized
142 Request
*req
= new Request(writeAddr
.getAddress(), 1, flags
, curTick
,
147 // 1 out of 8 chance, issue an atomic rather than a write
148 // if ((random() & 0x7) == 0) {
149 // cmd = MemCmd::SwapReq;
151 cmd
= MemCmd::WriteReq
;
154 PacketPtr pkt
= new Packet(req
, cmd
, port
->idx
);
155 uint8_t* writeData
= new uint8_t;
156 *writeData
= m_value
+ m_store_count
;
157 pkt
->dataDynamic(writeData
);
159 DPRINTF(RubyTest
, "data 0x%x check 0x%x\n",
160 *(pkt
->getPtr
<uint8_t>()), *writeData
);
162 // push the subblock onto the sender state. The sequencer will
163 // update the subblock on the return
165 new SenderState(writeAddr
, req
->getSize(), pkt
->senderState
);
167 if (port
->sendTiming(pkt
)) {
168 DPRINTF(RubyTest
, "initiating action - successful\n");
169 DPRINTF(RubyTest
, "status before action update: %s\n",
170 (TesterStatus_to_string(m_status
)).c_str());
171 m_status
= TesterStatus_Action_Pending
;
173 // If the packet did not issue, must delete
174 // Note: No need to delete the data, the packet destructor
176 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
177 pkt
->senderState
= senderState
->saved
;
182 DPRINTF(RubyTest
, "failed to initiate action - sequencer not ready\n");
185 DPRINTF(RubyTest
, "status after action update: %s\n",
186 (TesterStatus_to_string(m_status
)).c_str());
190 Check::initiateCheck()
192 DPRINTF(RubyTest
, "Initiating Check\n");
193 assert(m_status
== TesterStatus_Ready
);
195 int index
= random() % m_num_cpu_sequencers
;
196 RubyTester::CpuPort
* port
=
197 safe_cast
<RubyTester::CpuPort
*>(m_tester_ptr
->getCpuPort(index
));
199 Request::Flags flags
;
201 // 50% chance that the request will be an instruction fetch
202 if ((random() & 0x1) == 0) {
203 flags
.set(Request::INST_FETCH
);
206 // Checks are sized depending on the number of bytes written
207 Request
*req
= new Request(m_address
.getAddress(), CHECK_SIZE
, flags
,
208 curTick
, m_pc
.getAddress());
210 PacketPtr pkt
= new Packet(req
, MemCmd::ReadReq
, port
->idx
);
211 uint8_t* dataArray
= new uint8_t[CHECK_SIZE
];
212 pkt
->dataDynamicArray(dataArray
);
214 // push the subblock onto the sender state. The sequencer will
215 // update the subblock on the return
217 new SenderState(m_address
, req
->getSize(), pkt
->senderState
);
219 if (port
->sendTiming(pkt
)) {
220 DPRINTF(RubyTest
, "initiating check - successful\n");
221 DPRINTF(RubyTest
, "status before check update: %s\n",
222 TesterStatus_to_string(m_status
).c_str());
223 m_status
= TesterStatus_Check_Pending
;
225 // If the packet did not issue, must delete
226 // Note: No need to delete the data, the packet destructor
228 SenderState
* senderState
= safe_cast
<SenderState
*>(pkt
->senderState
);
229 pkt
->senderState
= senderState
->saved
;
234 DPRINTF(RubyTest
, "failed to initiate check - cpu port not ready\n");
237 DPRINTF(RubyTest
, "status after check update: %s\n",
238 TesterStatus_to_string(m_status
).c_str());
242 Check::performCallback(NodeID proc
, SubBlock
* data
)
244 Address address
= data
->getAddress();
246 // This isn't exactly right since we now have multi-byte checks
247 // assert(getAddress() == address);
249 assert(getAddress().getLineAddress() == address
.getLineAddress());
250 assert(data
!= NULL
);
252 DPRINTF(RubyTest
, "RubyTester Callback\n");
255 if (m_status
== TesterStatus_Action_Pending
) {
256 DPRINTF(RubyTest
, "Action callback write value: %d, currently %d\n",
257 (m_value
+ m_store_count
), data
->getByte(0));
258 // Perform store one byte at a time
259 data
->setByte(0, (m_value
+ m_store_count
));
261 if (m_store_count
== CHECK_SIZE
) {
262 m_status
= TesterStatus_Ready
;
264 m_status
= TesterStatus_Idle
;
266 DPRINTF(RubyTest
, "Action callback return data now %d\n",
268 } else if (m_status
== TesterStatus_Check_Pending
) {
269 DPRINTF(RubyTest
, "Check callback\n");
270 // Perform load/check
271 for (int byte_number
=0; byte_number
<CHECK_SIZE
; byte_number
++) {
272 if (uint8(m_value
+ byte_number
) != data
->getByte(byte_number
)) {
276 WARN_EXPR(byte_number
);
277 WARN_EXPR((int)m_value
+ byte_number
);
278 WARN_EXPR((int)data
->getByte(byte_number
));
280 WARN_EXPR(g_eventQueue_ptr
->getTime());
281 ERROR_MSG("Action/check failure");
284 DPRINTF(RubyTest
, "Action/check success\n");
287 // successful check complete, increment complete
288 m_tester_ptr
->incrementCheckCompletions();
290 m_status
= TesterStatus_Idle
;
298 WARN_EXPR(g_eventQueue_ptr
->getTime());
299 ERROR_MSG("Unexpected TesterStatus");
302 DPRINTF(RubyTest
, "proc: %d, Address: 0x%x\n", proc
,
303 getAddress().getLineAddress());
304 DPRINTF(RubyTest
, "Callback done\n");
309 Check::changeAddress(const Address
& address
)
311 assert(m_status
== TesterStatus_Idle
|| m_status
== TesterStatus_Ready
);
312 m_status
= TesterStatus_Idle
;
320 assert(m_status
== TesterStatus_Idle
);
321 m_status
= TesterStatus_Idle
;
322 m_value
= random() & 0xff; // One byte
327 Check::pickInitiatingNode()
329 assert(m_status
== TesterStatus_Idle
|| m_status
== TesterStatus_Ready
);
330 m_status
= TesterStatus_Idle
;
331 m_initiatingNode
= (random() % m_num_cpu_sequencers
);
332 DPRINTF(RubyTest
, "picked initiating node %d\n", m_initiatingNode
);
337 Check::print(std::ostream
& out
) const
340 << m_address
<< ", value: "
341 << (int)m_value
<< ", status: "
342 << m_status
<< ", initiating node: "
343 << m_initiatingNode
<< ", store_count: "
345 << "]" << std::flush
;
352 "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n",
353 m_address
.getAddress(), (int)m_value
,
354 TesterStatus_to_string(m_status
).c_str(),
355 m_initiatingNode
, m_store_count
);