e8400405aedeedaf47937eee57e5aa7585e8f203
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.
45 //This will help in the 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
,
52 StageWidth
* 2, 0, _cpu
, params
));
54 memObjects
.push_back(ICache
);
55 resources
.push_back(new CacheUnit("icache_port", ICache
,
56 StageWidth
* MaxThreads
, 0, _cpu
,
59 resources
.push_back(new DecodeUnit("Decode-Unit", Decode
,
60 StageWidth
, 0, _cpu
, params
));
62 resources
.push_back(new BranchPredictor("Branch-Predictor", BPred
,
63 StageWidth
, 0, _cpu
, params
));
65 resources
.push_back(new InstBuffer("Fetch-Buffer-T0", FetchBuff
, 4,
68 resources
.push_back(new UseDefUnit("RegFile-Manager", RegManager
,
69 StageWidth
* MaxThreads
, 0, _cpu
,
72 resources
.push_back(new AGENUnit("AGEN-Unit", AGEN
,
73 StageWidth
, 0, _cpu
, params
));
75 resources
.push_back(new ExecutionUnit("Execution-Unit", ExecUnit
,
76 StageWidth
, 0, _cpu
, params
));
78 resources
.push_back(new MultDivUnit("Mult-Div-Unit", MDU
, 5, 0, _cpu
,
81 memObjects
.push_back(DCache
);
82 resources
.push_back(new CacheUnit("dcache_port", DCache
,
83 StageWidth
* MaxThreads
, 0, _cpu
,
86 resources
.push_back(new GraduationUnit("Graduation-Unit", Grad
,
87 StageWidth
* MaxThreads
, 0, _cpu
,
90 resources
.push_back(new InstBuffer("Fetch-Buffer-T1", FetchBuff2
, 4,
94 ResourcePool::~ResourcePool()
96 cout
<< "Deleting resources ..." << endl
;
98 for (int i
=0; i
< resources
.size(); i
++) {
99 DPRINTF(Resource
, "Deleting resource: %s.\n", resources
[i
]->name());
109 for (int i
=0; i
< resources
.size(); i
++) {
110 DPRINTF(Resource
, "Initializing resource: %s.\n",
111 resources
[i
]->name());
113 resources
[i
]->init();
120 return cpu
->name() + ".ResourcePool";
125 ResourcePool::regStats()
127 DPRINTF(Resource
, "Registering Stats Throughout Resource Pool.\n");
129 int num_resources
= resources
.size();
131 for (int idx
= 0; idx
< num_resources
; idx
++) {
132 resources
[idx
]->regStats();
137 ResourcePool::getPort(const std::string
&if_name
, int idx
)
139 DPRINTF(Resource
, "Binding %s in Resource Pool.\n", if_name
);
141 for (int i
= 0; i
< memObjects
.size(); i
++) {
142 int obj_idx
= memObjects
[i
];
143 Port
*port
= resources
[obj_idx
]->getPort(if_name
, idx
);
145 DPRINTF(Resource
, "%s set to resource %s(#%i) in Resource Pool.\n",
146 if_name
, resources
[obj_idx
]->name(), obj_idx
);
155 ResourcePool::getPortIdx(const std::string
&port_name
)
157 DPRINTF(Resource
, "Finding Port Idx for %s.\n", port_name
);
159 for (int i
= 0; i
< memObjects
.size(); i
++) {
160 unsigned obj_idx
= memObjects
[i
];
161 Port
*port
= resources
[obj_idx
]->getPort(port_name
, obj_idx
);
163 DPRINTF(Resource
, "Returning Port Idx %i for %s.\n", obj_idx
,
173 ResourcePool::getResIdx(const std::string
&res_name
)
175 DPRINTF(Resource
, "Finding Resource Idx for %s.\n", res_name
);
177 int num_resources
= resources
.size();
179 for (int idx
= 0; idx
< num_resources
; idx
++) {
180 if (resources
[idx
]->name() == res_name
)
184 panic("Can't find resource idx for: %s\n", res_name
);
189 ResourcePool::getResIdx(const ThePipeline::ResourceId
&res_id
)
191 int num_resources
= resources
.size();
193 for (int idx
= 0; idx
< num_resources
; idx
++) {
194 if (resources
[idx
]->getId() == res_id
)
198 // todo: change return value to int and return a -1 here
199 // maybe even have enumerated type
201 panic("Can't find resource idx for: %i\n", res_id
);
207 ResourcePool::request(int res_idx
, DynInstPtr inst
)
209 //Make Sure This is a valid resource ID
210 assert(res_idx
>= 0 && res_idx
< resources
.size());
212 return resources
[res_idx
]->request(inst
);
216 ResourcePool::squash(DynInstPtr inst
, int res_idx
, InstSeqNum done_seq_num
,
219 resources
[res_idx
]->squash(inst
, ThePipeline::NumStages
-1, done_seq_num
,
224 ResourcePool::slotsAvail(int res_idx
)
226 return resources
[res_idx
]->slotsAvail();
230 ResourcePool::slotsInUse(int res_idx
)
232 return resources
[res_idx
]->slotsInUse();
235 //@todo: split this function and call this version schedulePoolEvent
236 // and use this scheduleEvent for scheduling a specific event on
238 //@todo: For arguments that arent being used in a ResPoolEvent, a dummyParam
239 // or some typedef can be used to signify what's important info
240 // to the event construction
242 ResourcePool::scheduleEvent(InOrderCPU::CPUEventType e_type
, DynInstPtr inst
,
243 int delay
, int res_idx
, ThreadID tid
)
247 Tick when
= cpu
->nextCycle(curTick() + cpu
->ticks(delay
));
251 case InOrderCPU::ActivateThread
:
253 DPRINTF(Resource
, "Scheduling Activate Thread Resource Pool Event "
254 "for tick %i, [tid:%i].\n", curTick() + delay
,
256 ResPoolEvent
*res_pool_event
=
257 new ResPoolEvent(this,
260 inst
->squashingStage
,
263 cpu
->schedule(res_pool_event
, when
);
267 case InOrderCPU::HaltThread
:
268 case InOrderCPU::DeactivateThread
:
271 DPRINTF(Resource
, "Scheduling Deactivate Thread Resource Pool "
272 "Event for tick %i.\n", curTick() + delay
);
273 ResPoolEvent
*res_pool_event
=
274 new ResPoolEvent(this,
277 inst
->squashingStage
,
281 cpu
->schedule(res_pool_event
, when
);
285 case InOrderCPU::SuspendThread
:
287 // not sure why we add another nextCycle() call here...
288 Tick sked_tick
= cpu
->nextCycle(when
);
290 DPRINTF(Resource
, "Scheduling Suspend Thread Resource Pool "
291 "Event for tick %i.\n", sked_tick
);
293 ResPoolEvent
*res_pool_event
= new ResPoolEvent(this,
296 inst
->squashingStage
,
300 cpu
->schedule(res_pool_event
, sked_tick
);
304 case ResourcePool::InstGraduated
:
306 DPRINTF(Resource
, "Scheduling Inst-Graduated Resource Pool "
307 "Event for tick %i.\n", curTick() + delay
);
308 ResPoolEvent
*res_pool_event
=
309 new ResPoolEvent(this,e_type
,
311 inst
->squashingStage
,
314 cpu
->schedule(res_pool_event
, when
);
318 case ResourcePool::SquashAll
:
320 DPRINTF(Resource
, "Scheduling Squash Resource Pool Event for "
321 "tick %i.\n", curTick() + delay
);
322 ResPoolEvent
*res_pool_event
=
323 new ResPoolEvent(this,e_type
,
325 inst
->squashingStage
,
328 cpu
->schedule(res_pool_event
, when
);
332 case InOrderCPU::SquashFromMemStall
:
334 DPRINTF(Resource
, "Scheduling Squash Due to Memory Stall Resource "
335 "Pool Event for tick %i.\n",
337 ResPoolEvent
*res_pool_event
=
338 new ResPoolEvent(this,e_type
,
340 inst
->squashingStage
,
343 cpu
->schedule(res_pool_event
, when
);
347 case ResourcePool::UpdateAfterContextSwitch
:
349 DPRINTF(Resource
, "Scheduling UpdatePC Resource Pool Event "
352 ResPoolEvent
*res_pool_event
= new ResPoolEvent(this,e_type
,
354 inst
->squashingStage
,
357 cpu
->schedule(res_pool_event
, when
);
362 DPRINTF(Resource
, "Ignoring Unrecognized CPU Event (%s).\n",
363 InOrderCPU::eventNames
[e_type
]);
368 ResourcePool::unscheduleEvent(int res_idx
, DynInstPtr inst
)
370 resources
[res_idx
]->unscheduleEvent(inst
);
374 ResourcePool::squashAll(DynInstPtr inst
, int stage_num
,
375 InstSeqNum done_seq_num
, ThreadID tid
)
377 DPRINTF(Resource
, "[tid:%i] Broadcasting Squash All Event "
378 " starting w/stage %i for all instructions above [sn:%i].\n",
379 tid
, stage_num
, done_seq_num
);
381 int num_resources
= resources
.size();
383 for (int idx
= 0; idx
< num_resources
; idx
++) {
384 resources
[idx
]->squash(inst
, stage_num
, done_seq_num
, tid
);
389 ResourcePool::squashDueToMemStall(DynInstPtr inst
, int stage_num
,
390 InstSeqNum done_seq_num
, ThreadID tid
)
392 DPRINTF(Resource
, "[tid:%i] Broadcasting SquashDueToMemStall Event"
393 " starting w/stage %i for all instructions above [sn:%i].\n",
394 tid
, stage_num
, done_seq_num
);
396 int num_resources
= resources
.size();
398 for (int idx
= 0; idx
< num_resources
; idx
++) {
399 resources
[idx
]->squashDueToMemStall(inst
, stage_num
, done_seq_num
,
405 ResourcePool::activateAll(ThreadID tid
)
407 bool do_activate
= cpu
->threadModel
!= InOrderCPU::SwitchOnCacheMiss
||
408 cpu
->numActiveThreads() < 1 ||
409 cpu
->activeThreadId() == tid
;
413 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Activation to all "
414 "resources.\n", tid
);
416 int num_resources
= resources
.size();
418 for (int idx
= 0; idx
< num_resources
; idx
++) {
419 resources
[idx
]->activateThread(tid
);
422 DPRINTF(Resource
, "[tid:%i] Ignoring Thread Activation to all "
423 "resources.\n", tid
);
428 ResourcePool::deactivateAll(ThreadID tid
)
430 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Deactivation to all "
431 "resources.\n", tid
);
433 int num_resources
= resources
.size();
435 for (int idx
= 0; idx
< num_resources
; idx
++) {
436 resources
[idx
]->deactivateThread(tid
);
441 ResourcePool::suspendAll(ThreadID tid
)
443 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Suspension to all "
444 "resources.\n", tid
);
446 int num_resources
= resources
.size();
448 for (int idx
= 0; idx
< num_resources
; idx
++) {
449 resources
[idx
]->suspendThread(tid
);
454 ResourcePool::instGraduated(InstSeqNum seq_num
, ThreadID tid
)
456 DPRINTF(Resource
, "[tid:%i] Broadcasting [sn:%i] graduation to all "
457 "resources.\n", tid
, seq_num
);
459 int num_resources
= resources
.size();
461 for (int idx
= 0; idx
< num_resources
; idx
++) {
462 resources
[idx
]->instGraduated(seq_num
, tid
);
467 ResourcePool::updateAfterContextSwitch(DynInstPtr inst
, ThreadID tid
)
469 DPRINTF(Resource
, "[tid:%i] Broadcasting Update PC to all resources.\n",
472 int num_resources
= resources
.size();
474 for (int idx
= 0; idx
< num_resources
; idx
++) {
475 resources
[idx
]->updateAfterContextSwitch(inst
, tid
);
479 ResourcePool::ResPoolEvent::ResPoolEvent(ResourcePool
*_resPool
,
480 InOrderCPU::CPUEventType e_type
,
485 : Event(CPU_Tick_Pri
), resPool(_resPool
),
486 eventType(e_type
), inst(_inst
), seqNum(seq_num
),
487 stageNum(stage_num
), tid(_tid
)
492 ResourcePool::ResPoolEvent::process()
496 case InOrderCPU::ActivateThread
:
497 resPool
->activateAll(tid
);
500 case InOrderCPU::DeactivateThread
:
501 case InOrderCPU::HaltThread
:
502 resPool
->deactivateAll(tid
);
505 case InOrderCPU::SuspendThread
:
506 resPool
->suspendAll(tid
);
509 case ResourcePool::InstGraduated
:
510 resPool
->instGraduated(seqNum
, tid
);
513 case ResourcePool::SquashAll
:
514 resPool
->squashAll(inst
, stageNum
, seqNum
, tid
);
517 case InOrderCPU::SquashFromMemStall
:
518 resPool
->squashDueToMemStall(inst
, stageNum
, seqNum
, tid
);
521 case ResourcePool::UpdateAfterContextSwitch
:
522 resPool
->updateAfterContextSwitch(inst
, tid
);
526 fatal("Unrecognized Event Type");
529 resPool
->cpu
->cpuEventRemoveList
.push(this);
534 ResourcePool::ResPoolEvent::description()
536 return "Resource Pool event";
539 /** Schedule resource event, regardless of its current state. */
541 ResourcePool::ResPoolEvent::scheduleEvent(int delay
)
543 InOrderCPU
*cpu
= resPool
->cpu
;
544 assert(!scheduled() || squashed());
545 cpu
->reschedule(this, cpu
->nextCycle(curTick() + cpu
->ticks(delay
)), true);
548 /** Unschedule resource event, regardless of its current state. */
550 ResourcePool::ResPoolEvent::unscheduleEvent()