2 * Copyright (c) 2007 MIPS Technologies, Inc.
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.
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.
28 * Authors: Korey Sewell
32 #include "cpu/inorder/resource_pool.hh"
33 #include "cpu/inorder/resources/resource_list.hh"
39 using namespace ThePipeline
;
41 ResourcePool::ResourcePool(InOrderCPU
*_cpu
, InOrderCPUParams
*params
)
44 //@todo: use this function to instantiate the resources in resource pool. This will help in the
45 //auto-generation of this pipeline model.
46 //ThePipeline::addResources(resources, memObjects);
48 // Declare Resource Objects
49 // name - id - bandwidth - latency - CPU - Parameters
50 // --------------------------------------------------
51 resources
.push_back(new FetchSeqUnit("Fetch-Seq-Unit", FetchSeq
, StageWidth
* 2, 0, _cpu
, params
));
53 resources
.push_back(new TLBUnit("I-TLB", ITLB
, StageWidth
, 0, _cpu
, params
));
55 memObjects
.push_back(ICache
);
56 resources
.push_back(new CacheUnit("icache_port", ICache
, StageWidth
* MaxThreads
, 0, _cpu
, params
));
58 resources
.push_back(new DecodeUnit("Decode-Unit", Decode
, StageWidth
, 0, _cpu
, params
));
60 resources
.push_back(new BranchPredictor("Branch-Predictor", BPred
, StageWidth
, 0, _cpu
, params
));
62 for (int i
= 0; i
< params
->numberOfThreads
; i
++) {
64 sprintf(fbuff_name
, "Fetch-Buffer-T%i", i
);
65 resources
.push_back(new InstBuffer(fbuff_name
, FetchBuff
+ i
, 4, 0, _cpu
, params
));
68 resources
.push_back(new UseDefUnit("RegFile-Manager", RegManager
, StageWidth
* MaxThreads
, 0, _cpu
, params
));
70 resources
.push_back(new AGENUnit("AGEN-Unit", AGEN
, StageWidth
, 0, _cpu
, params
));
72 resources
.push_back(new ExecutionUnit("Execution-Unit", ExecUnit
, StageWidth
, 0, _cpu
, params
));
74 resources
.push_back(new MultDivUnit("Mult-Div-Unit", MDU
, 5, 0, _cpu
, params
));
76 resources
.push_back(new TLBUnit("D-TLB", DTLB
, StageWidth
, 0, _cpu
, params
));
78 memObjects
.push_back(DCache
);
79 resources
.push_back(new CacheUnit("dcache_port", DCache
, StageWidth
* MaxThreads
, 0, _cpu
, params
));
81 resources
.push_back(new GraduationUnit("Graduation-Unit", Grad
, StageWidth
* MaxThreads
, 0, _cpu
, params
));
87 for (int i
=0; i
< resources
.size(); i
++) {
95 return cpu
->name() + ".ResourcePool";
100 ResourcePool::regStats()
102 DPRINTF(Resource
, "Registering Stats Throughout Resource Pool.\n");
104 int num_resources
= resources
.size();
106 for (int idx
= 0; idx
< num_resources
; idx
++) {
107 resources
[idx
]->regStats();
112 ResourcePool::getPort(const std::string
&if_name
, int idx
)
114 for (int i
= 0; i
< memObjects
.size(); i
++) {
115 int obj_idx
= memObjects
[i
];
116 Port
*port
= resources
[obj_idx
]->getPort(if_name
, idx
);
126 ResourcePool::getPortIdx(const std::string
&port_name
)
128 for (int i
= 0; i
< memObjects
.size(); i
++) {
129 unsigned obj_idx
= memObjects
[i
];
130 Port
*port
= resources
[obj_idx
]->getPort(port_name
, obj_idx
);
140 ResourcePool::request(int res_idx
, DynInstPtr inst
)
142 //Make Sure This is a valid resource ID
143 assert(res_idx
>= 0 && res_idx
< resources
.size());
145 return resources
[res_idx
]->request(inst
);
149 ResourcePool::squash(DynInstPtr inst
, int res_idx
, InstSeqNum done_seq_num
,
152 resources
[res_idx
]->squash(inst
, ThePipeline::NumStages
-1, done_seq_num
, tid
);
156 ResourcePool::slotsAvail(int res_idx
)
158 return resources
[res_idx
]->slotsAvail();
162 ResourcePool::slotsInUse(int res_idx
)
164 return resources
[res_idx
]->slotsInUse();
168 ResourcePool::scheduleEvent(InOrderCPU::CPUEventType e_type
, DynInstPtr inst
,
169 int delay
, int res_idx
, ThreadID tid
)
173 ResPoolEvent
*res_pool_event
= new ResPoolEvent(this);
177 case InOrderCPU::ActivateThread
:
179 DPRINTF(Resource
, "Scheduling Activate Thread Resource Pool Event for tick %i.\n",
181 res_pool_event
->setEvent(e_type
,
183 inst
->squashingStage
,
186 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
191 case InOrderCPU::SuspendThread
:
192 case InOrderCPU::DeallocateThread
:
194 DPRINTF(Resource
, "Scheduling Deactivate Thread Resource Pool Event for tick %i.\n",
197 res_pool_event
->setEvent(e_type
,
199 inst
->squashingStage
,
203 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
208 case ResourcePool::InstGraduated
:
210 DPRINTF(Resource
, "Scheduling Inst-Graduated Resource Pool Event for tick %i.\n",
213 res_pool_event
->setEvent(e_type
,
215 inst
->squashingStage
,
218 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
223 case ResourcePool::SquashAll
:
225 DPRINTF(Resource
, "Scheduling Squash Resource Pool Event for tick %i.\n",
227 res_pool_event
->setEvent(e_type
,
229 inst
->squashingStage
,
232 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
238 DPRINTF(Resource
, "Ignoring Unrecognized CPU Event Type #%i.\n", e_type
);
239 ; // If Resource Pool doesnt recognize event, we ignore it.
244 ResourcePool::unscheduleEvent(int res_idx
, DynInstPtr inst
)
246 resources
[res_idx
]->unscheduleEvent(inst
);
250 ResourcePool::squashAll(DynInstPtr inst
, int stage_num
,
251 InstSeqNum done_seq_num
, ThreadID tid
)
253 DPRINTF(Resource
, "[tid:%i] Stage %i squashing all instructions above [sn:%i].\n",
254 stage_num
, tid
, done_seq_num
);
256 int num_resources
= resources
.size();
258 for (int idx
= 0; idx
< num_resources
; idx
++) {
259 resources
[idx
]->squash(inst
, stage_num
, done_seq_num
, tid
);
264 ResourcePool::activateAll(ThreadID tid
)
266 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Activation to all resources.\n",
269 int num_resources
= resources
.size();
271 for (int idx
= 0; idx
< num_resources
; idx
++) {
272 resources
[idx
]->activateThread(tid
);
277 ResourcePool::deactivateAll(ThreadID tid
)
279 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Deactivation to all resources.\n",
282 int num_resources
= resources
.size();
284 for (int idx
= 0; idx
< num_resources
; idx
++) {
285 resources
[idx
]->deactivateThread(tid
);
290 ResourcePool::instGraduated(InstSeqNum seq_num
, ThreadID tid
)
292 DPRINTF(Resource
, "[tid:%i] Broadcasting [sn:%i] graduation to all resources.\n",
295 int num_resources
= resources
.size();
297 for (int idx
= 0; idx
< num_resources
; idx
++) {
298 resources
[idx
]->instGraduated(seq_num
, tid
);
302 ResourcePool::ResPoolEvent::ResPoolEvent(ResourcePool
*_resPool
)
303 : Event(&mainEventQueue
, CPU_Tick_Pri
),
305 { eventType
= (InOrderCPU::CPUEventType
) Default
; }
308 ResourcePool::ResPoolEvent::process()
312 case InOrderCPU::ActivateThread
:
313 resPool
->activateAll(tid
);
316 case InOrderCPU::SuspendThread
:
317 case InOrderCPU::DeallocateThread
:
318 resPool
->deactivateAll(tid
);
321 case ResourcePool::InstGraduated
:
322 resPool
->instGraduated(seqNum
, tid
);
325 case ResourcePool::SquashAll
:
326 resPool
->squashAll(inst
, stageNum
, seqNum
, tid
);
330 fatal("Unrecognized Event Type");
333 resPool
->cpu
->cpuEventRemoveList
.push(this);
338 ResourcePool::ResPoolEvent::description()
340 return "Resource Pool event";
343 /** Schedule resource event, regardless of its current state. */
345 ResourcePool::ResPoolEvent::scheduleEvent(int delay
)
348 reschedule(curTick
+ resPool
->cpu
->cycles(delay
));
349 else if (!scheduled())
350 schedule(curTick
+ resPool
->cpu
->cycles(delay
));
353 /** Unschedule resource event, regardless of its current state. */
355 ResourcePool::ResPoolEvent::unscheduleEvent()