gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
timing.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013,2015,2018 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  * Copyright (c) 2002-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Steve Reinhardt
41  */
42 
43 #ifndef __CPU_SIMPLE_TIMING_HH__
44 #define __CPU_SIMPLE_TIMING_HH__
45 
46 #include "cpu/simple/base.hh"
48 #include "cpu/translation.hh"
49 #include "params/TimingSimpleCPU.hh"
50 
52 {
53  public:
54 
55  TimingSimpleCPU(TimingSimpleCPUParams * params);
56  virtual ~TimingSimpleCPU();
57 
58  void init() override;
59 
60  private:
61 
62  /*
63  * If an access needs to be broken into fragments, currently at most two,
64  * the the following two classes are used as the sender state of the
65  * packets so the CPU can keep track of everything. In the main packet
66  * sender state, there's an array with a spot for each fragment. If a
67  * fragment has already been accepted by the CPU, aka isn't waiting for
68  * a retry, it's pointer is NULL. After each fragment has successfully
69  * been processed, the "outstanding" counter is decremented. Once the
70  * count is zero, the entire larger access is complete.
71  */
73  {
74  public:
77 
78  int
80  {
81  if (fragments[0]) {
82  return 0;
83  } else if (fragments[1]) {
84  return 1;
85  } else {
86  return -1;
87  }
88  }
89  };
90 
92  {
93  public:
94  SplitFragmentSenderState(PacketPtr _bigPkt, int _index) :
95  bigPkt(_bigPkt), index(_index)
96  {}
98  int index;
99 
100  void
102  {
103  SplitMainSenderState * main_send_state =
104  dynamic_cast<SplitMainSenderState *>(bigPkt->senderState);
105  main_send_state->fragments[index] = NULL;
106  }
107  };
108 
110  {
111  protected:
113 
114  public:
116  : cpu(_cpu)
117  {}
118 
119  void
121  {
122  assert(cpu->_status == BaseSimpleCPU::Running);
123  cpu->_status = ITBWaitResponse;
124  }
125 
126  void
127  finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc,
129  {
130  cpu->sendFetch(fault, req, tc);
131  }
132  };
134 
135  void threadSnoop(PacketPtr pkt, ThreadID sender);
136  void sendData(const RequestPtr &req,
137  uint8_t *data, uint64_t *res, bool read);
138  void sendSplitData(const RequestPtr &req1, const RequestPtr &req2,
139  const RequestPtr &req,
140  uint8_t *data, bool read);
141 
142  void translationFault(const Fault &fault);
143 
144  PacketPtr buildPacket(const RequestPtr &req, bool read);
145  void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
146  const RequestPtr &req1, const RequestPtr &req2,
147  const RequestPtr &req,
148  uint8_t *data, bool read);
149 
150  bool handleReadPacket(PacketPtr pkt);
151  // This function always implicitly uses dcache_pkt.
152  bool handleWritePacket();
153 
160  class TimingCPUPort : public MasterPort
161  {
162  public:
163 
164  TimingCPUPort(const std::string& _name, TimingSimpleCPU* _cpu)
165  : MasterPort(_name, _cpu), cpu(_cpu),
166  retryRespEvent([this]{ sendRetryResp(); }, name())
167  { }
168 
169  protected:
170 
172 
173  struct TickEvent : public Event
174  {
177 
178  TickEvent(TimingSimpleCPU *_cpu) : pkt(NULL), cpu(_cpu) {}
179  const char *description() const { return "Timing CPU tick"; }
180  void schedule(PacketPtr _pkt, Tick t);
181  };
182 
184  };
185 
186  class IcachePort : public TimingCPUPort
187  {
188  public:
189 
191  : TimingCPUPort(_cpu->name() + ".icache_port", _cpu),
192  tickEvent(_cpu)
193  { }
194 
195  protected:
196 
197  virtual bool recvTimingResp(PacketPtr pkt);
198 
199  virtual void recvReqRetry();
200 
201  struct ITickEvent : public TickEvent
202  {
203 
205  : TickEvent(_cpu) {}
206  void process();
207  const char *description() const { return "Timing CPU icache tick"; }
208  };
209 
211 
212  };
213 
214  class DcachePort : public TimingCPUPort
215  {
216  public:
217 
219  : TimingCPUPort(_cpu->name() + ".dcache_port", _cpu),
220  tickEvent(_cpu)
221  {
222  cacheBlockMask = ~(cpu->cacheLineSize() - 1);
223  }
224 
226  protected:
227 
231  virtual void recvTimingSnoopReq(PacketPtr pkt);
232  virtual void recvFunctionalSnoop(PacketPtr pkt);
233 
234  virtual bool recvTimingResp(PacketPtr pkt);
235 
236  virtual void recvReqRetry();
237 
238  virtual bool isSnooping() const {
239  return true;
240  }
241 
242  struct DTickEvent : public TickEvent
243  {
245  : TickEvent(_cpu) {}
246  void process();
247  const char *description() const { return "Timing CPU dcache tick"; }
248  };
249 
251 
252  };
253 
254  void updateCycleCounts();
255 
258 
261 
263 
264  protected:
265 
267  Port &getDataPort() override { return dcachePort; }
268 
270  Port &getInstPort() override { return icachePort; }
271 
272  public:
273 
274  DrainState drain() override;
275  void drainResume() override;
276 
277  void switchOut() override;
278  void takeOverFrom(BaseCPU *oldCPU) override;
279 
280  void verifyMemoryMode() const override;
281 
282  void activateContext(ThreadID thread_num) override;
283  void suspendContext(ThreadID thread_num) override;
284 
285  Fault initiateMemRead(Addr addr, unsigned size,
286  Request::Flags flags,
287  const std::vector<bool>& byte_enable =std::vector<bool>())
288  override;
289 
290  Fault writeMem(uint8_t *data, unsigned size,
291  Addr addr, Request::Flags flags, uint64_t *res,
292  const std::vector<bool>& byte_enable = std::vector<bool>())
293  override;
294 
295  Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags,
296  AtomicOpFunctorPtr amo_op) override;
297 
298  void fetch();
299  void sendFetch(const Fault &fault,
300  const RequestPtr &req, ThreadContext *tc);
301  void completeIfetch(PacketPtr );
302  void completeDataAccess(PacketPtr pkt);
303  void advanceInst(const Fault &fault);
304 
311  bool isSquashed() const { return false; }
312 
317  void printAddr(Addr a);
318 
324 
325  private:
326 
328 
329  struct IprEvent : Event {
332  IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, Tick t);
333  virtual void process();
334  virtual const char *description() const;
335  };
336 
353  bool isCpuDrained() const {
355  SimpleThread* thread = t_info.thread;
356 
357  return thread->microPC() == 0 && !t_info.stayAtPC &&
358  !fetchEvent.scheduled();
359  }
360 
366  bool tryCompleteDrain();
367 };
368 
369 #endif // __CPU_SIMPLE_TIMING_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:75
A TimingCPUPort overrides the default behaviour of the recvTiming and recvRetry and implements events...
Definition: timing.hh:160
Ports are used to interface objects to each other.
Definition: port.hh:60
Bitfield< 30, 0 > index
PacketPtr dcache_pkt
Definition: timing.hh:260
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
DcachePort dcachePort
Definition: timing.hh:257
void switchOut() override
Prepare for another CPU to take over execution.
Definition: timing.cc:174
DrainState
Object drain/handover states.
Definition: drain.hh:71
bool isCpuDrained() const
Check if a system is in a drained state.
Definition: timing.hh:353
void sendData(const RequestPtr &req, uint8_t *data, uint64_t *res, bool read)
Definition: timing.cc:288
void finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc, BaseTLB::Mode mode)
Definition: timing.hh:127
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
Bitfield< 8 > a
void suspendContext(ThreadID thread_num) override
Notify the CPU that the indicated context is now suspended.
Definition: timing.cc:233
ip6_addr_t addr
Definition: inet.hh:335
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition: amo.hh:230
void verifyMemoryMode() const override
Verify that the system is in a memory mode supported by the CPU.
Definition: timing.cc:200
Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags, AtomicOpFunctorPtr amo_op) override
Definition: timing.cc:565
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
virtual bool isSnooping() const
Determine if this master port is snooping or not.
Definition: timing.hh:238
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: timing.cc:67
IcachePort(TimingSimpleCPU *_cpu)
Definition: timing.hh:190
This class captures the state of an address translation.
Definition: translation.hh:61
ThreadID curThread
Definition: base.hh:87
Bitfield< 4, 0 > mode
TimingCPUPort(const std::string &_name, TimingSimpleCPU *_cpu)
Definition: timing.hh:164
Port & getInstPort() override
Return a reference to the instruction port.
Definition: timing.hh:270
DcachePort(TimingSimpleCPU *_cpu)
Definition: timing.hh:218
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags, const std::vector< bool > &byte_enable=std::vector< bool >()) override
Definition: timing.cc:419
void completeIfetch(PacketPtr)
Definition: timing.cc:774
void fetch()
Definition: timing.cc:654
PacketPtr ifetch_pkt
Definition: timing.hh:259
bool tryCompleteDrain()
Try to complete a drain request.
Definition: timing.cc:158
EventFunctionWrapper retryRespEvent
Definition: timing.hh:183
void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2, const RequestPtr &req1, const RequestPtr &req2, const RequestPtr &req, uint8_t *data, bool read)
Definition: timing.cc:387
PacketPtr buildPacket(const RequestPtr &req, bool read)
Definition: timing.cc:381
void markDelayed()
Signal that the translation has been delayed due to a hw page table walk.
Definition: timing.hh:120
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:385
void sendSplitData(const RequestPtr &req1, const RequestPtr &req2, const RequestPtr &req, uint8_t *data, bool read)
Definition: timing.cc:325
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool handleReadPacket(PacketPtr pkt)
Definition: timing.cc:259
FetchTranslation fetchTranslation
Definition: timing.hh:133
SplitFragmentSenderState(PacketPtr _bigPkt, int _index)
Definition: timing.hh:94
TickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:178
void translationFault(const Fault &fault)
Definition: timing.cc:362
void takeOverFrom(BaseCPU *oldCPU) override
Load the state of a CPU from the previous CPU object, invoked on all new CPUs that are about to be sw...
Definition: timing.cc:192
Fault writeMem(uint8_t *data, unsigned size, Addr addr, Request::Flags flags, uint64_t *res, const std::vector< bool > &byte_enable=std::vector< bool >()) override
Definition: timing.cc:497
Port & getDataPort() override
Return a reference to the data port.
Definition: timing.hh:267
void sendFetch(const Fault &fault, const RequestPtr &req, ThreadContext *tc)
Definition: timing.cc:697
TimingSimpleCPU * cpu
Definition: timing.hh:171
Status _status
Definition: base.hh:125
SimpleThread * thread
Definition: exec_context.hh:68
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
virtual const std::string name() const
Definition: sim_object.hh:120
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
ITickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:204
void threadSnoop(PacketPtr pkt, ThreadID sender)
Definition: timing.cc:614
EventFunctionWrapper fetchEvent
Definition: timing.hh:327
A virtual base opaque structure used to hold state associated with the packet (e.g., an MSHR), specific to a SimObject that sees the packet.
Definition: packet.hh:403
void activateContext(ThreadID thread_num) override
Notify the CPU that the indicated context is now active.
Definition: timing.cc:209
const char * description() const
Return a C string describing the event.
Definition: timing.hh:207
virtual ~TimingSimpleCPU()
Definition: timing.cc:89
Mode
Definition: tlb.hh:59
FetchTranslation(TimingSimpleCPU *_cpu)
Definition: timing.hh:115
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
Cycles previousCycle
Definition: timing.hh:262
const char * description() const
Return a C string describing the event.
Definition: timing.hh:179
SenderState * senderState
This packet&#39;s sender state.
Definition: packet.hh:480
Definition: eventq.hh:189
DTickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:244
void advanceInst(const Fault &fault)
Definition: timing.cc:729
std::vector< SimpleExecContext * > threadInfo
Definition: base.hh:102
MicroPC microPC() const override
IcachePort icachePort
Definition: timing.hh:256
void schedule(Event &event, Tick when)
Definition: eventq.hh:744
void finishTranslation(WholeTranslationState *state)
Finish a DTB translation.
Definition: timing.cc:628
void completeDataAccess(PacketPtr pkt)
Definition: timing.cc:878
TimingSimpleCPU * cpu
Definition: timing.hh:331
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: timing.cc:94
TimingSimpleCPU(TimingSimpleCPUParams *params)
Definition: timing.cc:79
Bitfield< 5 > t
void printAddr(Addr a)
Print state of address in memory system via PrintReq (for debugging).
Definition: timing.cc:1068
const char data[]
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
const Params * params() const
Definition: base.hh:311
void drainResume() override
Resume execution after a successful drain.
Definition: timing.cc:121
bool handleWritePacket()
Definition: timing.cc:475
bool isSquashed() const
This function is used by the page table walker to determine if it could translate the a pending reque...
Definition: timing.hh:311
const char * description() const
Definition: timing.hh:247
void updateCycleCounts()
Definition: timing.cc:937

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13