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.
31 #include "sim/param.hh"
32 #include "sim/eventq.hh"
33 #include "base/hostinfo.hh"
34 #include "sim/sim_events.hh"
35 #include "sim/sim_exit.hh"
36 #include "sim/sim_stats.hh"
41 // handle termination event
44 SimExitEvent::process()
46 // This event does not autodelete because exitNow may be called,
47 // and the function will never be allowed to finish.
48 if (theQueue() == &mainEventQueue
) {
49 string _cause
= cause
;
52 exitNow(_cause
, _code
);
54 new SimExitEvent(cause
, code
);
61 SimExitEvent::description()
63 return "simulation termination";
68 // constructor: automatically schedules at specified time
70 CountedExitEvent::CountedExitEvent(EventQueue
*q
, const std::string
&_cause
,
71 Tick _when
, int &_downCounter
)
74 downCounter(_downCounter
)
76 // catch stupid mistakes
77 assert(downCounter
> 0);
79 schedule(_when
, 1000);
84 // handle termination event
87 CountedExitEvent::process()
89 if (--downCounter
== 0) {
90 new SimExitEvent(cause
, 1);
96 CountedExitEvent::description()
98 return "counted exit";
103 DumpStatsEvent::process()
109 DumpStatsEvent::description()
115 #ifdef CHECK_SWAP_CYCLES
116 new CheckSwapEvent(&mainEventQueue
, CHECK_SWAP_CYCLES
);
120 CheckSwapEvent::process()
122 /* Check the amount of free swap space */
125 /* returns free swap in KBytes */
126 swap
= procInfo("/proc/meminfo", "SwapFree:");
129 ccprintf(cerr
, "\a\a\aWarning! Swap space is low (%d)\n", swap
);
132 cerr
<< "\a\aAborting Simulation! Inadequate swap space!\n\n";
133 new SimExitEvent("Lack of swap space");
136 schedule(curTick
+ interval
);
140 CheckSwapEvent::description()
146 class DumpStatsContext
: public ParamContext
149 DumpStatsContext(const string
&_iniSection
)
150 : ParamContext(_iniSection
) {}
154 DumpStatsContext
dumpStatsParams("stats");
156 VectorParam
<Tick
> dump_cycle(&dumpStatsParams
, "dump_cycles",
157 "cycles on which to dump stats");
160 DumpStatsContext::checkParams()
162 if (dump_cycle
.isValid()) {
163 vector
<Tick
> &cycles
= dump_cycle
;
165 vector
<Tick
>::iterator i
= cycles
.begin();
166 vector
<Tick
>::iterator end
= cycles
.end();
169 new DumpStatsEvent(*i
);
173 ///////////////////////////////////////////////////
175 // Simulation termination parameters
177 ///////////////////////////////////////////////////
179 class TermParamContext
: public ParamContext
182 TermParamContext(const string
&_iniSection
)
183 : ParamContext(_iniSection
) {}
187 TermParamContext
simTerminationParams("max");
189 Param
<Tick
> max_cycle(&simTerminationParams
, "cycle",
190 "maximum number of cycles to execute");
193 TermParamContext::checkParams()
195 // if a max cycle count was specified, put a termination event on
196 // the event queue at that point
197 if (max_cycle
.isValid())
198 new SimExitEvent(max_cycle
, "reached maximum cycle count");
202 // Progress event: print out cycle every so often so we know we're
203 // making forward progress.
205 class ProgressEvent
: public Event
211 ProgressEvent(EventQueue
*q
, Tick interval
);
213 void process(); // process event
214 virtual const char *description();
218 // constructor: schedule at specified time
220 ProgressEvent::ProgressEvent(EventQueue
*q
, Tick _interval
)
221 : Event(q
), interval(_interval
)
227 // handle progress event: print message and reschedule
230 ProgressEvent::process()
232 DPRINTFN("ProgressEvent\n");
233 // reschedule for next interval
234 schedule(curTick
+ interval
);
239 ProgressEvent::description()
241 return "progress message";
246 // Periodic progress message support: print out a message every n
247 // cycles so we know we're making forward progress.
251 // Parameter space for execution address tracing options. Derive
252 // from ParamContext so we can override checkParams() function.
253 class ProgressParamContext
: public ParamContext
256 ProgressParamContext(const string
&_iniSection
)
257 : ParamContext(_iniSection
) {}
261 ProgressParamContext
progessMessageParams("progress");
263 Param
<Tick
> progress_interval(&progessMessageParams
, "cycle",
264 "cycle interval for progress messages");
266 /* check execute options */
268 ProgressParamContext::checkParams()
270 if (progress_interval
.isValid())
271 new ProgressEvent(&mainEventQueue
, progress_interval
);