Deleted Added
sdiff udiff text old ( 9557:8666e81607a6 ) new ( 9666:74aca4cb081e )
full compact
1/*
2 * Copyright (c) 2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: Thomas Grass
38 * Andreas Hansson
39 * Sascha Bischoff
40 */
41#ifndef __CPU_TRAFFIC_GEN_TRAFFIC_GEN_HH__
42#define __CPU_TRAFFIC_GEN_TRAFFIC_GEN_HH__
43
44#include "base/hashmap.hh"
45#include "cpu/testers/traffic_gen/generators.hh"
46#include "mem/mem_object.hh"
47#include "mem/qport.hh"
48#include "params/TrafficGen.hh"
49
50/**
51 * The traffic generator is a master module that generates stimuli for
52 * the memory system, based on a collection of simple behaviours that
53 * are either probabilistic or based on traces. It can be used stand
54 * alone for creating test cases for interconnect and memory
55 * controllers, or function as a black box replacement for system
56 * components that are not yet modelled in detail, e.g. a video engine
57 * or baseband subsystem.
58 */
59class TrafficGen : public MemObject
60{
61
62 private:
63
64 /**
65 * The system used to determine which mode we are currently operating
66 * in.
67 */
68 System* system;
69
70 /**
71 * MasterID used in generated requests.
72 */
73 MasterID masterID;
74
75 protected:
76
77 /**
78 * The state graph is responsible for instantiating and keeping
79 * track of the various generator states and also perform the
80 * transitions and call the appropriate functions when entering,
81 * executing and exiting a state.
82 */
83 class StateGraph
84 {
85
86 public:
87
88 /**
89 * Create a state graph from an input file.
90 *
91 * @param _owner used solely for the name
92 * @param _port port used to send requests
93 * @param file_name configuration description to read in
94 * @param master_id the unique id used for all requests
95 */
96 StateGraph(TrafficGen& _owner, QueuedMasterPort& _port,
97 const std::string& file_name, MasterID master_id)
98 : nextTransitionTick(0), owner(_owner), port(_port)
99 {
100 parseConfig(file_name, master_id);
101 }
102
103 /**
104 * Get the name, used for DPRINTFs.
105 *
106 * @return the owner's name
107 */
108 std::string name() const { return owner.name(); }
109
110 /**
111 * Either perform a state transition or execute the current
112 * state, depending on the current time.
113 */
114 void update();
115
116 /**
117 * Determine next state and perform the transition.
118 */
119 void transition();
120
121 /**
122 * Enter a new state.
123 *
124 * @param newState identifier of state to enter
125 */
126 void enterState(uint32_t newState);
127
128 /**
129 * Get the tick of the next event, either an execution or a
130 * transition.
131 *
132 * @return tick of the next state graph event
133 */
134 Tick nextEventTick()
135 {
136 return std::min(states[currState]->nextExecuteTick(),
137 nextTransitionTick);
138
139 }
140
141 /** Time of next transition */
142 Tick nextTransitionTick;
143
144 private:
145
146 /**
147 * Parse the config file and build the state map and
148 * transition matrix.
149 *
150 * @param file_name Config file name to parse
151 * @param master_id MasterID to use for generated requests
152 */
153 void parseConfig(const std::string& file_name, MasterID master_id);
154
155 /** Struct to represent a probabilistic transition during parsing. */
156 struct Transition {
157 uint32_t from;
158 uint32_t to;
159 double p;
160 };
161
162 /** Pointer to owner of request handler */
163 TrafficGen& owner;
164
165 /** Pointer to request handler */
166 QueuedMasterPort& port;
167
168 /** State transition matrix */
169 std::vector<std::vector<double> > transitionMatrix;
170
171 public:
172
173 /** Index of the current state */
174 uint32_t currState;
175
176 /** Map of states */
177 m5::hash_map<uint32_t, BaseGen*> states;
178 };
179
180
181 /** Queued handler */
182 class TrafficGenPort : public QueuedMasterPort
183 {
184 public:
185
186 TrafficGenPort(const std::string& name, TrafficGen& _owner)
187 : QueuedMasterPort(name, &_owner, queue), queue(_owner, *this)
188 { }
189
190 protected:
191
192 bool recvTimingResp(PacketPtr pkt);
193
194 private:
195
196 MasterPacketQueue queue;
197
198 };
199
200 TrafficGenPort port;
201
202 /** Request generator state graph */
203 StateGraph stateGraph;
204
205 /**
206 * Schedules event for next update and executes an update on the
207 * state graph.
208 */
209 void updateStateGraph();
210
211 /** Event for updating the state graph */
212 EventWrapper<TrafficGen,
213 &TrafficGen::updateStateGraph> updateStateGraphEvent;
214
215
216 public:
217
218 TrafficGen(const TrafficGenParams* p);
219
220 ~TrafficGen() {}
221
222 virtual BaseMasterPort& getMasterPort(const std::string &if_name,
223 PortID idx = InvalidPortID);
224
225 void init();
226
227 void initState();
228
229 unsigned int drain(DrainManager *dm);
230
231 void serialize(std::ostream &os);
232
233 void unserialize(Checkpoint* cp, const std::string& section);
234
235};
236
237#endif //__CPU_TRAFFIC_GEN_TRAFFIC_GEN_HH__