2 * Copyright (c) 2012-2013, 2016-2018 ARM Limited
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.
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.
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.
37 * Authors: Thomas Grass
42 #ifndef __CPU_TRAFFIC_GEN_BASE_HH__
43 #define __CPU_TRAFFIC_GEN_BASE_HH__
48 #include "base/statistics.hh"
49 #include "mem/mem_object.hh"
50 #include "mem/qport.hh"
55 struct BaseTrafficGenParams;
58 * The traffic generator is a master module that generates stimuli for
59 * the memory system, based on a collection of simple generator
60 * behaviours that are either probabilistic or based on traces. It can
61 * be used stand alone for creating test cases for interconnect and
62 * memory controllers, or function as a black box replacement for
63 * system components that are not yet modelled in detail, e.g. a video
64 * engine or baseband subsystem.
66 class BaseTrafficGen : public MemObject
72 * The system used to determine which mode we are currently operating
78 * Determine whether to add elasticity in the request injection,
79 * thus responding to backpressure by slowing things down.
81 const bool elasticReq;
84 * Time to tolerate waiting for retries (not making progress),
85 * until we declare things broken.
87 const Tick progressCheck;
91 * Receive a retry from the neighbouring port and attempt to
92 * resend the waiting packet.
96 /** Transition to the next generator */
100 * Schedule the update event based on nextPacketTick and
101 * nextTransitionTick.
103 void scheduleUpdate();
106 * Method to inform the user we have made no progress.
111 * Event to keep track of our progress, or lack thereof.
113 EventFunctionWrapper noProgressEvent;
115 /** Time of next transition */
116 Tick nextTransitionTick;
118 /** Time of the next packet. */
122 /** Master port specialisation for the traffic generator */
123 class TrafficGenPort : public MasterPort
127 TrafficGenPort(const std::string& name, BaseTrafficGen& traffic_gen)
128 : MasterPort(name, &traffic_gen), trafficGen(traffic_gen)
133 void recvReqRetry() { trafficGen.recvReqRetry(); }
135 bool recvTimingResp(PacketPtr pkt);
137 void recvTimingSnoopReq(PacketPtr pkt) { }
139 void recvFunctionalSnoop(PacketPtr pkt) { }
141 Tick recvAtomicSnoop(PacketPtr pkt) { return 0; }
145 BaseTrafficGen& trafficGen;
150 * Schedules event for next update and generates a new packet or
151 * requests a new generatoir depending on the current time.
155 /** The instance of master port used by the traffic generator. */
158 /** Packet waiting to be sent. */
161 /** Tick when the stalled packet was meant to be sent. */
164 /** Event for scheduling updates */
165 EventFunctionWrapper updateEvent;
167 /** Count the number of dropped requests. */
168 Stats::Scalar numSuppressed;
171 /** Count the number of generated packets. */
172 Stats::Scalar numPackets;
174 /** Count the number of retries. */
175 Stats::Scalar numRetries;
177 /** Count the time incurred from back-pressure. */
178 Stats::Scalar retryTicks;
181 BaseTrafficGen(const BaseTrafficGenParams* p);
185 Port &getPort(const std::string &if_name,
186 PortID idx=InvalidPortID) override;
188 void init() override;
190 DrainState drain() override;
192 void serialize(CheckpointOut &cp) const override;
193 void unserialize(CheckpointIn &cp) override;
195 /** Register statistics */
196 void regStats() override;
198 public: // Generator factory methods
199 std::shared_ptr<BaseGen> createIdle(Tick duration);
200 std::shared_ptr<BaseGen> createExit(Tick duration);
202 std::shared_ptr<BaseGen> createLinear(
204 Addr start_addr, Addr end_addr, Addr blocksize,
205 Tick min_period, Tick max_period,
206 uint8_t read_percent, Addr data_limit);
208 std::shared_ptr<BaseGen> createRandom(
210 Addr start_addr, Addr end_addr, Addr blocksize,
211 Tick min_period, Tick max_period,
212 uint8_t read_percent, Addr data_limit);
214 std::shared_ptr<BaseGen> createDram(
216 Addr start_addr, Addr end_addr, Addr blocksize,
217 Tick min_period, Tick max_period,
218 uint8_t read_percent, Addr data_limit,
219 unsigned int num_seq_pkts, unsigned int page_size,
220 unsigned int nbr_of_banks_DRAM, unsigned int nbr_of_banks_util,
221 unsigned int addr_mapping,
222 unsigned int nbr_of_ranks);
224 std::shared_ptr<BaseGen> createDramRot(
226 Addr start_addr, Addr end_addr, Addr blocksize,
227 Tick min_period, Tick max_period,
228 uint8_t read_percent, Addr data_limit,
229 unsigned int num_seq_pkts, unsigned int page_size,
230 unsigned int nbr_of_banks_DRAM, unsigned int nbr_of_banks_util,
231 unsigned int addr_mapping,
232 unsigned int nbr_of_ranks,
233 unsigned int max_seq_count_per_rank);
235 std::shared_ptr<BaseGen> createTrace(
237 const std::string& trace_file, Addr addr_offset);
242 virtual std::shared_ptr<BaseGen> nextGenerator() = 0;
245 * MasterID used in generated requests.
247 const MasterID masterID;
249 /** Currently active generator */
250 std::shared_ptr<BaseGen> activeGenerator;
252 /** Stream/SubStreamID Generator */
253 std::unique_ptr<StreamGen> streamGenerator;
256 #endif //__CPU_TRAFFIC_GEN_BASE_HH__