misc: Replaced master/slave terminology
[gem5.git] / src / cpu / testers / garnet_synthetic_traffic / GarnetSyntheticTraffic.hh
1 /*
2 * Copyright (c) 2016 Georgia Institute of Technology
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 #ifndef __CPU_GARNET_SYNTHETIC_TRAFFIC_HH__
30 #define __CPU_GARNET_SYNTHETIC_TRAFFIC_HH__
31
32 #include <set>
33
34 #include "base/statistics.hh"
35 #include "mem/port.hh"
36 #include "params/GarnetSyntheticTraffic.hh"
37 #include "sim/clocked_object.hh"
38 #include "sim/eventq.hh"
39 #include "sim/sim_exit.hh"
40 #include "sim/sim_object.hh"
41 #include "sim/stats.hh"
42
43 enum TrafficType {BIT_COMPLEMENT_ = 0,
44 BIT_REVERSE_ = 1,
45 BIT_ROTATION_ = 2,
46 NEIGHBOR_ = 3,
47 SHUFFLE_ = 4,
48 TORNADO_ = 5,
49 TRANSPOSE_ = 6,
50 UNIFORM_RANDOM_ = 7,
51 NUM_TRAFFIC_PATTERNS_};
52
53 class Packet;
54 class GarnetSyntheticTraffic : public ClockedObject
55 {
56 public:
57 typedef GarnetSyntheticTrafficParams Params;
58 GarnetSyntheticTraffic(const Params *p);
59
60 void init() override;
61
62 // main simulation loop (one cycle)
63 void tick();
64
65 Port &getPort(const std::string &if_name,
66 PortID idx=InvalidPortID) override;
67
68 /**
69 * Print state of address in memory system via PrintReq (for
70 * debugging).
71 */
72 void printAddr(Addr a);
73
74 protected:
75 EventFunctionWrapper tickEvent;
76
77 class CpuPort : public RequestPort
78 {
79 GarnetSyntheticTraffic *tester;
80
81 public:
82
83 CpuPort(const std::string &_name, GarnetSyntheticTraffic *_tester)
84 : RequestPort(_name, _tester), tester(_tester)
85 { }
86
87 protected:
88
89 virtual bool recvTimingResp(PacketPtr pkt);
90
91 virtual void recvReqRetry();
92 };
93
94 CpuPort cachePort;
95
96 class GarnetSyntheticTrafficSenderState : public Packet::SenderState
97 {
98 public:
99 /** Constructor. */
100 GarnetSyntheticTrafficSenderState(uint8_t *_data)
101 : data(_data)
102 { }
103
104 // Hold onto data pointer
105 uint8_t *data;
106 };
107
108 PacketPtr retryPkt;
109 unsigned size;
110 int id;
111
112 std::map<std::string, TrafficType> trafficStringToEnum;
113
114 unsigned blockSizeBits;
115
116 Tick noResponseCycles;
117
118 int numDestinations;
119 Tick simCycles;
120 int numPacketsMax;
121 int numPacketsSent;
122 int singleSender;
123 int singleDest;
124
125 std::string trafficType; // string
126 TrafficType traffic; // enum from string
127 double injRate;
128 int injVnet;
129 int precision;
130
131 const Cycles responseLimit;
132
133 RequestorID requestorId;
134
135 void completeRequest(PacketPtr pkt);
136
137 void generatePkt();
138 void sendPkt(PacketPtr pkt);
139 void initTrafficType();
140
141 void doRetry();
142
143 friend class MemCompleteEvent;
144 };
145
146 #endif // __CPU_GARNET_SYNTHETIC_TRAFFIC_HH__