RubyDirectedTester.cc revision 7823:dac01f14f20f
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * Copyright (c) 2009-2010 Advanced Micro Devices, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include "cpu/testers/directedtest/DirectedGenerator.hh"
31#include "cpu/testers/directedtest/RubyDirectedTester.hh"
32#include "mem/ruby/eventqueue/RubyEventQueue.hh"
33#include "sim/sim_exit.hh"
34
35RubyDirectedTester::RubyDirectedTester(const Params *p)
36  : MemObject(p), directedStartEvent(this),
37    m_requests_to_complete(p->requests_to_complete),
38    generator(p->generator)
39{
40    m_requests_completed = 0;
41
42    // add the check start event to the event queue
43    schedule(directedStartEvent, 1);
44}
45
46RubyDirectedTester::~RubyDirectedTester()
47{
48    for (int i = 0; i < ports.size(); i++)
49        delete ports[i];
50}
51
52void
53RubyDirectedTester::init()
54{
55    assert(ports.size() > 0);
56    generator->setDirectedTester(this);
57}
58
59Port *
60RubyDirectedTester::getPort(const std::string &if_name, int idx)
61{
62    if (if_name != "cpuPort") {
63        panic("RubyDirectedTester::getPort: unknown port %s requested", if_name);
64    }
65
66    if (idx >= (int)ports.size()) {
67        ports.resize(idx + 1);
68    }
69
70    if (ports[idx] != NULL) {
71        panic("RubyDirectedTester::getPort: port %d already assigned", idx);
72    }
73
74    CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx);
75
76    ports[idx] = port;
77    return port;
78}
79
80Tick
81RubyDirectedTester::CpuPort::recvAtomic(PacketPtr pkt)
82{
83    panic("RubyDirectedTester::CpuPort::recvAtomic() not implemented!\n");
84    return 0;
85}
86
87bool
88RubyDirectedTester::CpuPort::recvTiming(PacketPtr pkt)
89{
90    tester->hitCallback(idx, pkt->getAddr());
91
92    //
93    // Now that the tester has completed, delete the packet, then return
94    //
95    delete pkt->req;
96    delete pkt;
97    return true;
98}
99
100Port*
101RubyDirectedTester::getCpuPort(int idx)
102{
103    assert(idx >= 0 && idx < ports.size());
104
105    return ports[idx];
106}
107
108void
109RubyDirectedTester::hitCallback(NodeID proc, Addr addr)
110{
111    DPRINTF(DirectedTest,
112            "completed request for proc: %d addr: 0x%x\n",
113            proc,
114            addr);
115
116    generator->performCallback(proc, addr);
117    schedule(directedStartEvent, curTick());
118}
119
120void
121RubyDirectedTester::wakeup()
122{
123    if (m_requests_completed < m_requests_to_complete) {
124        if (!generator->initiate()) {
125            schedule(directedStartEvent, curTick() + 1);
126        }
127    } else {
128        exitSimLoop("Ruby DirectedTester completed");
129    }
130}
131
132RubyDirectedTester *
133RubyDirectedTesterParams::create()
134{
135    return new RubyDirectedTester(this);
136}
137