2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __CPU_OZONE_FRONT_END_HH__
32 #define __CPU_OZONE_FRONT_END_HH__
36 #include "arch/utility.hh"
37 #include "cpu/inst_seq.hh"
38 #include "cpu/o3/bpred_unit.hh"
39 #include "cpu/ozone/rename_table.hh"
40 #include "mem/port.hh"
41 #include "mem/request.hh"
42 #include "sim/eventq.hh"
43 #include "sim/stats.hh"
48 class OzoneThreadState;
57 typedef typename Impl::Params Params;
58 typedef typename Impl::DynInst DynInst;
59 typedef typename Impl::DynInstPtr DynInstPtr;
60 typedef typename Impl::CPUType CPUType;
61 typedef typename Impl::BackEnd BackEnd;
63 typedef typename Impl::CPUType::OzoneTC OzoneTC;
64 typedef typename Impl::CPUType::CommStruct CommStruct;
66 /** IcachePort class. Handles doing the communication with the
69 class IcachePort : public Port
76 /** Default constructor. */
77 IcachePort(FrontEnd<Impl> *_fe)
82 /** Atomic version of receive. Panics. */
83 virtual Tick recvAtomic(PacketPtr pkt);
85 /** Functional version of receive. Panics. */
86 virtual void recvFunctional(PacketPtr pkt);
88 /** Receives status change. Other than range changing, panics. */
89 virtual void recvStatusChange(Status status);
91 /** Returns the address ranges of this device. */
92 virtual void getDeviceAddressRanges(AddrRangeList &resp,
94 { resp.clear(); snoop.clear(); }
96 /** Timing version of receive. Handles setting fetch to the
97 * proper status to start fetching. */
98 virtual bool recvTiming(PacketPtr pkt);
100 /** Handles doing a retry of a failed fetch. */
101 virtual void recvRetry();
104 FrontEnd(Params *params);
106 std::string name() const;
108 void setCPU(CPUType *cpu_ptr);
110 void setBackEnd(BackEnd *back_end_ptr)
111 { backEnd = back_end_ptr; }
113 void setCommBuffer(TimeBuffer<CommStruct> *_comm);
115 void setTC(ThreadContext *tc_ptr);
117 void setThreadState(OzoneThreadState<Impl> *thread_ptr)
118 { thread = thread_ptr; }
123 Fault fetchCacheLine();
124 void processInst(DynInstPtr &inst);
125 void squash(const InstSeqNum &squash_num, const Addr &next_PC,
126 const bool is_branch = false, const bool branch_taken = false);
127 DynInstPtr getInst();
129 void processCacheCompletion(Packet *pkt);
131 void addFreeRegs(int num_freed);
133 bool isEmpty() { return instBuffer.empty(); }
139 void takeOverFrom(ThreadContext *old_tc = NULL);
141 bool isSwitchedOut() { return switchedOut; }
151 DynInstPtr getInstFromCacheline();
152 void renameInst(DynInstPtr &inst);
153 // Returns true if we need to stop the front end this cycle
154 bool processBarriers(DynInstPtr &inst);
156 void handleFault(Fault &fault);
158 Fault getFault() { return fetchFault; }
162 // Align an address (typically a PC) to the start of an I-cache block.
163 // We fold in the PISA 64- to 32-bit conversion here as well.
164 Addr icacheBlockAlignPC(Addr addr)
166 addr = TheISA::realPCToFetchPC(addr);
167 return (addr & ~(cacheBlkMask));
170 InstSeqNum getAndIncrementInstSeq()
171 { return cpu->globalSeqNum++; }
180 OzoneThreadState<Impl> *thread;
187 IcacheAccessComplete,
199 TimeBuffer<CommStruct> *comm;
200 typename TimeBuffer<CommStruct>::wire fromCommit;
202 typedef typename Impl::BranchPred BranchPred;
204 BranchPred branchPred;
206 IcachePort icachePort;
212 /** Mask to get a cache block's address. */
215 unsigned cacheBlkSize;
219 /** The cache line being fetched. */
222 bool fetchCacheLineNextCycle;
228 /** The packet that is waiting to be retried. */
232 RenameTable<Impl> renameTable;
239 void setPC(Addr val) { PC = val; }
240 void setNextPC(Addr val) { nextPC = val; }
242 void wakeFromQuiesce();
247 typedef typename std::deque<DynInstPtr> InstBuff;
248 typedef typename InstBuff::iterator InstBuffIt;
254 int maxInstBufferSize;
264 DynInstPtr barrierInst;
267 bool interruptPending;
269 // number of idle cycles
271 Stats::Average<> notIdleFraction;
272 Stats::Formula idleFraction;
274 // @todo: Consider making these vectors and tracking on a per thread basis.
275 /** Stat for total number of cycles stalled due to an icache miss. */
276 Stats::Scalar<> icacheStallCycles;
277 /** Stat for total number of fetched instructions. */
278 Stats::Scalar<> fetchedInsts;
279 Stats::Scalar<> fetchedBranches;
280 /** Stat for total number of predicted branches. */
281 Stats::Scalar<> predictedBranches;
282 /** Stat for total number of cycles spent fetching. */
283 Stats::Scalar<> fetchCycles;
285 Stats::Scalar<> fetchIdleCycles;
286 /** Stat for total number of cycles spent squashing. */
287 Stats::Scalar<> fetchSquashCycles;
288 /** Stat for total number of cycles spent blocked due to other stages in
291 Stats::Scalar<> fetchBlockedCycles;
292 /** Stat for total number of fetched cache lines. */
293 Stats::Scalar<> fetchedCacheLines;
295 Stats::Scalar<> fetchIcacheSquashes;
296 /** Distribution of number of instructions fetched each cycle. */
297 Stats::Distribution<> fetchNisnDist;
298 // Stats::Vector<> qfull_iq_occupancy;
299 // Stats::VectorDistribution<> qfull_iq_occ_dist_;
300 Stats::Formula idleRate;
301 Stats::Formula branchRate;
302 Stats::Formula fetchRate;
303 Stats::Scalar<> IFQCount; // cumulative IFQ occupancy
304 Stats::Formula IFQOccupancy;
305 Stats::Formula IFQLatency;
306 Stats::Scalar<> IFQFcount; // cumulative IFQ full count
307 Stats::Formula IFQFullRate;
309 Stats::Scalar<> dispatchCountStat;
310 Stats::Scalar<> dispatchedSerializing;
311 Stats::Scalar<> dispatchedTempSerializing;
312 Stats::Scalar<> dispatchSerializeStallCycles;
313 Stats::Formula dispatchRate;
314 Stats::Formula regIntFull;
315 Stats::Formula regFpFull;
318 #endif // __CPU_OZONE_FRONT_END_HH__