RubyDirectedTester.cc revision 6899
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * Copyright (c) 2009 Advanced Micro Devices, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "mem/ruby/common/Global.hh"
32#include "mem/ruby/system/System.hh"
33#include "cpu/rubytest/RubyTester.hh"
34#include "mem/ruby/eventqueue/RubyEventQueue.hh"
35#include "mem/ruby/common/SubBlock.hh"
36#include "cpu/rubytest/Check.hh"
37#include "sim/sim_exit.hh"
38
39RubyTester::RubyTester(const Params *p)
40  : MemObject(p),
41    checkStartEvent(this),
42    m_checks_to_complete(p->checks_to_complete),
43    m_deadlock_threshold(p->deadlock_threshold),
44    m_wakeup_frequency(p->wakeup_frequency)
45{
46  m_checks_completed = 0;
47
48  // add the check start event to the event queue
49  schedule(checkStartEvent, 1);
50
51}
52
53RubyTester::~RubyTester()
54{
55  delete m_checkTable_ptr;
56  for (int i = 0; i < ports.size(); i++) {
57    delete ports[i];
58  }
59}
60
61void RubyTester::init()
62{
63  assert(ports.size() > 0);
64
65  m_last_progress_vector.setSize(ports.size());
66  for (int i = 0; i < m_last_progress_vector.size(); i++) {
67    m_last_progress_vector[i] = 0;
68  }
69
70  m_num_cpu_sequencers = ports.size();
71
72  m_checkTable_ptr = new CheckTable(m_num_cpu_sequencers, this);
73}
74
75Port *
76RubyTester::getPort(const std::string &if_name, int idx)
77{
78
79    if (if_name != "cpuPort") {
80        panic("RubyTester::getPort: unknown port %s requested", if_name);
81    }
82
83    if (idx >= (int)ports.size()) {
84        ports.resize(idx + 1);
85    }
86
87    if (ports[idx] != NULL) {
88        panic("RubyTester::getPort: port %d already assigned", idx);
89    }
90
91    CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx);
92
93    ports[idx] = port;
94    return port;
95}
96
97Tick
98RubyTester::CpuPort::recvAtomic(PacketPtr pkt)
99{
100  panic("RubyTester::CpuPort::recvAtomic() not implemented!\n");
101  return 0;
102}
103
104bool
105RubyTester::CpuPort::recvTiming(PacketPtr pkt)
106{
107  //
108  // retrieve the subblock and call hitCallback
109  //
110  RubyTester::SenderState* senderState =
111    safe_cast<RubyTester::SenderState*>(pkt->senderState);
112  SubBlock* subblock = senderState->subBlock;
113  assert(subblock != NULL);
114
115  // pop the sender state from the packet
116  pkt->senderState = senderState->saved;
117
118  tester->hitCallback(idx, subblock);
119
120  //
121  // Now that the tester has completed, delete the senderState
122  // (includes sublock) and the packet, then return
123  //
124  delete senderState;
125  delete pkt->req;
126  delete pkt;
127  return true;
128}
129
130Port*
131RubyTester::getCpuPort(int idx)
132{
133  assert(idx >= 0 && idx < ports.size());
134
135  return ports[idx];
136}
137
138void RubyTester::hitCallback(NodeID proc, SubBlock* data)
139{
140  // Mark that we made progress
141  m_last_progress_vector[proc] = g_eventQueue_ptr->getTime();
142
143  DPRINTF(RubyTest, "completed request for proc: %d\n", proc);
144  DPRINTF(RubyTest,
145          "addr: 0x%x, size: %d, data: ",
146          data->getAddress(),
147          data->getSize());
148  for (int byte = 0; byte < data->getSize(); byte++) {
149    DPRINTF(RubyTest, "%d", data->getByte(byte));
150  }
151  DPRINTF(RubyTest, "\n");
152
153  //
154  // This tells us our store has 'completed' or for a load gives us
155  // back the data to make the check
156  //
157  Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress());
158  assert(check_ptr != NULL);
159  check_ptr->performCallback(proc, data);
160}
161
162void RubyTester::wakeup()
163{
164  if (m_checks_completed < m_checks_to_complete) {
165    // Try to perform an action or check
166    Check* check_ptr = m_checkTable_ptr->getRandomCheck();
167    assert(check_ptr != NULL);
168    check_ptr->initiate();
169
170    checkForDeadlock();
171
172    schedule(checkStartEvent, curTick + m_wakeup_frequency);
173  } else {
174    exitSimLoop("Ruby Tester completed");
175  }
176}
177
178void RubyTester::checkForDeadlock()
179{
180  int size = m_last_progress_vector.size();
181  Time current_time = g_eventQueue_ptr->getTime();
182  for (int processor = 0; processor < size; processor++) {
183    if ((current_time - m_last_progress_vector[processor]) > m_deadlock_threshold) {
184      WARN_EXPR(current_time);
185      WARN_EXPR(m_last_progress_vector[processor]);
186      WARN_EXPR(current_time - m_last_progress_vector[processor]);
187      WARN_EXPR(processor);
188      ERROR_MSG("Deadlock detected.");
189    }
190  }
191}
192
193void RubyTester::print(ostream& out) const
194{
195  out << "[RubyTester]" << endl;
196}
197
198RubyTester *
199RubyTesterParams::create()
200{
201    return new RubyTester(this);
202}
203