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
, int tid
)
151 resources
[res_idx
]->squash(inst
, ThePipeline::NumStages
-1, done_seq_num
, tid
);
155 ResourcePool::slotsAvail(int res_idx
)
157 return resources
[res_idx
]->slotsAvail();
161 ResourcePool::slotsInUse(int res_idx
)
163 return resources
[res_idx
]->slotsInUse();
167 ResourcePool::scheduleEvent(InOrderCPU::CPUEventType e_type
, DynInstPtr inst
,
168 int delay
, int res_idx
, int tid
)
172 ResPoolEvent
*res_pool_event
= new ResPoolEvent(this);
176 case InOrderCPU::ActivateThread
:
178 DPRINTF(Resource
, "Scheduling Activate Thread Resource Pool Event for tick %i.\n",
180 res_pool_event
->setEvent(e_type
,
182 inst
->squashingStage
,
185 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
190 case InOrderCPU::SuspendThread
:
191 case InOrderCPU::DeallocateThread
:
193 DPRINTF(Resource
, "Scheduling Deactivate Thread Resource Pool Event for tick %i.\n",
196 res_pool_event
->setEvent(e_type
,
198 inst
->squashingStage
,
202 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
207 case ResourcePool::InstGraduated
:
209 DPRINTF(Resource
, "Scheduling Inst-Graduated Resource Pool Event for tick %i.\n",
212 res_pool_event
->setEvent(e_type
,
214 inst
->squashingStage
,
217 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
222 case ResourcePool::SquashAll
:
224 DPRINTF(Resource
, "Scheduling Squash Resource Pool Event for tick %i.\n",
226 res_pool_event
->setEvent(e_type
,
228 inst
->squashingStage
,
231 res_pool_event
->schedule(curTick
+ cpu
->cycles(delay
));
237 DPRINTF(Resource
, "Ignoring Unrecognized CPU Event Type #%i.\n", e_type
);
238 ; // If Resource Pool doesnt recognize event, we ignore it.
243 ResourcePool::unscheduleEvent(int res_idx
, DynInstPtr inst
)
245 resources
[res_idx
]->unscheduleEvent(inst
);
249 ResourcePool::squashAll(DynInstPtr inst
, int stage_num
, InstSeqNum done_seq_num
, unsigned tid
)
251 DPRINTF(Resource
, "[tid:%i] Stage %i squashing all instructions above [sn:%i].\n",
252 stage_num
, tid
, done_seq_num
);
254 int num_resources
= resources
.size();
256 for (int idx
= 0; idx
< num_resources
; idx
++) {
257 resources
[idx
]->squash(inst
, stage_num
, done_seq_num
, tid
);
262 ResourcePool::activateAll(unsigned tid
)
264 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Activation to all resources.\n",
267 int num_resources
= resources
.size();
269 for (int idx
= 0; idx
< num_resources
; idx
++) {
270 resources
[idx
]->activateThread(tid
);
275 ResourcePool::deactivateAll(unsigned tid
)
277 DPRINTF(Resource
, "[tid:%i] Broadcasting Thread Deactivation to all resources.\n",
280 int num_resources
= resources
.size();
282 for (int idx
= 0; idx
< num_resources
; idx
++) {
283 resources
[idx
]->deactivateThread(tid
);
288 ResourcePool::instGraduated(InstSeqNum seq_num
,unsigned tid
)
290 DPRINTF(Resource
, "[tid:%i] Broadcasting [sn:%i] graduation to all resources.\n",
293 int num_resources
= resources
.size();
295 for (int idx
= 0; idx
< num_resources
; idx
++) {
296 resources
[idx
]->instGraduated(seq_num
, tid
);
300 ResourcePool::ResPoolEvent::ResPoolEvent(ResourcePool
*_resPool
)
301 : Event(&mainEventQueue
, CPU_Tick_Pri
),
303 { eventType
= (InOrderCPU::CPUEventType
) Default
; }
306 ResourcePool::ResPoolEvent::process()
310 case InOrderCPU::ActivateThread
:
311 resPool
->activateAll(tid
);
314 case InOrderCPU::SuspendThread
:
315 case InOrderCPU::DeallocateThread
:
316 resPool
->deactivateAll(tid
);
319 case ResourcePool::InstGraduated
:
320 resPool
->instGraduated(seqNum
, tid
);
323 case ResourcePool::SquashAll
:
324 resPool
->squashAll(inst
, stageNum
, seqNum
, tid
);
328 fatal("Unrecognized Event Type");
331 resPool
->cpu
->cpuEventRemoveList
.push(this);
336 ResourcePool::ResPoolEvent::description()
338 return "Resource Pool event";
341 /** Schedule resource event, regardless of its current state. */
343 ResourcePool::ResPoolEvent::scheduleEvent(int delay
)
346 reschedule(curTick
+ resPool
->cpu
->cycles(delay
));
347 else if (!scheduled())
348 schedule(curTick
+ resPool
->cpu
->cycles(delay
));
351 /** Unschedule resource event, regardless of its current state. */
353 ResourcePool::ResPoolEvent::unscheduleEvent()