fu_pool.hh revision 9444
1/*
2 * Copyright (c) 2012 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) 2006 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: Kevin Lim
41 */
42
43#ifndef __CPU_O3_FU_POOL_HH__
44#define __CPU_O3_FU_POOL_HH__
45
46#include <bitset>
47#include <list>
48#include <string>
49#include <vector>
50
51#include "cpu/op_class.hh"
52#include "params/FUPool.hh"
53#include "sim/sim_object.hh"
54
55class FUDesc;
56class FuncUnit;
57
58/**
59 * Pool of FU's, specific to the new CPU model. The old FU pool had lists of
60 * free units and busy units, and whenever a FU was needed it would iterate
61 * through the free units to find a FU that provided the capability. This pool
62 * has lists of units specific to each of the capabilities, and whenever a FU
63 * is needed, it iterates through that list to find a free unit. The previous
64 * FU pool would have to be ticked each cycle to update which units became
65 * free. This FU pool lets the IEW stage handle freeing units, which frees
66 * them as their scheduled execution events complete. This limits units in this
67 * model to either have identical issue and op latencies, or 1 cycle issue
68 * latencies.
69 */
70class FUPool : public SimObject
71{
72  private:
73    /** Maximum op execution latencies, per op class. */
74    Cycles maxOpLatencies[Num_OpClasses];
75    /** Maximum issue latencies, per op class. */
76    Cycles maxIssueLatencies[Num_OpClasses];
77
78    /** Bitvector listing capabilities of this FU pool. */
79    std::bitset<Num_OpClasses> capabilityList;
80
81    /** Bitvector listing which FUs are busy. */
82    std::vector<bool> unitBusy;
83
84    /** List of units to be freed at the end of this cycle. */
85    std::vector<int> unitsToBeFreed;
86
87    /**
88     * Class that implements a circular queue to hold FU indices. The hope is
89     * that FUs that have been just used will be moved to the end of the queue
90     * by iterating through it, thus leaving free units at the head of the
91     * queue.
92     */
93    class FUIdxQueue {
94      public:
95        /** Constructs a circular queue of FU indices. */
96        FUIdxQueue()
97            : idx(0), size(0)
98        { }
99
100        /** Adds a FU to the queue. */
101        inline void addFU(int fu_idx);
102
103        /** Returns the index of the FU at the head of the queue, and changes
104         *  the index to the next element.
105         */
106        inline int getFU();
107
108      private:
109        /** Circular queue index. */
110        int idx;
111
112        /** Size of the queue. */
113        int size;
114
115        /** Queue of FU indices. */
116        std::vector<int> funcUnitsIdx;
117    };
118
119    /** Per op class queues of FUs that provide that capability. */
120    FUIdxQueue fuPerCapList[Num_OpClasses];
121
122    /** Number of FUs. */
123    int numFU;
124
125    /** Functional units. */
126    std::vector<FuncUnit *> funcUnits;
127
128    typedef std::vector<FuncUnit *>::iterator fuListIterator;
129
130  public:
131    typedef FUPoolParams Params;
132    /** Constructs a FU pool. */
133    FUPool(const Params *p);
134    ~FUPool();
135
136    /** Annotates units that provide memory operations. Included only because
137     *  old FU pool provided this function.
138     */
139    void annotateMemoryUnits(Cycles hit_latency);
140
141    /**
142     * Gets a FU providing the requested capability. Will mark the unit as busy,
143     * but leaves the freeing of the unit up to the IEW stage.
144     * @param capability The capability requested.
145     * @return Returns -2 if the FU pool does not have the capability, -1 if
146     * there is no free FU, and the FU's index otherwise.
147     */
148    int getUnit(OpClass capability);
149
150    /** Frees a FU at the end of this cycle. */
151    void freeUnitNextCycle(int fu_idx);
152
153    /** Frees all FUs on the list. */
154    void processFreeUnits();
155
156    /** Returns the total number of FUs. */
157    int size() { return numFU; }
158
159    /** Debugging function used to dump FU information. */
160    void dump();
161
162    /** Returns the operation execution latency of the given capability. */
163    Cycles getOpLatency(OpClass capability) {
164        return maxOpLatencies[capability];
165    }
166
167    /** Returns the issue latency of the given capability. */
168    Cycles getIssueLatency(OpClass capability) {
169        return maxIssueLatencies[capability];
170    }
171
172    /** Perform sanity checks after a drain. */
173    void drainSanityCheck() const;
174
175    /** Takes over from another CPU's thread. */
176    void takeOverFrom() {};
177};
178
179#endif // __CPU_O3_FU_POOL_HH__
180