Sequencer.cc (7454:3a3e8e8cce1b) Sequencer.cc (7455:586f99bf0dc4)
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#include "base/str.hh"
30#include "cpu/rubytest/RubyTester.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;
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#include "base/str.hh"
30#include "cpu/rubytest/RubyTester.hh"
31#include "mem/gems_common/Map.hh"
32#include "mem/protocol/CacheMsg.hh"
33#include "mem/protocol/Protocol.hh"
34#include "mem/protocol/Protocol.hh"
35#include "mem/ruby/buffers/MessageBuffer.hh"
36#include "mem/ruby/common/Global.hh"
37#include "mem/ruby/common/SubBlock.hh"
38#include "mem/ruby/libruby.hh"
39#include "mem/ruby/profiler/Profiler.hh"
40#include "mem/ruby/recorder/Tracer.hh"
41#include "mem/ruby/slicc_interface/AbstractController.hh"
42#include "mem/ruby/system/CacheMemory.hh"
43#include "mem/ruby/system/Sequencer.hh"
44#include "mem/ruby/system/System.hh"
45#include "params/RubySequencer.hh"
46
47using namespace std;
48
49Sequencer *
50RubySequencerParams::create()
51{
52 return new Sequencer(this);
53}
54
55Sequencer::Sequencer(const Params *p)
56 : RubyPort(p), deadlockCheckEvent(this)
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
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;
74 m_usingRubyTester = p->using_ruby_tester;
75
76 assert(m_max_outstanding_requests > 0);
77 assert(m_deadlock_threshold > 0);
78 assert(m_instCache_ptr != NULL);
79 assert(m_dataCache_ptr != NULL);
80}
81
82Sequencer::~Sequencer()
83{
84}
85
86void
87Sequencer::wakeup()
88{
89 // Check for deadlock of any of the requests
90 Time current_time = g_eventQueue_ptr->getTime();
91
92 // Check across all outstanding requests
93 int total_outstanding = 0;
94
31#include "mem/protocol/CacheMsg.hh"
32#include "mem/protocol/Protocol.hh"
33#include "mem/protocol/Protocol.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/libruby.hh"
38#include "mem/ruby/profiler/Profiler.hh"
39#include "mem/ruby/recorder/Tracer.hh"
40#include "mem/ruby/slicc_interface/AbstractController.hh"
41#include "mem/ruby/system/CacheMemory.hh"
42#include "mem/ruby/system/Sequencer.hh"
43#include "mem/ruby/system/System.hh"
44#include "params/RubySequencer.hh"
45
46using namespace std;
47
48Sequencer *
49RubySequencerParams::create()
50{
51 return new Sequencer(this);
52}
53
54Sequencer::Sequencer(const Params *p)
55 : RubyPort(p), deadlockCheckEvent(this)
56{
57 m_store_waiting_on_load_cycles = 0;
58 m_store_waiting_on_store_cycles = 0;
59 m_load_waiting_on_store_cycles = 0;
60 m_load_waiting_on_load_cycles = 0;
61
62 m_outstanding_count = 0;
63
64 m_max_outstanding_requests = 0;
65 m_deadlock_threshold = 0;
66 m_instCache_ptr = NULL;
67 m_dataCache_ptr = NULL;
68
69 m_instCache_ptr = p->icache;
70 m_dataCache_ptr = p->dcache;
71 m_max_outstanding_requests = p->max_outstanding_requests;
72 m_deadlock_threshold = p->deadlock_threshold;
73 m_usingRubyTester = p->using_ruby_tester;
74
75 assert(m_max_outstanding_requests > 0);
76 assert(m_deadlock_threshold > 0);
77 assert(m_instCache_ptr != NULL);
78 assert(m_dataCache_ptr != NULL);
79}
80
81Sequencer::~Sequencer()
82{
83}
84
85void
86Sequencer::wakeup()
87{
88 // Check for deadlock of any of the requests
89 Time current_time = g_eventQueue_ptr->getTime();
90
91 // Check across all outstanding requests
92 int total_outstanding = 0;
93
95 std::vector<Address> keys = m_readRequestTable.keys();
96 for (int i = 0; i < keys.size(); i++) {
97 SequencerRequest* request = m_readRequestTable.lookup(keys[i]);
98 if (current_time - request->issue_time >= m_deadlock_threshold) {
99 WARN_MSG("Possible Deadlock detected");
100 WARN_EXPR(request);
101 WARN_EXPR(m_version);
102 WARN_EXPR(request->ruby_request.paddr);
103 WARN_EXPR(keys.size());
104 WARN_EXPR(current_time);
105 WARN_EXPR(request->issue_time);
106 WARN_EXPR(current_time - request->issue_time);
107 ERROR_MSG("Aborting");
108 }
94 RequestTable::iterator read = m_readRequestTable.begin();
95 RequestTable::iterator read_end = m_readRequestTable.end();
96 for (; read != read_end; ++read) {
97 SequencerRequest* request = read->second;
98 if (current_time - request->issue_time < m_deadlock_threshold)
99 continue;
100
101 WARN_MSG("Possible Deadlock detected");
102 WARN_EXPR(request);
103 WARN_EXPR(m_version);
104 WARN_EXPR(request->ruby_request.paddr);
105 WARN_EXPR(m_readRequestTable.size());
106 WARN_EXPR(current_time);
107 WARN_EXPR(request->issue_time);
108 WARN_EXPR(current_time - request->issue_time);
109 ERROR_MSG("Aborting");
109 }
110
110 }
111
111 keys = m_writeRequestTable.keys();
112 for (int i = 0; i < keys.size(); i++) {
113 SequencerRequest* request = m_writeRequestTable.lookup(keys[i]);
114 if (current_time - request->issue_time >= m_deadlock_threshold) {
115 WARN_MSG("Possible Deadlock detected");
116 WARN_EXPR(request);
117 WARN_EXPR(m_version);
118 WARN_EXPR(current_time);
119 WARN_EXPR(request->issue_time);
120 WARN_EXPR(current_time - request->issue_time);
121 WARN_EXPR(keys.size());
122 ERROR_MSG("Aborting");
123 }
112 RequestTable::iterator write = m_writeRequestTable.begin();
113 RequestTable::iterator write_end = m_writeRequestTable.end();
114 for (; write != write_end; ++write) {
115 SequencerRequest* request = write->second;
116 if (current_time - request->issue_time < m_deadlock_threshold)
117 continue;
118
119 WARN_MSG("Possible Deadlock detected");
120 WARN_EXPR(request);
121 WARN_EXPR(m_version);
122 WARN_EXPR(current_time);
123 WARN_EXPR(request->issue_time);
124 WARN_EXPR(current_time - request->issue_time);
125 WARN_EXPR(m_writeRequestTable.size());
126 ERROR_MSG("Aborting");
124 }
125
126 total_outstanding += m_writeRequestTable.size();
127 total_outstanding += m_readRequestTable.size();
128
129 assert(m_outstanding_count == total_outstanding);
130
131 if (m_outstanding_count > 0) {
132 // If there are still outstanding requests, keep checking
133 schedule(deadlockCheckEvent,
134 m_deadlock_threshold * g_eventQueue_ptr->getClock() +
135 curTick);
136 }
137}
138
139void
140Sequencer::printStats(ostream & out) const
141{
142 out << "Sequencer: " << m_name << endl
143 << " store_waiting_on_load_cycles: "
144 << m_store_waiting_on_load_cycles << endl
145 << " store_waiting_on_store_cycles: "
146 << m_store_waiting_on_store_cycles << endl
147 << " load_waiting_on_load_cycles: "
148 << m_load_waiting_on_load_cycles << endl
149 << " load_waiting_on_store_cycles: "
150 << m_load_waiting_on_store_cycles << endl;
151}
152
153void
154Sequencer::printProgress(ostream& out) const
155{
156#if 0
157 int total_demand = 0;
158 out << "Sequencer Stats Version " << m_version << endl;
159 out << "Current time = " << g_eventQueue_ptr->getTime() << endl;
160 out << "---------------" << endl;
161 out << "outstanding requests" << endl;
162
127 }
128
129 total_outstanding += m_writeRequestTable.size();
130 total_outstanding += m_readRequestTable.size();
131
132 assert(m_outstanding_count == total_outstanding);
133
134 if (m_outstanding_count > 0) {
135 // If there are still outstanding requests, keep checking
136 schedule(deadlockCheckEvent,
137 m_deadlock_threshold * g_eventQueue_ptr->getClock() +
138 curTick);
139 }
140}
141
142void
143Sequencer::printStats(ostream & out) const
144{
145 out << "Sequencer: " << m_name << endl
146 << " store_waiting_on_load_cycles: "
147 << m_store_waiting_on_load_cycles << endl
148 << " store_waiting_on_store_cycles: "
149 << m_store_waiting_on_store_cycles << endl
150 << " load_waiting_on_load_cycles: "
151 << m_load_waiting_on_load_cycles << endl
152 << " load_waiting_on_store_cycles: "
153 << m_load_waiting_on_store_cycles << endl;
154}
155
156void
157Sequencer::printProgress(ostream& out) const
158{
159#if 0
160 int total_demand = 0;
161 out << "Sequencer Stats Version " << m_version << endl;
162 out << "Current time = " << g_eventQueue_ptr->getTime() << endl;
163 out << "---------------" << endl;
164 out << "outstanding requests" << endl;
165
163 std::vector<Address> rkeys = m_readRequestTable.keys();
164 int read_size = rkeys.size();
165 out << "proc " << m_version << " Read Requests = " << read_size << endl;
166 out << "proc " << m_Read
167 << " version Requests = " << m_readRequestTable.size() << endl;
166
167 // print the request table
168
169 // print the request table
168 for (int i = 0; i < read_size; ++i) {
169 SequencerRequest *request = m_readRequestTable.lookup(rkeys[i]);
170 RequestTable::iterator read = m_readRequestTable.begin();
171 RequestTable::iterator read_end = m_readRequestTable.end();
172 for (; read != read_end; ++read) {
173 SequencerRequest* request = read->second;
170 out << "\tRequest[ " << i << " ] = " << request->type
171 << " Address " << rkeys[i]
172 << " Posted " << request->issue_time
173 << " PF " << PrefetchBit_No << endl;
174 total_demand++;
175 }
176
174 out << "\tRequest[ " << i << " ] = " << request->type
175 << " Address " << rkeys[i]
176 << " Posted " << request->issue_time
177 << " PF " << PrefetchBit_No << endl;
178 total_demand++;
179 }
180
177 std::vector<Address> wkeys = m_writeRequestTable.keys();
178 int write_size = wkeys.size();
179 out << "proc " << m_version << " Write Requests = " << write_size << endl;
181 out << "proc " << m_version
182 << " Write Requests = " << m_writeRequestTable.size << endl;
180
181 // print the request table
183
184 // print the request table
182 for (int i = 0; i < write_size; ++i){
183 CacheMsg &request = m_writeRequestTable.lookup(wkeys[i]);
185 RequestTable::iterator write = m_writeRequestTable.begin();
186 RequestTable::iterator write_end = m_writeRequestTable.end();
187 for (; write != write_end; ++write) {
188 SequencerRequest* request = write->second;
184 out << "\tRequest[ " << i << " ] = " << request.getType()
185 << " Address " << wkeys[i]
186 << " Posted " << request.getTime()
187 << " PF " << request.getPrefetch() << endl;
188 if (request.getPrefetch() == PrefetchBit_No) {
189 total_demand++;
190 }
191 }
192
193 out << endl;
194
195 out << "Total Number Outstanding: " << m_outstanding_count << endl
196 << "Total Number Demand : " << total_demand << endl
197 << "Total Number Prefetches : " << m_outstanding_count - total_demand
198 << endl << endl << endl;
199#endif
200}
201
202void
203Sequencer::printConfig(ostream& out) const
204{
205 out << "Seqeuncer config: " << m_name << endl
206 << " controller: " << m_controller->getName() << endl
207 << " version: " << m_version << endl
208 << " max_outstanding_requests: " << m_max_outstanding_requests << endl
209 << " deadlock_threshold: " << m_deadlock_threshold << endl;
210}
211
212// Insert the request on the correct request table. Return true if
213// the entry was already present.
214bool
215Sequencer::insertRequest(SequencerRequest* request)
216{
217 int total_outstanding =
218 m_writeRequestTable.size() + m_readRequestTable.size();
219
220 assert(m_outstanding_count == total_outstanding);
221
222 // See if we should schedule a deadlock check
223 if (deadlockCheckEvent.scheduled() == false) {
224 schedule(deadlockCheckEvent, m_deadlock_threshold + curTick);
225 }
226
227 Address line_addr(request->ruby_request.paddr);
228 line_addr.makeLineAddress();
229 if ((request->ruby_request.type == RubyRequestType_ST) ||
230 (request->ruby_request.type == RubyRequestType_RMW_Read) ||
231 (request->ruby_request.type == RubyRequestType_RMW_Write) ||
232 (request->ruby_request.type == RubyRequestType_Locked_Read) ||
233 (request->ruby_request.type == RubyRequestType_Locked_Write)) {
189 out << "\tRequest[ " << i << " ] = " << request.getType()
190 << " Address " << wkeys[i]
191 << " Posted " << request.getTime()
192 << " PF " << request.getPrefetch() << endl;
193 if (request.getPrefetch() == PrefetchBit_No) {
194 total_demand++;
195 }
196 }
197
198 out << endl;
199
200 out << "Total Number Outstanding: " << m_outstanding_count << endl
201 << "Total Number Demand : " << total_demand << endl
202 << "Total Number Prefetches : " << m_outstanding_count - total_demand
203 << endl << endl << endl;
204#endif
205}
206
207void
208Sequencer::printConfig(ostream& out) const
209{
210 out << "Seqeuncer config: " << m_name << endl
211 << " controller: " << m_controller->getName() << endl
212 << " version: " << m_version << endl
213 << " max_outstanding_requests: " << m_max_outstanding_requests << endl
214 << " deadlock_threshold: " << m_deadlock_threshold << endl;
215}
216
217// Insert the request on the correct request table. Return true if
218// the entry was already present.
219bool
220Sequencer::insertRequest(SequencerRequest* request)
221{
222 int total_outstanding =
223 m_writeRequestTable.size() + m_readRequestTable.size();
224
225 assert(m_outstanding_count == total_outstanding);
226
227 // See if we should schedule a deadlock check
228 if (deadlockCheckEvent.scheduled() == false) {
229 schedule(deadlockCheckEvent, m_deadlock_threshold + curTick);
230 }
231
232 Address line_addr(request->ruby_request.paddr);
233 line_addr.makeLineAddress();
234 if ((request->ruby_request.type == RubyRequestType_ST) ||
235 (request->ruby_request.type == RubyRequestType_RMW_Read) ||
236 (request->ruby_request.type == RubyRequestType_RMW_Write) ||
237 (request->ruby_request.type == RubyRequestType_Locked_Read) ||
238 (request->ruby_request.type == RubyRequestType_Locked_Write)) {
234 if (m_writeRequestTable.exist(line_addr)) {
235 m_writeRequestTable.lookup(line_addr) = request;
239 pair<RequestTable::iterator, bool> r =
240 m_writeRequestTable.insert(RequestTable::value_type(line_addr, 0));
241 bool success = r.second;
242 RequestTable::iterator i = r.first;
243 if (!success) {
244 i->second = request;
236 // return true;
237
238 // drh5: isn't this an error? do you lose the initial request?
239 assert(0);
240 }
245 // return true;
246
247 // drh5: isn't this an error? do you lose the initial request?
248 assert(0);
249 }
241 m_writeRequestTable.allocate(line_addr);
242 m_writeRequestTable.lookup(line_addr) = request;
250 i->second = request;
243 m_outstanding_count++;
244 } else {
251 m_outstanding_count++;
252 } else {
245 if (m_readRequestTable.exist(line_addr)) {
246 m_readRequestTable.lookup(line_addr) = request;
253 pair<RequestTable::iterator, bool> r =
254 m_readRequestTable.insert(RequestTable::value_type(line_addr, 0));
255 bool success = r.second;
256 RequestTable::iterator i = r.first;
257 if (!success) {
258 i->second = request;
247 // return true;
248
249 // drh5: isn't this an error? do you lose the initial request?
250 assert(0);
251 }
259 // return true;
260
261 // drh5: isn't this an error? do you lose the initial request?
262 assert(0);
263 }
252 m_readRequestTable.allocate(line_addr);
253 m_readRequestTable.lookup(line_addr) = request;
264 i->second = request;
254 m_outstanding_count++;
255 }
256
257 g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count);
258
259 total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size();
260 assert(m_outstanding_count == total_outstanding);
261
262 return false;
263}
264
265void
265 m_outstanding_count++;
266 }
267
268 g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count);
269
270 total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size();
271 assert(m_outstanding_count == total_outstanding);
272
273 return false;
274}
275
276void
277Sequencer::markRemoved()
278{
279 m_outstanding_count--;
280 assert(m_outstanding_count ==
281 m_writeRequestTable.size() + m_readRequestTable.size());
282}
283
284void
266Sequencer::removeRequest(SequencerRequest* srequest)
267{
268 assert(m_outstanding_count ==
269 m_writeRequestTable.size() + m_readRequestTable.size());
270
271 const RubyRequest & ruby_request = srequest->ruby_request;
272 Address line_addr(ruby_request.paddr);
273 line_addr.makeLineAddress();
274 if ((ruby_request.type == RubyRequestType_ST) ||
275 (ruby_request.type == RubyRequestType_RMW_Read) ||
276 (ruby_request.type == RubyRequestType_RMW_Write) ||
277 (ruby_request.type == RubyRequestType_Locked_Read) ||
278 (ruby_request.type == RubyRequestType_Locked_Write)) {
285Sequencer::removeRequest(SequencerRequest* srequest)
286{
287 assert(m_outstanding_count ==
288 m_writeRequestTable.size() + m_readRequestTable.size());
289
290 const RubyRequest & ruby_request = srequest->ruby_request;
291 Address line_addr(ruby_request.paddr);
292 line_addr.makeLineAddress();
293 if ((ruby_request.type == RubyRequestType_ST) ||
294 (ruby_request.type == RubyRequestType_RMW_Read) ||
295 (ruby_request.type == RubyRequestType_RMW_Write) ||
296 (ruby_request.type == RubyRequestType_Locked_Read) ||
297 (ruby_request.type == RubyRequestType_Locked_Write)) {
279 m_writeRequestTable.deallocate(line_addr);
298 m_writeRequestTable.erase(line_addr);
280 } else {
299 } else {
281 m_readRequestTable.deallocate(line_addr);
300 m_readRequestTable.erase(line_addr);
282 }
301 }
283 m_outstanding_count--;
284
302
285 assert(m_outstanding_count == m_writeRequestTable.size() + m_readRequestTable.size());
303 markRemoved();
286}
287
288void
289Sequencer::writeCallback(const Address& address, DataBlock& data)
290{
291 assert(address == line_address(address));
304}
305
306void
307Sequencer::writeCallback(const Address& address, DataBlock& data)
308{
309 assert(address == line_address(address));
292 assert(m_writeRequestTable.exist(line_address(address)));
310 assert(m_writeRequestTable.count(line_address(address)));
293
311
294 SequencerRequest* request = m_writeRequestTable.lookup(address);
312 RequestTable::iterator i = m_writeRequestTable.find(address);
313 assert(i != m_writeRequestTable.end());
314 SequencerRequest* request = i->second;
295
315
296 removeRequest(request);
316 m_writeRequestTable.erase(i);
317 markRemoved();
297
298 assert((request->ruby_request.type == RubyRequestType_ST) ||
299 (request->ruby_request.type == RubyRequestType_RMW_Read) ||
300 (request->ruby_request.type == RubyRequestType_RMW_Write) ||
301 (request->ruby_request.type == RubyRequestType_Locked_Read) ||
302 (request->ruby_request.type == RubyRequestType_Locked_Write));
303
304 if (request->ruby_request.type == RubyRequestType_Locked_Read) {
305 m_dataCache_ptr->setLocked(address, m_version);
306 } else if (request->ruby_request.type == RubyRequestType_RMW_Read) {
307 m_controller->blockOnQueue(address, m_mandatory_q_ptr);
308 } else if (request->ruby_request.type == RubyRequestType_RMW_Write) {
309 m_controller->unblock(address);
310 }
311
312 hitCallback(request, data);
313}
314
315void
316Sequencer::readCallback(const Address& address, DataBlock& data)
317{
318 assert(address == line_address(address));
318
319 assert((request->ruby_request.type == RubyRequestType_ST) ||
320 (request->ruby_request.type == RubyRequestType_RMW_Read) ||
321 (request->ruby_request.type == RubyRequestType_RMW_Write) ||
322 (request->ruby_request.type == RubyRequestType_Locked_Read) ||
323 (request->ruby_request.type == RubyRequestType_Locked_Write));
324
325 if (request->ruby_request.type == RubyRequestType_Locked_Read) {
326 m_dataCache_ptr->setLocked(address, m_version);
327 } else if (request->ruby_request.type == RubyRequestType_RMW_Read) {
328 m_controller->blockOnQueue(address, m_mandatory_q_ptr);
329 } else if (request->ruby_request.type == RubyRequestType_RMW_Write) {
330 m_controller->unblock(address);
331 }
332
333 hitCallback(request, data);
334}
335
336void
337Sequencer::readCallback(const Address& address, DataBlock& data)
338{
339 assert(address == line_address(address));
319 assert(m_readRequestTable.exist(line_address(address)));
340 assert(m_readRequestTable.count(line_address(address)));
320
341
321 SequencerRequest* request = m_readRequestTable.lookup(address);
322 removeRequest(request);
342 RequestTable::iterator i = m_readRequestTable.find(address);
343 assert(i != m_readRequestTable.end());
344 SequencerRequest* request = i->second;
323
345
346 m_readRequestTable.erase(i);
347 markRemoved();
348
324 assert((request->ruby_request.type == RubyRequestType_LD) ||
325 (request->ruby_request.type == RubyRequestType_RMW_Read) ||
326 (request->ruby_request.type == RubyRequestType_IFETCH));
327
328 hitCallback(request, data);
329}
330
331void
332Sequencer::hitCallback(SequencerRequest* srequest, DataBlock& data)
333{
334 const RubyRequest & ruby_request = srequest->ruby_request;
335 Address request_address(ruby_request.paddr);
336 Address request_line_address(ruby_request.paddr);
337 request_line_address.makeLineAddress();
338 RubyRequestType type = ruby_request.type;
339 Time issued_time = srequest->issue_time;
340
341 // Set this cache entry to the most recently used
342 if (type == RubyRequestType_IFETCH) {
343 if (m_instCache_ptr->isTagPresent(request_line_address))
344 m_instCache_ptr->setMRU(request_line_address);
345 } else {
346 if (m_dataCache_ptr->isTagPresent(request_line_address))
347 m_dataCache_ptr->setMRU(request_line_address);
348 }
349
350 assert(g_eventQueue_ptr->getTime() >= issued_time);
351 Time miss_latency = g_eventQueue_ptr->getTime() - issued_time;
352
353 // Profile the miss latency for all non-zero demand misses
354 if (miss_latency != 0) {
355 g_system_ptr->getProfiler()->missLatency(miss_latency, type);
356
357 if (Debug::getProtocolTrace()) {
358 g_system_ptr->getProfiler()->
359 profileTransition("Seq", m_version,
360 Address(ruby_request.paddr), "", "Done", "",
361 csprintf("%d cycles", miss_latency));
362 }
363 }
364#if 0
365 if (request.getPrefetch() == PrefetchBit_Yes) {
366 return; // Ignore the prefetch
367 }
368#endif
369
370 // update the data
371 if (ruby_request.data != NULL) {
372 if ((type == RubyRequestType_LD) ||
373 (type == RubyRequestType_IFETCH) ||
374 (type == RubyRequestType_RMW_Read) ||
375 (type == RubyRequestType_Locked_Read)) {
376
377 memcpy(ruby_request.data,
378 data.getData(request_address.getOffset(), ruby_request.len),
379 ruby_request.len);
380 } else {
381 data.setData(ruby_request.data, request_address.getOffset(),
382 ruby_request.len);
383 }
384 } else {
385 DPRINTF(MemoryAccess,
386 "WARNING. Data not transfered from Ruby to M5 for type %s\n",
387 RubyRequestType_to_string(type));
388 }
389
390 // If using the RubyTester, update the RubyTester sender state's
391 // subBlock with the recieved data. The tester will later access
392 // this state.
393 // Note: RubyPort will access it's sender state before the
394 // RubyTester.
395 if (m_usingRubyTester) {
396 RubyPort::SenderState *requestSenderState =
397 safe_cast<RubyPort::SenderState*>(ruby_request.pkt->senderState);
398 RubyTester::SenderState* testerSenderState =
399 safe_cast<RubyTester::SenderState*>(requestSenderState->saved);
400 testerSenderState->subBlock->mergeFrom(data);
401 }
402
403 ruby_hit_callback(ruby_request.pkt);
404 delete srequest;
405}
406
407// Returns true if the sequencer already has a load or store outstanding
408RequestStatus
409Sequencer::getRequestStatus(const RubyRequest& request)
410{
411 bool is_outstanding_store =
349 assert((request->ruby_request.type == RubyRequestType_LD) ||
350 (request->ruby_request.type == RubyRequestType_RMW_Read) ||
351 (request->ruby_request.type == RubyRequestType_IFETCH));
352
353 hitCallback(request, data);
354}
355
356void
357Sequencer::hitCallback(SequencerRequest* srequest, DataBlock& data)
358{
359 const RubyRequest & ruby_request = srequest->ruby_request;
360 Address request_address(ruby_request.paddr);
361 Address request_line_address(ruby_request.paddr);
362 request_line_address.makeLineAddress();
363 RubyRequestType type = ruby_request.type;
364 Time issued_time = srequest->issue_time;
365
366 // Set this cache entry to the most recently used
367 if (type == RubyRequestType_IFETCH) {
368 if (m_instCache_ptr->isTagPresent(request_line_address))
369 m_instCache_ptr->setMRU(request_line_address);
370 } else {
371 if (m_dataCache_ptr->isTagPresent(request_line_address))
372 m_dataCache_ptr->setMRU(request_line_address);
373 }
374
375 assert(g_eventQueue_ptr->getTime() >= issued_time);
376 Time miss_latency = g_eventQueue_ptr->getTime() - issued_time;
377
378 // Profile the miss latency for all non-zero demand misses
379 if (miss_latency != 0) {
380 g_system_ptr->getProfiler()->missLatency(miss_latency, type);
381
382 if (Debug::getProtocolTrace()) {
383 g_system_ptr->getProfiler()->
384 profileTransition("Seq", m_version,
385 Address(ruby_request.paddr), "", "Done", "",
386 csprintf("%d cycles", miss_latency));
387 }
388 }
389#if 0
390 if (request.getPrefetch() == PrefetchBit_Yes) {
391 return; // Ignore the prefetch
392 }
393#endif
394
395 // update the data
396 if (ruby_request.data != NULL) {
397 if ((type == RubyRequestType_LD) ||
398 (type == RubyRequestType_IFETCH) ||
399 (type == RubyRequestType_RMW_Read) ||
400 (type == RubyRequestType_Locked_Read)) {
401
402 memcpy(ruby_request.data,
403 data.getData(request_address.getOffset(), ruby_request.len),
404 ruby_request.len);
405 } else {
406 data.setData(ruby_request.data, request_address.getOffset(),
407 ruby_request.len);
408 }
409 } else {
410 DPRINTF(MemoryAccess,
411 "WARNING. Data not transfered from Ruby to M5 for type %s\n",
412 RubyRequestType_to_string(type));
413 }
414
415 // If using the RubyTester, update the RubyTester sender state's
416 // subBlock with the recieved data. The tester will later access
417 // this state.
418 // Note: RubyPort will access it's sender state before the
419 // RubyTester.
420 if (m_usingRubyTester) {
421 RubyPort::SenderState *requestSenderState =
422 safe_cast<RubyPort::SenderState*>(ruby_request.pkt->senderState);
423 RubyTester::SenderState* testerSenderState =
424 safe_cast<RubyTester::SenderState*>(requestSenderState->saved);
425 testerSenderState->subBlock->mergeFrom(data);
426 }
427
428 ruby_hit_callback(ruby_request.pkt);
429 delete srequest;
430}
431
432// Returns true if the sequencer already has a load or store outstanding
433RequestStatus
434Sequencer::getRequestStatus(const RubyRequest& request)
435{
436 bool is_outstanding_store =
412 m_writeRequestTable.exist(line_address(Address(request.paddr)));
437 !!m_writeRequestTable.count(line_address(Address(request.paddr)));
413 bool is_outstanding_load =
438 bool is_outstanding_load =
414 m_readRequestTable.exist(line_address(Address(request.paddr)));
439 !!m_readRequestTable.count(line_address(Address(request.paddr)));
415 if (is_outstanding_store) {
416 if ((request.type == RubyRequestType_LD) ||
417 (request.type == RubyRequestType_IFETCH) ||
418 (request.type == RubyRequestType_RMW_Read)) {
419 m_store_waiting_on_load_cycles++;
420 } else {
421 m_store_waiting_on_store_cycles++;
422 }
423 return RequestStatus_Aliased;
424 } else if (is_outstanding_load) {
425 if ((request.type == RubyRequestType_ST) ||
426 (request.type == RubyRequestType_RMW_Write)) {
427 m_load_waiting_on_store_cycles++;
428 } else {
429 m_load_waiting_on_load_cycles++;
430 }
431 return RequestStatus_Aliased;
432 }
433
434 if (m_outstanding_count >= m_max_outstanding_requests) {
435 return RequestStatus_BufferFull;
436 }
437
438 return RequestStatus_Ready;
439}
440
441bool
442Sequencer::empty() const
443{
440 if (is_outstanding_store) {
441 if ((request.type == RubyRequestType_LD) ||
442 (request.type == RubyRequestType_IFETCH) ||
443 (request.type == RubyRequestType_RMW_Read)) {
444 m_store_waiting_on_load_cycles++;
445 } else {
446 m_store_waiting_on_store_cycles++;
447 }
448 return RequestStatus_Aliased;
449 } else if (is_outstanding_load) {
450 if ((request.type == RubyRequestType_ST) ||
451 (request.type == RubyRequestType_RMW_Write)) {
452 m_load_waiting_on_store_cycles++;
453 } else {
454 m_load_waiting_on_load_cycles++;
455 }
456 return RequestStatus_Aliased;
457 }
458
459 if (m_outstanding_count >= m_max_outstanding_requests) {
460 return RequestStatus_BufferFull;
461 }
462
463 return RequestStatus_Ready;
464}
465
466bool
467Sequencer::empty() const
468{
444 return m_writeRequestTable.size() == 0 && m_readRequestTable.size() == 0;
469 return m_writeRequestTable.empty() && m_readRequestTable.empty();
445}
446
447RequestStatus
448Sequencer::makeRequest(const RubyRequest &request)
449{
450 assert(Address(request.paddr).getOffset() + request.len <=
451 RubySystem::getBlockSizeBytes());
452 RequestStatus status = getRequestStatus(request);
453 if (status != RequestStatus_Ready)
454 return status;
455
456 SequencerRequest *srequest =
457 new SequencerRequest(request, g_eventQueue_ptr->getTime());
458 bool found = insertRequest(srequest);
459 if (found) {
460 panic("Sequencer::makeRequest should never be called if the "
461 "request is already outstanding\n");
462 return RequestStatus_NULL;
463 }
464
465 if (request.type == RubyRequestType_Locked_Write) {
466 // NOTE: it is OK to check the locked flag here as the
467 // mandatory queue will be checked first ensuring that nothing
468 // comes between checking the flag and servicing the store.
469
470 Address line_addr = line_address(Address(request.paddr));
471 if (!m_dataCache_ptr->isLocked(line_addr, m_version)) {
472 removeRequest(srequest);
473 if (Debug::getProtocolTrace()) {
474 g_system_ptr->getProfiler()->
475 profileTransition("Seq", m_version,
476 Address(request.paddr),
477 "", "SC Fail", "",
478 RubyRequestType_to_string(request.type));
479 }
480 return RequestStatus_LlscFailed;
481 } else {
482 m_dataCache_ptr->clearLocked(line_addr);
483 }
484 }
485 issueRequest(request);
486
487 // TODO: issue hardware prefetches here
488 return RequestStatus_Issued;
489}
490
491void
492Sequencer::issueRequest(const RubyRequest& request)
493{
494 // TODO: get rid of CacheMsg, CacheRequestType, and
495 // AccessModeTYpe, & have SLICC use RubyRequest and subtypes
496 // natively
497 CacheRequestType ctype;
498 switch(request.type) {
499 case RubyRequestType_IFETCH:
500 ctype = CacheRequestType_IFETCH;
501 break;
502 case RubyRequestType_LD:
503 ctype = CacheRequestType_LD;
504 break;
505 case RubyRequestType_ST:
506 ctype = CacheRequestType_ST;
507 break;
508 case RubyRequestType_Locked_Read:
509 case RubyRequestType_Locked_Write:
510 ctype = CacheRequestType_ATOMIC;
511 break;
512 case RubyRequestType_RMW_Read:
513 ctype = CacheRequestType_ATOMIC;
514 break;
515 case RubyRequestType_RMW_Write:
516 ctype = CacheRequestType_ATOMIC;
517 break;
518 default:
519 assert(0);
520 }
521
522 AccessModeType amtype;
523 switch(request.access_mode){
524 case RubyAccessMode_User:
525 amtype = AccessModeType_UserMode;
526 break;
527 case RubyAccessMode_Supervisor:
528 amtype = AccessModeType_SupervisorMode;
529 break;
530 case RubyAccessMode_Device:
531 amtype = AccessModeType_UserMode;
532 break;
533 default:
534 assert(0);
535 }
536
537 Address line_addr(request.paddr);
538 line_addr.makeLineAddress();
539 CacheMsg *msg = new CacheMsg(line_addr, Address(request.paddr), ctype,
540 Address(request.pc), amtype, request.len, PrefetchBit_No,
541 request.proc_id);
542
543 if (Debug::getProtocolTrace()) {
544 g_system_ptr->getProfiler()->
545 profileTransition("Seq", m_version, Address(request.paddr),
546 "", "Begin", "",
547 RubyRequestType_to_string(request.type));
548 }
549
550 if (g_system_ptr->getTracer()->traceEnabled()) {
551 g_system_ptr->getTracer()->
552 traceRequest(this, line_addr, Address(request.pc),
553 request.type, g_eventQueue_ptr->getTime());
554 }
555
556 Time latency = 0; // initialzed to an null value
557
558 if (request.type == RubyRequestType_IFETCH)
559 latency = m_instCache_ptr->getLatency();
560 else
561 latency = m_dataCache_ptr->getLatency();
562
563 // Send the message to the cache controller
564 assert(latency > 0);
565
566 assert(m_mandatory_q_ptr != NULL);
567 m_mandatory_q_ptr->enqueue(msg, latency);
568}
569
570#if 0
571bool
572Sequencer::tryCacheAccess(const Address& addr, CacheRequestType type,
573 AccessModeType access_mode,
574 int size, DataBlock*& data_ptr)
575{
576 CacheMemory *cache =
577 (type == CacheRequestType_IFETCH) ? m_instCache_ptr : m_dataCache_ptr;
578
579 return cache->tryCacheAccess(line_address(addr), type, data_ptr);
580}
581#endif
582
470}
471
472RequestStatus
473Sequencer::makeRequest(const RubyRequest &request)
474{
475 assert(Address(request.paddr).getOffset() + request.len <=
476 RubySystem::getBlockSizeBytes());
477 RequestStatus status = getRequestStatus(request);
478 if (status != RequestStatus_Ready)
479 return status;
480
481 SequencerRequest *srequest =
482 new SequencerRequest(request, g_eventQueue_ptr->getTime());
483 bool found = insertRequest(srequest);
484 if (found) {
485 panic("Sequencer::makeRequest should never be called if the "
486 "request is already outstanding\n");
487 return RequestStatus_NULL;
488 }
489
490 if (request.type == RubyRequestType_Locked_Write) {
491 // NOTE: it is OK to check the locked flag here as the
492 // mandatory queue will be checked first ensuring that nothing
493 // comes between checking the flag and servicing the store.
494
495 Address line_addr = line_address(Address(request.paddr));
496 if (!m_dataCache_ptr->isLocked(line_addr, m_version)) {
497 removeRequest(srequest);
498 if (Debug::getProtocolTrace()) {
499 g_system_ptr->getProfiler()->
500 profileTransition("Seq", m_version,
501 Address(request.paddr),
502 "", "SC Fail", "",
503 RubyRequestType_to_string(request.type));
504 }
505 return RequestStatus_LlscFailed;
506 } else {
507 m_dataCache_ptr->clearLocked(line_addr);
508 }
509 }
510 issueRequest(request);
511
512 // TODO: issue hardware prefetches here
513 return RequestStatus_Issued;
514}
515
516void
517Sequencer::issueRequest(const RubyRequest& request)
518{
519 // TODO: get rid of CacheMsg, CacheRequestType, and
520 // AccessModeTYpe, & have SLICC use RubyRequest and subtypes
521 // natively
522 CacheRequestType ctype;
523 switch(request.type) {
524 case RubyRequestType_IFETCH:
525 ctype = CacheRequestType_IFETCH;
526 break;
527 case RubyRequestType_LD:
528 ctype = CacheRequestType_LD;
529 break;
530 case RubyRequestType_ST:
531 ctype = CacheRequestType_ST;
532 break;
533 case RubyRequestType_Locked_Read:
534 case RubyRequestType_Locked_Write:
535 ctype = CacheRequestType_ATOMIC;
536 break;
537 case RubyRequestType_RMW_Read:
538 ctype = CacheRequestType_ATOMIC;
539 break;
540 case RubyRequestType_RMW_Write:
541 ctype = CacheRequestType_ATOMIC;
542 break;
543 default:
544 assert(0);
545 }
546
547 AccessModeType amtype;
548 switch(request.access_mode){
549 case RubyAccessMode_User:
550 amtype = AccessModeType_UserMode;
551 break;
552 case RubyAccessMode_Supervisor:
553 amtype = AccessModeType_SupervisorMode;
554 break;
555 case RubyAccessMode_Device:
556 amtype = AccessModeType_UserMode;
557 break;
558 default:
559 assert(0);
560 }
561
562 Address line_addr(request.paddr);
563 line_addr.makeLineAddress();
564 CacheMsg *msg = new CacheMsg(line_addr, Address(request.paddr), ctype,
565 Address(request.pc), amtype, request.len, PrefetchBit_No,
566 request.proc_id);
567
568 if (Debug::getProtocolTrace()) {
569 g_system_ptr->getProfiler()->
570 profileTransition("Seq", m_version, Address(request.paddr),
571 "", "Begin", "",
572 RubyRequestType_to_string(request.type));
573 }
574
575 if (g_system_ptr->getTracer()->traceEnabled()) {
576 g_system_ptr->getTracer()->
577 traceRequest(this, line_addr, Address(request.pc),
578 request.type, g_eventQueue_ptr->getTime());
579 }
580
581 Time latency = 0; // initialzed to an null value
582
583 if (request.type == RubyRequestType_IFETCH)
584 latency = m_instCache_ptr->getLatency();
585 else
586 latency = m_dataCache_ptr->getLatency();
587
588 // Send the message to the cache controller
589 assert(latency > 0);
590
591 assert(m_mandatory_q_ptr != NULL);
592 m_mandatory_q_ptr->enqueue(msg, latency);
593}
594
595#if 0
596bool
597Sequencer::tryCacheAccess(const Address& addr, CacheRequestType type,
598 AccessModeType access_mode,
599 int size, DataBlock*& data_ptr)
600{
601 CacheMemory *cache =
602 (type == CacheRequestType_IFETCH) ? m_instCache_ptr : m_dataCache_ptr;
603
604 return cache->tryCacheAccess(line_address(addr), type, data_ptr);
605}
606#endif
607
608template <class KEY, class VALUE>
609std::ostream &
610operator<<(ostream &out, const m5::hash_map<KEY, VALUE> &map)
611{
612 typename m5::hash_map<KEY, VALUE>::const_iterator i = map.begin();
613 typename m5::hash_map<KEY, VALUE>::const_iterator end = map.end();
614
615 out << "[";
616 for (; i != end; ++i)
617 out << " " << i->first << "=" << i->second;
618 out << " ]";
619
620 return out;
621}
622
583void
584Sequencer::print(ostream& out) const
585{
586 out << "[Sequencer: " << m_version
587 << ", outstanding requests: " << m_outstanding_count
588 << ", read request table: " << m_readRequestTable
589 << ", write request table: " << m_writeRequestTable
590 << "]";
591}
592
593// this can be called from setState whenever coherence permissions are
594// upgraded when invoked, coherence violations will be checked for the
595// given block
596void
597Sequencer::checkCoherence(const Address& addr)
598{
599#ifdef CHECK_COHERENCE
600 g_system_ptr->checkGlobalCoherenceInvariant(addr);
601#endif
602}
623void
624Sequencer::print(ostream& out) const
625{
626 out << "[Sequencer: " << m_version
627 << ", outstanding requests: " << m_outstanding_count
628 << ", read request table: " << m_readRequestTable
629 << ", write request table: " << m_writeRequestTable
630 << "]";
631}
632
633// this can be called from setState whenever coherence permissions are
634// upgraded when invoked, coherence violations will be checked for the
635// given block
636void
637Sequencer::checkCoherence(const Address& addr)
638{
639#ifdef CHECK_COHERENCE
640 g_system_ptr->checkGlobalCoherenceInvariant(addr);
641#endif
642}