gem5  v20.1.0.0
trace_gen.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2016-2017 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 here under. 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 
39 
40 #include <algorithm>
41 
42 #include "base/random.hh"
43 #include "base/trace.hh"
44 #include "debug/TrafficGen.hh"
45 #include "proto/packet.pb.h"
46 
47 TraceGen::InputStream::InputStream(const std::string& filename)
48  : trace(filename)
49 {
50  init();
51 }
52 
53 void
55 {
56  // Create a protobuf message for the header and read it from the stream
57  ProtoMessage::PacketHeader header_msg;
58  if (!trace.read(header_msg)) {
59  panic("Failed to read packet header from trace\n");
60  } else if (header_msg.tick_freq() != SimClock::Frequency) {
61  panic("Trace was recorded with a different tick frequency %d\n",
62  header_msg.tick_freq());
63  }
64 }
65 
66 void
68 {
69  trace.reset();
70  init();
71 }
72 
73 bool
75 {
76  ProtoMessage::Packet pkt_msg;
77  if (trace.read(pkt_msg)) {
78  element.cmd = pkt_msg.cmd();
79  element.addr = pkt_msg.addr();
80  element.blocksize = pkt_msg.size();
81  element.tick = pkt_msg.tick();
82  element.flags = pkt_msg.has_flags() ? pkt_msg.flags() : 0;
83  return true;
84  }
85 
86  // We have reached the end of the file
87  return false;
88 }
89 
90 Tick
91 TraceGen::nextPacketTick(bool elastic, Tick delay) const
92 {
93  if (traceComplete) {
94  DPRINTF(TrafficGen, "No next tick as trace is finished\n");
95  // We are at the end of the file, thus we have no more data in
96  // the trace Return MaxTick to signal that there will be no
97  // more transactions in this active period for the state.
98  return MaxTick;
99  }
100 
101  assert(nextElement.isValid());
102 
103  DPRINTF(TrafficGen, "Next packet tick is %d\n", tickOffset +
104  nextElement.tick);
105 
106  // if the playback is supposed to be elastic, add the delay
107  if (elastic)
108  tickOffset += delay;
109 
110  return std::max(tickOffset + nextElement.tick, curTick());
111 }
112 
113 void
115 {
116  // update the trace offset to the time where the state was entered.
117  tickOffset = curTick();
118 
119  // clear everything
120  currElement.clear();
121 
122  // read the first element in the file and set the complete flag
124 }
125 
126 PacketPtr
128 {
129  // shift things one step forward
131  nextElement.clear();
132 
133  // read the next element and set the complete flag
135 
136  // it is the responsibility of the traceComplete flag to ensure we
137  // always have a valid element here
138  assert(currElement.isValid());
139 
140  DPRINTF(TrafficGen, "TraceGen::getNextPacket: %c %d %d %d 0x%x\n",
141  currElement.cmd.isRead() ? 'r' : 'w',
146 
150 
151  if (!traceComplete)
152  DPRINTF(TrafficGen, "nextElement: %c addr %d size %d tick %d (%d)\n",
153  nextElement.cmd.isRead() ? 'r' : 'w',
157  nextElement.tick);
158 
159  return pkt;
160 }
161 
162 void
164 {
165  // Check if we reached the end of the trace file. If we did not
166  // then we want to generate a warning stating that not the entire
167  // trace was played.
168  if (!traceComplete) {
169  warn("Trace player %s was unable to replay the entire trace!\n",
170  name());
171  }
172 
173  // Clear any flags and start over again from the beginning of the
174  // file
175  trace.reset();
176 }
TraceGen::TraceElement::tick
Tick tick
The time at which the request should be sent.
Definition: trace_gen.hh:78
Stats::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:45
warn
#define warn(...)
Definition: logging.hh:239
TraceGen::InputStream::read
bool read(TraceElement &element)
Attempt to read a trace element from the stream, and also notify the caller if the end of the file wa...
Definition: trace_gen.cc:74
random.hh
TraceGen::tickOffset
Tick tickOffset
Stores the time when the state was entered.
Definition: trace_gen.hh:193
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
trace_gen.hh
TraceGen::InputStream::InputStream
InputStream(const std::string &filename)
Create a trace input stream for a given file name.
Definition: trace_gen.cc:47
BaseGen::name
std::string name() const
Get the name, useful for DPRINTFs.
Definition: base_gen.hh:100
TraceGen::TraceElement
This struct stores a line in the trace file.
Definition: trace_gen.hh:66
TraceGen::TraceElement::cmd
MemCmd cmd
Specifies if the request is to be a read or a write.
Definition: trace_gen.hh:69
TraceGen::TraceElement::blocksize
Addr blocksize
The size of the access for the request.
Definition: trace_gen.hh:75
TraceGen::addrOffset
Addr addrOffset
Offset for memory requests.
Definition: trace_gen.hh:199
TraceGen::getNextPacket
PacketPtr getNextPacket()
Get the next generated packet.
Definition: trace_gen.cc:127
SimClock::Frequency
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:46
MemCmd::isRead
bool isRead() const
Definition: packet.hh:199
TraceGen::TraceElement::addr
Addr addr
The address for the request.
Definition: trace_gen.hh:72
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
TraceGen::TraceElement::clear
void clear()
Make this element invalid.
Definition: trace_gen.hh:95
TraceGen::nextElement
TraceElement nextElement
Definition: trace_gen.hh:186
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
TraceGen::enter
void enter()
Enter this generator state.
Definition: trace_gen.cc:114
TraceGen::currElement
TraceElement currElement
Store the current and next element in the trace.
Definition: trace_gen.hh:185
MemCmd::cmd
Command cmd
Definition: packet.hh:189
TraceGen::nextPacketTick
Tick nextPacketTick(bool elastic, Tick delay) const
Returns the tick when the next request should be generated.
Definition: trace_gen.cc:91
BaseGen::getPacket
PacketPtr getPacket(Addr addr, unsigned size, const MemCmd &cmd, Request::FlagsType flags=0)
Generate a new request and associated packet.
Definition: base_gen.cc:56
TraceGen::traceComplete
bool traceComplete
Set to true when the trace replay for one instance of state is complete.
Definition: trace_gen.hh:205
TraceGen::TraceElement::isValid
bool isValid() const
Check validity of this element.
Definition: trace_gen.hh:88
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
TraceGen::InputStream::reset
void reset()
Reset the stream such that it can be played once again.
Definition: trace_gen.cc:67
trace.hh
TraceGen::exit
void exit()
Exit this generator state.
Definition: trace_gen.cc:163
TraceGen::trace
InputStream trace
Input stream used for reading the input trace file.
Definition: trace_gen.hh:182
TraceGen::TraceElement::flags
Request::FlagsType flags
Potential request flags to use.
Definition: trace_gen.hh:81
TraceGen::InputStream::init
void init()
Check the trace header to make sure that it is of the right format.
Definition: trace_gen.cc:54
MaxTick
const Tick MaxTick
Definition: types.hh:65
TrafficGen
The traffic generator is a module that generates stimuli for the memory system, based on a collection...
Definition: traffic_gen.hh:67
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

Generated on Wed Sep 30 2020 14:02:10 for gem5 by doxygen 1.8.17