fu_pool.hh revision 7813
12292SN/A/*
22689Sktlim@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
32292SN/A * All rights reserved.
42292SN/A *
52292SN/A * Redistribution and use in source and binary forms, with or without
62292SN/A * modification, are permitted provided that the following conditions are
72292SN/A * met: redistributions of source code must retain the above copyright
82292SN/A * notice, this list of conditions and the following disclaimer;
92292SN/A * redistributions in binary form must reproduce the above copyright
102292SN/A * notice, this list of conditions and the following disclaimer in the
112292SN/A * documentation and/or other materials provided with the distribution;
122292SN/A * neither the name of the copyright holders nor the names of its
132292SN/A * contributors may be used to endorse or promote products derived from
142292SN/A * this software without specific prior written permission.
152292SN/A *
162292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272689Sktlim@umich.edu *
282689Sktlim@umich.edu * Authors: Kevin Lim
292292SN/A */
302292SN/A
312292SN/A#ifndef __CPU_O3_FU_POOL_HH__
322292SN/A#define __CPU_O3_FU_POOL_HH__
332292SN/A
342292SN/A#include <bitset>
352292SN/A#include <list>
362292SN/A#include <string>
372292SN/A#include <vector>
382292SN/A
397813Ssteve.reinhardt@amd.com#include "cpu/sched_list.hh"
402669Sktlim@umich.edu#include "cpu/op_class.hh"
415034Smilesck@eecs.umich.edu#include "params/FUPool.hh"
422292SN/A#include "sim/sim_object.hh"
432292SN/A
442292SN/Aclass FUDesc;
452292SN/Aclass FuncUnit;
462292SN/A
472292SN/A/**
482292SN/A * Pool of FU's, specific to the new CPU model. The old FU pool had lists of
492292SN/A * free units and busy units, and whenever a FU was needed it would iterate
502292SN/A * through the free units to find a FU that provided the capability. This pool
512292SN/A * has lists of units specific to each of the capabilities, and whenever a FU
522292SN/A * is needed, it iterates through that list to find a free unit. The previous
532292SN/A * FU pool would have to be ticked each cycle to update which units became
542292SN/A * free. This FU pool lets the IEW stage handle freeing units, which frees
552292SN/A * them as their scheduled execution events complete. This limits units in this
562292SN/A * model to either have identical issue and op latencies, or 1 cycle issue
572292SN/A * latencies.
582292SN/A */
592292SN/Aclass FUPool : public SimObject
602292SN/A{
612292SN/A  private:
622292SN/A    /** Maximum op execution latencies, per op class. */
632292SN/A    unsigned maxOpLatencies[Num_OpClasses];
642292SN/A    /** Maximum issue latencies, per op class. */
652292SN/A    unsigned maxIssueLatencies[Num_OpClasses];
662292SN/A
672292SN/A    /** Bitvector listing capabilities of this FU pool. */
682292SN/A    std::bitset<Num_OpClasses> capabilityList;
692292SN/A
702292SN/A    /** Bitvector listing which FUs are busy. */
712292SN/A    std::vector<bool> unitBusy;
722292SN/A
732292SN/A    /** List of units to be freed at the end of this cycle. */
742292SN/A    std::vector<int> unitsToBeFreed;
752292SN/A
762292SN/A    /**
772292SN/A     * Class that implements a circular queue to hold FU indices. The hope is
782292SN/A     * that FUs that have been just used will be moved to the end of the queue
792292SN/A     * by iterating through it, thus leaving free units at the head of the
802292SN/A     * queue.
812292SN/A     */
822292SN/A    class FUIdxQueue {
832292SN/A      public:
842292SN/A        /** Constructs a circular queue of FU indices. */
852292SN/A        FUIdxQueue()
862292SN/A            : idx(0), size(0)
872292SN/A        { }
882292SN/A
892292SN/A        /** Adds a FU to the queue. */
902292SN/A        inline void addFU(int fu_idx);
912292SN/A
922292SN/A        /** Returns the index of the FU at the head of the queue, and changes
932292SN/A         *  the index to the next element.
942292SN/A         */
952292SN/A        inline int getFU();
962292SN/A
972292SN/A      private:
982292SN/A        /** Circular queue index. */
992292SN/A        int idx;
1002292SN/A
1012292SN/A        /** Size of the queue. */
1022292SN/A        int size;
1032292SN/A
1042292SN/A        /** Queue of FU indices. */
1052292SN/A        std::vector<int> funcUnitsIdx;
1062292SN/A    };
1072292SN/A
1082292SN/A    /** Per op class queues of FUs that provide that capability. */
1092292SN/A    FUIdxQueue fuPerCapList[Num_OpClasses];
1102292SN/A
1112292SN/A    /** Number of FUs. */
1122292SN/A    int numFU;
1132292SN/A
1142292SN/A    /** Functional units. */
1152292SN/A    std::vector<FuncUnit *> funcUnits;
1162292SN/A
1172292SN/A    typedef std::vector<FuncUnit *>::iterator fuListIterator;
1182292SN/A
1192292SN/A  public:
1205034Smilesck@eecs.umich.edu    typedef FUPoolParams Params;
1212292SN/A    /** Constructs a FU pool. */
1225034Smilesck@eecs.umich.edu    FUPool(const Params *p);
1232292SN/A    ~FUPool();
1242292SN/A
1252292SN/A    /** Annotates units that provide memory operations. Included only because
1262292SN/A     *  old FU pool provided this function.
1272292SN/A     */
1282292SN/A    void annotateMemoryUnits(unsigned hit_latency);
1292292SN/A
1302292SN/A    /**
1312292SN/A     * Gets a FU providing the requested capability. Will mark the unit as busy,
1322292SN/A     * but leaves the freeing of the unit up to the IEW stage.
1332292SN/A     * @param capability The capability requested.
1342292SN/A     * @return Returns -2 if the FU pool does not have the capability, -1 if
1352292SN/A     * there is no free FU, and the FU's index otherwise.
1362292SN/A     */
1372292SN/A    int getUnit(OpClass capability);
1382292SN/A
1392292SN/A    /** Frees a FU at the end of this cycle. */
1402327SN/A    void freeUnitNextCycle(int fu_idx);
1412292SN/A
1422292SN/A    /** Frees all FUs on the list. */
1432292SN/A    void processFreeUnits();
1442292SN/A
1452292SN/A    /** Returns the total number of FUs. */
1462292SN/A    int size() { return numFU; }
1472292SN/A
1482292SN/A    /** Debugging function used to dump FU information. */
1492292SN/A    void dump();
1502292SN/A
1512292SN/A    /** Returns the operation execution latency of the given capability. */
1522292SN/A    unsigned getOpLatency(OpClass capability) {
1532292SN/A        return maxOpLatencies[capability];
1542292SN/A    }
1552292SN/A
1562292SN/A    /** Returns the issue latency of the given capability. */
1572292SN/A    unsigned getIssueLatency(OpClass capability) {
1582292SN/A        return maxIssueLatencies[capability];
1592292SN/A    }
1602307SN/A
1612348SN/A    /** Switches out functional unit pool. */
1622307SN/A    void switchOut();
1632348SN/A
1642348SN/A    /** Takes over from another CPU's thread. */
1652307SN/A    void takeOverFrom();
1662292SN/A};
1672292SN/A
1682292SN/A#endif // __CPU_O3_FU_POOL_HH__
169