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
, ThePipeline::Params
*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 resources
.push_back(new InstBuffer("Fetch-Buffer-T0", FetchBuff
, 4, 0, _cpu
, params
));
64 resources
.push_back(new UseDefUnit("RegFile-Manager", RegManager
, StageWidth
* MaxThreads
, 0, _cpu
, params
));
66 resources
.push_back(new AGENUnit("AGEN-Unit", AGEN
, StageWidth
, 0, _cpu
, params
));
68 resources
.push_back(new ExecutionUnit("Execution-Unit", ExecUnit
, StageWidth
, 0, _cpu
, params
));
70 resources
.push_back(new MultDivUnit("Mult-Div-Unit", MDU
, 5, 0, _cpu
, params
));
72 resources
.push_back(new TLBUnit("D-TLB", DTLB
, StageWidth
, 0, _cpu
, params
));
74 memObjects
.push_back(DCache
);
75 resources
.push_back(new CacheUnit("dcache_port", DCache
, StageWidth
* MaxThreads
, 0, _cpu
, params
));
77 resources
.push_back(new GraduationUnit("Graduation-Unit", Grad
, StageWidth
* MaxThreads
, 0, _cpu
, params
));
79 resources
.push_back(new InstBuffer("Fetch-Buffer-T1", FetchBuff2
, 4, 0, _cpu
, params
));
85 for (int i
=0; i
< resources
.size(); i
++) {
86 DPRINTF(Resource
, "Initializing resource: %s.\n", resources
[i
]->name());
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 DPRINTF(Resource
, "Binding %s in Resource Pool.\n", if_name
);
116 for (int i
= 0; i
< memObjects
.size(); i
++) {
117 int obj_idx
= memObjects
[i
];
118 Port
*port
= resources
[obj_idx
]->getPort(if_name
, idx
);
120 DPRINTF(Resource
, "%s set to resource %s(#%i) in Resource Pool.\n", if_name
,
121 resources
[obj_idx
]->name(), obj_idx
);
130 ResourcePool::getPortIdx(const std::string
&port_name
)
132 DPRINTF(Resource
, "Finding Port Idx for %s.\n", port_name
);
134 for (int i
= 0; i
< memObjects
.size(); i
++) {
135 unsigned obj_idx
= memObjects
[i
];
136 Port
*port
= resources
[obj_idx
]->getPort(port_name
, obj_idx
);
138 DPRINTF(Resource
, "Returning Port Idx %i for %s.\n", obj_idx
, port_name
);
147 ResourcePool::getResIdx(const std::string
&res_name
)
149 DPRINTF(Resource
, "Finding Resource Idx for %s.\n", res_name
);
151 int num_resources
= resources
.size();
153 for (int idx
= 0; idx
< num_resources
; idx
++) {
154 if (resources
[idx
]->name() == res_name
)
162 ResourcePool::request(int res_idx
, DynInstPtr inst
)
164 //Make Sure This is a valid resource ID
165 assert(res_idx
>= 0 && res_idx
< resources
.size());
167 return resources
[res_idx
]->request(inst
);
171 ResourcePool::squash(DynInstPtr inst
, int res_idx
, InstSeqNum done_seq_num
, int tid
)
173 resources
[res_idx
]->squash(inst
, ThePipeline::NumStages
-1, done_seq_num
, tid
);
177 ResourcePool::slotsAvail(int res_idx
)
179 return resources
[res_idx
]->slotsAvail();
183 ResourcePool::slotsInUse(int res_idx
)
185 return resources
[res_idx
]->slotsInUse();
189 ResourcePool::scheduleEvent(InOrderCPU::CPUEventType e_type
, DynInstPtr inst
,
190 int delay
, int res_idx
, int tid
)
194 ResPoolEvent
*res_pool_event
= new ResPoolEvent(this);
198 case InOrderCPU::ActivateThread
:
200 DPRINTF(Resource
, "Scheduling Activate Thread Resource Pool Event for tick %i.\n",
202 res_pool_event
->setEvent(e_type
,
204 inst
->squashingStage
,
207 mainEventQueue
.schedule(res_pool_event
, curTick
+ cpu
->ticks(delay
));
212 case InOrderCPU::SuspendThread
:
213 case InOrderCPU::DeallocateThread
:
215 DPRINTF(Resource
, "Scheduling Deactivate Thread Resource Pool Event for tick %i.\n",
218 res_pool_event
->setEvent(e_type
,
220 inst
->squashingStage
,
224 mainEventQueue
.schedule(res_pool_event
, curTick
+ cpu
->ticks(delay
));
229 case ResourcePool::InstGraduated
:
231 DPRINTF(Resource
, "Scheduling Inst-Graduated Resource Pool Event for tick %i.\n",
234 res_pool_event
->setEvent(e_type
,
236 inst
->squashingStage
,
239 mainEventQueue
.schedule(res_pool_event
, curTick
+ cpu
->ticks(delay
));
244 case ResourcePool::SquashAll
:
246 DPRINTF(Resource
, "Scheduling Squash Resource Pool Event for tick %i.\n",
248 res_pool_event
->setEvent(e_type
,
250 inst
->squashingStage
,
253 mainEventQueue
.schedule(res_pool_event
, curTick
+ cpu
->ticks(delay
));
259 DPRINTF(Resource
, "Ignoring Unrecognized CPU Event Type #%i.\n", e_type
);
260 ; // If Resource Pool doesnt recognize event, we ignore it.
265 ResourcePool::unscheduleEvent(int res_idx
, DynInstPtr inst
)
267 resources
[res_idx
]->unscheduleEvent(inst
);
271 ResourcePool::squashAll(DynInstPtr inst
, int stage_num
, InstSeqNum done_seq_num
, unsigned tid
)
273 DPRINTF(Resource
, "[tid:%i] Stage %i squashing all instructions above [sn:%i].\n",
274 stage_num
, tid
, done_seq_num
);
276 int num_resources
= resources
.size();
278 for (int idx
= 0; idx
< num_resources
; idx
++) {
279 resources
[idx
]->squash(inst
, stage_num
, done_seq_num
, tid
);
284 ResourcePool::activateAll(unsigned tid
)
286 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Activation to all resources.\n",
289 int num_resources
= resources
.size();
291 for (int idx
= 0; idx
< num_resources
; idx
++) {
292 resources
[idx
]->activateThread(tid
);
297 ResourcePool::deactivateAll(unsigned tid
)
299 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Deactivation to all resources.\n",
302 int num_resources
= resources
.size();
304 for (int idx
= 0; idx
< num_resources
; idx
++) {
305 resources
[idx
]->deactivateThread(tid
);
310 ResourcePool::instGraduated(InstSeqNum seq_num
,unsigned tid
)
312 DPRINTF(Resource
, "[tid:%i] Broadcasting [sn:%i] graduation to all resources.\n",
315 int num_resources
= resources
.size();
317 for (int idx
= 0; idx
< num_resources
; idx
++) {
318 resources
[idx
]->instGraduated(seq_num
, tid
);
322 ResourcePool::ResPoolEvent::ResPoolEvent(ResourcePool
*_resPool
)
323 : Event(CPU_Tick_Pri
),
325 { eventType
= (InOrderCPU::CPUEventType
) Default
; }
328 ResourcePool::ResPoolEvent::process()
332 case InOrderCPU::ActivateThread
:
333 resPool
->activateAll(tid
);
336 case InOrderCPU::SuspendThread
:
337 case InOrderCPU::DeallocateThread
:
338 resPool
->deactivateAll(tid
);
341 case ResourcePool::InstGraduated
:
342 resPool
->instGraduated(seqNum
, tid
);
345 case ResourcePool::SquashAll
:
346 resPool
->squashAll(inst
, stageNum
, seqNum
, tid
);
350 fatal("Unrecognized Event Type");
353 resPool
->cpu
->cpuEventRemoveList
.push(this);
358 ResourcePool::ResPoolEvent::description()
360 return "Resource Pool event";
363 /** Schedule resource event, regardless of its current state. */
365 ResourcePool::ResPoolEvent::scheduleEvent(int delay
)
368 mainEventQueue
.reschedule(this,curTick
+ resPool
->cpu
->ticks(delay
));
369 else if (!scheduled())
370 mainEventQueue
.schedule(this,curTick
+ resPool
->cpu
->ticks(delay
));
373 /** Unschedule resource event, regardless of its current state. */
375 ResourcePool::ResPoolEvent::unscheduleEvent()