Sequencer.hh revision 8615
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com */ 2812855Sgabeblack@google.com 2912855Sgabeblack@google.com#ifndef __MEM_RUBY_SYSTEM_SEQUENCER_HH__ 3012855Sgabeblack@google.com#define __MEM_RUBY_SYSTEM_SEQUENCER_HH__ 3112855Sgabeblack@google.com 3212855Sgabeblack@google.com#include <iostream> 3312855Sgabeblack@google.com 3412855Sgabeblack@google.com#include "base/hashmap.hh" 3512855Sgabeblack@google.com#include "mem/protocol/GenericMachineType.hh" 3612855Sgabeblack@google.com#include "mem/protocol/RubyRequestType.hh" 3712855Sgabeblack@google.com#include "mem/ruby/common/Address.hh" 3812855Sgabeblack@google.com#include "mem/ruby/common/Consumer.hh" 3912855Sgabeblack@google.com#include "mem/ruby/system/RubyPort.hh" 4012855Sgabeblack@google.com 4112855Sgabeblack@google.comclass DataBlock; 4212855Sgabeblack@google.comclass CacheMsg; 4312855Sgabeblack@google.comclass MachineID; 4412855Sgabeblack@google.comclass CacheMemory; 4512855Sgabeblack@google.com 4612855Sgabeblack@google.comclass RubySequencerParams; 4712855Sgabeblack@google.com 4812855Sgabeblack@google.comstruct SequencerRequest 4912855Sgabeblack@google.com{ 5012855Sgabeblack@google.com PacketPtr pkt; 5112855Sgabeblack@google.com RubyRequestType m_type; 5212855Sgabeblack@google.com Time issue_time; 5312855Sgabeblack@google.com 5412855Sgabeblack@google.com SequencerRequest(PacketPtr _pkt, RubyRequestType _m_type, Time _issue_time) 5512855Sgabeblack@google.com : pkt(_pkt), m_type(_m_type), issue_time(_issue_time) 5612855Sgabeblack@google.com {} 5712855Sgabeblack@google.com}; 5812855Sgabeblack@google.com 5912855Sgabeblack@google.comstd::ostream& operator<<(std::ostream& out, const SequencerRequest& obj); 6012855Sgabeblack@google.com 6112855Sgabeblack@google.comclass Sequencer : public RubyPort, public Consumer 6212855Sgabeblack@google.com{ 6312855Sgabeblack@google.com public: 6412855Sgabeblack@google.com typedef RubySequencerParams Params; 65 Sequencer(const Params *); 66 ~Sequencer(); 67 68 // Public Methods 69 void wakeup(); // Used only for deadlock detection 70 71 void printConfig(std::ostream& out) const; 72 73 void printProgress(std::ostream& out) const; 74 75 void writeCallback(const Address& address, DataBlock& data); 76 77 void writeCallback(const Address& address, 78 GenericMachineType mach, 79 DataBlock& data); 80 81 void writeCallback(const Address& address, 82 GenericMachineType mach, 83 DataBlock& data, 84 Time initialRequestTime, 85 Time forwardRequestTime, 86 Time firstResponseTime); 87 88 void readCallback(const Address& address, DataBlock& data); 89 90 void readCallback(const Address& address, 91 GenericMachineType mach, 92 DataBlock& data); 93 94 void readCallback(const Address& address, 95 GenericMachineType mach, 96 DataBlock& data, 97 Time initialRequestTime, 98 Time forwardRequestTime, 99 Time firstResponseTime); 100 101 RequestStatus makeRequest(PacketPtr pkt); 102 bool empty() const; 103 104 void print(std::ostream& out) const; 105 void printStats(std::ostream& out) const; 106 void checkCoherence(const Address& address); 107 108 void markRemoved(); 109 void removeRequest(SequencerRequest* request); 110 111 private: 112 void issueRequest(PacketPtr pkt, RubyRequestType type); 113 114 void hitCallback(SequencerRequest* request, 115 GenericMachineType mach, 116 DataBlock& data, 117 bool success, 118 Time initialRequestTime, 119 Time forwardRequestTime, 120 Time firstResponseTime); 121 122 RequestStatus insertRequest(PacketPtr pkt, RubyRequestType request_type); 123 124 bool handleLlsc(const Address& address, SequencerRequest* request); 125 126 // Private copy constructor and assignment operator 127 Sequencer(const Sequencer& obj); 128 Sequencer& operator=(const Sequencer& obj); 129 130 private: 131 int m_max_outstanding_requests; 132 int m_deadlock_threshold; 133 134 CacheMemory* m_dataCache_ptr; 135 CacheMemory* m_instCache_ptr; 136 137 typedef m5::hash_map<Address, SequencerRequest*> RequestTable; 138 RequestTable m_writeRequestTable; 139 RequestTable m_readRequestTable; 140 // Global outstanding request count, across all request tables 141 int m_outstanding_count; 142 bool m_deadlock_check_scheduled; 143 144 int m_store_waiting_on_load_cycles; 145 int m_store_waiting_on_store_cycles; 146 int m_load_waiting_on_store_cycles; 147 int m_load_waiting_on_load_cycles; 148 149 bool m_usingNetworkTester; 150 151 class SequencerWakeupEvent : public Event 152 { 153 private: 154 Sequencer *m_sequencer_ptr; 155 156 public: 157 SequencerWakeupEvent(Sequencer *_seq) : m_sequencer_ptr(_seq) {} 158 void process() { m_sequencer_ptr->wakeup(); } 159 const char *description() const { return "Sequencer deadlock check"; } 160 }; 161 162 SequencerWakeupEvent deadlockCheckEvent; 163}; 164 165inline std::ostream& 166operator<<(std::ostream& out, const Sequencer& obj) 167{ 168 obj.print(out); 169 out << std::flush; 170 return out; 171} 172 173#endif // __MEM_RUBY_SYSTEM_SEQUENCER_HH__ 174 175