Sequencer.hh revision 9104:27d56b644e78
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; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 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#ifndef __MEM_RUBY_SYSTEM_SEQUENCER_HH__ 30#define __MEM_RUBY_SYSTEM_SEQUENCER_HH__ 31 32#include <iostream> 33 34#include "base/hashmap.hh" 35#include "mem/protocol/GenericMachineType.hh" 36#include "mem/protocol/RubyRequestType.hh" 37#include "mem/protocol/SequencerRequestType.hh" 38#include "mem/ruby/common/Address.hh" 39#include "mem/ruby/common/Consumer.hh" 40#include "mem/ruby/system/RubyPort.hh" 41 42class DataBlock; 43class CacheMemory; 44 45struct RubySequencerParams; 46 47struct SequencerRequest 48{ 49 PacketPtr pkt; 50 RubyRequestType m_type; 51 Time issue_time; 52 53 SequencerRequest(PacketPtr _pkt, RubyRequestType _m_type, Time _issue_time) 54 : pkt(_pkt), m_type(_m_type), issue_time(_issue_time) 55 {} 56}; 57 58std::ostream& operator<<(std::ostream& out, const SequencerRequest& obj); 59 60class Sequencer : public RubyPort, public Consumer 61{ 62 public: 63 typedef RubySequencerParams Params; 64 Sequencer(const Params *); 65 ~Sequencer(); 66 67 // Public Methods 68 void wakeup(); // Used only for deadlock detection 69 70 void printConfig(std::ostream& out) const; 71 72 void printProgress(std::ostream& out) const; 73 74 void writeCallback(const Address& address, DataBlock& data); 75 76 void writeCallback(const Address& address, 77 GenericMachineType mach, 78 DataBlock& data); 79 80 void writeCallback(const Address& address, 81 GenericMachineType mach, 82 DataBlock& data, 83 Time initialRequestTime, 84 Time forwardRequestTime, 85 Time firstResponseTime); 86 87 void readCallback(const Address& address, DataBlock& data); 88 89 void readCallback(const Address& address, 90 GenericMachineType mach, 91 DataBlock& data); 92 93 void readCallback(const Address& address, 94 GenericMachineType mach, 95 DataBlock& data, 96 Time initialRequestTime, 97 Time forwardRequestTime, 98 Time firstResponseTime); 99 100 RequestStatus makeRequest(PacketPtr pkt); 101 bool empty() const; 102 int outstandingCount() const { return m_outstanding_count; } 103 bool 104 isDeadlockEventScheduled() const 105 { 106 return deadlockCheckEvent.scheduled(); 107 } 108 109 void 110 descheduleDeadlockEvent() 111 { 112 deschedule(deadlockCheckEvent); 113 } 114 115 void print(std::ostream& out) const; 116 void printStats(std::ostream& out) const; 117 void checkCoherence(const Address& address); 118 119 void markRemoved(); 120 void removeRequest(SequencerRequest* request); 121 void evictionCallback(const Address& address); 122 123 void recordRequestType(SequencerRequestType requestType); 124 125 private: 126 void issueRequest(PacketPtr pkt, RubyRequestType type); 127 128 void hitCallback(SequencerRequest* request, 129 GenericMachineType mach, 130 DataBlock& data, 131 bool success, 132 Time initialRequestTime, 133 Time forwardRequestTime, 134 Time firstResponseTime); 135 136 RequestStatus insertRequest(PacketPtr pkt, RubyRequestType request_type); 137 138 bool handleLlsc(const Address& address, SequencerRequest* request); 139 140 // Private copy constructor and assignment operator 141 Sequencer(const Sequencer& obj); 142 Sequencer& operator=(const Sequencer& obj); 143 144 private: 145 int m_max_outstanding_requests; 146 int m_deadlock_threshold; 147 148 CacheMemory* m_dataCache_ptr; 149 CacheMemory* m_instCache_ptr; 150 151 typedef m5::hash_map<Address, SequencerRequest*> RequestTable; 152 RequestTable m_writeRequestTable; 153 RequestTable m_readRequestTable; 154 // Global outstanding request count, across all request tables 155 int m_outstanding_count; 156 bool m_deadlock_check_scheduled; 157 158 int m_store_waiting_on_load_cycles; 159 int m_store_waiting_on_store_cycles; 160 int m_load_waiting_on_store_cycles; 161 int m_load_waiting_on_load_cycles; 162 163 bool m_usingNetworkTester; 164 165 class SequencerWakeupEvent : public Event 166 { 167 private: 168 Sequencer *m_sequencer_ptr; 169 170 public: 171 SequencerWakeupEvent(Sequencer *_seq) : m_sequencer_ptr(_seq) {} 172 void process() { m_sequencer_ptr->wakeup(); } 173 const char *description() const { return "Sequencer deadlock check"; } 174 }; 175 176 SequencerWakeupEvent deadlockCheckEvent; 177}; 178 179inline std::ostream& 180operator<<(std::ostream& out, const Sequencer& obj) 181{ 182 obj.print(out); 183 out << std::flush; 184 return out; 185} 186 187#endif // __MEM_RUBY_SYSTEM_SEQUENCER_HH__ 188