MEM: Introduce the master/slave port sub-classes in C++
[gem5.git] / src / cpu / testers / networktest / networktest.hh
1 /*
2 * Copyright (c) 2009 Advanced Micro Devices, Inc.
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 * Authors: Tushar Krishna
29 */
30
31 #ifndef __CPU_NETWORKTEST_NETWORKTEST_HH__
32 #define __CPU_NETWORKTEST_NETWORKTEST_HH__
33
34 #include <set>
35
36 #include "base/fast_alloc.hh"
37 #include "base/statistics.hh"
38 #include "mem/mem_object.hh"
39 #include "mem/port.hh"
40 #include "params/NetworkTest.hh"
41 #include "sim/eventq.hh"
42 #include "sim/sim_exit.hh"
43 #include "sim/sim_object.hh"
44 #include "sim/stats.hh"
45
46 class Packet;
47 class NetworkTest : public MemObject
48 {
49 public:
50 typedef NetworkTestParams Params;
51 NetworkTest(const Params *p);
52
53 virtual void init();
54
55 inline Tick ticks(int numCycles) const { return numCycles; }
56
57 // main simulation loop (one cycle)
58 void tick();
59
60 virtual MasterPort &getMasterPort(const std::string &if_name,
61 int idx = -1);
62
63 /**
64 * Print state of address in memory system via PrintReq (for
65 * debugging).
66 */
67 void printAddr(Addr a);
68
69 protected:
70 class TickEvent : public Event
71 {
72 private:
73 NetworkTest *cpu;
74
75 public:
76 TickEvent(NetworkTest *c) : Event(CPU_Tick_Pri), cpu(c) {}
77 void process() { cpu->tick(); }
78 virtual const char *description() const { return "NetworkTest tick"; }
79 };
80
81 TickEvent tickEvent;
82
83 class CpuPort : public MasterPort
84 {
85 NetworkTest *networktest;
86
87 public:
88
89 CpuPort(const std::string &_name, NetworkTest *_networktest)
90 : MasterPort(_name, _networktest), networktest(_networktest)
91 { }
92
93 protected:
94
95 virtual bool recvTiming(PacketPtr pkt);
96
97 virtual Tick recvAtomic(PacketPtr pkt);
98
99 virtual void recvFunctional(PacketPtr pkt);
100
101 virtual void recvRetry();
102 };
103
104 CpuPort cachePort;
105
106 class NetworkTestSenderState : public Packet::SenderState, public FastAlloc
107 {
108 public:
109 /** Constructor. */
110 NetworkTestSenderState(uint8_t *_data)
111 : data(_data)
112 { }
113
114 // Hold onto data pointer
115 uint8_t *data;
116 };
117
118 PacketPtr retryPkt;
119 unsigned size;
120 int id;
121
122 unsigned blockSizeBits;
123
124 Tick noResponseCycles;
125
126 int numMemories;
127 Tick simCycles;
128 bool fixedPkts;
129 int maxPackets;
130 int numPacketsSent;
131
132 int trafficType;
133 double injRate;
134 int precision;
135
136 MasterID masterId;
137
138 void completeRequest(PacketPtr pkt);
139
140 void generatePkt();
141 void sendPkt(PacketPtr pkt);
142
143 void doRetry();
144
145 friend class MemCompleteEvent;
146 };
147
148 #endif // __CPU_NETWORKTEST_NETWORKTEST_HH__
149
150
151