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