NetworkTest: added sim_cycles parameter to the network tester.
[gem5.git] / src / cpu / testers / directedtest / RubyDirectedTester.cc
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 "debug/DirectedTest.hh"
33 #include "mem/ruby/eventqueue/RubyEventQueue.hh"
34 #include "sim/sim_exit.hh"
35
36 RubyDirectedTester::RubyDirectedTester(const Params *p)
37 : MemObject(p), directedStartEvent(this),
38 m_requests_to_complete(p->requests_to_complete),
39 generator(p->generator)
40 {
41 m_requests_completed = 0;
42
43 // add the check start event to the event queue
44 schedule(directedStartEvent, 1);
45 }
46
47 RubyDirectedTester::~RubyDirectedTester()
48 {
49 for (int i = 0; i < ports.size(); i++)
50 delete ports[i];
51 }
52
53 void
54 RubyDirectedTester::init()
55 {
56 assert(ports.size() > 0);
57 generator->setDirectedTester(this);
58 }
59
60 Port *
61 RubyDirectedTester::getPort(const std::string &if_name, int idx)
62 {
63 if (if_name != "cpuPort") {
64 panic("RubyDirectedTester::getPort: unknown port %s requested", if_name);
65 }
66
67 if (idx >= (int)ports.size()) {
68 ports.resize(idx + 1);
69 }
70
71 if (ports[idx] != NULL) {
72 panic("RubyDirectedTester::getPort: port %d already assigned", idx);
73 }
74
75 CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx);
76
77 ports[idx] = port;
78 return port;
79 }
80
81 Tick
82 RubyDirectedTester::CpuPort::recvAtomic(PacketPtr pkt)
83 {
84 panic("RubyDirectedTester::CpuPort::recvAtomic() not implemented!\n");
85 return 0;
86 }
87
88 bool
89 RubyDirectedTester::CpuPort::recvTiming(PacketPtr pkt)
90 {
91 tester->hitCallback(idx, pkt->getAddr());
92
93 //
94 // Now that the tester has completed, delete the packet, then return
95 //
96 delete pkt->req;
97 delete pkt;
98 return true;
99 }
100
101 Port*
102 RubyDirectedTester::getCpuPort(int idx)
103 {
104 assert(idx >= 0 && idx < ports.size());
105
106 return ports[idx];
107 }
108
109 void
110 RubyDirectedTester::hitCallback(NodeID proc, Addr addr)
111 {
112 DPRINTF(DirectedTest,
113 "completed request for proc: %d addr: 0x%x\n",
114 proc,
115 addr);
116
117 generator->performCallback(proc, addr);
118 schedule(directedStartEvent, curTick());
119 }
120
121 void
122 RubyDirectedTester::wakeup()
123 {
124 if (m_requests_completed < m_requests_to_complete) {
125 if (!generator->initiate()) {
126 schedule(directedStartEvent, curTick() + 1);
127 }
128 } else {
129 exitSimLoop("Ruby DirectedTester completed");
130 }
131 }
132
133 RubyDirectedTester *
134 RubyDirectedTesterParams::create()
135 {
136 return new RubyDirectedTester(this);
137 }