gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timing.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013,2015 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);
124  }
125 
126  void
127  finish(const Fault &fault, RequestPtr req, ThreadContext *tc,
129  {
130  cpu->sendFetch(fault, req, tc);
131  }
132  };
134 
135  void threadSnoop(PacketPtr pkt, ThreadID sender);
136  void sendData(RequestPtr req, uint8_t *data, uint64_t *res, bool read);
137  void sendSplitData(RequestPtr req1, RequestPtr req2, RequestPtr req,
138  uint8_t *data, bool read);
139 
140  void translationFault(const Fault &fault);
141 
142  PacketPtr buildPacket(RequestPtr req, bool read);
143  void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
144  RequestPtr req1, RequestPtr req2, RequestPtr req,
145  uint8_t *data, bool read);
146 
147  bool handleReadPacket(PacketPtr pkt);
148  // This function always implicitly uses dcache_pkt.
149  bool handleWritePacket();
150 
157  class TimingCPUPort : public MasterPort
158  {
159  public:
160 
161  TimingCPUPort(const std::string& _name, TimingSimpleCPU* _cpu)
162  : MasterPort(_name, _cpu), cpu(_cpu), retryRespEvent(this)
163  { }
164 
165  protected:
166 
168 
169  struct TickEvent : public Event
170  {
173 
174  TickEvent(TimingSimpleCPU *_cpu) : pkt(NULL), cpu(_cpu) {}
175  const char *description() const { return "Timing CPU tick"; }
176  void schedule(PacketPtr _pkt, Tick t);
177  };
178 
180  };
181 
182  class IcachePort : public TimingCPUPort
183  {
184  public:
185 
187  : TimingCPUPort(_cpu->name() + ".icache_port", _cpu),
188  tickEvent(_cpu)
189  { }
190 
191  protected:
192 
193  virtual bool recvTimingResp(PacketPtr pkt);
194 
195  virtual void recvReqRetry();
196 
197  struct ITickEvent : public TickEvent
198  {
199 
201  : TickEvent(_cpu) {}
202  void process();
203  const char *description() const { return "Timing CPU icache tick"; }
204  };
205 
207 
208  };
209 
210  class DcachePort : public TimingCPUPort
211  {
212  public:
213 
215  : TimingCPUPort(_cpu->name() + ".dcache_port", _cpu),
216  tickEvent(_cpu)
217  {
218  cacheBlockMask = ~(cpu->cacheLineSize() - 1);
219  }
220 
222  protected:
223 
227  virtual void recvTimingSnoopReq(PacketPtr pkt);
228  virtual void recvFunctionalSnoop(PacketPtr pkt);
229 
230  virtual bool recvTimingResp(PacketPtr pkt);
231 
232  virtual void recvReqRetry();
233 
234  virtual bool isSnooping() const {
235  return true;
236  }
237 
238  struct DTickEvent : public TickEvent
239  {
241  : TickEvent(_cpu) {}
242  void process();
243  const char *description() const { return "Timing CPU dcache tick"; }
244  };
245 
247 
248  };
249 
250  void updateCycleCounts();
251 
254 
257 
259 
260  protected:
261 
263  MasterPort &getDataPort() override { return dcachePort; }
264 
266  MasterPort &getInstPort() override { return icachePort; }
267 
268  public:
269 
270  DrainState drain() override;
271  void drainResume() override;
272 
273  void switchOut() override;
274  void takeOverFrom(BaseCPU *oldCPU) override;
275 
276  void verifyMemoryMode() const override;
277 
278  void activateContext(ThreadID thread_num) override;
279  void suspendContext(ThreadID thread_num) override;
280 
281  Fault readMem(Addr addr, uint8_t *data, unsigned size,
282  Request::Flags flags) override;
283 
284  Fault initiateMemRead(Addr addr, unsigned size,
285  Request::Flags flags) override;
286 
287  Fault writeMem(uint8_t *data, unsigned size,
288  Addr addr, Request::Flags flags, uint64_t *res) override;
289 
290  void fetch();
291  void sendFetch(const Fault &fault, RequestPtr req, ThreadContext *tc);
292  void completeIfetch(PacketPtr );
293  void completeDataAccess(PacketPtr pkt);
294  void advanceInst(const Fault &fault);
295 
302  bool isSquashed() const { return false; }
303 
308  void printAddr(Addr a);
309 
315 
316  private:
317 
320 
321  struct IprEvent : Event {
324  IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, Tick t);
325  virtual void process();
326  virtual const char *description() const;
327  };
328 
345  bool isDrained() {
347  SimpleThread* thread = t_info.thread;
348 
349  return thread->microPC() == 0 && !t_info.stayAtPC &&
351  }
352 
358  bool tryCompleteDrain();
359 };
360 
361 #endif // __CPU_SIMPLE_TIMING_HH__
const char * description() const
Definition: timing.hh:243
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:167
A TimingCPUPort overrides the default behaviour of the recvTiming and recvRetry and implements events...
Definition: timing.hh:157
virtual const char * description() const
Return a C string describing the event.
Definition: timing.cc:992
PacketPtr dcache_pkt
Definition: timing.hh:256
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
DcachePort dcachePort
Definition: timing.hh:253
void switchOut() override
Definition: timing.cc:169
DrainState
Object drain/handover states.
Definition: drain.hh:71
void schedule(PacketPtr _pkt, Tick t)
Definition: timing.cc:74
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the slave port.
Definition: timing.cc:780
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:99
bool isDrained()
Check if a system is in a drained state.
Definition: timing.hh:345
const char * description() const
Return a C string describing the event.
Definition: timing.hh:175
Bitfield< 8 > a
Definition: miscregs.hh:1377
void suspendContext(ThreadID thread_num) override
Definition: timing.cc:227
const char * description() const
Return a C string describing the event.
Definition: timing.hh:203
ip6_addr_t addr
Definition: inet.hh:335
void sendData(RequestPtr req, uint8_t *data, uint64_t *res, bool read)
Definition: timing.cc:282
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:381
void verifyMemoryMode() const override
Definition: timing.cc:194
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
void init() override
Definition: timing.cc:68
IcachePort(TimingSimpleCPU *_cpu)
Definition: timing.hh:186
PacketPtr buildPacket(RequestPtr req, bool read)
Definition: timing.cc:373
This class captures the state of an address translation.
Definition: translation.hh:61
ThreadID curThread
Definition: base.hh:87
Bitfield< 4, 0 > mode
Definition: miscregs.hh:1385
TimingCPUPort(const std::string &_name, TimingSimpleCPU *_cpu)
Definition: timing.hh:161
DcachePort(TimingSimpleCPU *_cpu)
Definition: timing.hh:214
virtual bool isSnooping() const
Determine if this master port is snooping or not.
Definition: timing.hh:234
ThreadContext is the external interface to all thread state for anything outside of the CPU...
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:302
const char data[]
Definition: circlebuf.cc:43
MicroPC microPC()
void completeIfetch(PacketPtr)
Definition: timing.cc:703
void fetch()
Definition: timing.cc:591
void buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2, RequestPtr req1, RequestPtr req2, RequestPtr req, uint8_t *data, bool read)
Definition: timing.cc:379
PacketPtr ifetch_pkt
Definition: timing.hh:255
bool tryCompleteDrain()
Try to complete a drain request.
Definition: timing.cc:153
void markDelayed()
Signal that the translation has been delayed due to a hw page table walk.
Definition: timing.hh:120
void sendFetch(const Fault &fault, RequestPtr req, ThreadContext *tc)
Definition: timing.cc:633
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool handleReadPacket(PacketPtr pkt)
Definition: timing.cc:253
FetchTranslation fetchTranslation
Definition: timing.hh:133
SplitFragmentSenderState(PacketPtr _bigPkt, int _index)
Definition: timing.hh:94
TickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:174
void translationFault(const Fault &fault)
Definition: timing.cc:355
EventWrapper< MasterPort,&MasterPort::sendRetryResp > retryRespEvent
Definition: timing.hh:179
void takeOverFrom(BaseCPU *oldCPU) override
Definition: timing.cc:186
virtual void recvFunctionalSnoop(PacketPtr pkt)
Receive a functional snoop request packet from the slave port.
Definition: timing.cc:898
TimingSimpleCPU * cpu
Definition: timing.hh:167
Status _status
Definition: base.hh:125
SimpleThread * thread
Definition: exec_context.hh:69
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
virtual void recvReqRetry()
Called by the slave port if sendTimingReq was called on this master port (causing recvTimingReq to be...
Definition: timing.cc:793
ITickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:200
void threadSnoop(PacketPtr pkt, ThreadID sender)
Definition: timing.cc:551
A virtual base opaque structure used to hold state associated with the packet (e.g., an MSHR), specific to a MemObject that sees the packet.
Definition: packet.hh:377
void activateContext(ThreadID thread_num) override
Definition: timing.cc:203
virtual ~TimingSimpleCPU()
Definition: timing.cc:90
void sendSplitData(RequestPtr req1, RequestPtr req2, RequestPtr req, uint8_t *data, bool read)
Definition: timing.cc:318
Mode
Definition: tlb.hh:61
FetchTranslation(TimingSimpleCPU *_cpu)
Definition: timing.hh:115
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
MasterPort & getDataPort() override
Return a reference to the data port.
Definition: timing.hh:263
int size()
Definition: pagetable.hh:146
Cycles previousCycle
Definition: timing.hh:258
virtual void recvReqRetry()
Called by the slave port if sendTimingReq was called on this master port (causing recvTimingReq to be...
Definition: timing.cc:935
IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, Tick t)
Definition: timing.cc:978
EventWrapper< TimingSimpleCPU,&TimingSimpleCPU::fetch > FetchEvent
Definition: timing.hh:318
SenderState * senderState
This packet's sender state.
Definition: packet.hh:454
Definition: eventq.hh:185
void finish(const Fault &fault, RequestPtr req, ThreadContext *tc, BaseTLB::Mode mode)
Definition: timing.hh:127
DTickEvent(TimingSimpleCPU *_cpu)
Definition: timing.hh:240
void advanceInst(const Fault &fault)
Definition: timing.cc:665
virtual bool recvTimingResp(PacketPtr pkt)
Receive a timing response from the slave port.
Definition: timing.cc:908
std::vector< SimpleExecContext * > threadInfo
Definition: base.hh:102
Fault readMem(Addr addr, uint8_t *data, unsigned size, Request::Flags flags) override
Definition: timing.cc:411
IcachePort icachePort
Definition: timing.hh:252
void finishTranslation(WholeTranslationState *state)
Finish a DTB translation.
Definition: timing.cc:565
Fault writeMem(uint8_t *data, unsigned size, Addr addr, Request::Flags flags, uint64_t *res) override
Definition: timing.cc:492
void completeDataAccess(PacketPtr pkt)
Definition: timing.cc:807
FetchEvent fetchEvent
Definition: timing.hh:319
TimingSimpleCPU * cpu
Definition: timing.hh:323
DrainState drain() override
Definition: timing.cc:95
TimingSimpleCPU(TimingSimpleCPUParams *params)
Definition: timing.cc:80
Bitfield< 5 > t
Definition: miscregs.hh:1382
virtual void process()
Definition: timing.cc:986
void printAddr(Addr a)
Print state of address in memory system via PrintReq (for debugging).
Definition: timing.cc:999
virtual void recvTimingSnoopReq(PacketPtr pkt)
Snoop a coherence request, we need to check if this causes a wakeup event on a cpu that is monitoring...
Definition: timing.cc:878
Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags) override
Definition: timing.cc:419
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
void drainResume() override
Definition: timing.cc:119
bool handleWritePacket()
Definition: timing.cc:470
void updateCycleCounts()
Definition: timing.cc:867
MasterPort & getInstPort() override
Return a reference to the instruction port.
Definition: timing.hh:266

Generated on Fri Jun 9 2017 13:03:44 for gem5 by doxygen 1.8.6