fu_pool.hh revision 8229
1955SN/A/*
2955SN/A * Copyright (c) 2006 The Regents of The University of Michigan
312230Sgiacomo.travaglini@arm.com * All rights reserved.
49812Sandreas.hansson@arm.com *
59812Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
69812Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
79812Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
89812Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
99812Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
109812Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
119812Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
129812Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
139812Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
149812Sandreas.hansson@arm.com * this software without specific prior written permission.
157816Ssteve.reinhardt@amd.com *
165871Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171762SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A *
28955SN/A * Authors: Kevin Lim
29955SN/A */
30955SN/A
31955SN/A#ifndef __CPU_O3_FU_POOL_HH__
32955SN/A#define __CPU_O3_FU_POOL_HH__
33955SN/A
34955SN/A#include <bitset>
35955SN/A#include <list>
36955SN/A#include <string>
37955SN/A#include <vector>
38955SN/A
39955SN/A#include "cpu/op_class.hh"
40955SN/A#include "cpu/sched_list.hh"
41955SN/A#include "params/FUPool.hh"
422665Ssaidi@eecs.umich.edu#include "sim/sim_object.hh"
432665Ssaidi@eecs.umich.edu
445863Snate@binkert.orgclass FUDesc;
45955SN/Aclass FuncUnit;
46955SN/A
47955SN/A/**
48955SN/A * Pool of FU's, specific to the new CPU model. The old FU pool had lists of
49955SN/A * free units and busy units, and whenever a FU was needed it would iterate
508878Ssteve.reinhardt@amd.com * through the free units to find a FU that provided the capability. This pool
512632Sstever@eecs.umich.edu * has lists of units specific to each of the capabilities, and whenever a FU
528878Ssteve.reinhardt@amd.com * is needed, it iterates through that list to find a free unit. The previous
532632Sstever@eecs.umich.edu * FU pool would have to be ticked each cycle to update which units became
54955SN/A * free. This FU pool lets the IEW stage handle freeing units, which frees
558878Ssteve.reinhardt@amd.com * them as their scheduled execution events complete. This limits units in this
562632Sstever@eecs.umich.edu * model to either have identical issue and op latencies, or 1 cycle issue
572761Sstever@eecs.umich.edu * latencies.
582632Sstever@eecs.umich.edu */
592632Sstever@eecs.umich.educlass FUPool : public SimObject
602632Sstever@eecs.umich.edu{
612761Sstever@eecs.umich.edu  private:
622761Sstever@eecs.umich.edu    /** Maximum op execution latencies, per op class. */
632761Sstever@eecs.umich.edu    unsigned maxOpLatencies[Num_OpClasses];
648878Ssteve.reinhardt@amd.com    /** Maximum issue latencies, per op class. */
658878Ssteve.reinhardt@amd.com    unsigned maxIssueLatencies[Num_OpClasses];
662761Sstever@eecs.umich.edu
672761Sstever@eecs.umich.edu    /** Bitvector listing capabilities of this FU pool. */
682761Sstever@eecs.umich.edu    std::bitset<Num_OpClasses> capabilityList;
692761Sstever@eecs.umich.edu
702761Sstever@eecs.umich.edu    /** Bitvector listing which FUs are busy. */
718878Ssteve.reinhardt@amd.com    std::vector<bool> unitBusy;
728878Ssteve.reinhardt@amd.com
732632Sstever@eecs.umich.edu    /** List of units to be freed at the end of this cycle. */
742632Sstever@eecs.umich.edu    std::vector<int> unitsToBeFreed;
758878Ssteve.reinhardt@amd.com
768878Ssteve.reinhardt@amd.com    /**
772632Sstever@eecs.umich.edu     * Class that implements a circular queue to hold FU indices. The hope is
78955SN/A     * that FUs that have been just used will be moved to the end of the queue
79955SN/A     * by iterating through it, thus leaving free units at the head of the
80955SN/A     * queue.
8112563Sgabeblack@google.com     */
8212563Sgabeblack@google.com    class FUIdxQueue {
836654Snate@binkert.org      public:
8410196SCurtis.Dunham@arm.com        /** Constructs a circular queue of FU indices. */
85955SN/A        FUIdxQueue()
865396Ssaidi@eecs.umich.edu            : idx(0), size(0)
8711401Sandreas.sandberg@arm.com        { }
885863Snate@binkert.org
895863Snate@binkert.org        /** Adds a FU to the queue. */
904202Sbinkertn@umich.edu        inline void addFU(int fu_idx);
915863Snate@binkert.org
925863Snate@binkert.org        /** Returns the index of the FU at the head of the queue, and changes
935863Snate@binkert.org         *  the index to the next element.
945863Snate@binkert.org         */
9513541Sandrea.mondelli@ucf.edu        inline int getFU();
96955SN/A
976654Snate@binkert.org      private:
985273Sstever@gmail.com        /** Circular queue index. */
995871Snate@binkert.org        int idx;
1005273Sstever@gmail.com
1016654Snate@binkert.org        /** Size of the queue. */
1025396Ssaidi@eecs.umich.edu        int size;
1038120Sgblack@eecs.umich.edu
1048120Sgblack@eecs.umich.edu        /** Queue of FU indices. */
1058120Sgblack@eecs.umich.edu        std::vector<int> funcUnitsIdx;
1068120Sgblack@eecs.umich.edu    };
1078120Sgblack@eecs.umich.edu
1088120Sgblack@eecs.umich.edu    /** Per op class queues of FUs that provide that capability. */
1098120Sgblack@eecs.umich.edu    FUIdxQueue fuPerCapList[Num_OpClasses];
1108120Sgblack@eecs.umich.edu
1118879Ssteve.reinhardt@amd.com    /** Number of FUs. */
1128879Ssteve.reinhardt@amd.com    int numFU;
1138879Ssteve.reinhardt@amd.com
1148879Ssteve.reinhardt@amd.com    /** Functional units. */
1158879Ssteve.reinhardt@amd.com    std::vector<FuncUnit *> funcUnits;
1168879Ssteve.reinhardt@amd.com
1178879Ssteve.reinhardt@amd.com    typedef std::vector<FuncUnit *>::iterator fuListIterator;
1188879Ssteve.reinhardt@amd.com
1198879Ssteve.reinhardt@amd.com  public:
1208879Ssteve.reinhardt@amd.com    typedef FUPoolParams Params;
1218879Ssteve.reinhardt@amd.com    /** Constructs a FU pool. */
1228879Ssteve.reinhardt@amd.com    FUPool(const Params *p);
1238879Ssteve.reinhardt@amd.com    ~FUPool();
1248120Sgblack@eecs.umich.edu
1258120Sgblack@eecs.umich.edu    /** Annotates units that provide memory operations. Included only because
1268120Sgblack@eecs.umich.edu     *  old FU pool provided this function.
1278120Sgblack@eecs.umich.edu     */
1288120Sgblack@eecs.umich.edu    void annotateMemoryUnits(unsigned hit_latency);
1298120Sgblack@eecs.umich.edu
1308120Sgblack@eecs.umich.edu    /**
1318120Sgblack@eecs.umich.edu     * Gets a FU providing the requested capability. Will mark the unit as busy,
1328120Sgblack@eecs.umich.edu     * but leaves the freeing of the unit up to the IEW stage.
1338120Sgblack@eecs.umich.edu     * @param capability The capability requested.
1348120Sgblack@eecs.umich.edu     * @return Returns -2 if the FU pool does not have the capability, -1 if
1358120Sgblack@eecs.umich.edu     * there is no free FU, and the FU's index otherwise.
1368120Sgblack@eecs.umich.edu     */
1378120Sgblack@eecs.umich.edu    int getUnit(OpClass capability);
1388879Ssteve.reinhardt@amd.com
1398879Ssteve.reinhardt@amd.com    /** Frees a FU at the end of this cycle. */
1408879Ssteve.reinhardt@amd.com    void freeUnitNextCycle(int fu_idx);
1418879Ssteve.reinhardt@amd.com
14210458Sandreas.hansson@arm.com    /** Frees all FUs on the list. */
14310458Sandreas.hansson@arm.com    void processFreeUnits();
14410458Sandreas.hansson@arm.com
1458879Ssteve.reinhardt@amd.com    /** Returns the total number of FUs. */
1468879Ssteve.reinhardt@amd.com    int size() { return numFU; }
1478879Ssteve.reinhardt@amd.com
1488879Ssteve.reinhardt@amd.com    /** Debugging function used to dump FU information. */
14913421Sciro.santilli@arm.com    void dump();
15013421Sciro.santilli@arm.com
1519227Sandreas.hansson@arm.com    /** Returns the operation execution latency of the given capability. */
1529227Sandreas.hansson@arm.com    unsigned getOpLatency(OpClass capability) {
15312063Sgabeblack@google.com        return maxOpLatencies[capability];
15412063Sgabeblack@google.com    }
15512063Sgabeblack@google.com
1568879Ssteve.reinhardt@amd.com    /** Returns the issue latency of the given capability. */
1578879Ssteve.reinhardt@amd.com    unsigned getIssueLatency(OpClass capability) {
1588879Ssteve.reinhardt@amd.com        return maxIssueLatencies[capability];
1598879Ssteve.reinhardt@amd.com    }
16010453SAndrew.Bardsley@arm.com
16110453SAndrew.Bardsley@arm.com    /** Switches out functional unit pool. */
16210453SAndrew.Bardsley@arm.com    void switchOut();
16310456SCurtis.Dunham@arm.com
16410456SCurtis.Dunham@arm.com    /** Takes over from another CPU's thread. */
16510456SCurtis.Dunham@arm.com    void takeOverFrom();
16610457Sandreas.hansson@arm.com};
16710457Sandreas.hansson@arm.com
16811342Sandreas.hansson@arm.com#endif // __CPU_O3_FU_POOL_HH__
16911342Sandreas.hansson@arm.com