inorder: user per-thread dummy insts/reqs
[gem5.git] / src / cpu / inorder / resource_pool.hh
1 /*
2 * Copyright (c) 2007 MIPS Technologies, Inc.
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Korey Sewell
29 *
30 */
31
32 #ifndef __CPU_INORDER_RESOURCE_POOL_HH__
33 #define __CPU_INORDER_RESOURCE_POOL_HH__
34
35 #include <vector>
36 #include <list>
37 #include <string>
38
39 #include "cpu/inst_seq.hh"
40 #include "cpu/inorder/inorder_dyn_inst.hh"
41 #include "cpu/inorder/resource.hh"
42 #include "cpu/inorder/pipeline_traits.hh"
43 #include "cpu/inorder/params.hh"
44 #include "params/InOrderCPU.hh"
45 #include "cpu/inorder/cpu.hh"
46 #include "sim/eventq.hh"
47 #include "sim/sim_object.hh"
48
49 class Event;
50 class InOrderCPU;
51 class Resource;
52 class ResourceEvent;
53
54 class ResourcePool {
55 public:
56 typedef InOrderDynInst::DynInstPtr DynInstPtr;
57
58 public:
59 // List of Resource Pool Events that extends
60 // the list started by the CPU
61 // NOTE(1): Resource Pool also uses event list
62 // CPUEventType defined in inorder/cpu.hh
63 enum ResPoolEventType {
64 InstGraduated = InOrderCPU::NumCPUEvents,
65 SquashAll,
66 UpdateAfterContextSwitch,
67 Default
68 };
69
70 class ResPoolEvent : public Event
71 {
72 protected:
73 /** Resource Pool */
74 ResourcePool *resPool;
75
76 public:
77 InOrderCPU::CPUEventType eventType;
78
79 DynInstPtr inst;
80
81 InstSeqNum seqNum;
82
83 int stageNum;
84
85 ThreadID tid;
86
87 public:
88 /** Constructs a resource event. */
89 ResPoolEvent(ResourcePool *_resPool,
90 InOrderCPU::CPUEventType e_type,
91 DynInstPtr _inst,
92 int stage_num,
93 InstSeqNum seq_num,
94 ThreadID _tid);
95
96 /** Set Type of Event To Be Scheduled */
97 void setEvent(InOrderCPU::CPUEventType e_type,
98 DynInstPtr _inst,
99 int stage_num,
100 InstSeqNum seq_num,
101 ThreadID _tid)
102 {
103 eventType = e_type;
104 inst = _inst;
105 seqNum = seq_num;
106 stageNum = stage_num;
107 tid = _tid;
108 }
109
110 /** Processes a resource event. */
111 virtual void process();
112
113 /** Returns the description of the resource event. */
114 const char *description();
115
116 /** Schedule Event */
117 void scheduleEvent(int delay);
118
119 /** Unschedule This Event */
120 void unscheduleEvent();
121 };
122
123 public:
124 ResourcePool(InOrderCPU *_cpu, ThePipeline::Params *params);
125 virtual ~ResourcePool() {}
126
127 std::string name();
128
129 std::string name(int res_idx) { return resources[res_idx]->name(); }
130
131 void init();
132
133 /** Register Statistics in All Resources */
134 void regStats();
135
136 /** Returns a specific port. */
137 Port* getPort(const std::string &if_name, int idx);
138
139 /** Returns a specific port. */
140 unsigned getPortIdx(const std::string &port_name);
141
142 /** Returns a specific resource. */
143 unsigned getResIdx(const std::string &res_name);
144
145 /** Returns a pointer to a resource */
146 Resource* getResource(int res_idx) { return resources[res_idx]; }
147
148 /** Request usage of this resource. Returns -1 if not granted and
149 * a positive request tag if granted.
150 */
151 ResReqPtr request(int res_idx, DynInstPtr inst);
152
153 /** Squash The Resource */
154 void squash(DynInstPtr inst, int res_idx, InstSeqNum done_seq_num,
155 ThreadID tid);
156
157 /** Squash All Resources in Pool after Done Seq. Num */
158 void squashAll(DynInstPtr inst, int stage_num,
159 InstSeqNum done_seq_num, ThreadID tid);
160
161 /** Squash Resources in Pool after a memory stall
162 * NOTE: Only use during Switch-On-Miss Thread model
163 */
164 void squashDueToMemStall(DynInstPtr inst, int stage_num,
165 InstSeqNum done_seq_num, ThreadID tid);
166
167 /** Activate Thread in all resources */
168 void activateAll(ThreadID tid);
169
170 /** De-Activate Thread in all resources */
171 void deactivateAll(ThreadID tid);
172
173 /** De-Activate Thread in all resources */
174 void suspendAll(ThreadID tid);
175
176 /** Broadcast Context Switch Update to all resources */
177 void updateAfterContextSwitch(DynInstPtr inst, ThreadID tid);
178
179 /** Broadcast graduation to all resources */
180 void instGraduated(InstSeqNum seq_num, ThreadID tid);
181
182 /** The number of instructions available that a resource can
183 * can still process.
184 */
185 int slotsAvail(int res_idx);
186
187 /** The number of instructions using a resource */
188 int slotsInUse(int res_idx);
189
190 /** Schedule resource event, regardless of its current state. */
191 void scheduleEvent(InOrderCPU::CPUEventType e_type, DynInstPtr inst = NULL,
192 int delay = 0, int res_idx = 0, ThreadID tid = 0);
193
194 /** UnSchedule resource event, regardless of its current state. */
195 void unscheduleEvent(int res_idx, DynInstPtr inst);
196
197 /** Tasks to perform when simulation starts */
198 virtual void startup() { }
199
200 /** The CPU(s) that this resource interacts with */
201 InOrderCPU *cpu;
202
203 DynInstPtr dummyInst[ThePipeline::MaxThreads];
204
205 private:
206 std::vector<Resource *> resources;
207
208 std::vector<int> memObjects;
209
210 };
211
212 #endif //__CPU_INORDER_RESOURCE_HH__