inorder: stall signal handling
[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 ~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 unsigned getResIdx(const ThePipeline::ResourceId &res_id);
145
146 /** Returns a pointer to a resource */
147 Resource* getResource(int res_idx) { return resources[res_idx]; }
148
149 /** Request usage of this resource. Returns -1 if not granted and
150 * a positive request tag if granted.
151 */
152 ResReqPtr request(int res_idx, DynInstPtr inst);
153
154 /** Squash The Resource */
155 void squash(DynInstPtr inst, int res_idx, InstSeqNum done_seq_num,
156 ThreadID tid);
157
158 /** Squash All Resources in Pool after Done Seq. Num */
159 void squashAll(DynInstPtr inst, int stage_num,
160 InstSeqNum done_seq_num, ThreadID tid);
161
162 /** Squash Resources in Pool after a memory stall
163 * NOTE: Only use during Switch-On-Miss Thread model
164 */
165 void squashDueToMemStall(DynInstPtr inst, int stage_num,
166 InstSeqNum done_seq_num, ThreadID tid);
167
168 /** Activate Thread in all resources */
169 void activateAll(ThreadID tid);
170
171 /** De-Activate Thread in all resources */
172 void deactivateAll(ThreadID tid);
173
174 /** De-Activate Thread in all resources */
175 void suspendAll(ThreadID tid);
176
177 /** Broadcast Context Switch Update to all resources */
178 void updateAfterContextSwitch(DynInstPtr inst, ThreadID tid);
179
180 /** Broadcast graduation to all resources */
181 void instGraduated(InstSeqNum seq_num, ThreadID tid);
182
183 /** The number of instructions available that a resource can
184 * can still process.
185 */
186 int slotsAvail(int res_idx);
187
188 /** The number of instructions using a resource */
189 int slotsInUse(int res_idx);
190
191 /** Schedule resource event, regardless of its current state. */
192 void scheduleEvent(InOrderCPU::CPUEventType e_type, DynInstPtr inst = NULL,
193 int delay = 0, int res_idx = 0, ThreadID tid = 0);
194
195 /** UnSchedule resource event, regardless of its current state. */
196 void unscheduleEvent(int res_idx, DynInstPtr inst);
197
198 /** Tasks to perform when simulation starts */
199 virtual void startup() { }
200
201 /** The CPU(s) that this resource interacts with */
202 InOrderCPU *cpu;
203
204 DynInstPtr dummyInst[ThePipeline::MaxThreads];
205
206 private:
207 std::vector<Resource *> resources;
208
209 std::vector<int> memObjects;
210
211 };
212
213 #endif //__CPU_INORDER_RESOURCE_HH__