2 * Copyright (c) 2003 The Regents of The University of Michigan
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.
29 #include "cpu/exec_context.hh"
30 #include "targetarch/vtophys.hh"
31 #include "sim/param.hh"
32 #include "sim/system.hh"
33 #include "base/trace.hh"
37 vector
<System
*> System::systemList
;
39 int System::numSystemsRunning
= 0;
41 System::System(const std::string _name
,
42 const uint64_t _init_param
,
43 MemoryController
*_memCtrl
,
44 PhysicalMemory
*_physmem
,
46 const std::vector
<string
> &binned_fns
)
49 init_param(_init_param
),
53 binned_fns(binned_fns
)
55 // increment the number of running systems
58 // add self to global system list
59 systemList
.push_back(this);
61 Kernel
= new Stats::MainBin("non TCPIP Kernel stats");
63 User
= new Stats::MainBin("User stats");
65 int end
= binned_fns
.size();
70 fnEvents
.resize(end
>>1);
72 for (int i
= 0; i
< end
; i
+=2) {
73 Bin
= new Stats::MainBin(binned_fns
[i
]);
74 fnBins
.insert(make_pair(binned_fns
[i
], Bin
));
76 fnEvents
[(i
>>1)] = new FnEvent(&pcEventQueue
, binned_fns
[i
], this);
78 if (binned_fns
[i
+1] == "null")
79 populateMap(binned_fns
[i
], "");
81 populateMap(binned_fns
[i
], binned_fns
[i
+1]);
85 .name(name() + ":fnCalls")
86 .desc("all fn calls being tracked")
97 int end
= fnEvents
.size();
98 for (int i
= 0; i
< end
; ++i
) {
107 System::registerExecContext(ExecContext
*xc
)
109 int myIndex
= execContexts
.size();
110 execContexts
.push_back(xc
);
116 System::replaceExecContext(int xcIndex
, ExecContext
*xc
)
118 if (xcIndex
>= execContexts
.size()) {
119 panic("replaceExecContext: bad xcIndex, %d >= %d\n",
120 xcIndex
, execContexts
.size());
123 execContexts
[xcIndex
] = xc
;
128 System::printSystems()
130 vector
<System
*>::iterator i
= systemList
.begin();
131 vector
<System
*>::iterator end
= systemList
.end();
132 for (; i
!= end
; ++i
) {
134 cerr
<< "System " << sys
->name() << ": " << hex
<< sys
<< endl
;
142 System::printSystems();
146 System::populateMap(std::string callee
, std::string caller
)
148 multimap
<const string
, string
>::const_iterator i
;
149 i
= callerMap
.insert(make_pair(callee
, caller
));
150 assert(i
!= callerMap
.end() && "should not fail populating callerMap");
154 System::findCaller(std::string callee
, std::string caller
) const
156 typedef multimap
<const std::string
, std::string
>::const_iterator iter
;
157 pair
<iter
, iter
> range
;
159 range
= callerMap
.equal_range(callee
);
160 for (iter i
= range
.first
; i
!= range
.second
; ++i
) {
161 if ((*i
).second
== caller
)
168 System::dumpState(ExecContext
*xc
) const
171 stack
<fnCall
*> copy(xc
->swCtx
->callStack
);
174 DPRINTF(TCPIP
, "xc->swCtx, size: %d:\n", copy
.size());
176 DPRINTF(TCPIP
, "|| call : %d\n",xc
->swCtx
->calls
);
177 for (top
= copy
.top(); !copy
.empty(); copy
.pop() ) {
179 DPRINTF(TCPIP
, "|| %13s : %s \n", top
->name
, top
->myBin
->name());
185 System::getBin(const std::string
&name
)
187 std::map
<const std::string
, Stats::MainBin
*>::const_iterator i
;
188 i
= fnBins
.find(name
);
189 if (i
== fnBins
.end())
190 panic("trying to getBin %s that is not on system map!", name
);
195 System::findContext(Addr pcb
)
197 std::map
<Addr
, SWContext
*>::const_iterator iter
;
198 iter
= swCtxMap
.find(pcb
);
199 if (iter
!= swCtxMap
.end()) {
200 SWContext
*ctx
= (*iter
).second
;
201 assert(ctx
!= NULL
&& "should never have a null ctx in ctxMap");
208 System::serialize(std::ostream
&os
)
211 map
<const Addr
, SWContext
*>::const_iterator iter
, end
;
212 iter
= swCtxMap
.begin();
213 end
= swCtxMap
.end();
215 int numCtxs
= swCtxMap
.size();
216 SERIALIZE_SCALAR(numCtxs
);
218 for (int i
= 0; iter
!= end
; ++i
, ++iter
) {
219 paramOut(os
, csprintf("Addr[%d]",i
), (*iter
).first
);
220 ctx
= (*iter
).second
;
221 paramOut(os
, csprintf("calls[%d]",i
), ctx
->calls
);
223 stack
<fnCall
*> *stack
= &(ctx
->callStack
);
225 int size
= stack
->size();
226 paramOut(os
, csprintf("stacksize[%d]",i
), size
);
227 for (int j
=0; j
<size
; ++j
) {
229 paramOut(os
, csprintf("ctx[%d].stackpos[%d]",i
,j
),
239 System::unserialize(Checkpoint
*cp
, const std::string
§ion
)
243 UNSERIALIZE_SCALAR(numCtxs
);
248 for(int i
= 0; i
< numCtxs
; ++i
) {
250 paramIn(cp
, section
, csprintf("Addr[%d]",i
), addr
);
251 paramIn(cp
, section
, csprintf("calls[%d]",i
), ctx
->calls
);
253 paramIn(cp
, section
, csprintf("stacksize[%d]",i
), size
);
255 vector
<fnCall
*> calls
;
257 for (int j
= 0; j
< size
; ++j
) {
259 paramIn(cp
, section
, csprintf("ctx[%d].stackpos[%d]",i
,j
),
261 call
->myBin
= getBin(call
->name
);
262 calls
.push_back(call
);
265 for (int j
=size
-1; j
>=0; --j
) {
266 ctx
->callStack
.push(calls
[j
]);
269 addContext(addr
, ctx
);
274 DEFINE_SIM_OBJECT_CLASS_NAME("System", System
)