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; }
122 Port *getIcachePort() { return &icachePort; }
125 Fault fetchCacheLine();
126 void processInst(DynInstPtr &inst);
127 void squash(const InstSeqNum &squash_num, const Addr &next_PC,
128 const bool is_branch = false, const bool branch_taken = false);
129 DynInstPtr getInst();
131 void processCacheCompletion(Packet *pkt);
133 void addFreeRegs(int num_freed);
135 bool isEmpty() { return instBuffer.empty(); }
141 void takeOverFrom(ThreadContext *old_tc = NULL);
143 bool isSwitchedOut() { return switchedOut; }
153 DynInstPtr getInstFromCacheline();
154 void renameInst(DynInstPtr &inst);
155 // Returns true if we need to stop the front end this cycle
156 bool processBarriers(DynInstPtr &inst);
158 void handleFault(Fault &fault);
160 Fault getFault() { return fetchFault; }
164 // Align an address (typically a PC) to the start of an I-cache block.
165 // We fold in the PISA 64- to 32-bit conversion here as well.
166 Addr icacheBlockAlignPC(Addr addr)
168 addr = TheISA::realPCToFetchPC(addr);
169 return (addr & ~(cacheBlkMask));
172 InstSeqNum getAndIncrementInstSeq()
173 { return cpu->globalSeqNum++; }
182 OzoneThreadState<Impl> *thread;
189 IcacheAccessComplete,
201 TimeBuffer<CommStruct> *comm;
202 typename TimeBuffer<CommStruct>::wire fromCommit;
204 typedef typename Impl::BranchPred BranchPred;
206 BranchPred branchPred;
208 IcachePort icachePort;
214 /** Mask to get a cache block's address. */
217 unsigned cacheBlkSize;
221 /** The cache line being fetched. */
224 bool fetchCacheLineNextCycle;
230 /** The packet that is waiting to be retried. */
234 RenameTable<Impl> renameTable;
241 void setPC(Addr val) { PC = val; }
242 void setNextPC(Addr val) { nextPC = val; }
244 void wakeFromQuiesce();
249 typedef typename std::deque<DynInstPtr> InstBuff;
250 typedef typename InstBuff::iterator InstBuffIt;
256 int maxInstBufferSize;
266 DynInstPtr barrierInst;
269 bool interruptPending;
271 // number of idle cycles
273 Stats::Average<> notIdleFraction;
274 Stats::Formula idleFraction;
276 // @todo: Consider making these vectors and tracking on a per thread basis.
277 /** Stat for total number of cycles stalled due to an icache miss. */
278 Stats::Scalar<> icacheStallCycles;
279 /** Stat for total number of fetched instructions. */
280 Stats::Scalar<> fetchedInsts;
281 Stats::Scalar<> fetchedBranches;
282 /** Stat for total number of predicted branches. */
283 Stats::Scalar<> predictedBranches;
284 /** Stat for total number of cycles spent fetching. */
285 Stats::Scalar<> fetchCycles;
287 Stats::Scalar<> fetchIdleCycles;
288 /** Stat for total number of cycles spent squashing. */
289 Stats::Scalar<> fetchSquashCycles;
290 /** Stat for total number of cycles spent blocked due to other stages in
293 Stats::Scalar<> fetchBlockedCycles;
294 /** Stat for total number of fetched cache lines. */
295 Stats::Scalar<> fetchedCacheLines;
297 Stats::Scalar<> fetchIcacheSquashes;
298 /** Distribution of number of instructions fetched each cycle. */
299 Stats::Distribution<> fetchNisnDist;
300 // Stats::Vector<> qfull_iq_occupancy;
301 // Stats::VectorDistribution<> qfull_iq_occ_dist_;
302 Stats::Formula idleRate;
303 Stats::Formula branchRate;
304 Stats::Formula fetchRate;
305 Stats::Scalar<> IFQCount; // cumulative IFQ occupancy
306 Stats::Formula IFQOccupancy;
307 Stats::Formula IFQLatency;
308 Stats::Scalar<> IFQFcount; // cumulative IFQ full count
309 Stats::Formula IFQFullRate;
311 Stats::Scalar<> dispatchCountStat;
312 Stats::Scalar<> dispatchedSerializing;
313 Stats::Scalar<> dispatchedTempSerializing;
314 Stats::Scalar<> dispatchSerializeStallCycles;
315 Stats::Formula dispatchRate;
316 Stats::Formula regIntFull;
317 Stats::Formula regFpFull;
320 #endif // __CPU_OZONE_FRONT_END_HH__