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.
33 #include "sim_events.hh"
34 #include "sim_exit.hh"
35 #include "sim_stats.hh"
40 // handle termination event
43 SimExitEvent::process()
45 // This event does not autodelete because exitNow may be called,
46 // and the function will never be allowed to finish.
47 if (theQueue() == &mainEventQueue
) {
48 string _cause
= cause
;
51 exitNow(_cause
, _code
);
53 new SimExitEvent(cause
, code
);
60 SimExitEvent::description()
62 return "simulation termination";
67 // constructor: automatically schedules at specified time
69 CountedExitEvent::CountedExitEvent(EventQueue
*q
, const std::string
&_cause
,
70 Tick _when
, int &_downCounter
)
73 downCounter(_downCounter
)
75 // catch stupid mistakes
76 assert(downCounter
> 0);
78 schedule(_when
, 1000);
83 // handle termination event
86 CountedExitEvent::process()
88 if (--downCounter
== 0) {
89 new SimExitEvent(cause
, 1);
95 CountedExitEvent::description()
97 return "counted exit";
102 DumpStatsEvent::process()
108 DumpStatsEvent::description()
114 #ifdef CHECK_SWAP_CYCLES
115 new CheckSwapEvent(&mainEventQueue
, CHECK_SWAP_CYCLES
);
119 CheckSwapEvent::process()
121 /* Check the amount of free swap space */
124 /* returns free swap in KBytes */
125 swap
= proc_info("/proc/meminfo", "SwapFree:");
128 ccprintf(cerr
, "\a\a\aWarning! Swap space is low (%d)\n", swap
);
131 cerr
<< "\a\aAborting Simulation! Inadequate swap space!\n\n";
132 new SimExitEvent("Lack of swap space");
135 schedule(curTick
+ interval
);
139 CheckSwapEvent::description()
145 class DumpStatsContext
: public ParamContext
148 DumpStatsContext(const string
&_iniSection
)
149 : ParamContext(_iniSection
) {}
153 DumpStatsContext
dumpStatsParams("stats");
155 VectorParam
<Tick
> dump_cycle(&dumpStatsParams
, "dump_cycles",
156 "cycles on which to dump stats");
159 DumpStatsContext::checkParams()
161 if (dump_cycle
.isValid()) {
162 vector
<Tick
> &cycles
= dump_cycle
;
164 vector
<Tick
>::iterator i
= cycles
.begin();
165 vector
<Tick
>::iterator end
= cycles
.end();
168 new DumpStatsEvent(*i
);
172 ///////////////////////////////////////////////////
174 // Simulation termination parameters
176 ///////////////////////////////////////////////////
178 class TermParamContext
: public ParamContext
181 TermParamContext(const string
&_iniSection
)
182 : ParamContext(_iniSection
) {}
186 TermParamContext
simTerminationParams("max");
188 Param
<Tick
> max_cycle(&simTerminationParams
, "cycle",
189 "maximum number of cycles to execute");
192 TermParamContext::checkParams()
194 // if a max cycle count was specified, put a termination event on
195 // the event queue at that point
196 if (max_cycle
.isValid())
197 new SimExitEvent(max_cycle
, "reached maximum cycle count");
201 // Progress event: print out cycle every so often so we know we're
202 // making forward progress.
204 class ProgressEvent
: public Event
210 ProgressEvent(EventQueue
*q
, Tick interval
);
212 void process(); // process event
213 virtual const char *description();
217 // constructor: schedule at specified time
219 ProgressEvent::ProgressEvent(EventQueue
*q
, Tick _interval
)
220 : Event(q
), interval(_interval
)
226 // handle progress event: print message and reschedule
229 ProgressEvent::process()
231 DPRINTFN("ProgressEvent\n");
232 // reschedule for next interval
233 schedule(curTick
+ interval
);
238 ProgressEvent::description()
240 return "progress message";
245 // Periodic progress message support: print out a message every n
246 // cycles so we know we're making forward progress.
250 // Parameter space for execution address tracing options. Derive
251 // from ParamContext so we can override checkParams() function.
252 class ProgressParamContext
: public ParamContext
255 ProgressParamContext(const string
&_iniSection
)
256 : ParamContext(_iniSection
) {}
260 ProgressParamContext
progessMessageParams("progress");
262 Param
<Tick
> progress_interval(&progessMessageParams
, "cycle",
263 "cycle interval for progress messages");
265 /* check execute options */
267 ProgressParamContext::checkParams()
269 if (progress_interval
.isValid())
270 new ProgressEvent(&mainEventQueue
, progress_interval
);