Sequencer.cc (8530:3aaa99208a84) Sequencer.cc (8615:e66a566f2cfa)
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 14 unchanged lines hidden (view full) ---

23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "base/misc.hh"
30#include "base/str.hh"
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 14 unchanged lines hidden (view full) ---

23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "base/misc.hh"
30#include "base/str.hh"
31#include "config/the_isa.hh"
32#if THE_ISA == X86_ISA
33#include "arch/x86/insts/microldstop.hh"
34#endif // X86_ISA
31#include "cpu/testers/rubytest/RubyTester.hh"
32#include "debug/MemoryAccess.hh"
33#include "debug/ProtocolTrace.hh"
35#include "cpu/testers/rubytest/RubyTester.hh"
36#include "debug/MemoryAccess.hh"
37#include "debug/ProtocolTrace.hh"
38#include "debug/RubySequencer.hh"
39#include "mem/protocol/PrefetchBit.hh"
40#include "mem/protocol/RubyAccessMode.hh"
34#include "mem/ruby/buffers/MessageBuffer.hh"
35#include "mem/ruby/common/Global.hh"
36#include "mem/ruby/common/SubBlock.hh"
37#include "mem/ruby/profiler/Profiler.hh"
38#include "mem/ruby/recorder/Tracer.hh"
41#include "mem/ruby/buffers/MessageBuffer.hh"
42#include "mem/ruby/common/Global.hh"
43#include "mem/ruby/common/SubBlock.hh"
44#include "mem/ruby/profiler/Profiler.hh"
45#include "mem/ruby/recorder/Tracer.hh"
39#include "mem/ruby/slicc_interface/AbstractController.hh"
40#include "mem/ruby/slicc_interface/RubyRequest.hh"
41#include "mem/ruby/system/CacheMemory.hh"
42#include "mem/ruby/system/Sequencer.hh"
43#include "mem/ruby/system/System.hh"
44#include "mem/packet.hh"
45#include "params/RubySequencer.hh"
46
47using namespace std;

--- 9 unchanged lines hidden (view full) ---

57{
58 m_store_waiting_on_load_cycles = 0;
59 m_store_waiting_on_store_cycles = 0;
60 m_load_waiting_on_store_cycles = 0;
61 m_load_waiting_on_load_cycles = 0;
62
63 m_outstanding_count = 0;
64
46#include "mem/ruby/slicc_interface/RubyRequest.hh"
47#include "mem/ruby/system/CacheMemory.hh"
48#include "mem/ruby/system/Sequencer.hh"
49#include "mem/ruby/system/System.hh"
50#include "mem/packet.hh"
51#include "params/RubySequencer.hh"
52
53using namespace std;

--- 9 unchanged lines hidden (view full) ---

63{
64 m_store_waiting_on_load_cycles = 0;
65 m_store_waiting_on_store_cycles = 0;
66 m_load_waiting_on_store_cycles = 0;
67 m_load_waiting_on_load_cycles = 0;
68
69 m_outstanding_count = 0;
70
65 m_max_outstanding_requests = 0;
66 m_deadlock_threshold = 0;
67 m_instCache_ptr = NULL;
68 m_dataCache_ptr = NULL;
69
70 m_instCache_ptr = p->icache;
71 m_dataCache_ptr = p->dcache;
72 m_max_outstanding_requests = p->max_outstanding_requests;
73 m_deadlock_threshold = p->deadlock_threshold;

--- 24 unchanged lines hidden (view full) ---

98 for (; read != read_end; ++read) {
99 SequencerRequest* request = read->second;
100 if (current_time - request->issue_time < m_deadlock_threshold)
101 continue;
102
103 panic("Possible Deadlock detected. Aborting!\n"
104 "version: %d request.paddr: 0x%x m_readRequestTable: %d "
105 "current time: %u issue_time: %d difference: %d\n", m_version,
71 m_deadlock_threshold = 0;
72 m_instCache_ptr = NULL;
73 m_dataCache_ptr = NULL;
74
75 m_instCache_ptr = p->icache;
76 m_dataCache_ptr = p->dcache;
77 m_max_outstanding_requests = p->max_outstanding_requests;
78 m_deadlock_threshold = p->deadlock_threshold;

--- 24 unchanged lines hidden (view full) ---

103 for (; read != read_end; ++read) {
104 SequencerRequest* request = read->second;
105 if (current_time - request->issue_time < m_deadlock_threshold)
106 continue;
107
108 panic("Possible Deadlock detected. Aborting!\n"
109 "version: %d request.paddr: 0x%x m_readRequestTable: %d "
110 "current time: %u issue_time: %d difference: %d\n", m_version,
106 request->ruby_request.m_PhysicalAddress, m_readRequestTable.size(),
111 Address(request->pkt->getAddr()), m_readRequestTable.size(),
107 current_time, request->issue_time,
108 current_time - request->issue_time);
109 }
110
111 RequestTable::iterator write = m_writeRequestTable.begin();
112 RequestTable::iterator write_end = m_writeRequestTable.end();
113 for (; write != write_end; ++write) {
114 SequencerRequest* request = write->second;
115 if (current_time - request->issue_time < m_deadlock_threshold)
116 continue;
117
118 panic("Possible Deadlock detected. Aborting!\n"
119 "version: %d request.paddr: 0x%x m_writeRequestTable: %d "
120 "current time: %u issue_time: %d difference: %d\n", m_version,
112 current_time, request->issue_time,
113 current_time - request->issue_time);
114 }
115
116 RequestTable::iterator write = m_writeRequestTable.begin();
117 RequestTable::iterator write_end = m_writeRequestTable.end();
118 for (; write != write_end; ++write) {
119 SequencerRequest* request = write->second;
120 if (current_time - request->issue_time < m_deadlock_threshold)
121 continue;
122
123 panic("Possible Deadlock detected. Aborting!\n"
124 "version: %d request.paddr: 0x%x m_writeRequestTable: %d "
125 "current time: %u issue_time: %d difference: %d\n", m_version,
121 request->ruby_request.m_PhysicalAddress, m_writeRequestTable.size(),
126 Address(request->pkt->getAddr()), m_writeRequestTable.size(),
122 current_time, request->issue_time,
123 current_time - request->issue_time);
124 }
125
126 total_outstanding += m_writeRequestTable.size();
127 total_outstanding += m_readRequestTable.size();
128
129 assert(m_outstanding_count == total_outstanding);

--- 78 unchanged lines hidden (view full) ---

208 << " controller: " << m_controller->getName() << endl
209 << " version: " << m_version << endl
210 << " max_outstanding_requests: " << m_max_outstanding_requests << endl
211 << " deadlock_threshold: " << m_deadlock_threshold << endl;
212}
213
214// Insert the request on the correct request table. Return true if
215// the entry was already present.
127 current_time, request->issue_time,
128 current_time - request->issue_time);
129 }
130
131 total_outstanding += m_writeRequestTable.size();
132 total_outstanding += m_readRequestTable.size();
133
134 assert(m_outstanding_count == total_outstanding);

--- 78 unchanged lines hidden (view full) ---

213 << " controller: " << m_controller->getName() << endl
214 << " version: " << m_version << endl
215 << " max_outstanding_requests: " << m_max_outstanding_requests << endl
216 << " deadlock_threshold: " << m_deadlock_threshold << endl;
217}
218
219// Insert the request on the correct request table. Return true if
220// the entry was already present.
216bool
217Sequencer::insertRequest(SequencerRequest* request)
221RequestStatus
222Sequencer::insertRequest(PacketPtr pkt, RubyRequestType request_type)
218{
219 int total_outstanding =
220 m_writeRequestTable.size() + m_readRequestTable.size();
221
222 assert(m_outstanding_count == total_outstanding);
223
224 // See if we should schedule a deadlock check
225 if (deadlockCheckEvent.scheduled() == false) {
226 schedule(deadlockCheckEvent, m_deadlock_threshold + curTick());
227 }
228
223{
224 int total_outstanding =
225 m_writeRequestTable.size() + m_readRequestTable.size();
226
227 assert(m_outstanding_count == total_outstanding);
228
229 // See if we should schedule a deadlock check
230 if (deadlockCheckEvent.scheduled() == false) {
231 schedule(deadlockCheckEvent, m_deadlock_threshold + curTick());
232 }
233
229 Address line_addr(request->ruby_request.m_PhysicalAddress);
234 Address line_addr(pkt->getAddr());
230 line_addr.makeLineAddress();
235 line_addr.makeLineAddress();
231 if ((request->ruby_request.m_Type == RubyRequestType_ST) ||
232 (request->ruby_request.m_Type == RubyRequestType_ATOMIC) ||
233 (request->ruby_request.m_Type == RubyRequestType_RMW_Read) ||
234 (request->ruby_request.m_Type == RubyRequestType_RMW_Write) ||
235 (request->ruby_request.m_Type == RubyRequestType_Load_Linked) ||
236 (request->ruby_request.m_Type == RubyRequestType_Store_Conditional) ||
237 (request->ruby_request.m_Type == RubyRequestType_Locked_RMW_Read) ||
238 (request->ruby_request.m_Type == RubyRequestType_Locked_RMW_Write) ||
239 (request->ruby_request.m_Type == RubyRequestType_FLUSH)) {
236 if ((request_type == RubyRequestType_ST) ||
237 (request_type == RubyRequestType_RMW_Read) ||
238 (request_type == RubyRequestType_RMW_Write) ||
239 (request_type == RubyRequestType_Load_Linked) ||
240 (request_type == RubyRequestType_Store_Conditional) ||
241 (request_type == RubyRequestType_Locked_RMW_Read) ||
242 (request_type == RubyRequestType_Locked_RMW_Write) ||
243 (request_type == RubyRequestType_FLUSH)) {
244
245 // Check if there is any outstanding read request for the same
246 // cache line.
247 if (m_readRequestTable.count(line_addr) > 0) {
248 m_store_waiting_on_load_cycles++;
249 return RequestStatus_Aliased;
250 }
251
240 pair<RequestTable::iterator, bool> r =
241 m_writeRequestTable.insert(RequestTable::value_type(line_addr, 0));
252 pair<RequestTable::iterator, bool> r =
253 m_writeRequestTable.insert(RequestTable::value_type(line_addr, 0));
242 bool success = r.second;
243 RequestTable::iterator i = r.first;
244 if (!success) {
245 i->second = request;
246 // return true;
247
248 // drh5: isn't this an error? do you lose the initial request?
249 assert(0);
254 if (r.second) {
255 RequestTable::iterator i = r.first;
256 i->second = new SequencerRequest(pkt, request_type,
257 g_eventQueue_ptr->getTime());
258 m_outstanding_count++;
259 } else {
260 // There is an outstanding write request for the cache line
261 m_store_waiting_on_store_cycles++;
262 return RequestStatus_Aliased;
250 }
263 }
251 i->second = request;
252 m_outstanding_count++;
253 } else {
264 } else {
265 // Check if there is any outstanding write request for the same
266 // cache line.
267 if (m_writeRequestTable.count(line_addr) > 0) {
268 m_load_waiting_on_store_cycles++;
269 return RequestStatus_Aliased;
270 }
271
254 pair<RequestTable::iterator, bool> r =
255 m_readRequestTable.insert(RequestTable::value_type(line_addr, 0));
272 pair<RequestTable::iterator, bool> r =
273 m_readRequestTable.insert(RequestTable::value_type(line_addr, 0));
256 bool success = r.second;
257 RequestTable::iterator i = r.first;
258 if (!success) {
259 i->second = request;
260 // return true;
261
274
262 // drh5: isn't this an error? do you lose the initial request?
263 assert(0);
275 if (r.second) {
276 RequestTable::iterator i = r.first;
277 i->second = new SequencerRequest(pkt, request_type,
278 g_eventQueue_ptr->getTime());
279 m_outstanding_count++;
280 } else {
281 // There is an outstanding read request for the cache line
282 m_load_waiting_on_load_cycles++;
283 return RequestStatus_Aliased;
264 }
284 }
265 i->second = request;
266 m_outstanding_count++;
267 }
268
269 g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count);
285 }
286
287 g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count);
270
271 total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size();
272 assert(m_outstanding_count == total_outstanding);
273
288 total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size();
289 assert(m_outstanding_count == total_outstanding);
290
274 return false;
291 return RequestStatus_Ready;
275}
276
277void
278Sequencer::markRemoved()
279{
280 m_outstanding_count--;
281 assert(m_outstanding_count ==
282 m_writeRequestTable.size() + m_readRequestTable.size());
283}
284
285void
286Sequencer::removeRequest(SequencerRequest* srequest)
287{
288 assert(m_outstanding_count ==
289 m_writeRequestTable.size() + m_readRequestTable.size());
290
292}
293
294void
295Sequencer::markRemoved()
296{
297 m_outstanding_count--;
298 assert(m_outstanding_count ==
299 m_writeRequestTable.size() + m_readRequestTable.size());
300}
301
302void
303Sequencer::removeRequest(SequencerRequest* srequest)
304{
305 assert(m_outstanding_count ==
306 m_writeRequestTable.size() + m_readRequestTable.size());
307
291 const RubyRequest & ruby_request = srequest->ruby_request;
292 Address line_addr(ruby_request.m_PhysicalAddress);
308 Address line_addr(srequest->pkt->getAddr());
293 line_addr.makeLineAddress();
309 line_addr.makeLineAddress();
294 if ((ruby_request.m_Type == RubyRequestType_ST) ||
295 (ruby_request.m_Type == RubyRequestType_RMW_Read) ||
296 (ruby_request.m_Type == RubyRequestType_RMW_Write) ||
297 (ruby_request.m_Type == RubyRequestType_Load_Linked) ||
298 (ruby_request.m_Type == RubyRequestType_Store_Conditional) ||
299 (ruby_request.m_Type == RubyRequestType_Locked_RMW_Read) ||
300 (ruby_request.m_Type == RubyRequestType_Locked_RMW_Write)) {
310 if ((srequest->m_type == RubyRequestType_ST) ||
311 (srequest->m_type == RubyRequestType_RMW_Read) ||
312 (srequest->m_type == RubyRequestType_RMW_Write) ||
313 (srequest->m_type == RubyRequestType_Load_Linked) ||
314 (srequest->m_type == RubyRequestType_Store_Conditional) ||
315 (srequest->m_type == RubyRequestType_Locked_RMW_Read) ||
316 (srequest->m_type == RubyRequestType_Locked_RMW_Write)) {
301 m_writeRequestTable.erase(line_addr);
302 } else {
303 m_readRequestTable.erase(line_addr);
304 }
305
306 markRemoved();
307}
308
309bool
310Sequencer::handleLlsc(const Address& address, SequencerRequest* request)
311{
312 //
313 // The success flag indicates whether the LLSC operation was successful.
314 // LL ops will always succeed, but SC may fail if the cache line is no
315 // longer locked.
316 //
317 bool success = true;
317 m_writeRequestTable.erase(line_addr);
318 } else {
319 m_readRequestTable.erase(line_addr);
320 }
321
322 markRemoved();
323}
324
325bool
326Sequencer::handleLlsc(const Address& address, SequencerRequest* request)
327{
328 //
329 // The success flag indicates whether the LLSC operation was successful.
330 // LL ops will always succeed, but SC may fail if the cache line is no
331 // longer locked.
332 //
333 bool success = true;
318 if (request->ruby_request.m_Type == RubyRequestType_Store_Conditional) {
334 if (request->m_type == RubyRequestType_Store_Conditional) {
319 if (!m_dataCache_ptr->isLocked(address, m_version)) {
320 //
321 // For failed SC requests, indicate the failure to the cpu by
322 // setting the extra data to zero.
323 //
335 if (!m_dataCache_ptr->isLocked(address, m_version)) {
336 //
337 // For failed SC requests, indicate the failure to the cpu by
338 // setting the extra data to zero.
339 //
324 request->ruby_request.pkt->req->setExtraData(0);
340 request->pkt->req->setExtraData(0);
325 success = false;
326 } else {
327 //
328 // For successful SC requests, indicate the success to the cpu by
329 // setting the extra data to one.
330 //
341 success = false;
342 } else {
343 //
344 // For successful SC requests, indicate the success to the cpu by
345 // setting the extra data to one.
346 //
331 request->ruby_request.pkt->req->setExtraData(1);
347 request->pkt->req->setExtraData(1);
332 }
333 //
334 // Independent of success, all SC operations must clear the lock
335 //
336 m_dataCache_ptr->clearLocked(address);
348 }
349 //
350 // Independent of success, all SC operations must clear the lock
351 //
352 m_dataCache_ptr->clearLocked(address);
337 } else if (request->ruby_request.m_Type == RubyRequestType_Load_Linked) {
353 } else if (request->m_type == RubyRequestType_Load_Linked) {
338 //
339 // Note: To fully follow Alpha LLSC semantics, should the LL clear any
340 // previously locked cache lines?
341 //
342 m_dataCache_ptr->setLocked(address, m_version);
354 //
355 // Note: To fully follow Alpha LLSC semantics, should the LL clear any
356 // previously locked cache lines?
357 //
358 m_dataCache_ptr->setLocked(address, m_version);
343 } else if ((m_dataCache_ptr->isTagPresent(address)) && (m_dataCache_ptr->isLocked(address, m_version))) {
359 } else if ((m_dataCache_ptr->isTagPresent(address)) &&
360 (m_dataCache_ptr->isLocked(address, m_version))) {
344 //
345 // Normal writes should clear the locked address
346 //
347 m_dataCache_ptr->clearLocked(address);
348 }
349 return success;
350}
351

--- 24 unchanged lines hidden (view full) ---

376
377 RequestTable::iterator i = m_writeRequestTable.find(address);
378 assert(i != m_writeRequestTable.end());
379 SequencerRequest* request = i->second;
380
381 m_writeRequestTable.erase(i);
382 markRemoved();
383
361 //
362 // Normal writes should clear the locked address
363 //
364 m_dataCache_ptr->clearLocked(address);
365 }
366 return success;
367}
368

--- 24 unchanged lines hidden (view full) ---

393
394 RequestTable::iterator i = m_writeRequestTable.find(address);
395 assert(i != m_writeRequestTable.end());
396 SequencerRequest* request = i->second;
397
398 m_writeRequestTable.erase(i);
399 markRemoved();
400
384 assert((request->ruby_request.m_Type == RubyRequestType_ST) ||
385 (request->ruby_request.m_Type == RubyRequestType_ATOMIC) ||
386 (request->ruby_request.m_Type == RubyRequestType_RMW_Read) ||
387 (request->ruby_request.m_Type == RubyRequestType_RMW_Write) ||
388 (request->ruby_request.m_Type == RubyRequestType_Load_Linked) ||
389 (request->ruby_request.m_Type == RubyRequestType_Store_Conditional) ||
390 (request->ruby_request.m_Type == RubyRequestType_Locked_RMW_Read) ||
391 (request->ruby_request.m_Type == RubyRequestType_Locked_RMW_Write) ||
392 (request->ruby_request.m_Type == RubyRequestType_FLUSH));
401 assert((request->m_type == RubyRequestType_ST) ||
402 (request->m_type == RubyRequestType_ATOMIC) ||
403 (request->m_type == RubyRequestType_RMW_Read) ||
404 (request->m_type == RubyRequestType_RMW_Write) ||
405 (request->m_type == RubyRequestType_Load_Linked) ||
406 (request->m_type == RubyRequestType_Store_Conditional) ||
407 (request->m_type == RubyRequestType_Locked_RMW_Read) ||
408 (request->m_type == RubyRequestType_Locked_RMW_Write) ||
409 (request->m_type == RubyRequestType_FLUSH));
393
394
395 //
396 // For Alpha, properly handle LL, SC, and write requests with respect to
397 // locked cache blocks.
398 //
399 // Not valid for Network_test protocl
400 //
401 bool success = true;
402 if(!m_usingNetworkTester)
403 success = handleLlsc(address, request);
404
410
411
412 //
413 // For Alpha, properly handle LL, SC, and write requests with respect to
414 // locked cache blocks.
415 //
416 // Not valid for Network_test protocl
417 //
418 bool success = true;
419 if(!m_usingNetworkTester)
420 success = handleLlsc(address, request);
421
405 if (request->ruby_request.m_Type == RubyRequestType_Locked_RMW_Read) {
422 if (request->m_type == RubyRequestType_Locked_RMW_Read) {
406 m_controller->blockOnQueue(address, m_mandatory_q_ptr);
423 m_controller->blockOnQueue(address, m_mandatory_q_ptr);
407 } else if (request->ruby_request.m_Type == RubyRequestType_Locked_RMW_Write) {
424 } else if (request->m_type == RubyRequestType_Locked_RMW_Write) {
408 m_controller->unblock(address);
409 }
410
411 hitCallback(request, mach, data, success,
412 initialRequestTime, forwardRequestTime, firstResponseTime);
413}
414
415void

--- 23 unchanged lines hidden (view full) ---

439
440 RequestTable::iterator i = m_readRequestTable.find(address);
441 assert(i != m_readRequestTable.end());
442 SequencerRequest* request = i->second;
443
444 m_readRequestTable.erase(i);
445 markRemoved();
446
425 m_controller->unblock(address);
426 }
427
428 hitCallback(request, mach, data, success,
429 initialRequestTime, forwardRequestTime, firstResponseTime);
430}
431
432void

--- 23 unchanged lines hidden (view full) ---

456
457 RequestTable::iterator i = m_readRequestTable.find(address);
458 assert(i != m_readRequestTable.end());
459 SequencerRequest* request = i->second;
460
461 m_readRequestTable.erase(i);
462 markRemoved();
463
447 assert((request->ruby_request.m_Type == RubyRequestType_LD) ||
448 (request->ruby_request.m_Type == RubyRequestType_IFETCH));
464 assert((request->m_type == RubyRequestType_LD) ||
465 (request->m_type == RubyRequestType_IFETCH));
449
450 hitCallback(request, mach, data, true,
451 initialRequestTime, forwardRequestTime, firstResponseTime);
452}
453
454void
455Sequencer::hitCallback(SequencerRequest* srequest,
456 GenericMachineType mach,
457 DataBlock& data,
458 bool success,
459 Time initialRequestTime,
460 Time forwardRequestTime,
461 Time firstResponseTime)
462{
466
467 hitCallback(request, mach, data, true,
468 initialRequestTime, forwardRequestTime, firstResponseTime);
469}
470
471void
472Sequencer::hitCallback(SequencerRequest* srequest,
473 GenericMachineType mach,
474 DataBlock& data,
475 bool success,
476 Time initialRequestTime,
477 Time forwardRequestTime,
478 Time firstResponseTime)
479{
463 const RubyRequest & ruby_request = srequest->ruby_request;
464 Address request_address(ruby_request.m_PhysicalAddress);
465 Address request_line_address(ruby_request.m_PhysicalAddress);
480 PacketPtr pkt = srequest->pkt;
481 Address request_address(pkt->getAddr());
482 Address request_line_address(pkt->getAddr());
466 request_line_address.makeLineAddress();
483 request_line_address.makeLineAddress();
467 RubyRequestType type = ruby_request.m_Type;
484 RubyRequestType type = srequest->m_type;
468 Time issued_time = srequest->issue_time;
469
470 // Set this cache entry to the most recently used
471 if (type == RubyRequestType_IFETCH) {
472 if (m_instCache_ptr->isTagPresent(request_line_address))
473 m_instCache_ptr->setMRU(request_line_address);
474 } else {
475 if (m_dataCache_ptr->isTagPresent(request_line_address))

--- 21 unchanged lines hidden (view full) ---

497 forwardRequestTime,
498 firstResponseTime,
499 g_eventQueue_ptr->getTime());
500 }
501
502 DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %d cycles\n",
503 curTick(), m_version, "Seq",
504 success ? "Done" : "SC_Failed", "", "",
485 Time issued_time = srequest->issue_time;
486
487 // Set this cache entry to the most recently used
488 if (type == RubyRequestType_IFETCH) {
489 if (m_instCache_ptr->isTagPresent(request_line_address))
490 m_instCache_ptr->setMRU(request_line_address);
491 } else {
492 if (m_dataCache_ptr->isTagPresent(request_line_address))

--- 21 unchanged lines hidden (view full) ---

514 forwardRequestTime,
515 firstResponseTime,
516 g_eventQueue_ptr->getTime());
517 }
518
519 DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %d cycles\n",
520 curTick(), m_version, "Seq",
521 success ? "Done" : "SC_Failed", "", "",
505 ruby_request.m_PhysicalAddress, miss_latency);
522 request_address, miss_latency);
506 }
507
508 // update the data
523 }
524
525 // update the data
509 if (ruby_request.data != NULL) {
526 if (pkt->getPtr<uint8_t>(true) != NULL) {
510 if ((type == RubyRequestType_LD) ||
511 (type == RubyRequestType_IFETCH) ||
512 (type == RubyRequestType_RMW_Read) ||
513 (type == RubyRequestType_Locked_RMW_Read) ||
514 (type == RubyRequestType_Load_Linked)) {
527 if ((type == RubyRequestType_LD) ||
528 (type == RubyRequestType_IFETCH) ||
529 (type == RubyRequestType_RMW_Read) ||
530 (type == RubyRequestType_Locked_RMW_Read) ||
531 (type == RubyRequestType_Load_Linked)) {
515 memcpy(ruby_request.data,
516 data.getData(request_address.getOffset(), ruby_request.m_Size),
517 ruby_request.m_Size);
532 memcpy(pkt->getPtr<uint8_t>(true),
533 data.getData(request_address.getOffset(), pkt->getSize()),
534 pkt->getSize());
518 } else {
535 } else {
519 data.setData(ruby_request.data, request_address.getOffset(),
520 ruby_request.m_Size);
536 data.setData(pkt->getPtr<uint8_t>(true),
537 request_address.getOffset(), pkt->getSize());
521 }
522 } else {
523 DPRINTF(MemoryAccess,
524 "WARNING. Data not transfered from Ruby to M5 for type %s\n",
525 RubyRequestType_to_string(type));
526 }
527
528 // If using the RubyTester, update the RubyTester sender state's
529 // subBlock with the recieved data. The tester will later access
530 // this state.
531 // Note: RubyPort will access it's sender state before the
532 // RubyTester.
533 if (m_usingRubyTester) {
534 RubyPort::SenderState *requestSenderState =
538 }
539 } else {
540 DPRINTF(MemoryAccess,
541 "WARNING. Data not transfered from Ruby to M5 for type %s\n",
542 RubyRequestType_to_string(type));
543 }
544
545 // If using the RubyTester, update the RubyTester sender state's
546 // subBlock with the recieved data. The tester will later access
547 // this state.
548 // Note: RubyPort will access it's sender state before the
549 // RubyTester.
550 if (m_usingRubyTester) {
551 RubyPort::SenderState *requestSenderState =
535 safe_cast<RubyPort::SenderState*>(ruby_request.pkt->senderState);
552 safe_cast(pkt->senderState);
536 RubyTester::SenderState* testerSenderState =
537 safe_cast<RubyTester::SenderState*>(requestSenderState->saved);
538 testerSenderState->subBlock->mergeFrom(data);
539 }
540
553 RubyTester::SenderState* testerSenderState =
554 safe_cast<RubyTester::SenderState*>(requestSenderState->saved);
555 testerSenderState->subBlock->mergeFrom(data);
556 }
557
541 ruby_hit_callback(ruby_request.pkt);
558 ruby_hit_callback(pkt);
542 delete srequest;
543}
544
559 delete srequest;
560}
561
545// Returns true if the sequencer already has a load or store outstanding
546RequestStatus
547Sequencer::getRequestStatus(const RubyRequest& request)
548{
549 bool is_outstanding_store =
550 !!m_writeRequestTable.count(line_address(request.m_PhysicalAddress));
551 bool is_outstanding_load =
552 !!m_readRequestTable.count(line_address(request.m_PhysicalAddress));
553 if (is_outstanding_store) {
554 if ((request.m_Type == RubyRequestType_LD) ||
555 (request.m_Type == RubyRequestType_IFETCH) ||
556 (request.m_Type == RubyRequestType_RMW_Read)) {
557 m_store_waiting_on_load_cycles++;
558 } else {
559 m_store_waiting_on_store_cycles++;
560 }
561 return RequestStatus_Aliased;
562 } else if (is_outstanding_load) {
563 if ((request.m_Type == RubyRequestType_ST) ||
564 (request.m_Type == RubyRequestType_RMW_Write)) {
565 m_load_waiting_on_store_cycles++;
566 } else {
567 m_load_waiting_on_load_cycles++;
568 }
569 return RequestStatus_Aliased;
570 }
571
572 if (m_outstanding_count >= m_max_outstanding_requests) {
573 return RequestStatus_BufferFull;
574 }
575
576 return RequestStatus_Ready;
577}
578
579bool
580Sequencer::empty() const
581{
582 return m_writeRequestTable.empty() && m_readRequestTable.empty();
583}
584
585RequestStatus
562bool
563Sequencer::empty() const
564{
565 return m_writeRequestTable.empty() && m_readRequestTable.empty();
566}
567
568RequestStatus
586Sequencer::makeRequest(const RubyRequest &request)
569Sequencer::makeRequest(PacketPtr pkt)
587{
570{
588 assert(request.m_PhysicalAddress.getOffset() + request.m_Size <=
589 RubySystem::getBlockSizeBytes());
590 RequestStatus status = getRequestStatus(request);
591 if (status != RequestStatus_Ready)
592 return status;
571 if (m_outstanding_count >= m_max_outstanding_requests) {
572 return RequestStatus_BufferFull;
573 }
593
574
594 SequencerRequest *srequest =
595 new SequencerRequest(request, g_eventQueue_ptr->getTime());
596 bool found = insertRequest(srequest);
597 if (found) {
598 panic("Sequencer::makeRequest should never be called if the "
599 "request is already outstanding\n");
600 return RequestStatus_NULL;
575 RubyRequestType primary_type = RubyRequestType_NULL;
576 RubyRequestType secondary_type = RubyRequestType_NULL;
577
578 if (pkt->isLLSC()) {
579 //
580 // Alpha LL/SC instructions need to be handled carefully by the cache
581 // coherence protocol to ensure they follow the proper semantics. In
582 // particular, by identifying the operations as atomic, the protocol
583 // should understand that migratory sharing optimizations should not
584 // be performed (i.e. a load between the LL and SC should not steal
585 // away exclusive permission).
586 //
587 if (pkt->isWrite()) {
588 DPRINTF(RubySequencer, "Issuing SC\n");
589 primary_type = RubyRequestType_Store_Conditional;
590 } else {
591 DPRINTF(RubySequencer, "Issuing LL\n");
592 assert(pkt->isRead());
593 primary_type = RubyRequestType_Load_Linked;
594 }
595 secondary_type = RubyRequestType_ATOMIC;
596 } else if (pkt->req->isLocked()) {
597 //
598 // x86 locked instructions are translated to store cache coherence
599 // requests because these requests should always be treated as read
600 // exclusive operations and should leverage any migratory sharing
601 // optimization built into the protocol.
602 //
603 if (pkt->isWrite()) {
604 DPRINTF(RubySequencer, "Issuing Locked RMW Write\n");
605 primary_type = RubyRequestType_Locked_RMW_Write;
606 } else {
607 DPRINTF(RubySequencer, "Issuing Locked RMW Read\n");
608 assert(pkt->isRead());
609 primary_type = RubyRequestType_Locked_RMW_Read;
610 }
611 secondary_type = RubyRequestType_ST;
612 } else {
613 if (pkt->isRead()) {
614 if (pkt->req->isInstFetch()) {
615 primary_type = secondary_type = RubyRequestType_IFETCH;
616 } else {
617#if THE_ISA == X86_ISA
618 uint32_t flags = pkt->req->getFlags();
619 bool storeCheck = flags &
620 (TheISA::StoreCheck << TheISA::FlagShift);
621#else
622 bool storeCheck = false;
623#endif // X86_ISA
624 if (storeCheck) {
625 primary_type = RubyRequestType_RMW_Read;
626 secondary_type = RubyRequestType_ST;
627 } else {
628 primary_type = secondary_type = RubyRequestType_LD;
629 }
630 }
631 } else if (pkt->isWrite()) {
632 //
633 // Note: M5 packets do not differentiate ST from RMW_Write
634 //
635 primary_type = secondary_type = RubyRequestType_ST;
636 } else if (pkt->isFlush()) {
637 primary_type = secondary_type = RubyRequestType_FLUSH;
638 } else {
639 panic("Unsupported ruby packet type\n");
640 }
601 }
602
641 }
642
603 issueRequest(request);
643 RequestStatus status = insertRequest(pkt, primary_type);
644 if (status != RequestStatus_Ready)
645 return status;
604
646
647 issueRequest(pkt, secondary_type);
648
605 // TODO: issue hardware prefetches here
606 return RequestStatus_Issued;
607}
608
609void
649 // TODO: issue hardware prefetches here
650 return RequestStatus_Issued;
651}
652
653void
610Sequencer::issueRequest(const RubyRequest& request)
654Sequencer::issueRequest(PacketPtr pkt, RubyRequestType secondary_type)
611{
655{
612 // TODO: Eliminate RubyRequest being copied again.
613
614 RubyRequestType ctype = RubyRequestType_NUM;
615 switch(request.m_Type) {
616 case RubyRequestType_IFETCH:
617 ctype = RubyRequestType_IFETCH;
618 break;
619 case RubyRequestType_LD:
620 ctype = RubyRequestType_LD;
621 break;
622 case RubyRequestType_FLUSH:
623 ctype = RubyRequestType_FLUSH;
624 break;
625 case RubyRequestType_ST:
626 case RubyRequestType_RMW_Read:
627 case RubyRequestType_RMW_Write:
628 //
629 // x86 locked instructions are translated to store cache coherence
630 // requests because these requests should always be treated as read
631 // exclusive operations and should leverage any migratory sharing
632 // optimization built into the protocol.
633 //
634 case RubyRequestType_Locked_RMW_Read:
635 case RubyRequestType_Locked_RMW_Write:
636 ctype = RubyRequestType_ST;
637 break;
638 //
639 // Alpha LL/SC instructions need to be handled carefully by the cache
640 // coherence protocol to ensure they follow the proper semantics. In
641 // particular, by identifying the operations as atomic, the protocol
642 // should understand that migratory sharing optimizations should not be
643 // performed (i.e. a load between the LL and SC should not steal away
644 // exclusive permission).
645 //
646 case RubyRequestType_Load_Linked:
647 case RubyRequestType_Store_Conditional:
648 case RubyRequestType_ATOMIC:
649 ctype = RubyRequestType_ATOMIC;
650 break;
651 default:
652 assert(0);
656 int proc_id = -1;
657 if (pkt != NULL && pkt->req->hasContextId()) {
658 proc_id = pkt->req->contextId();
653 }
654
659 }
660
655 RubyAccessMode amtype = RubyAccessMode_NUM;
656 switch(request.m_AccessMode){
657 case RubyAccessMode_User:
658 amtype = RubyAccessMode_User;
659 break;
660 case RubyAccessMode_Supervisor:
661 amtype = RubyAccessMode_Supervisor;
662 break;
663 case RubyAccessMode_Device:
664 amtype = RubyAccessMode_User;
665 break;
666 default:
667 assert(0);
661 // If valid, copy the pc to the ruby request
662 Addr pc = 0;
663 if (pkt->req->hasPC()) {
664 pc = pkt->req->getPC();
668 }
669
665 }
666
670 Address line_addr(request.m_PhysicalAddress);
671 line_addr.makeLineAddress();
672 int proc_id = -1;
673 if (request.pkt != NULL && request.pkt->req->hasContextId()) {
674 proc_id = request.pkt->req->contextId();
675 }
676 RubyRequest *msg = new RubyRequest(request.m_PhysicalAddress.getAddress(),
677 request.data, request.m_Size,
678 request.m_ProgramCounter.getAddress(),
679 ctype, amtype, request.pkt,
667 RubyRequest *msg = new RubyRequest(pkt->getAddr(),
668 pkt->getPtr<uint8_t>(true),
669 pkt->getSize(), pc, secondary_type,
670 RubyAccessMode_Supervisor, pkt,
680 PrefetchBit_No, proc_id);
681
682 DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\n",
683 curTick(), m_version, "Seq", "Begin", "", "",
671 PrefetchBit_No, proc_id);
672
673 DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\n",
674 curTick(), m_version, "Seq", "Begin", "", "",
684 request.m_PhysicalAddress, RubyRequestType_to_string(request.m_Type));
675 msg->getPhysicalAddress(),
676 RubyRequestType_to_string(secondary_type));
685
686 Time latency = 0; // initialzed to an null value
687
677
678 Time latency = 0; // initialzed to an null value
679
688 if (request.m_Type == RubyRequestType_IFETCH)
680 if (secondary_type == RubyRequestType_IFETCH)
689 latency = m_instCache_ptr->getLatency();
690 else
691 latency = m_dataCache_ptr->getLatency();
692
693 // Send the message to the cache controller
694 assert(latency > 0);
695
696 assert(m_mandatory_q_ptr != NULL);

--- 38 unchanged lines hidden ---
681 latency = m_instCache_ptr->getLatency();
682 else
683 latency = m_dataCache_ptr->getLatency();
684
685 // Send the message to the cache controller
686 assert(latency > 0);
687
688 assert(m_mandatory_q_ptr != NULL);

--- 38 unchanged lines hidden ---