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 #ifndef __CPU_INORDER_RESOURCE_POOL_HH__
33 #define __CPU_INORDER_RESOURCE_POOL_HH__
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"
56 typedef InOrderDynInst::DynInstPtr DynInstPtr;
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,
69 class ResPoolEvent : public Event
73 ResourcePool *resPool;
76 InOrderCPU::CPUEventType eventType;
87 /** Constructs a resource event. */
88 ResPoolEvent(ResourcePool *_resPool);
90 /** Set Type of Event To Be Scheduled */
91 void setEvent(InOrderCPU::CPUEventType e_type,
100 stageNum = stage_num;
104 /** Processes a resource event. */
105 virtual void process();
107 /** Returns the description of the resource event. */
108 const char *description();
110 /** Schedule Event */
111 void scheduleEvent(int delay);
113 /** Unschedule This Event */
114 void unscheduleEvent();
118 ResourcePool(InOrderCPU *_cpu, ThePipeline::Params *params);
119 virtual ~ResourcePool() {}
123 std::string name(int res_idx) { return resources[res_idx]->name(); }
127 /** Register Statistics in All Resources */
130 /** Returns a specific port. */
131 Port* getPort(const std::string &if_name, int idx);
133 /** Returns a specific port. */
134 unsigned getPortIdx(const std::string &port_name);
136 /** Returns a specific resource. */
137 unsigned getResIdx(const std::string &res_name);
139 /** Returns a pointer to a resource */
140 Resource* getResource(int res_idx) { return resources[res_idx]; }
142 /** Request usage of this resource. Returns -1 if not granted and
143 * a positive request tag if granted.
145 ResReqPtr request(int res_idx, DynInstPtr inst);
147 /** Squash The Resource */
148 void squash(DynInstPtr inst, int res_idx, InstSeqNum done_seq_num, int tid);
150 /** Squash All Resources in Pool after Done Seq. Num */
151 void squashAll(DynInstPtr inst, int stage_num,
152 InstSeqNum done_seq_num, unsigned tid);
154 /** Activate Thread in all resources */
155 void activateAll(unsigned tid);
157 /** De-Activate Thread in all resources */
158 void deactivateAll(unsigned tid);
160 /** Broadcast graduation to all resources */
161 void instGraduated(InstSeqNum seq_num,unsigned tid);
163 /** The number of instructions available that a resource can
166 int slotsAvail(int res_idx);
168 /** The number of instructions using a resource */
169 int slotsInUse(int res_idx);
171 /** Schedule resource event, regardless of its current state. */
172 void scheduleEvent(InOrderCPU::CPUEventType e_type, DynInstPtr inst = NULL,
173 int delay = 0, int res_idx = 0, int tid = 0);
175 /** UnSchedule resource event, regardless of its current state. */
176 void unscheduleEvent(int res_idx, DynInstPtr inst);
178 /** Tasks to perform when simulation starts */
179 virtual void startup() { }
181 /** The CPU(s) that this resource interacts with */
184 DynInstPtr dummyInst[ThePipeline::MaxThreads];
187 std::vector<Resource *> resources;
189 std::vector<int> memObjects;
193 #endif //__CPU_INORDER_RESOURCE_HH__