gem5  v20.0.0.3
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 
41 #ifndef __CPU_SIMPLE_TIMING_HH__
42 #define __CPU_SIMPLE_TIMING_HH__
43 
44 #include "cpu/simple/base.hh"
46 #include "cpu/translation.hh"
47 #include "params/TimingSimpleCPU.hh"
48 
50 {
51  public:
52 
53  TimingSimpleCPU(TimingSimpleCPUParams * params);
54  virtual ~TimingSimpleCPU();
55 
56  void init() override;
57 
58  private:
59 
60  /*
61  * If an access needs to be broken into fragments, currently at most two,
62  * the the following two classes are used as the sender state of the
63  * packets so the CPU can keep track of everything. In the main packet
64  * sender state, there's an array with a spot for each fragment. If a
65  * fragment has already been accepted by the CPU, aka isn't waiting for
66  * a retry, it's pointer is NULL. After each fragment has successfully
67  * been processed, the "outstanding" counter is decremented. Once the
68  * count is zero, the entire larger access is complete.
69  */
71  {
72  public:
75 
76  int
78  {
79  if (fragments[0]) {
80  return 0;
81  } else if (fragments[1]) {
82  return 1;
83  } else {
84  return -1;
85  }
86  }
87  };
88 
90  {
91  public:
92  SplitFragmentSenderState(PacketPtr _bigPkt, int _index) :
93  bigPkt(_bigPkt), index(_index)
94  {}
96  int index;
97 
98  void
100  {
101  SplitMainSenderState * main_send_state =
102  dynamic_cast<SplitMainSenderState *>(bigPkt->senderState);
103  main_send_state->fragments[index] = NULL;
104  }
105  };
106 
108  {
109  protected:
111 
112  public:
114  : cpu(_cpu)
115  {}
116 
117  void
119  {
120  assert(cpu->_status == BaseSimpleCPU::Running);
121  cpu->_status = ITBWaitResponse;
122  }
123 
124  void
125  finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc,
127  {
128  cpu->sendFetch(fault, req, tc);
129  }
130  };
132 
133  void threadSnoop(PacketPtr pkt, ThreadID sender);
134  void sendData(const RequestPtr &req,
135  uint8_t *data, uint64_t *res, bool read);
136  void sendSplitData(const RequestPtr &req1, const RequestPtr &req2,
137  const RequestPtr &req,
138  uint8_t *data, bool read);
139 
140  void translationFault(const Fault &fault);
141 
142  PacketPtr buildPacket(const RequestPtr &req, bool read);
143  void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
144  const RequestPtr &req1, const RequestPtr &req2,
145  const RequestPtr &req,
146  uint8_t *data, bool read);
147 
148  bool handleReadPacket(PacketPtr pkt);
149  // This function always implicitly uses dcache_pkt.
150  bool handleWritePacket();
151 
158  class TimingCPUPort : public MasterPort
159  {
160  public:
161 
162  TimingCPUPort(const std::string& _name, TimingSimpleCPU* _cpu)
163  : MasterPort(_name, _cpu), cpu(_cpu),
164  retryRespEvent([this]{ sendRetryResp(); }, name())
165  { }
166 
167  protected:
168 
170 
171  struct TickEvent : public Event
172  {
175 
176  TickEvent(TimingSimpleCPU *_cpu) : pkt(NULL), cpu(_cpu) {}
177  const char *description() const { return "Timing CPU tick"; }
178  void schedule(PacketPtr _pkt, Tick t);
179  };
180 
182  };
183 
184  class IcachePort : public TimingCPUPort
185  {
186  public:
187 
189  : TimingCPUPort(_cpu->name() + ".icache_port", _cpu),
190  tickEvent(_cpu)
191  { }
192 
193  protected:
194 
195  virtual bool recvTimingResp(PacketPtr pkt);
196 
197  virtual void recvReqRetry();
198 
199  struct ITickEvent : public TickEvent
200  {
201 
203  : TickEvent(_cpu) {}
204  void process();
205  const char *description() const { return "Timing CPU icache tick"; }
206  };
207 
209 
210  };
211 
212  class DcachePort : public TimingCPUPort
213  {
214  public:
215 
217  : TimingCPUPort(_cpu->name() + ".dcache_port", _cpu),
218  tickEvent(_cpu)
219  {
220  cacheBlockMask = ~(cpu->cacheLineSize() - 1);
221  }
222 
224  protected:
225 
229  virtual void recvTimingSnoopReq(PacketPtr pkt);
230  virtual void recvFunctionalSnoop(PacketPtr pkt);
231 
232  virtual bool recvTimingResp(PacketPtr pkt);
233 
234  virtual void recvReqRetry();
235 
236  virtual bool isSnooping() const {
237  return true;
238  }
239 
240  struct DTickEvent : public TickEvent
241  {
243  : TickEvent(_cpu) {}
244  void process();
245  const char *description() const { return "Timing CPU dcache tick"; }
246  };
247 
249 
250  };
251 
252  void updateCycleCounts();
253 
256 
259 
261 
262  protected:
263 
265  Port &getDataPort() override { return dcachePort; }
266 
268  Port &getInstPort() override { return icachePort; }
269 
270  public:
271 
272  DrainState drain() override;
273  void drainResume() override;
274 
275  void switchOut() override;
276  void takeOverFrom(BaseCPU *oldCPU) override;
277 
278  void verifyMemoryMode() const override;
279 
280  void activateContext(ThreadID thread_num) override;
281  void suspendContext(ThreadID thread_num) override;
282 
283  Fault initiateMemRead(Addr addr, unsigned size,
284  Request::Flags flags,
285  const std::vector<bool>& byte_enable =std::vector<bool>())
286  override;
287 
288  Fault writeMem(uint8_t *data, unsigned size,
289  Addr addr, Request::Flags flags, uint64_t *res,
290  const std::vector<bool>& byte_enable = std::vector<bool>())
291  override;
292 
293  Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags,
294  AtomicOpFunctorPtr amo_op) override;
295 
296  void fetch();
297  void sendFetch(const Fault &fault,
298  const RequestPtr &req, ThreadContext *tc);
299  void completeIfetch(PacketPtr );
300  void completeDataAccess(PacketPtr pkt);
301  void advanceInst(const Fault &fault);
302 
309  bool isSquashed() const { return false; }
310 
315  void printAddr(Addr a);
316 
322 
323  private:
324 
326 
327  struct IprEvent : Event {
330  IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, Tick t);
331  virtual void process();
332  virtual const char *description() const;
333  };
334 
351  bool isCpuDrained() const {
353  SimpleThread* thread = t_info.thread;
354 
355  return thread->microPC() == 0 && !t_info.stayAtPC &&
356  !fetchEvent.scheduled();
357  }
358 
364  bool tryCompleteDrain();
365 };
366 
367 #endif // __CPU_SIMPLE_TIMING_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:71
A TimingCPUPort overrides the default behaviour of the recvTiming and recvRetry and implements events...
Definition: timing.hh:158
Ports are used to interface objects to each other.
Definition: port.hh:56
Bitfield< 30, 0 > index
PacketPtr dcache_pkt
Definition: timing.hh:258
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:81
DcachePort dcachePort
Definition: timing.hh:255
void switchOut() override
Prepare for another CPU to take over execution.
Definition: timing.cc:171
bool isCpuDrained() const
Check if a system is in a drained state.
Definition: timing.hh:351
void sendData(const RequestPtr &req, uint8_t *data, uint64_t *res, bool read)
Definition: timing.cc:285
void finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc, BaseTLB::Mode mode)
Definition: timing.hh:125
std::shared_ptr< Request > RequestPtr
Definition: request.hh:81
Bitfield< 8 > a
void suspendContext(ThreadID thread_num) override
Notify the CPU that the indicated context is now suspended.
Definition: timing.cc:230
ip6_addr_t addr
Definition: inet.hh:330
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition: amo.hh:228
void verifyMemoryMode() const override
Verify that the system is in a memory mode supported by the CPU.
Definition: timing.cc:197
Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags, AtomicOpFunctorPtr amo_op) override
Definition: timing.cc:558
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:236
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: timing.cc:64
IcachePort(TimingSimpleCPU *_cpu)
Definition: timing.hh:188
This class captures the state of an address translation.
Definition: translation.hh:58
ThreadID curThread
Definition: base.hh:83
Bitfield< 4, 0 > mode
TimingCPUPort(const std::string &_name, TimingSimpleCPU *_cpu)
Definition: timing.hh:162
Port & getInstPort() override
Return a reference to the instruction port.
Definition: timing.hh:268
DcachePort(TimingSimpleCPU *_cpu)
Definition: timing.hh:216
ThreadContext is the external interface to all thread state for anything outside of the CPU...
DrainState
Object drain/handover states.
Definition: drain.hh:71
Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags, const std::vector< bool > &byte_enable=std::vector< bool >()) override
Definition: timing.cc:416
void completeIfetch(PacketPtr)
Definition: timing.cc:766
void fetch()
Definition: timing.cc:646
PacketPtr ifetch_pkt
Definition: timing.hh:257
bool tryCompleteDrain()
Try to complete a drain request.
Definition: timing.cc:155
EventFunctionWrapper retryRespEvent
Definition: timing.hh:181
void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2, const RequestPtr &req1, const RequestPtr &req2, const RequestPtr &req, uint8_t *data, bool read)
Definition: timing.cc:384
PacketPtr buildPacket(const RequestPtr &req, bool read)
Definition: timing.cc:378
void markDelayed()
Signal that the translation has been delayed due to a hw page table walk.
Definition: timing.hh:118
void sendSplitData(const RequestPtr &req1, const RequestPtr &req2, const RequestPtr &req, uint8_t *data, bool read)
Definition: timing.cc:322
uint64_t Tick
Tick count type.
Definition: types.hh:61
bool handleReadPacket(PacketPtr pkt)
Definition: timing.cc:256
FetchTranslation fetchTranslation
Definition: timing.hh:131
SplitFragmentSenderState(PacketPtr _bigPkt, int _index)
Definition: timing.hh:92
TickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:176
void translationFault(const Fault &fault)
Definition: timing.cc:359
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:189
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:492
Port & getDataPort() override
Return a reference to the data port.
Definition: timing.hh:265
void schedule(Event &event, Tick when)
Definition: eventq.hh:934
void sendFetch(const Fault &fault, const RequestPtr &req, ThreadContext *tc)
Definition: timing.cc:689
TimingSimpleCPU * cpu
Definition: timing.hh:169
Status _status
Definition: base.hh:121
SimpleThread * thread
Definition: exec_context.hh:64
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
ITickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:202
void threadSnoop(PacketPtr pkt, ThreadID sender)
Definition: timing.cc:606
EventFunctionWrapper fetchEvent
Definition: timing.hh:325
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:397
void activateContext(ThreadID thread_num) override
Notify the CPU that the indicated context is now active.
Definition: timing.cc:206
const char * description() const
Return a C string describing the event.
Definition: timing.hh:205
virtual ~TimingSimpleCPU()
Definition: timing.cc:86
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:459
Mode
Definition: tlb.hh:57
FetchTranslation(TimingSimpleCPU *_cpu)
Definition: timing.hh:113
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:225
virtual const std::string name() const
Definition: sim_object.hh:129
Cycles previousCycle
Definition: timing.hh:260
const char * description() const
Return a C string describing the event.
Definition: timing.hh:177
SenderState * senderState
This packet&#39;s sender state.
Definition: packet.hh:474
Definition: eventq.hh:245
DTickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:242
void advanceInst(const Fault &fault)
Definition: timing.cc:721
std::vector< SimpleExecContext * > threadInfo
Definition: base.hh:98
MicroPC microPC() const override
IcachePort icachePort
Definition: timing.hh:254
void finishTranslation(WholeTranslationState *state)
Finish a DTB translation.
Definition: timing.cc:620
void completeDataAccess(PacketPtr pkt)
Definition: timing.cc:870
TimingSimpleCPU * cpu
Definition: timing.hh:329
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: timing.cc:91
TimingSimpleCPU(TimingSimpleCPUParams *params)
Definition: timing.cc:76
Bitfield< 5 > t
void printAddr(Addr a)
Print state of address in memory system via PrintReq (for debugging).
Definition: timing.cc:1060
const char data[]
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
const Params * params() const
Definition: base.hh:307
void drainResume() override
Resume execution after a successful drain.
Definition: timing.cc:118
bool handleWritePacket()
Definition: timing.cc:470
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:309
const char * description() const
Definition: timing.hh:245
void updateCycleCounts()
Definition: timing.cc:929

Generated on Fri Jul 3 2020 15:53:01 for gem5 by doxygen 1.8.13