fix some broken .ini's
[gem5.git] / sim / sim_object.cc
1 /*
2 * Copyright (c) 2001-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29 #include <assert.h>
30
31 #include "base/callback.hh"
32 #include "base/inifile.hh"
33 #include "base/misc.hh"
34 #include "base/trace.hh"
35 #include "base/stats/events.hh"
36 #include "sim/configfile.hh"
37 #include "sim/host.hh"
38 #include "sim/sim_object.hh"
39 #include "sim/stats.hh"
40 #include "sim/param.hh"
41
42 using namespace std;
43
44
45 ////////////////////////////////////////////////////////////////////////
46 //
47 // SimObject member definitions
48 //
49 ////////////////////////////////////////////////////////////////////////
50
51 //
52 // static list of all SimObjects, used for initialization etc.
53 //
54 SimObject::SimObjectList SimObject::simObjectList;
55
56 //
57 // SimObject constructor: used to maintain static simObjectList
58 //
59 SimObject::SimObject(const string &_name)
60 : objName(_name)
61 {
62 doRecordEvent = !Stats::ignoreEvent(_name);
63 simObjectList.push_back(this);
64 }
65
66 void
67 SimObject::init()
68 {
69 }
70
71 //
72 // no default statistics, so nothing to do in base implementation
73 //
74 void
75 SimObject::regStats()
76 {
77 }
78
79 void
80 SimObject::regFormulas()
81 {
82 }
83
84 void
85 SimObject::resetStats()
86 {
87 }
88
89 //
90 // static function:
91 // call regStats() on all SimObjects and then regFormulas() on all
92 // SimObjects.
93 //
94 struct SimObjectResetCB : public Callback
95 {
96 virtual void process() { SimObject::resetAllStats(); }
97 };
98
99 namespace {
100 static SimObjectResetCB StatResetCB;
101 }
102
103 void
104 SimObject::regAllStats()
105 {
106 SimObjectList::iterator i;
107 SimObjectList::iterator end = simObjectList.end();
108
109 /**
110 * @todo change cprintfs to DPRINTFs
111 */
112 for (i = simObjectList.begin(); i != end; ++i) {
113 #ifdef STAT_DEBUG
114 cprintf("registering stats for %s\n", (*i)->name());
115 #endif
116 (*i)->regStats();
117 }
118
119 for (i = simObjectList.begin(); i != end; ++i) {
120 #ifdef STAT_DEBUG
121 cprintf("registering formulas for %s\n", (*i)->name());
122 #endif
123 (*i)->regFormulas();
124 }
125
126 Stats::registerResetCallback(&StatResetCB);
127 }
128
129 //
130 // static function: call init() on all SimObjects.
131 //
132 void
133 SimObject::initAll()
134 {
135 SimObjectList::iterator i = simObjectList.begin();
136 SimObjectList::iterator end = simObjectList.end();
137
138 for (; i != end; ++i) {
139 SimObject *obj = *i;
140 obj->init();
141 }
142 }
143
144 //
145 // static function: call resetStats() on all SimObjects.
146 //
147 void
148 SimObject::resetAllStats()
149 {
150 SimObjectList::iterator i = simObjectList.begin();
151 SimObjectList::iterator end = simObjectList.end();
152
153 for (; i != end; ++i) {
154 SimObject *obj = *i;
155 obj->resetStats();
156 }
157 }
158
159 //
160 // static function: serialize all SimObjects.
161 //
162 void
163 SimObject::serializeAll(ostream &os)
164 {
165 SimObjectList::reverse_iterator ri = simObjectList.rbegin();
166 SimObjectList::reverse_iterator rend = simObjectList.rend();
167
168 for (; ri != rend; ++ri) {
169 SimObject *obj = *ri;
170 obj->nameOut(os);
171 obj->serialize(os);
172 }
173 }
174
175 void
176 SimObject::recordEvent(const std::string &stat)
177 {
178 if (doRecordEvent)
179 Stats::recordEvent(stat);
180 }
181
182 DEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject)